feat : ide config

This commit is contained in:
2025-03-17 17:29:51 +08:00
parent 4758aa598d
commit 9e22529161
14 changed files with 259 additions and 52 deletions

View File

@@ -79,6 +79,8 @@ class PlaceOrderService extends BaseOrderService
$this->sendStockMq($this->orderId,OrderCode::WAIT_PAY);
$this->orderRes['order_id'] = $this->orderId;
return $this->return->success('success',$this->orderRes);
}
@@ -195,7 +197,7 @@ class PlaceOrderService extends BaseOrderService
$orderInsertModel->copies = $this->orderRes['copies'];
$orderInsertModel->type = $this->orderType;
$orderInsertModel->total_price = $this->orderRes['total_price'];
$orderInsertModel->actual_price = $this->orderRes['actual_price'];
$orderInsertModel->actual_price = max($this->orderRes['actual_price'], 0);
$orderInsertModel->discount_price = $this->orderRes['favorable_sundry_price'] + $this->orderRes['favorable_good_price'];
$orderInsertModel->status = OrderCode::WAIT_PAY;
$orderInsertModel->is_refund_all = OrderCode::REFUND_NULL;

View File

@@ -15,11 +15,18 @@ use App\Cache\Redis\RedisCache;
use App\Constants\Common\OrderCode;
use App\Constants\Common\PayCode;
use App\Exception\ErrException;
use App\Extend\SystemUtil;
use App\Model\Order;
use App\Model\PayOrder;
use App\Model\UserThird;
use App\Service\Api\BaseService;
use App\Service\Common\Pay\Wx\WxJsRechargeOrderService;
use App\Service\ServiceTrait\Api\CateringTrait;
use App\Service\ServiceTrait\Api\CouponTrait;
use App\Service\ServiceTrait\Api\GoodOrderTrait;
use App\Service\ServiceTrait\Api\RefundOrderTrait;
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@@ -44,17 +51,18 @@ class PlacePayService extends BaseService
/**
* @var Order
*/
private Order $orderModel;
#[Inject]
protected Order $orderModel;
/**
* @var mixed
*/
private mixed $orderInfo;
private Order $orderInfo;
/**
* @var mixed
*/
private mixed $payInfo;
private PayOrder $payInfo;
/**
* @var string
@@ -91,10 +99,15 @@ class PlacePayService extends BaseService
$this->orderType = (int)$this->request->input('order_type');
$this->payType = (int)$this->request->input('pay_type');
$this->orderModel = (new OrderTypeFactory)->getPayOrderModel($this->payType);
$this->orderModel = (new OrderTypeFactory)->getPayOrderModel($this->orderType);
$this->checkOrder();
//小于等于 0 直接支付
if ($this->orderInfo->actual_price <= 0) return $this->directPayment();
$this->checkPayOrder();
$this->setPayInfo();
$rechargeService = match ($this->payType)
@@ -106,17 +119,22 @@ class PlacePayService extends BaseService
$rechargeService->setConfig();
$rechargeService->setNotify();
// 测试环境 0.01
if (!SystemUtil::checkProEnv() && $this->orderInfo->actual_price > 0) $this->orderInfo->actual_price = '0.01';
$payData = $rechargeService->pay(
(float)$this->orderInfo->actual_price,
$this->request->input('body','订单支付'),
$this->orderInfo->order_no,
// $this->request->input('body','订单支付'),
$this->orderInfo->id,
$this->orderInfo->order_sno,
$this->userId
);
$res = [
'orderId' => $this->orderId,
'wechat_pay' => [],
'alipay' => []
'alipay' => [],
'status' => $this->orderInfo->status
];
//返回支付数组
@@ -130,6 +148,62 @@ class PlacePayService extends BaseService
return $this->return->success('success', $res);
}
use GoodOrderTrait;
use CateringTrait;
use OrderChangeStatusTrait;
private bool $isCatering;
private function directPayment(): array
{
switch ($this->orderType) {
case OrderCode::ORDER_TYPE_GOOD:
Db::transaction(function (){
$this->manageOrder();
$this->isCatering = $this->manageAddCateringLog();
});
//已经截单 自动退款
if (!$this->isCatering) $this->directGoodRefund();
break;
case OrderCode::ORDER_TYPE_BALANCE:
echo 1;
break;
default:
throw new ErrException('订单类型错误');
}
$res = [
'orderId' => $this->orderId,
'wechat_pay' => [],
'alipay' => [],
'status' => $this->orderInfo->status
];
$this->redisCache->delLock($this->lockKey);
return $this->return->success('success', $res);
}
use RefundOrderTrait;
use CouponTrait;
/**
* @return void
*/
private function directGoodRefund(): void
{
Db::transaction(function (){
// $this->manageRefundOrder();
$this->manageOrderByRefund();
$this->manageSubCateringLog();
if ($this->orderInfo->coupin_id > 0) $this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$this->orderInfo);
});
}
private function setAliPayOrder(): null
{
return null;
@@ -176,7 +250,7 @@ class PlacePayService extends BaseService
$this->payInfo->user_id = $this->userId;
$this->payInfo->order_id = $this->orderId;
$this->payInfo->order_type = $this->orderType;
$this->payInfo->order_no = $this->orderInfo->order_no;
$this->payInfo->order_no = $this->orderInfo->order_sno;
$this->payInfo->pay_money = $this->orderInfo->actual_price;
$this->payInfo->recharge_type = $this->payType;
$this->payInfo->status = PayCode::WAIT_PAY;
@@ -195,7 +269,13 @@ class PlacePayService extends BaseService
if (empty($this->orderInfo)) throw new ErrException('该订单为空');
if ($this->orderInfo->user_id != $this->userId) throw new ErrException('该订单不属于你');
if ($this->orderInfo->status != OrderCode::WAIT_PAY) throw new ErrException('该订单已支付或已取消,请确认后重试');
}
/**
* @return void
*/
private function checkPayOrder(): void
{
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderId,$this->orderType);
if (empty($this->payInfo)) return;
if ($this->payInfo->status == PayCode::FINISH_PAY) throw new ErrException('该订单已支付,请确认后重试');