154 lines
3.9 KiB
PHP
154 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Service\Common\Pay\Wx;
|
|
|
|
use App\Constants\Common\OrderCode;
|
|
use App\Constants\Common\PayCode;
|
|
use App\Service\ServiceTrait\Api\CateringTrait;
|
|
use App\Service\ServiceTrait\Api\CheckOrderCallBackTrait;
|
|
use App\Service\ServiceTrait\Api\CouponTrait;
|
|
use App\Service\ServiceTrait\Api\GoodOrderTrait;
|
|
use App\Service\ServiceTrait\Api\OrderTrait;
|
|
use App\Service\ServiceTrait\Api\PayFinishTrait;
|
|
use App\Service\ServiceTrait\Api\RefundOrderTrait;
|
|
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
|
use Hyperf\DbConnection\Db;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Yansongda\Artful\Exception\InvalidParamsException;
|
|
use function Hyperf\Config\config;
|
|
|
|
class WxJsRechargeOrderService extends WxJsRechargeBaseService
|
|
{
|
|
use CheckOrderCallBackTrait,
|
|
GoodOrderTrait,
|
|
PayFinishTrait,
|
|
RefundOrderTrait,
|
|
OrderTrait,
|
|
OrderChangeStatusTrait,
|
|
CateringTrait,
|
|
CouponTrait;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
const int OrderType = OrderCode::ORDER_TYPE_GOOD;
|
|
const int PayType = PayCode::WECHAT_PAY;
|
|
|
|
/**
|
|
* 订单 id
|
|
* @var int
|
|
*/
|
|
protected int $orderId;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected string $orderNo;
|
|
|
|
/**
|
|
* @var mixed
|
|
*/
|
|
protected mixed $orderInfo;
|
|
|
|
/**
|
|
* @var mixed
|
|
*/
|
|
protected mixed $payInfo;
|
|
|
|
/**
|
|
* @var mixed
|
|
*/
|
|
protected mixed $refundInfo;
|
|
|
|
/**
|
|
* @var bool 是否加入配餐数据
|
|
*/
|
|
protected bool $isCatering = true;
|
|
|
|
/**
|
|
* @return ResponseInterface
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
* @throws InvalidParamsException
|
|
*/
|
|
public function callBackHandle(): ResponseInterface
|
|
{
|
|
$this->getWechatData();
|
|
|
|
$this->checkWxCallBackOrder();
|
|
|
|
$this->checkCallBackOrder();
|
|
|
|
Db::transaction(function (){
|
|
$this->manageOrder();
|
|
|
|
$this->manageWxOrder();
|
|
//
|
|
$this->isCatering = $this->manageAddCateringLog();
|
|
});
|
|
|
|
//已经截单 自动退款
|
|
if (!$this->isCatering) $this->joinRefundQueue($this->orderId,OrderCode::ORDER_TYPE_GOOD,$this->orderInfo->actual_price,'已截单,系统自动退款');
|
|
|
|
//todo 发送订阅通知
|
|
// $this->sendGainCoinMsg();
|
|
|
|
//发送mq通知报表结算
|
|
// $this->sendShareExMq($this->orderInfo->mid,ShareExCode::RECHARGE_COIN, [
|
|
// 'order_id' => $this->orderInfo->id,
|
|
// 'count' => $this->rechargeCoin,
|
|
// ]);
|
|
|
|
return $this->returnSuccess();
|
|
}
|
|
|
|
/**
|
|
* @return ResponseInterface
|
|
* @throws ContainerExceptionInterface
|
|
* @throws InvalidParamsException
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function refundCallBackHandle(): ResponseInterface
|
|
{
|
|
$this->log->callbackLog('退款回调'.json_encode($this->request->all()));
|
|
$this->getWechatData();
|
|
|
|
$this->checkWxRefundCallBackOrder();
|
|
|
|
$this->checkRefundOrder();
|
|
|
|
Db::transaction(function (){
|
|
$this->manageRefundOrder();
|
|
|
|
$this->manageOrderByRefund();
|
|
|
|
$this->manageSubCateringLog();
|
|
|
|
if ($this->orderInfo->coupin_id > 0) $this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$this->orderInfo);
|
|
});
|
|
|
|
$this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
|
|
|
return $this->returnSuccess();
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function setNotify(): void
|
|
{
|
|
//返回的回调地址
|
|
$this->config['wechat']['default']['notify_url'] = config('system.api_url').'/common/wxPay/order/js/callBack';
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function setRefundNotify(): void
|
|
{
|
|
//返回的退款回调地址
|
|
$this->config['wechat']['default']['notify_url'] = config('system.api_url').'/common/wxPay/order/js/refund/callBack';
|
|
}
|
|
} |