Browse Source

再次修复优惠码bug

TheCGDF 5 years ago
parent
commit
cace167d52
2 changed files with 11 additions and 10 deletions
  1. 1 10
      resources/views/material/admin/coupon.tpl
  2. 10 0
      src/Controllers/UserController.php

+ 1 - 10
resources/views/material/admin/coupon.tpl

@@ -37,19 +37,10 @@
                         </div>
 
                         <div class="form-group form-group-label">
-                            <label class="floating-label" for="shop">优惠码每个用户可用次数</label>
+                            <label class="floating-label" for="shop">优惠码每个用户可用次数,-1为无限次</label>
                             <input class="form-control maxwidth-edit" id="count" type="number" value="1">
                         </div>
 
-                        <div class="form-group form-group-label">
-                            <div class="checkbox switch">
-                                <label for="onetime">
-                                    <input class="access-hide" id="onetime" type="checkbox"><span
-                                            class="switch-toggle"></span>一次性的,只在用户当次购买时有效
-                                </label>
-                            </div>
-                        </div>
-
                         <div class="form-group form-group-label">
                             <label for="generate-type">
                                 <label class="floating-label" for="sort">选择生成方式</label>

+ 10 - 0
src/Controllers/UserController.php

@@ -845,6 +845,16 @@ class UserController extends BaseController
                 $res['msg'] = '此优惠码已过期';
                 return $response->getBody()->write(json_encode($res));
             }
+
+            $use_limit = $coupon->onetime;
+            if ($use_limit > 0) {
+                $use_count = Bought::where('userid', $user->id)->where('coupon', $coupon->code)->count();
+                if ($use_count >= $use_limit) {
+                    $res['ret'] = 0;
+                    $res['msg'] = '优惠码次数已用完';
+                    return $response->getBody()->write(json_encode($res));
+                }
+            }
         }
 
         $price = $shop->price * ((100 - $credit) / 100);