multi-store/app/queue/redis/OrderXprinterPushSend.php
mkm 1f82805875 fix(app): 修复支付回调和订单推送的相关问题
- 修改 PayNotifyLogic 中异常捕获,使用 Throwable 代替 Exception
- 优化 OrderXprinterPushSend 中的订单信息获取和处理
2024-12-24 09:27:39 +08:00

79 lines
2.6 KiB
PHP

<?php
namespace app\queue\redis;
use app\common\enum\PayEnum;
use app\common\model\dict\DictData;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\service\xpyun\XpsdkPrintApi;
use Webman\RedisQueue\Consumer;
use support\Log;
/**
* 芯华云订单推送队列消费
*/
class OrderXprinterPushSend implements Consumer
{
// 要消费的队列名
public $queue = 'order_xprinter_push_send';
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
public $connection = 'default';
// 消费
public function consume($data)
{
$order = $data['order'];
$total_price = $order['total_price'];
$pay_price = $order['pay_price'];
$store_id = $order['store_id'];
$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['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;
}
}