订单未支付取消时候才会退优惠券

This commit is contained in:
evoxwht 2023-03-27 17:13:25 +08:00
parent 7c6136e6aa
commit 01ca78ac7e
4 changed files with 24 additions and 36 deletions

View File

@ -430,6 +430,7 @@ class StoreOrderController
* 订单删除
* @param Request $request
* @return mixed
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function del(Request $request)
{

View File

@ -33,7 +33,7 @@ class UnpaidOrderCancelJob extends BaseJobs
public function doJob($orderId)
{
/** @var StoreOrderServices $services */
$services = app()->make(StoreOrderServices::class);
$services = app()->make(StoreOrderServices::class);
$orderInfo = $services->get($orderId);
if (!$orderInfo) {
return true;
@ -49,21 +49,21 @@ class UnpaidOrderCancelJob extends BaseJobs
}
/** @var StoreOrderCartInfoServices $cartServices */
$cartServices = app()->make(StoreOrderCartInfoServices::class);
$cartInfo = $cartServices->getOrderCartInfo($orderId);
$cartInfo = $cartServices->getOrderCartInfo($orderId);
/** @var StoreOrderRefundServices $refundServices */
$refundServices = app()->make(StoreOrderRefundServices::class);
try {
$res = $refundServices->transaction(function () use ($orderInfo, $refundServices) {
//回退积分和优惠卷
$refundServices->integralAndCouponBack($orderInfo);
$refundServices->integralAndCouponBack($orderInfo, 'cancel');
//回退库存和销量
$refundServices->regressionStock($orderInfo);
return true;
});
if ($res) {
$orderInfo->is_del = 1;
$orderInfo->mark = '订单未支付已超过系统预设时间';
$orderInfo->mark = '订单未支付已超过系统预设时间';
$orderInfo->save();
}
return $res;

View File

@ -426,25 +426,26 @@ class StoreOrderRefundServices extends BaseServices
/**
* 回退积分和优惠卷
* @param $order
* @param string $type
* @return bool
*/
public function integralAndCouponBack($order)
public function integralAndCouponBack($order, $type = 'refund')
{
/** @var StoreOrderStatusServices $statusService */
$statusService = app()->make(StoreOrderStatusServices::class);
$res = true;
// //回退优惠卷 拆分子订单不退优惠券
// if (!$order['pid'] && $order['coupon_id'] && $order['coupon_price']) {
// /** @var StoreCouponUserServices $couponUserServices */
// $couponUserServices = app()->make(StoreCouponUserServices::class);
// $res = $couponUserServices->recoverCoupon((int)$order['coupon_id']);
// $statusService->save([
// 'oid' => $order['id'],
// 'change_type' => 'coupon_back',
// 'change_message' => '商品退优惠券',
// 'change_time' => time()
// ]);
// }
//取消的订单退回优惠券
if ($type == 'cancel' && $order['coupon_id'] && $order['coupon_price']) {
/** @var StoreCouponUserServices $couponUserServices */
$couponUserServices = app()->make(StoreCouponUserServices::class);
$res = $couponUserServices->recoverCoupon((int)$order['coupon_id']);
$statusService->save([
'oid' => $order['id'],
'change_type' => 'coupon_back',
'change_message' => '商品退优惠券',
'change_time' => time()
]);
}
//回退积分
$order = $this->regressionIntegral($order);
$statusService->save([

View File

@ -1855,9 +1855,10 @@ HTML;
/**
* 删除订单
* @param $uni
* @param $uid
* @param string $uni
* @param int $uid
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function removeOrder(string $uni, int $uid)
{
@ -1879,21 +1880,6 @@ HTML;
'change_time' => time()
]);
if ($order->save() && $res) {
//未支付和已退款的状态下才可以退积分退库存退优惠券
if ($order['_status']['_type'] == 0 || $order['_status']['_type'] == -2) {
/** @var StoreOrderRefundServices $refundServices */
$refundServices = app()->make(StoreOrderRefundServices::class);
$this->transaction(function () use ($order, $refundServices) {
//回退积分和优惠卷
$res = $refundServices->integralAndCouponBack($order);
//回退库存
$res = $res && $refundServices->regressionStock($order);
if (!$res) {
throw new ApiException(100020);
}
});
}
return true;
} else
throw new ApiException(100020);
@ -1924,7 +1910,7 @@ HTML;
$refundServices = app()->make(StoreOrderRefundServices::class);
$this->transaction(function () use ($refundServices, $order) {
$res = $refundServices->integralAndCouponBack($order) && $refundServices->regressionStock($order);
$res = $refundServices->integralAndCouponBack($order, 'cancel') && $refundServices->regressionStock($order);
$order->is_del = 1;
if (!($res && $order->save())) {
throw new ApiException(100020);
@ -2136,7 +2122,7 @@ HTML;
try {
$this->transaction(function () use ($order, $refundServices) {
//回退积分和优惠卷
$res = $refundServices->integralAndCouponBack($order);
$res = $refundServices->integralAndCouponBack($order, 'cancel');
//回退库存和销量
$res = $res && $refundServices->regressionStock($order);
//修改订单状态