From 37257a2d9a88a736b9ac4c5830026836a53a0eda Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 12 May 2023 20:41:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=8D=B7=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/Coupon.php | 23 +++++++++++++++++++++++ app/Services/CouponService.php | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/app/Model/Coupon.php b/app/Model/Coupon.php index 717bb83..d4f464b 100644 --- a/app/Model/Coupon.php +++ b/app/Model/Coupon.php @@ -74,4 +74,27 @@ class Coupon extends Model return self::where($params)->get($fields); } + /** + * 自增 + * @param array $params + * @param string $field + * @param float $numeral + * @return int + */ + public static function inc(array $params,string $field,float $numeral = 1): int + { + return self::where($params)->increment($field,$numeral); + } + + /** + * 自减 + * @param array $params + * @param string $field + * @param float $numeral + * @return int + */ + public static function dec(array $params,string $field,float $numeral = 1): int + { + return self::where($params)->decrement($field,$numeral); + } } diff --git a/app/Services/CouponService.php b/app/Services/CouponService.php index 69e04d0..e3f7efa 100644 --- a/app/Services/CouponService.php +++ b/app/Services/CouponService.php @@ -130,6 +130,11 @@ class CouponService extends BaseService return false; } + // 增加优惠卷发放数量 + $params = array(); + $params['coupon_id'] = $value['coupon_id']; + Coupon::inc($params,'coupon_take_count'); + // 添加弹窗表 $data = array(); $data['user_id'] = $user_id;