新增了微信支付 关闭订单。在取消未支付订单中。
This commit is contained in:
parent
7d978c27bd
commit
914ddb5abf
@ -19,6 +19,7 @@ use App\Services\OrderProductService;
|
||||
use App\Services\OrderService;
|
||||
use App\Utils\Log;
|
||||
use App\Utils\Utils;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Result;
|
||||
@ -96,6 +97,12 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
// 关闭支付订单
|
||||
$WechatPay = new WechatPay("1", 1);
|
||||
|
||||
// 关闭订单
|
||||
$WechatPay->closeOrder($data['order_no']);
|
||||
|
||||
Db::commit();
|
||||
Log::getInstance("queue-CancelUnpayOrders")->info("成功");
|
||||
return Result::ACK;
|
||||
|
||||
@ -323,7 +323,6 @@ class Order extends Model
|
||||
->where($params)
|
||||
->whereIn('order_type',[1,4,5]);
|
||||
|
||||
// 问诊订单
|
||||
$query = $query->where(function ($query) use ($is_platform_deep_cooperation){
|
||||
$query->whereExists(function ($subQuery) use ($is_platform_deep_cooperation){
|
||||
$subQuery->from('order_inquiry');
|
||||
|
||||
@ -250,4 +250,47 @@ class WechatPay
|
||||
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭订单
|
||||
* @param string $out_trade_no 商户系统内部订单号
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function closeOrder(string $out_trade_no): array
|
||||
{
|
||||
$app = $this->createApp();
|
||||
|
||||
$options = [
|
||||
"mchid" => $this->pay_config['mch_id'], // <---- 商户号
|
||||
];
|
||||
|
||||
Log::getInstance()->info(json_encode($options,JSON_UNESCAPED_UNICODE));
|
||||
try {
|
||||
$url = "v3/pay/transactions/out-trade-no/" . $out_trade_no . "/close";
|
||||
|
||||
$response = $app->getClient()->postJson($url, $options);
|
||||
if ($response->isFailed()) {
|
||||
// 出错了,处理异常
|
||||
$result = $response->toArray(false);
|
||||
Log::getInstance()->info(json_encode($result,JSON_UNESCAPED_UNICODE));
|
||||
if(empty($result)){
|
||||
// 返回值为空
|
||||
throw new BusinessException("发起支付失败");
|
||||
}
|
||||
if (!empty($result['code'])){
|
||||
if ($result['code'] != 400){
|
||||
throw new BusinessException($result['message']);
|
||||
}
|
||||
}else{
|
||||
throw new BusinessException("关闭支付订单失败");
|
||||
}
|
||||
}
|
||||
|
||||
return $response->toArray(false);
|
||||
} catch (\Exception $e) {
|
||||
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user