From cc5cc8cf6192390d3af219620bf3e18be28785d0 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Thu, 21 Mar 2024 00:22:18 +0800 Subject: [PATCH] 1 --- addons/shopro/controller/user/Coupon.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/shopro/controller/user/Coupon.php b/addons/shopro/controller/user/Coupon.php index 522ce3e..a16f1c4 100755 --- a/addons/shopro/controller/user/Coupon.php +++ b/addons/shopro/controller/user/Coupon.php @@ -2,13 +2,16 @@ namespace addons\shopro\controller\user; +use addons\shopro\traits\CouponSend; +use app\admin\model\shopro\user\User; +use think\Db; use think\helper\Str; use addons\shopro\controller\Common; use app\admin\model\shopro\user\Coupon as UserCouponModel; class Coupon extends Common { - + use CouponSend; protected $noNeedLogin = []; protected $noNeedRight = ['*']; @@ -27,4 +30,21 @@ class Coupon extends Common $this->success('获取成功', $userCoupons); } + + /** + * 领取优惠券 + */ + public function ling() { + $user = auth_user(); + $user_id = $user->id; + $coupon_id = $this->request->param('coupon_id'); + + $users = User::whereIn('id', $user_id)->select(); + + Db::transaction(function () use ($users, $coupon_id) { + $this->manualSend($users, $coupon_id); + }); + + $this->success('领取成功'); + } }