feat : pay callback
This commit is contained in:
27
app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php
Normal file
27
app/Service/ServiceTrait/Api/CheckOrderCallBackTrait.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\ServiceTrait\Api;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
|
||||
trait CheckOrderCallBackTrait
|
||||
{
|
||||
public function checkWxCallBackOrder(): void
|
||||
{
|
||||
if (
|
||||
!isset($this->callbackData['return_code']) ||
|
||||
$this->callbackData['return_code'] != 'SUCCESS' ||
|
||||
!isset($this->callbackData['total_fee']) ||
|
||||
$this->callbackData['total_fee'] <= 0 ||
|
||||
!isset($this->callbackData['out_trade_no']) ||
|
||||
empty($this->callbackData['out_trade_no']) ||
|
||||
!isset($this->callbackData['mch_id']) ||
|
||||
empty($this->callbackData['mch_id']) ||
|
||||
!in_array($this->callbackData['trade_type'],['APP','JSAPI'])
|
||||
){
|
||||
throw new ErrException('此订单回调异常');
|
||||
}
|
||||
|
||||
$this->orderNo = $this->callbackData['out_trade_no'];
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,11 @@ use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\ApiCode;
|
||||
use App\Constants\Common\GoodCode;
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Constants\Common\PayCode;
|
||||
use App\Constants\ConfigCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use Exception;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Context\ApplicationContext;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -295,4 +298,73 @@ trait OrderTrait
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$producer->produce($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function checkGoodOrder(): void
|
||||
{
|
||||
$this->orderInfo = $this->orderModel->getInfoByOrderSno($this->orderNo);
|
||||
|
||||
if (empty($this->orderInfo)) {
|
||||
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);
|
||||
throw new ErrException('订单不存在');
|
||||
}
|
||||
|
||||
if ($this->orderInfo->status != OrderCode::WAIT_PAY) {
|
||||
$this->log->debug(__CLASS__.':订单已充值成功或取消,订单信息:'.json_encode($this->orderInfo->toArray()));
|
||||
throw new ErrException('订单已充值成功');
|
||||
}
|
||||
|
||||
if ($this->orderInfo->action != PayCode::WECHAT_PAY) {
|
||||
$this->log->debug(__CLASS__.':订单充值渠道错误,订单信息:'.json_encode($this->orderInfo->toArray()));
|
||||
throw new ErrException('订单充值渠道错误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作微信订单
|
||||
* @return void
|
||||
*/
|
||||
protected function manageWxOrder(): void
|
||||
{
|
||||
// $this->orderInfo->status = OrderCode::STATUS_PAY;
|
||||
// $this->orderInfo->isAdd = 1;
|
||||
// $this->orderInfo->tradeno = $this->callbackData['transaction_id'];
|
||||
//// $this->orderInfo->payTime = date('Y-m-d H:i:s',strtotime($this->callbackData['time_end']));
|
||||
// $this->orderInfo->payTime = strtotime($this->callbackData['success_time']);
|
||||
// $this->orderInfo->jsonData = [
|
||||
// 'payData' => $this->callbackData,
|
||||
// 'jsonData' => $this->orderInfo->jsonData
|
||||
// ];
|
||||
|
||||
if (!$this->orderInfo->save()) {
|
||||
$this->log->debug(__CLASS__.':Function:manageWxOrder:更新充值订单的状态失败:'.$this->orderInfo->id);
|
||||
throw new ErrException('更新充值订单的状态失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function manageGoodOrder(): void
|
||||
{
|
||||
try {
|
||||
|
||||
}catch (Exception $e) {
|
||||
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
throw new ErrException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user