|
|
@@ -948,6 +948,25 @@ class UserController extends Controller
|
|
|
return Response::json(['status' => 'fail', 'data' => '', 'message' => '支付失败:您的余额不足,请先充值']);
|
|
|
}
|
|
|
|
|
|
+ // 验证账号是否存在有效期更长的套餐
|
|
|
+ if ($goods->type == 2) {
|
|
|
+ $existOrderList = Order::query()
|
|
|
+ ->with(['goods'])
|
|
|
+ ->whereHas('goods', function ($q) {
|
|
|
+ $q->where('type', 2);
|
|
|
+ })
|
|
|
+ ->where('user_id', $user['id'])
|
|
|
+ ->where('is_expire', 0)
|
|
|
+ ->where('status', 2)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ foreach ($existOrderList as $vo) {
|
|
|
+ if ($vo->goods->days > $goods->days) {
|
|
|
+ return Response::json(['status' => 'fail', 'data' => '', 'message' => '支付失败:您已存在有效期更长的套餐,只能购买流量包']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
// 生成订单
|
|
|
@@ -981,14 +1000,28 @@ class UserController extends Controller
|
|
|
$this->addCouponLog($coupon->id, $goods_id, $order->oid, '余额支付订单使用');
|
|
|
}
|
|
|
|
|
|
- // 如果买的是套餐,则先将之前购买的所有套餐置都无效,并扣掉之前所有套餐的流量,并移除之前所有套餐的标签
|
|
|
- if ($goods->type === 2) {
|
|
|
- $existOrderList = Order::query()->with('goods')->whereHas('goods', function ($q) {
|
|
|
- $q->where('type', 2);
|
|
|
- })->where('user_id', $user->id)->where('oid', '<>', $order->oid)->where('is_expire', 0)->where('status', 2)->get();
|
|
|
+ // 如果买的是套餐,则先将之前购买的所有套餐置都无效,并扣掉之前所有套餐的流量,重置用户已用流量为0
|
|
|
+ if ($goods->type == 2) {
|
|
|
+ $existOrderList = Order::query()
|
|
|
+ ->with(['goods'])
|
|
|
+ ->whereHas('goods', function ($q) {
|
|
|
+ $q->where('type', 2);
|
|
|
+ })
|
|
|
+ ->where('user_id', $order->user_id)
|
|
|
+ ->where('oid', '<>', $order->oid)
|
|
|
+ ->where('is_expire', 0)
|
|
|
+ ->where('status', 2)
|
|
|
+ ->get();
|
|
|
+
|
|
|
foreach ($existOrderList as $vo) {
|
|
|
Order::query()->where('oid', $vo->oid)->update(['is_expire' => 1]);
|
|
|
- User::query()->where('id', $user->id)->decrement('transfer_enable', $vo->goods->traffic * 1048576);
|
|
|
+ // 先判断,防止手动扣减过流量的用户流量被扣成负数
|
|
|
+ if ($order->user->transfer_enable - $vo->goods->traffic * 1048576 <= 0) {
|
|
|
+ User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0, 'transfer_enable' => 0]);
|
|
|
+ } else {
|
|
|
+ User::query()->where('id', $order->user_id)->update(['u' => 0, 'd' => 0]);
|
|
|
+ User::query()->where('id', $order->user_id)->decrement('transfer_enable', $vo->goods->traffic * 1048576);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|