简化了患者端药品微信支付回调的再次发放优惠卷的方法调用、增加了发放优惠卷时数量的判断、增加了再次发放订单优惠卷的方法
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Model\Coupon;
|
||||
use App\Model\CouponGrant;
|
||||
use App\Services\CouponService;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
@@ -17,7 +18,7 @@ use Hyperf\DbConnection\Db;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
/**
|
||||
* 再次发放用户优惠卷
|
||||
* 发放用户优惠卷
|
||||
*/
|
||||
#[Consumer(nums: 1)]
|
||||
class GrantUserCouponDelayDirectConsumer extends ConsumerMessage
|
||||
@@ -37,20 +38,28 @@ class GrantUserCouponDelayDirectConsumer extends ConsumerMessage
|
||||
{
|
||||
Log::getInstance("queue-GrantUserCoupon")->info("开始执行 延迟发放用户优惠卷 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// 获取优惠卷数据
|
||||
$params = array();
|
||||
$params['coupon_id'] = $data["coupon_id"];
|
||||
$coupon = Coupon::getOne($params);
|
||||
if (empty($coupon)){
|
||||
Log::getInstance("queue-GrantUserCoupon")->error("无优惠卷数据");
|
||||
// 检测入参参数
|
||||
if (empty($data['coupon_id'])) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-GrantUserCoupon")->error("参数错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
if (empty($data['user_id'])) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-GrantUserCoupon")->error("参数错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
$grant_quantity = 1;
|
||||
if (!empty($data['grant_quantity'])) {
|
||||
$grant_quantity = $data['grant_quantity'];
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$couponService = new CouponService();
|
||||
$res = $couponService->GrantUserCoupon($data["coupon_id"],$data['user_id']);
|
||||
$res = $couponService->GrantUserCoupon($data["coupon_id"],$data['user_id'],$grant_quantity);
|
||||
if (!$res){
|
||||
// 发放失败
|
||||
Db::rollBack();
|
||||
|
||||
Reference in New Issue
Block a user