1、数据库执行以下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、语言包添加内容
\languages\zh_cn\admin\shop_config.php
$_LANG['cfg_name']['gprsprint'] = 'GPRS打印机设置';
$_LANG['cfg_name']['gprsprint_no'] = '打印机编号';
$_LANG['cfg_name']['gprsprint_key'] = '打印机秘钥';
$_LANG['cfg_name']['gprsprint_mobile'] = '手机号';
$_LANG['cfg_name']['gprsprint_host'] = '服务IP';
$_LANG['cfg_name']['gprsprint_port'] = '服务端口';
$_LANG['cfg_name']['gprsprint_open'] = '开启打印';
$_LANG['cfg_range']['gprsprint_open']['1'] = '开启';
$_LANG['cfg_range']['gprsprint_open']['0'] = '关闭';
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("未确认","已确认","已取消","无效","退货"); //订单状态
$pay_status = array("未付款","付款中","已付款"); //支付状态
//商品订单信息
$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>';//标题字体如需居中放大,就需要用标签套上
$orderInfo .= '订单号:'.$order['order_sn'].'<BR>';
//$orderInfo .= '订单状态:'.$order_status[$order['order_status']].'<BR>';
$orderInfo .= '支付状态:'.$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>商品明细</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中找到支付成功流程后,调用wp_print 方法来实现打印
如果是余额支付的情况
再代码
/* 处理余额、积分、红包 */
if ($order['user_id'] > 0 && $order['surplus'] > 0)
前面添加如下代码段
大概1650行
/* 如果订单金额为0(使用余额或积分或红包支付),修改订单状态为已确认、已付款 */
if ($order['order_amount'] <= 0){
if ($_CFG['gprsprint_open'] == '1') $rsprint = wp_print($new_order_id);
if ($rsprint){
//更新订单的打印状态
$sql = "UPDATE ". $ecs->table('order_info') ." SET gprsprint='1' WHERE order_id=".$new_order_id;
$db->query($sql);
}
}
6、后台管理员设置打印成功后,打印通知
adminstone\order.php 找到以下代码段
/* 标记订单为已确认、已付款,更新付款时间和已支付金额,如果是货到付款,同时修改订单为“收货确认” */
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){
//更新订单的打印状态
$sql = "UPDATE ". $ecs->table('order_info') ." SET gprsprint='1' WHERE order_id=".$order_id;
$db->query($sql);
}
7、用户在线支付后打印机通知
includes\lib_payment.php
找到如下代码段
/* 修改订单状态为已付款 */
$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);
后面添加
/* 客户付款时给商家发送打印信息 */
if ($GLOBALS['_CFG']['gprsprint_open'] == '1') $rsprint = wp_print($pay_log['order_id']);
if ($rsprint){
//更新订单的打印状态
$sql = "UPDATE ". $GLOBALS['ecs']->table('order_info') ." SET gprsprint='1' WHERE order_id=".$order_id;
$GLOBALS['db']->query($sql);
}
- PC官方版
- 安卓官方手机版
- IOS官方手机版