From 2be22adcb324bf5162870e6fee97b82ee9769315 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 23 Dec 2024 18:12:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(printer):=20=E4=BF=AE=E5=A4=8D=E5=B0=8F?= =?UTF-8?q?=E7=A5=A8=E6=89=93=E5=8D=B0=E5=95=86=E5=93=81=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 PayNotifyLogic 中添加 XpsdkPrintApi 类的引用 - 在 OrderXprinterPushSend 中修正商品名称的获取方式 - 优化代码格式和结构,提高可读性 --- app/common/logic/PayNotifyLogic.php | 2 + app/queue/redis/OrderXprinterPushSend.php | 70 +++++++++++------------ 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 52f6c5e8..9539d11c 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -32,6 +32,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; @@ -54,6 +55,7 @@ class PayNotifyLogic extends BaseLogic return true; } catch (\Exception $e) { Db::rollback(); + d($e); Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); throw new BusinessException($e->getMessage()); } diff --git a/app/queue/redis/OrderXprinterPushSend.php b/app/queue/redis/OrderXprinterPushSend.php index 01cb86f6..ec6682c1 100644 --- a/app/queue/redis/OrderXprinterPushSend.php +++ b/app/queue/redis/OrderXprinterPushSend.php @@ -25,43 +25,43 @@ class OrderXprinterPushSend implements Consumer public function consume($data) { - $order=$data['order']; - $total_price = $order['total_price']; - $pay_price = $order['pay_price']; - $deduction_price = $order['deduction_price']; - $pay_time = date('Y-m-d H:i:s', $order['pay_time']); - $pay_type = PayEnum::getPaySceneDesc($order['pay_type']); - $SystemStore = SystemStore::where('id', $order['store_id'])->find(); - $cart_info=StoreOrderCartInfo::where('oid',$order['id'])->select()->each(function($item){ - $find = StoreProduct::with('unitName')->withTrashed()->find(); - $item['store_name']=$find['store_name']; - return $item; - }); + $order = $data['order']; + $total_price = $order['total_price']; + $pay_price = $order['pay_price']; + $deduction_price = $order['deduction_price']; + $pay_time = date('Y-m-d H:i:s', $order['pay_time']); + $pay_type = PayEnum::getPaySceneDesc($order['pay_type']); + $SystemStore = SystemStore::where('id', $order['store_id'])->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['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 + $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->printFontAlign('74AMP5N6DP21148',$order)); + } + + $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 + ]; + $res = ($api->printFontAlign('74AMP5N6DP21148', $order)); } // 消费失败时 public function onConsumeFailure(\Throwable $exception, $package)