feat : check
This commit is contained in:
@@ -43,7 +43,7 @@ class CouponAutoDispenseConsumer extends ConsumerMessage
|
|||||||
$this->log->error('CouponAutoDispenseConsumer:error:NoData:'.json_encode($data));
|
$this->log->error('CouponAutoDispenseConsumer:error:NoData:'.json_encode($data));
|
||||||
return Result::ACK;
|
return Result::ACK;
|
||||||
}
|
}
|
||||||
$this->log->debug('data:'.json_encode($data));
|
// $this->log->debug('data:'.json_encode($data));
|
||||||
try {
|
try {
|
||||||
$service = new AutoDispenseService();
|
$service = new AutoDispenseService();
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ class WxSubMessageConsumer extends ConsumerMessage
|
|||||||
return Result::ACK;
|
return Result::ACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->log->debug('WxSubMessageConsumer:'.json_encode($data));
|
||||||
|
|
||||||
$openId = $this->userThirdModel->where('user_id',$data['user_id'])->where('type',ThirdCode::WX_LOGIN)->value('open_id') ?? null;
|
$openId = $this->userThirdModel->where('user_id',$data['user_id'])->where('type',ThirdCode::WX_LOGIN)->value('open_id') ?? null;
|
||||||
if (empty($openId)) {
|
if (empty($openId)) {
|
||||||
$this->log->error('WxSubMessageConsumer:error:NoOpenId:'.json_encode($data));
|
$this->log->error('WxSubMessageConsumer:error:NoOpenId:'.json_encode($data));
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace App\Service\Amqp\Coupon;
|
|||||||
use App\Amqp\Producer\WxSubMessageProducer;
|
use App\Amqp\Producer\WxSubMessageProducer;
|
||||||
use App\Constants\Common\CouponCode;
|
use App\Constants\Common\CouponCode;
|
||||||
use App\Constants\Common\WxMiniCode;
|
use App\Constants\Common\WxMiniCode;
|
||||||
|
use App\Lib\Log;
|
||||||
use App\Model\CouponDispenseLog;
|
use App\Model\CouponDispenseLog;
|
||||||
use App\Model\CouponDispenseUser;
|
use App\Model\CouponDispenseUser;
|
||||||
use App\Model\CouponTemplate;
|
use App\Model\CouponTemplate;
|
||||||
@@ -57,6 +58,12 @@ class AutoDispenseService
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected Producer $producer;
|
protected Producer $producer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Log
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Log $log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
@@ -69,15 +76,20 @@ class AutoDispenseService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$dispenseInfo = $this->couponDispenseLogModel->getInfoById($this->couponDispenseId);
|
$dispenseInfo = $this->couponDispenseLogModel->getInfoById($this->couponDispenseId);
|
||||||
if (empty($dispenseInfo)) throw new Exception('分发记录不存在');
|
if (empty($dispenseInfo)) throw new Exception('分发记录不存在');
|
||||||
|
|
||||||
|
$this->log->debug(json_encode($dispenseInfo->toArray()));
|
||||||
|
|
||||||
$templateInfo = $this->couponTemplateModel->getInfoById($dispenseInfo->coupon_template_id);
|
$templateInfo = $this->couponTemplateModel->getInfoById($dispenseInfo->coupon_template_id);
|
||||||
if (empty($templateInfo)) throw new Exception('优惠券模板不存在');
|
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);
|
$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')) {
|
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('该分发逻辑已失效');
|
throw new Exception('该分发逻辑已失效');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->log->debug(json_encode($validityTime));
|
||||||
|
|
||||||
$userDispenseInfo = $this->couponDispenseUserModel->getInfoByDispenseIdAndUserId($this->couponDispenseId,$this->userId);
|
$userDispenseInfo = $this->couponDispenseUserModel->getInfoByDispenseIdAndUserId($this->couponDispenseId,$this->userId);
|
||||||
if (empty($userDispenseInfo)) throw new Exception('该用户不属于该分发逻辑');
|
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;
|
$userCount = $this->userCouponModel->where('coupon_dispense_id',$this->couponDispenseId)->where('user_id',$this->userId)->count() ?? 0;
|
||||||
if ($userCount >= $dispenseInfo->item_count) throw new Exception('该用户该分发逻辑已分发完毕');
|
if ($userCount >= $dispenseInfo->item_count) throw new Exception('该用户该分发逻辑已分发完毕');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user