| xqd
@@ -15,7 +15,7 @@ class CouponController extends AuthController
|
|
|
{
|
|
|
public function couponList()
|
|
|
{
|
|
|
- $data = Coupon::orderBy('id', 'desc')->paginate();
|
|
|
+ $data = Coupon::where('position_type', 1)->where('num', '>', 0)->orderBy('id', 'desc')->paginate();
|
|
|
|
|
|
return out($data);
|
|
|
}
|
| xqd
@@ -28,8 +28,16 @@ class CouponController extends AuthController
|
|
|
]);
|
|
|
$user = $this->user;
|
|
|
|
|
|
+ $coupon = Coupon::select(['num', 'position_type'])->where('id', $req['coupon_id'])->first();
|
|
|
+ if ($coupon['num'] <= 0) {
|
|
|
+ return out(null, 10001, '该优惠券数量不足');
|
|
|
+ }
|
|
|
+ if ($coupon['position_type'] == 2) {
|
|
|
+ return out(null, 10002, '该优惠券不能领取');
|
|
|
+ }
|
|
|
+
|
|
|
if (UserCoupon::where('user_id', $user['id'])->where('coupon_id', $req['coupon_id'])->exists()) {
|
|
|
- return out(null, 10001, '您已经领取过该优惠券了');
|
|
|
+ return out(null, 10003, '您已经领取过该优惠券了');
|
|
|
}
|
|
|
|
|
|
$add = Coupon::select(['id as coupon_id', 'name', 'title', 'desc', 'rules', 'icon', 'type', 'usable_type', 'money', 'discount', 'min_consume_amount', 'max_reduce_amount', 'expire_type', 'effective_days', 'start_time', 'end_time'])->where('id', $req['coupon_id'])->first()->getOriginal();
|
| xqd
@@ -41,6 +49,8 @@ class CouponController extends AuthController
|
|
|
$add['expire_time'] = $expire_time;
|
|
|
UserCoupon::create($add);
|
|
|
|
|
|
+ Coupon::where('id', $req['coupon_id'])->decrement('num');
|
|
|
+
|
|
|
return out();
|
|
|
}
|
|
|
|