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

@@ -1,6 +1,6 @@
<?php
namespace App\Service\ServiceTrait;
namespace App\Service\ServiceTrait\Api;
use App\Cache\Redis\Api\SiteCache;
use App\Constants\Admin\CateringCode;

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Service\ServiceTrait\Api;
use App\Constants\Common\CouponCode;
use App\Constants\Common\OrderCode;
use App\Model\UserCoupon;
use Exception;
use Hyperf\Di\Annotation\Inject;
trait CouponTrait
{
/**
* @var UserCoupon
*/
#[Inject]
protected UserCoupon $userCouponModel;
/**
* @param $orderType
* @param $orderInfo
* @return void
* @throws Exception
*/
protected function rollbackCoupon($orderType,$orderInfo): void
{
if ($orderType != OrderCode::ORDER_TYPE_GOOD) return;
if ($orderInfo->coupon_id <= 0) return;
$couponInfo = $this->userCouponModel->where('coupon_id', $orderInfo->coupon_id)->where('user_id',$orderInfo->user_id)->first();
if (empty($couponInfo)) return;
$couponInfo->status = CouponCode::COUPON_STATUS_UNUSED;
if (date('Y-m-d H:i:s') > $couponInfo->validity_end_time) $couponInfo->status = CouponCode::COUPON_STATUS_EXPIRE;
if (!$couponInfo->save()) throw new Exception('CancelOrderConsumer:error:couponStatusUpdateError:'.json_encode($orderInfo->toArray()));
}
}

View File

@@ -102,11 +102,10 @@ trait OrderTrait
protected function checkGood(): void
{
foreach ($this->cartFirstData as $key => $one) {
if (!in_array($key, $this->goodIds)) throw new ErrException('商品不存在',ApiCode::ORDER_GOOD_IN_EXISTENCE);
if ($this->orderType == 0) $this->orderType = $this->skuArr[$key]['type'];
if ($this->skuArr[$key]['type'] != $this->orderType) throw new ErrException('自选菜品跟套餐菜品请分开订单下单');
if (in_array($key, $this->goodIds)) continue;
throw new ErrException('商品不存在',ApiCode::ORDER_GOOD_IN_EXISTENCE);
}
}
@@ -206,6 +205,7 @@ trait OrderTrait
$this->skuArr = array_column($skuArr,null,'id');
$this->skuImageArr = array_column($skuArr,null,'id');
$this->goodIds = array_column($skuArr,'id');
unset($skuArr);
}