调试信用购订单结算回调

This commit is contained in:
luofei 2023-07-06 13:59:40 +08:00
parent c0e1a39c1e
commit efaf48186b
6 changed files with 23 additions and 17 deletions

View File

@ -82,12 +82,12 @@ class PresellOrder extends BaseModel
]; ];
} }
public function getPayParams($return_url = '') public function getPayParams($return_url = '', $attach = 'presell')
{ {
$params = [ $params = [
'order_sn' => $this->presell_order_sn, 'order_sn' => $this->presell_order_sn,
'pay_price' => $this->pay_price, 'pay_price' => $this->pay_price,
'attach' => 'presell', 'attach' => $attach,
'body' => '尾款支付' 'body' => '尾款支付'
]; ];
if ($return_url) { if ($return_url) {

View File

@ -97,12 +97,12 @@ class StoreGroupOrder extends BaseModel
return $params; return $params;
} }
public function getPayParams($return_url = '') public function getPayParams($return_url = '', $attach = 'order')
{ {
$params = [ $params = [
'order_sn' => $this->group_order_sn, 'order_sn' => $this->group_order_sn,
'pay_price' => $this->pay_price, 'pay_price' => $this->pay_price,
'attach' => 'order', 'attach' => $attach,
'body' => '订单支付' 'body' => '订单支付'
]; ];
if ($return_url) { if ($return_url) {

View File

@ -2433,12 +2433,12 @@ class StoreOrderRepository extends BaseRepository
/** /**
* 订单结算 * 订单结算
* @param $id * @param $id
* @param $type * @param $payType
* @param $user * @param $user
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
public function settle($id, $type, $user) public function settle($id, $payType, $user)
{ {
/** @var StoreGroupOrderRepository $groupOrderRepository */ /** @var StoreGroupOrderRepository $groupOrderRepository */
$groupOrderRepository = app()->make(StoreGroupOrderRepository::class); $groupOrderRepository = app()->make(StoreGroupOrderRepository::class);
@ -2455,19 +2455,23 @@ class StoreOrderRepository extends BaseRepository
$interest = $groupOrder->interest->calculateInterest(); $interest = $groupOrder->interest->calculateInterest();
$payMoney = bcadd($groupOrder->interest->total_price, $interest, 2); $payMoney = bcadd($groupOrder->interest->total_price, $interest, 2);
$result = true; $result = true;
$type = array_search($payType, StoreOrderRepository::PAY_TYPE);
if (in_array($payType, ['weixin', 'alipay'], true) && request()->isApp()) {
$payType .= 'App';
}
$data = ['type' => $type, 'order_id' => $groupOrder->group_order_id, 'paid' => true]; $data = ['type' => $type, 'order_id' => $groupOrder->group_order_id, 'paid' => true];
if ($payMoney > 0) { if ($payMoney > 0) {
if (!in_array($type, ['balance', 'scrcu'])) { $groupOrder->pay_price = $payMoney;
if (!in_array($payType, ['balance', 'scrcu'])) {
if (systemConfig('open_wx_combine')) { if (systemConfig('open_wx_combine')) {
$service = new CombinePayService($type, $groupOrder->getCombinePayParams('order_settle')); $service = new CombinePayService($payType, $groupOrder->getCombinePayParams('order_settle'));
} else { } else {
$service = new PayService($type, $groupOrder->getPayParams($type === 'alipay' ? request()->param('return_url') : '')); $service = new PayService($payType, $groupOrder->getPayParams($payType === 'alipay' ? request()->param('return_url') : '', 'order_settle'));
} }
$result = $service->pay($user); $result = $service->pay($user);
$data = array_merge($data, $result, ['paid' => false]); $data = array_merge($data, $result, ['paid' => false]);
} else { } else {
$payTool = PayTool::instance($type); $payTool = PayTool::instance($payType);
$groupOrder->pay_price = $payMoney;
$result = $payTool->pay($groupOrder); $result = $payTool->pay($groupOrder);
} }
} }

View File

@ -195,7 +195,7 @@ class Common extends BaseController
*/ */
public function wechatCombinePayNotify($type) public function wechatCombinePayNotify($type)
{ {
if (!in_array($type, ['order', 'presell'], true)) if (!in_array($type, ['order', 'presell', 'order_settle'], true))
throw new ValidateException('参数错误'); throw new ValidateException('参数错误');
try { try {
return WechatService::create()->handleCombinePayNotify($type); return WechatService::create()->handleCombinePayNotify($type);

View File

@ -310,9 +310,9 @@ class StoreOrder extends BaseController
public function settle() public function settle()
{ {
$id = $this->request->param('id/d'); $id = $this->request->param('id/d');
$type = $this->request->param('type'); $payType = $this->request->param('pay_type');
try { try {
$data = $this->repository->settle($id, $type, $this->request->userInfo()); $data = $this->repository->settle($id, $payType, $this->request->userInfo());
return app('json')->success('success', $data); return app('json')->success('success', $data);
} catch (\Exception $e) { } catch (\Exception $e) {
return app('json')->fail($e->getMessage()); return app('json')->fail($e->getMessage());

View File

@ -27,11 +27,13 @@ class OrderSettlePaySuccessListen implements ListenerInterface
public function handle($data): void 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(); Db::startTrans();
try { try {
$orderSn = $data['order_sn'];
$groupOrder = app()->make(StoreGroupOrderRepository::class)->getWhere(['group_order_sn' => $orderSn]);
if (!$groupOrder || $groupOrder->paid == 1) {
throw new \Exception('订单不存在或已支付');
}
app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->order); app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->order);
$groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED; $groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED;
$groupOrder->interest->settle_time = date('Y-m-d H:i:s'); $groupOrder->interest->settle_time = date('Y-m-d H:i:s');