feat : check
This commit is contained in:
@@ -13,6 +13,7 @@ namespace App\Service\Amqp\Coupon;
|
||||
use App\Amqp\Producer\WxSubMessageProducer;
|
||||
use App\Constants\Common\CouponCode;
|
||||
use App\Constants\Common\WxMiniCode;
|
||||
use App\Lib\Log;
|
||||
use App\Model\CouponDispenseLog;
|
||||
use App\Model\CouponDispenseUser;
|
||||
use App\Model\CouponTemplate;
|
||||
@@ -57,6 +58,12 @@ class AutoDispenseService
|
||||
#[Inject]
|
||||
protected Producer $producer;
|
||||
|
||||
/**
|
||||
* @var Log
|
||||
*/
|
||||
#[Inject]
|
||||
protected Log $log;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@@ -69,15 +76,20 @@ class AutoDispenseService
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$dispenseInfo = $this->couponDispenseLogModel->getInfoById($this->couponDispenseId);
|
||||
if (empty($dispenseInfo)) throw new Exception('分发记录不存在');
|
||||
|
||||
$this->log->debug(json_encode($dispenseInfo->toArray()));
|
||||
|
||||
$templateInfo = $this->couponTemplateModel->getInfoById($dispenseInfo->coupon_template_id);
|
||||
if (empty($templateInfo)) throw new Exception('优惠券模板不存在');
|
||||
|
||||
$this->log->debug(json_encode($templateInfo->toArray()));
|
||||
|
||||
$validityTime = $this->getValidityTime((int)$dispenseInfo->validity_time_type, $dispenseInfo->validity_time_value);
|
||||
//有效期不存在或者到期销毁当前分发逻辑
|
||||
if (empty($validityTime) || empty($validityTime['start_time']) || empty($validityTime['end_time']) || $validityTime['end_time'] < date('Y-m-d H:i:s')) {
|
||||
@@ -86,9 +98,13 @@ class AutoDispenseService
|
||||
throw new Exception('该分发逻辑已失效');
|
||||
}
|
||||
|
||||
$this->log->debug(json_encode($validityTime));
|
||||
|
||||
$userDispenseInfo = $this->couponDispenseUserModel->getInfoByDispenseIdAndUserId($this->couponDispenseId,$this->userId);
|
||||
if (empty($userDispenseInfo)) throw new Exception('该用户不属于该分发逻辑');
|
||||
|
||||
$this->log->debug(json_encode($userDispenseInfo));
|
||||
|
||||
$userCount = $this->userCouponModel->where('coupon_dispense_id',$this->couponDispenseId)->where('user_id',$this->userId)->count() ?? 0;
|
||||
if ($userCount >= $dispenseInfo->item_count) throw new Exception('该用户该分发逻辑已分发完毕');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user