feat : check
This commit is contained in:
@@ -43,14 +43,13 @@ class CouponAutoDispenseConsumer extends ConsumerMessage
|
||||
$this->log->error('CouponAutoDispenseConsumer:error:NoData:'.json_encode($data));
|
||||
return Result::ACK;
|
||||
}
|
||||
$this->log->debug('data:'.json_encode($data));
|
||||
|
||||
try {
|
||||
$this->log->debug('data4:'.json_encode($data));
|
||||
$service = new AutoDispenseService();
|
||||
|
||||
$service->couponDispenseId = $data['coupon_dispense_id'];
|
||||
$service->userId = $data['user_id'];
|
||||
$this->log->debug('data2:'.json_encode($data));
|
||||
$service->couponDispenseId = (int)$data['coupon_dispense_id'];
|
||||
$service->userId = (int)$data['user_id'];
|
||||
|
||||
$service->handle();
|
||||
} catch (Exception $e) {
|
||||
$this->log->error('CouponAutoDispenseConsumer:error:'.$e->getMessage().':data:'.json_encode($data));
|
||||
|
||||
@@ -84,17 +84,12 @@ class AutoDispenseService
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->log->debug('data3:'.$this->couponDispenseId);
|
||||
$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')) {
|
||||
@@ -103,13 +98,9 @@ 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