commit
8a64c1cefa
@ -11,6 +11,7 @@ use app\common\enum\user\UserShipEnum;
|
|||||||
use app\common\enum\YesNoEnum;
|
use app\common\enum\YesNoEnum;
|
||||||
use app\common\logic\user_product_storage\UserProductStorageLogic;
|
use app\common\logic\user_product_storage\UserProductStorageLogic;
|
||||||
use app\common\model\Config;
|
use app\common\model\Config;
|
||||||
|
use app\common\model\dict\DictData;
|
||||||
use app\common\model\dict\DictType;
|
use app\common\model\dict\DictType;
|
||||||
use app\common\model\finance\CapitalFlow;
|
use app\common\model\finance\CapitalFlow;
|
||||||
use app\common\model\finance\PayNotifyLog;
|
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\model\vip_flow\VipFlow;
|
||||||
use app\common\service\Curl;
|
use app\common\service\Curl;
|
||||||
use app\common\service\PushService;
|
use app\common\service\PushService;
|
||||||
|
use app\common\service\xpyun\XpsdkPrintApi;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -52,8 +54,9 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
self::$action($orderSn, $extra, $type);
|
self::$action($orderSn, $extra, $type);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
|
d($e);
|
||||||
Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile());
|
Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile());
|
||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
}
|
}
|
||||||
@ -647,6 +650,9 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
if ($order['uid'] != 1) {
|
if ($order['uid'] != 1) {
|
||||||
Redis::send('order_wetcha_push_send', ['order' => $order]);
|
Redis::send('order_wetcha_push_send', ['order' => $order]);
|
||||||
}
|
}
|
||||||
|
if($order['store_id']==21){
|
||||||
|
Redis::send('order_xprinter_push_send', ['order' => $order]);
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error('订单推送失败:' . $e->getMessage());
|
Log::error('订单推送失败:' . $e->getMessage());
|
||||||
// 异常处理代码,例如记录日志或发送通知等。
|
// 异常处理代码,例如记录日志或发送通知等。
|
||||||
|
@ -25,44 +25,49 @@ class XpsdkPrintApi
|
|||||||
* 注意:对齐标签L C R CB 请勿嵌套使用,嵌套使用内层标签有效,外层失效;
|
* 注意:对齐标签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 = <<<EOF
|
$printContent = <<<EOF
|
||||||
不加标签:默认字体大小<BR>
|
<C><BOLD><B>{$system_store}</B></BOLD><BR></C>
|
||||||
<BR>
|
<L><N>==============================
|
||||||
L标签:<L>左对齐<BR></L>
|
<L><N>核销码:<BOLD>{$verify_code}</BOLD>
|
||||||
<BR>
|
<L><N>单号:{$order_id}
|
||||||
R标签:<R>右对齐<BR></R>
|
<L><N>下单时间:{$create_time}
|
||||||
<BR>
|
<L><N>==============================
|
||||||
C标签:<C>居中对齐<BR></C>
|
<L>单价 数量 小计
|
||||||
<BR>
|
<L>
|
||||||
N标签:<N>字体正常大小<BR></N>
|
|
||||||
<BR>
|
|
||||||
HB标签:<HB>字体变高一倍<BR></HB>
|
|
||||||
<BR>
|
|
||||||
WB标签:<WB>字体变宽一倍<BR></WB>
|
|
||||||
<BR>
|
|
||||||
B标签:<B>字体放大一倍<BR></B>
|
|
||||||
<BR>
|
|
||||||
HB2标签:<HB2>字体变高二倍<BR></HB2>
|
|
||||||
<BR>
|
|
||||||
WB2标签:<WB2>字体变宽二倍<BR></WB2>
|
|
||||||
<BR>
|
|
||||||
B2标签:<B2>字体放大二倍<BR></B2>
|
|
||||||
<BR>
|
|
||||||
BOLD标签:<BOLD>字体加粗<BR></BOLD>
|
|
||||||
EOF;
|
EOF;
|
||||||
|
// 使用 for 循环生成商品列表
|
||||||
|
foreach ($order['product_arr'] as $k=>$v) {
|
||||||
|
$printContent .= <<<EOF
|
||||||
|
<L>{$v['name']}
|
||||||
|
<L>{$v['price']} *{$v['quantity']} {$v['subtotal']}
|
||||||
|
EOF;
|
||||||
|
}
|
||||||
|
|
||||||
$printContent = $printContent . '<BR>';
|
// 继续生成剩余的 printContent
|
||||||
// 嵌套使用对齐和字体
|
$printContent .= <<<EOF
|
||||||
$printContent = $printContent . '<C>嵌套使用:<BOLD>居中加粗</BOLD><BR></C>';
|
<L>
|
||||||
|
<L><N>==============================
|
||||||
// 打印条形码和二维码
|
<N>合计:{$total_price}元
|
||||||
$printContent = $printContent . '<BR>';
|
<L><N>优惠:{$deduction_price}元
|
||||||
$printContent = $printContent . '<C><BARCODE>9884822189</BARCODE></C>';
|
<L><N>实付款:{$pay_price}元
|
||||||
$printContent = $printContent . '<C><QR>https://www.xpyun.net</QR></C>';
|
<L><N>支付方式:{$pay_type_name}
|
||||||
|
<L><N>店铺电话:{$system_phone}
|
||||||
|
<L><N>==============================
|
||||||
|
|
||||||
|
<C><BOLD>欢迎下次光临!</BOLD><BR></C>
|
||||||
|
EOF;
|
||||||
$request = new PrintRequest();
|
$request = new PrintRequest();
|
||||||
$request->generateSign();
|
$request->generateSign();
|
||||||
|
|
||||||
@ -81,7 +86,7 @@ EOF;
|
|||||||
//打印模式:
|
//打印模式:
|
||||||
//值为 0 或不指定则会检查打印机是否在线,如果不在线 则不生成打印订单,直接返回设备不在线状态码;如果在线则生成打印订单,并返回打印订单号。
|
//值为 0 或不指定则会检查打印机是否在线,如果不在线 则不生成打印订单,直接返回设备不在线状态码;如果在线则生成打印订单,并返回打印订单号。
|
||||||
//值为 1不检查打印机是否在线,直接生成打印订单,并返回打印订单号。如果打印机不在线,订单将缓存在打印队列中,打印机正常在线时会自动打印。
|
//值为 1不检查打印机是否在线,直接生成打印订单,并返回打印订单号。如果打印机不在线,订单将缓存在打印队列中,打印机正常在线时会自动打印。
|
||||||
$request->mode = 1;
|
$request->mode = 0;
|
||||||
|
|
||||||
$result = $this->service->xpYunPrint($request);
|
$result = $this->service->xpYunPrint($request);
|
||||||
return $result->content;
|
return $result->content;
|
||||||
|
78
app/queue/redis/OrderXprinterPushSend.php
Normal file
78
app/queue/redis/OrderXprinterPushSend.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user