feat : auto dispense coupon
This commit is contained in:
@@ -71,6 +71,12 @@ class DispenseAddService extends BaseService
|
||||
#[Inject]
|
||||
protected CouponTemplate $couponTemplateModel;
|
||||
|
||||
/**
|
||||
* @var Producer
|
||||
*/
|
||||
#[Inject]
|
||||
protected Producer $producer;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@@ -132,14 +138,7 @@ class DispenseAddService extends BaseService
|
||||
$this->addSubTableInformation($this->dispenseId);
|
||||
});
|
||||
|
||||
if ($this->claimRule == CouponCode::DISPENSE_CLAIM_RULE_POST_ACCOUNT) {
|
||||
//mq发放优惠券
|
||||
$message = new CouponAutoDispenseProducer([
|
||||
'coupon_dispense_id' => $this->dispenseId,
|
||||
]);
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$producer->produce($message);
|
||||
}
|
||||
$this->sendAutoMq();
|
||||
|
||||
return $this->return->success();
|
||||
}catch (Exception $e) {
|
||||
@@ -147,6 +146,28 @@ class DispenseAddService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function sendAutoMq(): void
|
||||
{
|
||||
if ($this->claimRule != CouponCode::DISPENSE_CLAIM_RULE_POST_ACCOUNT) return;
|
||||
|
||||
if (empty($this->userIds)) return;
|
||||
|
||||
foreach ($this->userIds as $userId) {
|
||||
//mq发放优惠券
|
||||
$message = new CouponAutoDispenseProducer([
|
||||
'coupon_dispense_id' => $this->dispenseId,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
// $producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$this->producer->produce($message);
|
||||
}
|
||||
|
||||
//todo 加一个缓存进度控制器 有没有必要
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $dispenseId
|
||||
* @return void
|
||||
|
||||
Reference in New Issue
Block a user