调试信用购订单支付回调

This commit is contained in:
luofei 2023-07-06 11:59:55 +08:00
parent 10e2ca5d06
commit c0e1a39c1e
5 changed files with 62 additions and 7 deletions

View File

@ -66,7 +66,7 @@ class PresellOrder extends BaseModel
return $status;
}
public function getCombinePayParams()
public function getCombinePayParams($attach = 'presell')
{
return [
'order_sn' => $this->presell_order_sn,
@ -77,7 +77,7 @@ class PresellOrder extends BaseModel
'sub_mchid' => $this->merchant->sub_mchid,
]
],
'attach' => 'presell',
'attach' => $attach,
'body' => '尾款支付',
];
}

View File

@ -76,12 +76,12 @@ class StoreGroupOrder extends BaseModel
return $value ? implode(',', $value) : '';
}
public function getCombinePayParams()
public function getCombinePayParams($attach = 'order')
{
$params = [
'order_sn' => $this->group_order_sn,
'sub_orders' => [],
'attach' => 'order',
'attach' => $attach,
'body' => '订单支付',
];
foreach ($this->orderList as $order) {

View File

@ -2459,7 +2459,7 @@ class StoreOrderRepository extends BaseRepository
if ($payMoney > 0) {
if (!in_array($type, ['balance', 'scrcu'])) {
if (systemConfig('open_wx_combine')) {
$service = new CombinePayService($type, $groupOrder->getCombinePayParams());
$service = new CombinePayService($type, $groupOrder->getCombinePayParams('order_settle'));
} else {
$service = new PayService($type, $groupOrder->getPayParams($type === 'alipay' ? request()->param('return_url') : ''));
}
@ -2471,12 +2471,11 @@ class StoreOrderRepository extends BaseRepository
$result = $payTool->pay($groupOrder);
}
}
$groupOrder->interest->interest = $interest;
if ($result === true) {
app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->order);
$groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED;
$groupOrder->interest->settle_time = date('Y-m-d H:i:s');
$groupOrder->interest->interest = $interest;
$groupOrder->interest->save();
/** @var UserBillRepository $userBillRepository */
$userBillRepository = app()->make(UserBillRepository::class);
@ -2495,6 +2494,7 @@ class StoreOrderRepository extends BaseRepository
$merchantRepo->unfreeze($groupOrder->interest->mer_id);
}
}
$groupOrder->interest->save();
Db::commit();
return $data;
} catch (\Exception $e) {

View File

@ -60,6 +60,7 @@ return [
'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class],
'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class],
'pay_success_order' => [\crmeb\listens\pay\OrderPaySuccessListen::class],
'pay_success_order_settle' => [\crmeb\listens\pay\OrderSettlePaySuccessListen::class],
'pay_success_micro_pay' => [\crmeb\listens\pay\OrderMicroPaySuccessListen::class],
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],

View File

@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\listens\pay;
use app\common\model\store\order\StoreOrderInterest;
use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use crmeb\interfaces\ListenerInterface;
use crmeb\utils\DingTalk;
use think\facade\Db;
use think\facade\Log;
class OrderSettlePaySuccessListen implements ListenerInterface
{
public function handle($data): void
{
$orderSn = $data['order_sn'];
$groupOrder = app()->make(StoreGroupOrderRepository::class)->getWhere(['group_order_sn' => $orderSn]);
if (!$groupOrder || $groupOrder->paid == 1) return;
Db::startTrans();
try {
app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->order);
$groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED;
$groupOrder->interest->settle_time = date('Y-m-d H:i:s');
if (!$groupOrder->interest->save()) {
throw new \Exception('订单结算信息保存失败');
}
$unSettleCount = StoreOrderInterest::where('mer_id', $groupOrder->interest->mer_id)->where('status', 0)->count();
if ($unSettleCount === 0) {
/** @var MerchantRepository $merchantRepo */
$merchantRepo = app()->make(MerchantRepository::class);
$merchantRepo->unfreeze($groupOrder->interest->mer_id);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::error($e->getMessage(), $data);
DingTalk::exception($e, $e->getMessage());
}
}
}