Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
3b4157c242
@ -15,6 +15,8 @@ use hg\apidoc\annotation as ApiDoc;
|
|||||||
use support\Log;
|
use support\Log;
|
||||||
use Yansongda\Pay\Exception\InvalidSignException;
|
use Yansongda\Pay\Exception\InvalidSignException;
|
||||||
use Monolog\Handler\RotatingFileHandler;
|
use Monolog\Handler\RotatingFileHandler;
|
||||||
|
use Webman\RedisQueue\Redis;
|
||||||
|
|
||||||
#[ApiDoc\NotParse()]
|
#[ApiDoc\NotParse()]
|
||||||
|
|
||||||
class IndexController extends BaseApiController
|
class IndexController extends BaseApiController
|
||||||
@ -23,8 +25,8 @@ class IndexController extends BaseApiController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
Log::error(222);
|
Redis::send('push-platform-print', ['order_id' => 119]);
|
||||||
d(2);
|
d(2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$wechat = new PayService(1);
|
$wechat = new PayService(1);
|
||||||
|
@ -316,7 +316,7 @@ class OrderController extends BaseApiController
|
|||||||
StoreOrder::where(['id' => $order_id, 'uid' => Request()->userId])->update($_order);
|
StoreOrder::where(['id' => $order_id, 'uid' => Request()->userId])->update($_order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'], $redirectUrl);
|
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal']??1, $redirectUrl);
|
||||||
if (PaymentLogic::hasError()) {
|
if (PaymentLogic::hasError()) {
|
||||||
return $this->fail(PaymentLogic::getError());
|
return $this->fail(PaymentLogic::getError());
|
||||||
}
|
}
|
||||||
@ -405,7 +405,7 @@ class OrderController extends BaseApiController
|
|||||||
];
|
];
|
||||||
$order = StoreOrder::where($where)->find();
|
$order = StoreOrder::where($where)->find();
|
||||||
if ($order) {
|
if ($order) {
|
||||||
$data = ['data' => $value, 'delete_time' => time()];
|
$data = ['cancle_reason' => $value, 'delete_time' => time()];
|
||||||
StoreOrder::where($where)->update($data);
|
StoreOrder::where($where)->update($data);
|
||||||
return $this->success('取消成功');
|
return $this->success('取消成功');
|
||||||
}
|
}
|
||||||
|
@ -114,11 +114,11 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
|
|
||||||
if ($order->pay_type == 9) {
|
if ($order->pay_type == 9) {
|
||||||
$extra['create_time'] = $order['create_time'];
|
$extra['create_time'] = $order['create_time'];
|
||||||
PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]);
|
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]);
|
||||||
} else {
|
} else {
|
||||||
PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
|
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
|
||||||
Redis::send('push-platform-print', ['order_id' => $order['id']], 60);
|
Redis::send('push-platform-print', ['order_id' => $order['id']], 60);
|
||||||
// Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
|
// Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
|
||||||
}
|
}
|
||||||
if (!empty($extra['payer']['openid']) && $order->pay_type != 9) {
|
if (!empty($extra['payer']['openid']) && $order->pay_type != 9) {
|
||||||
Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5);
|
Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5);
|
||||||
|
@ -84,16 +84,16 @@ class PaymentLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
$order = [
|
$order = [
|
||||||
'description' => '条码商品',
|
'description' => '条码商品',
|
||||||
'out_trade_no' => $order['number'],
|
'out_trade_no' => (string)$order['order_id'],
|
||||||
'payer' => [
|
'payer' => [
|
||||||
'auth_code' => (string)$auth_code
|
'auth_code' => (string)$auth_code
|
||||||
],
|
],
|
||||||
'amount' => [
|
'amount' => [
|
||||||
'total' => intval($order['actual'] * 100),
|
'total' => intval($order['pay_price'] * 100),
|
||||||
],
|
],
|
||||||
'scene_info' => [
|
'scene_info' => [
|
||||||
"store_info" => [
|
"store_info" => [
|
||||||
'id' => (string)$order['merchant']
|
'id' => (string)$order['store_id']??1
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -124,9 +124,9 @@ class PaymentLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
$order = [
|
$order = [
|
||||||
'subject' => '条码商品',
|
'subject' => '条码商品',
|
||||||
'out_trade_no' => $order['number'],
|
'out_trade_no' => (string)$order['order_id'],
|
||||||
'auth_code' => (string)$auth_code,
|
'auth_code' => (string)$auth_code,
|
||||||
'total_amount' => $order['actual'],
|
'total_amount' => $order['pay_price'],
|
||||||
'extend_params'=>['attach'=>'alipay_cashier']
|
'extend_params'=>['attach'=>'alipay_cashier']
|
||||||
];
|
];
|
||||||
$wechat = new PayService();
|
$wechat = new PayService();
|
||||||
|
57
app/queue/redis/CodePaySend.php
Normal file
57
app/queue/redis/CodePaySend.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\queue\redis;
|
||||||
|
|
||||||
|
use app\common\logic\PayNotifyLogic;
|
||||||
|
use app\common\model\retail\Cashierclass;
|
||||||
|
use app\common\model\store_order\StoreOrder;
|
||||||
|
use app\common\service\pay\PayService;
|
||||||
|
use app\common\service\PushService;
|
||||||
|
use Webman\RedisQueue\Consumer;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信条码支付队列消费
|
||||||
|
*/
|
||||||
|
class CodePaySend implements Consumer
|
||||||
|
{
|
||||||
|
// 要消费的队列名
|
||||||
|
public $queue = 'send-code-pay';
|
||||||
|
|
||||||
|
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||||
|
public $connection = 'default';
|
||||||
|
|
||||||
|
// 消费
|
||||||
|
public function consume($data)
|
||||||
|
{
|
||||||
|
$pay = new PayService();
|
||||||
|
$order = [
|
||||||
|
'out_trade_no' => $data['order_id'],
|
||||||
|
];
|
||||||
|
$res = $pay->wechat->query($order);
|
||||||
|
if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') {
|
||||||
|
PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res);
|
||||||
|
}else{
|
||||||
|
throw new BusinessException('订单支付中', 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 消费失败时
|
||||||
|
public function onConsumeFailure(\Throwable $exception, $package)
|
||||||
|
{
|
||||||
|
// 直接更改消息队列数据结构,将最大重试次数max_attempts字段设置为0,即不再重试。
|
||||||
|
if($package['attempts'] ==$exception['max_attempts']){
|
||||||
|
$data = [
|
||||||
|
'order_id' => $package['data']['order_id'],
|
||||||
|
'paid' => 0,
|
||||||
|
];
|
||||||
|
$find=StoreOrder::where($data)->find();
|
||||||
|
if($find){
|
||||||
|
$order = StoreOrder::update($data);
|
||||||
|
if($order){
|
||||||
|
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'cash_register','msg'=>'支付超时,订单已被取消,请重新提交订单']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $package;
|
||||||
|
}
|
||||||
|
}
|
70
app/queue/redis/PushPlatformPrintSend.php
Normal file
70
app/queue/redis/PushPlatformPrintSend.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\queue\redis;
|
||||||
|
|
||||||
|
use app\admin\logic\operation\OpurchaseclassLogic;
|
||||||
|
use app\common\model\goods\Goods;
|
||||||
|
use app\common\model\goods\Unit;
|
||||||
|
use app\common\model\merchant\Merchant;
|
||||||
|
use app\common\model\opurchase\Opurchaseinfo;
|
||||||
|
use app\common\model\retail\Cashierclass;
|
||||||
|
use app\common\model\retail\Cashierinfo;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_order\StoreOrder;
|
||||||
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
|
use app\common\model\system_store\SystemStore;
|
||||||
|
use app\common\model\system_store\SystemStoreStaff;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
use app\common\service\PushService;
|
||||||
|
use Webman\RedisQueue\Consumer;
|
||||||
|
use Webman\Push\Api;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
use support\Log;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单推送给收银台
|
||||||
|
*/
|
||||||
|
class PushPlatformPrintSend implements Consumer
|
||||||
|
{
|
||||||
|
// 要消费的队列名
|
||||||
|
public $queue = 'push-platform-print';
|
||||||
|
|
||||||
|
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||||
|
public $connection = 'default';
|
||||||
|
|
||||||
|
// 消费
|
||||||
|
public function consume($data)
|
||||||
|
{
|
||||||
|
$id=$data['order_id']??0;
|
||||||
|
Log::info('打印推送开始'.$id);
|
||||||
|
if(!$id)return false;
|
||||||
|
$find = StoreOrder::where('id', $id)->find();
|
||||||
|
if ($find) {
|
||||||
|
$merchant = SystemStore::where('id', $find['store_id'])->field('name,phone')->find();
|
||||||
|
$mer_user_info = SystemStoreStaff::where('store_id', $find['store_id'])->where('is_admin',1)->field('staff_name,phone')->find();
|
||||||
|
$user = User::where('id', $find['uid'])->field('nickname,mobile')->find();
|
||||||
|
$find['system_store_name'] = $merchant['name'];
|
||||||
|
$find['system_store_phone'] = $merchant['phone'];
|
||||||
|
$find['staff_name'] = $mer_user_info['staff_name'];
|
||||||
|
$find['staff_phone'] = $mer_user_info['phone'];
|
||||||
|
$find['nickname'] = $user['nickname']??'';
|
||||||
|
$find['user_mobile'] = $user['mobile']??'';
|
||||||
|
$find['info'] = StoreOrderCartInfo::where('oid', $find['id'])->field('store_id,product_id,cart_num,price,total_price')->select()->each(function ($item) {
|
||||||
|
$goods = StoreBranchProduct::where(['store_id'=>$item['store_id'],'product_id'=>$item['product_id']])->field('store_name,unit')->find();
|
||||||
|
$item['unit_name'] = StoreProductUnit::where('id', $goods['unit'])->value('name');
|
||||||
|
$item['store_name'] = $goods['store_name'];
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
PushService::push('store_merchant_'.$find['store_id'], 1, ['type'=>'platform_print','msg'=>'打印队列','data'=>$find]);
|
||||||
|
Log::info('打印推送结束'.$id);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function onConsumeFailure(\Throwable $exception, $package)
|
||||||
|
{
|
||||||
|
Log::error('打印队列推送失败。order_id:'. $package['data']['order_id'].',msg:'.$exception->getMessage());
|
||||||
|
return $package;
|
||||||
|
}
|
||||||
|
}
|
@ -96,7 +96,8 @@ class StoreOrderController extends BaseAdminController
|
|||||||
ApiDoc\NotHeaders(),
|
ApiDoc\NotHeaders(),
|
||||||
ApiDoc\Author('中国队长'),
|
ApiDoc\Author('中国队长'),
|
||||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||||
ApiDoc\Query(name: 'id', type: 'int', require: true, desc: '订单id'),
|
ApiDoc\Query(name: 'id', type: 'int', require: false, desc: '订单id'),
|
||||||
|
ApiDoc\Query(name: 'verify_code', type: 'string', require: false, desc: '核销码'),
|
||||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
]
|
]
|
||||||
public function detail(StoreOrderLogic $orderLogic)
|
public function detail(StoreOrderLogic $orderLogic)
|
||||||
@ -151,7 +152,7 @@ class StoreOrderController extends BaseAdminController
|
|||||||
return $this->fail(PaymentLogic::getError(), $params);
|
return $this->fail(PaymentLogic::getError(), $params);
|
||||||
}
|
}
|
||||||
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
||||||
PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result);
|
PayNotifyLogic::handle('wechat_common', $result['out_trade_no'], $result);
|
||||||
} else {
|
} else {
|
||||||
Redis::send('send-code-pay', ['number' => $order['number']]);
|
Redis::send('send-code-pay', ['number' => $order['number']]);
|
||||||
return $this->success('用户支付中');
|
return $this->success('用户支付中');
|
||||||
|
@ -19,7 +19,8 @@ class StoreOrderValidate extends BaseValidate
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'requireWithout:verify_code',
|
||||||
|
'verify_code' => 'requireWithout:id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ class StoreOrderValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
protected $field = [
|
protected $field = [
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
|
'verify_code' => '核销码',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ class StoreOrderValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneDetail()
|
public function sceneDetail()
|
||||||
{
|
{
|
||||||
return $this->only(['id']);
|
return $this->only(['id','verify_code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ return [
|
|||||||
[
|
[
|
||||||
'class' => \support\log\MonologExtendHandler::class,
|
'class' => \support\log\MonologExtendHandler::class,
|
||||||
'constructor' => [
|
'constructor' => [
|
||||||
'/logs/redis-queue/queue.log',
|
'redis-queue',
|
||||||
7, //$maxFiles
|
7, //$maxFiles
|
||||||
Monolog\Logger::DEBUG,
|
Monolog\Logger::DEBUG,
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user