diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index b2b2a6d04..c91074eee 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -11,6 +11,7 @@ use app\common\enum\user\UserShipEnum; use app\common\enum\YesNoEnum; use app\common\logic\user_product_storage\UserProductStorageLogic; use app\common\model\Config; +use app\common\model\dict\DictData; use app\common\model\dict\DictType; use app\common\model\finance\CapitalFlow; use app\common\model\finance\PayNotifyLog; @@ -32,6 +33,7 @@ use app\common\model\user_sign\UserSign; use app\common\model\vip_flow\VipFlow; use app\common\service\Curl; use app\common\service\PushService; +use app\common\service\xpyun\XpsdkPrintApi; use support\exception\BusinessException; use support\Log; use think\facade\Db; @@ -52,8 +54,9 @@ class PayNotifyLogic extends BaseLogic self::$action($orderSn, $extra, $type); Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); + d($e); Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); throw new BusinessException($e->getMessage()); } @@ -647,6 +650,9 @@ class PayNotifyLogic extends BaseLogic if ($order['uid'] != 1) { Redis::send('order_wetcha_push_send', ['order' => $order]); } + if($order['store_id']==21){ + Redis::send('order_xprinter_push_send', ['order' => $order]); + } } catch (\Exception $e) { Log::error('订单推送失败:' . $e->getMessage()); // 异常处理代码,例如记录日志或发送通知等。 diff --git a/app/common/service/xpyun/XpsdkPrintApi.php b/app/common/service/xpyun/XpsdkPrintApi.php index e363fec4a..db9fd7195 100644 --- a/app/common/service/xpyun/XpsdkPrintApi.php +++ b/app/common/service/xpyun/XpsdkPrintApi.php @@ -25,44 +25,49 @@ class XpsdkPrintApi * 注意:对齐标签L C R CB 请勿嵌套使用,嵌套使用内层标签有效,外层失效; * 同一行请勿使用多个对齐标签,否则只有最后一个对齐标签有效 */ - public function printFontAlign($sn) + public function printFontAlign($sn,$order) { + $system_store=$order['system_store']; + $system_phone=$order['system_phone']; + $verify_code=$order['verify_code']; + $order_id=$order['order_id']; + $create_time=$order['create_time']; + $pay_price=$order['pay_price']; + $total_price=$order['total_price']; + $deduction_price=$order['deduction_price']; + $pay_type_name=$order['pay_type_name']; + $printContent = << -
-L标签:左对齐
-
-R标签:右对齐
-
-C标签:居中对齐
-
-N标签:字体正常大小
-
-HB标签:字体变高一倍
-
-WB标签:字体变宽一倍
-
-B标签:字体放大一倍
-
-HB2标签:字体变高二倍
-
-WB2标签:字体变宽二倍
-
-B2标签:字体放大二倍
-
-BOLD标签:字体加粗
+{$system_store}
+============================== +核销码:{$verify_code} +单号:{$order_id} +下单时间:{$create_time} +============================== +单价 数量 小计 + EOF; +// 使用 for 循环生成商品列表 +foreach ($order['product_arr'] as $k=>$v) { + $printContent .= <<{$v['name']} +{$v['price']} *{$v['quantity']} {$v['subtotal']} +EOF; +} - $printContent = $printContent . '
'; - // 嵌套使用对齐和字体 - $printContent = $printContent . '嵌套使用:居中加粗
'; - - // 打印条形码和二维码 - $printContent = $printContent . '
'; - $printContent = $printContent . '9884822189'; - $printContent = $printContent . 'https://www.xpyun.net'; - +// 继续生成剩余的 printContent +$printContent .= << +============================== +合计:{$total_price}元 +优惠:{$deduction_price}元 +实付款:{$pay_price}元 +支付方式:{$pay_type_name} +店铺电话:{$system_phone} +============================== + 欢迎下次光临!
+EOF; $request = new PrintRequest(); $request->generateSign(); @@ -81,7 +86,7 @@ EOF; //打印模式: //值为 0 或不指定则会检查打印机是否在线,如果不在线 则不生成打印订单,直接返回设备不在线状态码;如果在线则生成打印订单,并返回打印订单号。 //值为 1不检查打印机是否在线,直接生成打印订单,并返回打印订单号。如果打印机不在线,订单将缓存在打印队列中,打印机正常在线时会自动打印。 - $request->mode = 1; + $request->mode = 0; $result = $this->service->xpYunPrint($request); return $result->content; diff --git a/app/queue/redis/OrderXprinterPushSend.php b/app/queue/redis/OrderXprinterPushSend.php new file mode 100644 index 000000000..205f09074 --- /dev/null +++ b/app/queue/redis/OrderXprinterPushSend.php @@ -0,0 +1,78 @@ +find(); + $cart_info = StoreOrderCartInfo::where('oid', $order['id'])->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); + $item['store_name'] = $find['store_name']; + return $item; + }); + + $product_arr = []; + foreach ($cart_info as $k => $v) { + $product_arr[] = [ + 'name' => $v['store_name'], + 'price' => $v['price'] . '元', + 'quantity' => $v['cart_num'], + 'subtotal' => $v['total_price'] . '元' + ]; + } + + $api = new XpsdkPrintApi(); + $order = [ + 'system_store' => $SystemStore['name'] ?? '', + 'system_phone' => $SystemStore['phone'] ?? '', + 'verify_code' => $order['verify_code'], + 'order_id' => $order['order_id'], + 'create_time' => $pay_time, + 'pay_price' => $pay_price, + 'total_price' => $total_price, + 'deduction_price' => $deduction_price, + 'pay_type_name' => $pay_type, + 'product_arr' => $product_arr + ]; + $value=DictData::where('name','xprinter_'.$store_id)->value('value'); + if($value){ + $res = ($api->printFontAlign($value, $order)); + } + } + // 消费失败时 + public function onConsumeFailure(\Throwable $exception, $package) + { + $package['max_attempts'] = 0; + Log::error('推送订单失败', ['order_id' => $package['data'], 'error' => $package['error']]); + return true; + } +}