1、數(shù)據(jù)庫執(zhí)行以下SQL
INSERT INTO `ysh_shop_config` VALUES ('11', '0', 'gprsprint', 'group', '', '', '', '1');
INSERT INTO `ysh_shop_config` VALUES ('1101', '11', 'gprsprint_no', 'text', '', '', '', '1');
INSERT INTO `ysh_shop_config` VALUES ('1102', '11', 'gprsprint_key', 'text', '', '', '', '1');
INSERT INTO `ysh_shop_config` VALUES ('1103', '11', 'gprsprint_mobile', 'text', '', '', '', '1');
INSERT INTO `ysh_shop_config` VALUES ('1104', '11', 'gprsprint_host', 'text', '', '', '', '1');
INSERT INTO `ysh_shop_config` VALUES ('1105', '11', 'gprsprint_port', 'text', '', '', '', '1');
INSERT INTO `ysh_shop_config` VALUES ('1106', '11', 'gprsprint_open', 'select', '1,0', '', '0', '1');
ALTER TABLE `ysh_order_info` ADD `gprsprint` TINYINT( 1 ) NOT NULL DEFAULT '0';
2、語言包添加內(nèi)容
\languages\zh_cn\admin\shop_config.php
$_LANG['cfg_name']['gprsprint'] = 'GPRS打印機設(shè)置';
$_LANG['cfg_name']['gprsprint_no'] = '打印機編號';
$_LANG['cfg_name']['gprsprint_key'] = '打印機秘鑰';
$_LANG['cfg_name']['gprsprint_mobile'] = '手機號';
$_LANG['cfg_name']['gprsprint_host'] = '服務(wù)IP';
$_LANG['cfg_name']['gprsprint_port'] = '服務(wù)端口';
$_LANG['cfg_name']['gprsprint_open'] = '開啟打印';
$_LANG['cfg_range']['gprsprint_open']['1'] = '開啟';
$_LANG['cfg_range']['gprsprint_open']['0'] = '關(guān)閉';
3、把cls_http.php拷貝到 includes目錄下
4、Includes/lib_base.php 中增加打印方法
function wp_print($oid,$times=1){
include_once(ROOT_PATH . 'includes/lib_order.php');
$order_status = array("未確認(rèn)","已確認(rèn)","已取消","無效","退貨"); //訂單狀態(tài)
$pay_status = array("未付款","付款中","已付款"); //支付狀態(tài)
//商品訂單信息
$order = order_info($oid);
//訂單中包含的商品
$ordergoods = order_goods($oid);
$sql = "SELECT concat(IFNULL(c.region_name, ''), ' ', IFNULL(p.region_name, ''), " .
"' ', IFNULL(t.region_name, ''), ' ', IFNULL(d.region_name, '')) AS region " .
"FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " .
"LEFT JOIN " . $GLOBALS['ecs']->table('region') . " AS c ON o.country = c.region_id " .
"LEFT JOIN " . $GLOBALS['ecs']->table('region') . " AS p ON o.province = p.region_id " .
"LEFT JOIN " . $GLOBALS['ecs']->table('region') . " AS t ON o.city = t.region_id " .
"LEFT JOIN " . $GLOBALS['ecs']->table('region') . " AS d ON o.district = d.region_id " .
"WHERE o.order_id = '$order[order_id]'";
$order['region'] = $GLOBALS['db']->getOne($sql);
$device_no = $GLOBALS['_CFG']['gprsprint_no'];
$key = $GLOBALS['_CFG']['gprsprint_key'];
$orderInfo = '<CB>訂單信息</CB><BR>';//標(biāo)題字體如需居中放大,就需要用標(biāo)簽套上
$orderInfo .= '訂單號:'.$order['order_sn'].'<BR>';
//$orderInfo .= '訂單狀態(tài):'.$order_status[$order['order_status']].'<BR>';
$orderInfo .= '支付狀態(tài):'.$pay_status[$order['pay_status']].'<BR>';
$orderInfo .= '收貨人:'.$order['consignee'].'<BR>';
$orderInfo .= '收貨地址:'.$order['region'].$order['address'].'<BR>';
$orderInfo .= '郵編:'.$order['zipcode'].'<BR>';
if ($order['tel'])$orderInfo .= '電話:'.$order['tel'].'<BR>';
if ($order['mobile'])$orderInfo .= '手機:'.$order['mobile'].'<BR>';
$orderInfo .= '配送方式:'.$order['shipping_name'].'<BR>';
$orderInfo .='------------------------------------<BR>';
if ($order['money_paid'])$orderInfo .= '已付款金額:'.$order['money_paid'].'<BR>';
$orderInfo .= '支付方式:'.$order['pay_name'].'<BR>';
$orderInfo .='------------------------------------<BR>';
$orderInfo .= '<CB>商品明細(xì)</CB><BR>';
$orderInfo .='------------------------------------<BR>';
foreach ($ordergoods as $v){
$orderInfo .= $v['goods_name'].'('.$v['goods_sn'].')'.'×'.$v['goods_number'].'(件)×'.$v['goods_price'].'='.$v['subtotal'].'<BR>';
}
$orderInfo .='------------------------------------<BR>';
$orderInfo .= '商品總價:'.$order['goods_amount'].'<BR>';
$orderInfo .= '支付費用:'.$order['pay_fee'].'<BR>';
$orderInfo .= '使用余額:'.$order['surplus'].'<BR>';
if ($order['discount'])$orderInfo .= '折扣金額:'.$order['discount'].'<BR>';
if ($order['pay_time'])$orderInfo .= '支付時間:'.$order['pay_time'].'<BR>';
if ($order['to_buyer'])$orderInfo .= '客戶留言:'.$order['to_buyer'].'<BR>';
$orderInfo .='------------------------------------<BR>';
$orderInfo .= '打印時間:'.date('Y-m-d H:i:s',time()).'<BR>';
$selfMessage = array(
'clientCode'=>$device_no,
'printInfo'=>$orderInfo,
'apitype'=>'php',
'key'=>$key,
'printTimes'=>$times
);
//日志記錄
$logfile = ROOT_PATH . '/printlog/' . $oid .'_'.time(). '.txt';
file_put_contents($logfile, json_encode($selfMessage), LOCK_EX);
$rs = sendSelfFormatMessage($selfMessage);
$rs = json_decode($rs,TRUE);
if($rs['reslutCode']=='0'){
return TRUE;
}
//{"reslutCode":0,"msg":"success"}
exit();
}
function sendSelfFormatMessage($msgInfo){
include_once(ROOT_PATH . 'includes/cls_http.php');
$client = new HttpClient($GLOBALS['_CFG']['gprsprint_host'],$GLOBALS['_CFG']['gprsprint_port']);
$client->HttpClient($GLOBALS['_CFG']['gprsprint_host'],$GLOBALS['_CFG']['gprsprint_port']);
if(!$client->post('/FeieServer/printSelfFormatOrder',$msgInfo)){ //提交失敗
return 'faild';
}
else{
return $client->getContent();
}
}
5、再flow.php中找到支付成功流程后,調(diào)用wp_print 方法來實現(xiàn)打印
如果是余額支付的情況
再代碼
/* 處理余額、積分、紅包 */
if ($order['user_id'] > 0 && $order['surplus'] > 0)
前面添加如下代碼段
大概1650行
/* 如果訂單金額為0(使用余額或積分或紅包支付),修改訂單狀態(tài)為已確認(rèn)、已付款 */
if ($order['order_amount'] <= 0){
if ($_CFG['gprsprint_open'] == '1') $rsprint = wp_print($new_order_id);
if ($rsprint){
//更新訂單的打印狀態(tài)
$sql = "UPDATE ". $ecs->table('order_info') ." SET gprsprint='1' WHERE order_id=".$new_order_id;
$db->query($sql);
}
}
6、后臺管理員設(shè)置打印成功后,打印通知
adminstone\order.php 找到以下代碼段
/* 標(biāo)記訂單為已確認(rèn)、已付款,更新付款時間和已支付金額,如果是貨到付款,同時修改訂單為“收貨確認(rèn)” */
if ($order['order_status'] != OS_CONFIRMED)
{
$arr['order_status'] = OS_CONFIRMED;
$arr['confirm_time'] = gmtime();
}
$arr['pay_status'] = PS_PAYED;
$arr['pay_time'] = gmtime();
$arr['money_paid'] = $order['money_paid'] + $order['order_amount'];
$arr['order_amount']= 0;
$payment = payment_info($order['pay_id']);
if ($payment['is_cod'])
{
$arr['shipping_status'] = SS_RECEIVED;
$order['shipping_status'] = SS_RECEIVED;
}
update_order($order_id, $arr);
代碼后面添加
if ($_CFG['gprsprint_open'] == '1') $rsprint = wp_print($order_id);
if ($rsprint){
//更新訂單的打印狀態(tài)
$sql = "UPDATE ". $ecs->table('order_info') ." SET gprsprint='1' WHERE order_id=".$order_id;
$db->query($sql);
}
7、用戶在線支付后打印機通知
includes\lib_payment.php
找到如下代碼段
/* 修改訂單狀態(tài)為已付款 */
$sql = 'UPDATE ' . $GLOBALS['ecs']->table('order_info') .
" SET order_status = '" . OS_CONFIRMED . "', " .
" confirm_time = '" . gmtime() . "', " .
" pay_status = '$pay_status', " .
" pay_time = '".gmtime()."', " .
" money_paid = order_amount," .
" order_amount = 0 ".
"WHERE order_id = '$order_id'";
$GLOBALS['db']->query($sql);
后面添加
/* 客戶付款時給商家發(fā)送打印信息 */
if ($GLOBALS['_CFG']['gprsprint_open'] == '1') $rsprint = wp_print($pay_log['order_id']);
if ($rsprint){
//更新訂單的打印狀態(tài)
$sql = "UPDATE ". $GLOBALS['ecs']->table('order_info') ." SET gprsprint='1' WHERE order_id=".$order_id;
$GLOBALS['db']->query($sql);
}
- PC官方版
- 安卓官方手機版
- IOS官方手機版