101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Service\ServiceTrait\Api;
|
|
|
|
use App\Constants\Common\OrderCode;
|
|
use App\Constants\Common\PayCode;
|
|
use App\Constants\Common\RefundCode;
|
|
use App\Exception\ErrException;
|
|
use App\Model\Order;
|
|
use App\Model\OrderGood;
|
|
use App\Model\OrderMealCateringLog;
|
|
use App\Model\OrderOptionCateringLog;
|
|
use App\Model\PayOrder;
|
|
use App\Model\RefundOrder;
|
|
use Exception;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
trait GoodOrderTrait
|
|
{
|
|
|
|
/**
|
|
* @var Order
|
|
*/
|
|
#[Inject]
|
|
protected Order $orderModel;
|
|
|
|
/**
|
|
* @var PayOrder
|
|
*/
|
|
#[Inject]
|
|
protected PayOrder $payOrderModel;
|
|
|
|
/**
|
|
* @var RefundOrder
|
|
*/
|
|
#[Inject]
|
|
protected RefundOrder $refundOrderModel;
|
|
|
|
/**
|
|
* @var OrderGood
|
|
*/
|
|
#[Inject]
|
|
protected OrderGood $orderGoodModel;
|
|
|
|
/**
|
|
* @var OrderOptionCateringLog
|
|
*/
|
|
#[Inject]
|
|
protected OrderOptionCateringLog $orderOptionCateringLogModel;
|
|
|
|
/**
|
|
* @var OrderMealCateringLog
|
|
*/
|
|
#[Inject]
|
|
protected OrderMealCateringLog $orderMealCateringLogModel;
|
|
|
|
/**
|
|
* @return void
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
protected function checkOrder(): void
|
|
{
|
|
$this->orderInfo = $this->orderModel->getInfoByOrderSno($this->orderNo);
|
|
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderInfo->id,self::OrderType);
|
|
|
|
if (empty($this->orderInfo) || empty($this->payInfo)) {
|
|
$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
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
protected function manageOrder(): void
|
|
{
|
|
try {
|
|
$this->orderInfo->status = OrderCode::PAYED;
|
|
$this->orderInfo->pay_time = date('Y-m-d H:i:s');
|
|
|
|
}catch (Exception $e) {
|
|
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
|
throw new ErrException($e->getMessage());
|
|
}
|
|
}
|
|
} |