feat: 增加微信支付回调处理逻辑

This commit is contained in:
mkm 2024-06-08 18:14:11 +08:00
parent 601aa01ab8
commit 3618a0bfee
7 changed files with 22 additions and 13 deletions

View File

@ -44,6 +44,7 @@ class PayNotifyLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error('支付回调处理失败' . $e->getMessage().',lien:'.$e->getLine().',file:'.$e->getFile());
throw new \Exception($e->getMessage());
}
}
@ -97,13 +98,14 @@ class PayNotifyLogic extends BaseLogic
} else {
$extra['transaction_id'] = time();
}
$user = User::where('id', $order['uid'])->find();
if ($order->pay_type == 9) {
$order->status = 2;
}else{
$capitalFlowDao = new CapitalFlowLogic($user);
//微信支付和用户余额无关
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price,'',1);
}
$user = User::where('id', $order['uid'])->find();
$capitalFlowDao = new CapitalFlowLogic($user);
//微信支付和用户余额无关
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price,'',1);
self::afterPay($order,$extra['transaction_id']);
//活动期间消费
@ -117,7 +119,7 @@ class PayNotifyLogic extends BaseLogic
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]);
} else {
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', ['id' => $order['id']], 60);
// Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
}
if (!empty($extra['payer']['openid']) && $order->pay_type != 9) {
@ -194,7 +196,7 @@ class PayNotifyLogic extends BaseLogic
}
/**
* @notes 零售回调
* @notes 阿里回调
* @param $orderSn
* @param array $extra
* @author 段誉
@ -223,10 +225,10 @@ class PayNotifyLogic extends BaseLogic
if ($order->pay_type == 9) {
$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 {
PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
Redis::send('push-platform-print', ['order_sn' => $order['order_id']], 60);
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
Redis::send('push-platform-print', ['id' => $order['id']], 60);
}
return true;
}

View File

@ -3,6 +3,7 @@
namespace app\common\logic\store_order;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\common\logic\BaseLogic;
use app\common\enum\YesNoEnum;
use app\common\model\dict\DictType;
@ -78,7 +79,7 @@ class StoreOrderLogic extends BaseLogic
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
} else {
$discountRate = bcdiv(1, '100', 2);
$discountRate = bcdiv(100, '100', 2);
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
}
if (!empty(self::$total) && !empty($pay_price)) {
@ -162,6 +163,8 @@ class StoreOrderLogic extends BaseLogic
$order['status_name'] = OrderEnum::getOrderType($order['status']) ?? '';
$order['refund_status_name'] = OrderEnum::refundStatus($order['refund_status']) ?? '';
$order['refund_type_name'] = OrderEnum::refundType($order['refund_type']) ?? '';
$order['pay_type_name'] =PayEnum::getPaySceneDesc($order['pay_type']) ?? '';
return $order->toArray();
}

View File

@ -29,7 +29,7 @@ class StoreOrder extends BaseModel
->bind(['store_name'=>'name', 'store_phone'=>'phone','store_detailed_address'=>'detailed_address','store_simple_address'=>'address']);
}
public function getPayTypeAttr($value, $data)
public function getPayTypeNameTextAttr($value, $data)
{
$status = PayEnum::getPaySceneDesc($value)??'';
return $status;

View File

@ -37,7 +37,7 @@ class PushPlatformPrintSend implements Consumer
// 消费
public function consume($data)
{
$id=$data['order_id']??0;
$id=$data['id']??0;
Log::info('打印推送开始'.$id);
if(!$id)return false;
$find = StoreOrder::where('id', $id)->find();

View File

@ -15,6 +15,7 @@ use app\common\logic\store_order\StoreOrderLogic;
use app\common\model\store_order\StoreOrder;
use app\store\validate\store_order\StoreOrderValidate;
use hg\apidoc\annotation as ApiDoc;
use support\Log;
use Webman\RedisQueue\Redis;
/**
@ -152,6 +153,7 @@ class StoreOrderController extends BaseAdminController
return $this->fail(PaymentLogic::getError(), $params);
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
Log::error(json_encode($result));
PayNotifyLogic::handle('wechat_common', $result['out_trade_no'], $result);
} else {
Redis::send('send-code-pay', ['number' => $order['number']]);

View File

@ -3,6 +3,7 @@
namespace app\store\lists\store_order;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\store\lists\BaseAdminDataLists;
use app\common\model\store_order\StoreOrder;
use app\common\lists\ListsSearchInterface;
@ -59,6 +60,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
->order(['id' => 'desc'])
->select()->each(function ($item) use ($store_id) {
$item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : '';
$item['pay_type_name'] =PayEnum::getPaySceneDesc($item['pay_type']) ?? '';
$item['status_name'] = OrderEnum::getOrderType($item['status']) ?? '';
if ($item['paid'] == 0) {
$item['paid_name'] = '待支付';

View File

@ -23,7 +23,7 @@ return [
// 断线重连
'break_reconnect' => true,
// 关闭SQL监听日志
'trigger_sql' => true,
'trigger_sql' => false,
// 自定义分页类
'bootstrap' => ''
],