调试信用购订单结算回调

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 = [
'order_sn' => $this->presell_order_sn,
'pay_price' => $this->pay_price,
'attach' => 'presell',
'attach' => $attach,
'body' => '尾款支付'
];
if ($return_url) {

View File

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

View File

@ -2433,12 +2433,12 @@ class StoreOrderRepository extends BaseRepository
/**
* 订单结算
* @param $id
* @param $type
* @param $payType
* @param $user
* @return array
* @throws Exception
*/
public function settle($id, $type, $user)
public function settle($id, $payType, $user)
{
/** @var StoreGroupOrderRepository $groupOrderRepository */
$groupOrderRepository = app()->make(StoreGroupOrderRepository::class);
@ -2455,19 +2455,23 @@ class StoreOrderRepository extends BaseRepository
$interest = $groupOrder->interest->calculateInterest();
$payMoney = bcadd($groupOrder->interest->total_price, $interest, 2);
$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];
if ($payMoney > 0) {
if (!in_array($type, ['balance', 'scrcu'])) {
$groupOrder->pay_price = $payMoney;
if (!in_array($payType, ['balance', 'scrcu'])) {
if (systemConfig('open_wx_combine')) {
$service = new CombinePayService($type, $groupOrder->getCombinePayParams('order_settle'));
$service = new CombinePayService($payType, $groupOrder->getCombinePayParams('order_settle'));
} 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);
$data = array_merge($data, $result, ['paid' => false]);
} else {
$payTool = PayTool::instance($type);
$groupOrder->pay_price = $payMoney;
$payTool = PayTool::instance($payType);
$result = $payTool->pay($groupOrder);
}
}

View File

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

View File

@ -310,9 +310,9 @@ class StoreOrder extends BaseController
public function settle()
{
$id = $this->request->param('id/d');
$type = $this->request->param('type');
$payType = $this->request->param('pay_type');
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);
} catch (\Exception $e) {
return app('json')->fail($e->getMessage());

View File

@ -27,11 +27,13 @@ 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 {
$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);
$groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED;
$groupOrder->interest->settle_time = date('Y-m-d H:i:s');