feat : ide config
This commit is contained in:
41
app/Service/ServiceTrait/Api/CouponTrait.php
Normal file
41
app/Service/ServiceTrait/Api/CouponTrait.php
Normal 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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user