Merge pull request 'feat(store_order): 添加查询订单支付状态功能' (#70) from dev into rose

Reviewed-on: #70
This commit is contained in:
mkm 2024-07-31 12:00:16 +08:00
commit bc40d950aa

View File

@ -25,6 +25,7 @@ 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_recharge\UserRecharge;
use app\common\service\pay\PayService;
use app\store\validate\store_order\StoreOrderValidate;
use support\Cache;
use support\Log;
@ -504,4 +505,41 @@ class StoreOrderController extends BaseAdminController
}
return $this->success('获取成功', $find?->toArray());
}
/**
* @notes 查询订单支付状态
*/
public function wechatQuery()
{
$order_no = $this->request->get('order_no');
$order = [
'out_trade_no' => $order_no,
];
$app = new PayService(0);
try {
$res = $app->wechat->query($order);
} catch (\Exception $e) {
return $this->fail($e->extra['message'] ?? $e->getMessage());
}
if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') {
$attach = $res['attach'];
switch ($attach) {
case 'recharge':
PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res);
$app->wechat->success();
break;
case 'wechat_common':
PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res);
$app->wechat->success();
break;
default:
Log::error('支付回调失败,订单号:' . $res['out_trade_no'], $res);
break;
}
return $this->success('支付成功');
} else {
return $this->fail('订单支付中');
}
}
}