541469799@qq.com 1 년 전
부모
커밋
04c4d8752e
2개의 변경된 파일30개의 추가작업 그리고 8개의 파일을 삭제
  1. 9 5
      app/index/controller/Cart.php
  2. 21 3
      app/index/view/cart/shoppingCart.html

+ 9 - 5
app/index/controller/Cart.php

@@ -50,7 +50,7 @@ class Cart extends Controller
             $cartMoney = bcadd($cartMoney, $temp, 2);
         }
 
-        return view('shoppingCart', ['list' => $list, 'cartTotal' => $cartTotal,'cartMoney'=>$cartMoney, 'points' => $user['points']]);
+        return view('shoppingCart', ['list' => $list, 'cartTotal' => $cartTotal, 'cartMoney' => $cartMoney, 'points' => $user['points']]);
     }
 
     /**
@@ -95,11 +95,11 @@ class Cart extends Controller
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function add(int $goodsId, string $goodsSkuId, int $goodsNum) :Json
+    public function add(int $goodsId, string $goodsSkuId, int $goodsNum): Json
     {
         $userId = Session::get('user_id');
         if (empty($userId)) {
-            return $this->renderJson( config('status.not_logged'),'Log in please!');
+            return $this->renderJson(config('status.not_logged'), 'Log in please!');
         }
 
         $model = new CartModel;
@@ -126,10 +126,10 @@ class Cart extends Controller
     {
         $userId = Session::get('user_id');
         if (empty($userId)) {
-            return $this->renderJson( config('status.not_logged'),'Log in please!');
+            return $this->renderJson(config('status.not_logged'), 'Log in please!');
         }
 
-        if ($goodsNum <= 0){
+        if ($goodsNum <= 0) {
             return $this->renderError('Action Not Supported!');
         }
 
@@ -151,6 +151,10 @@ class Cart extends Controller
      */
     public function clear(array $cartIds = []): Json
     {
+        $userId = Session::get('user_id');
+        if (empty($userId)) {
+            return $this->renderJson(config('status.not_logged'), 'Log in please!');
+        }
         $model = new CartModel;
         if (!$model->clear($cartIds)) {
             return $this->renderError($model->getError() ?: '操作失败');

+ 21 - 3
app/index/view/cart/shoppingCart.html

@@ -355,8 +355,16 @@
                         // "Access-Token": vapesToken
                     },
                     dataType: "json",
-                    success: function (response) {
-                        window.location.replace( '/index/cart/shoppingCart.html')
+                    success: function (obj) {
+                        if (obj.status === 200 || obj.status === '200') {
+                            showToast("Successful")
+                            window.location.href = '../cart/shoppingCart';
+                        }else if (obj.status === 401 || obj.status === '401'){
+                            window.location.replace('../passport/logIn.html')
+                        }else {
+                            showToast(obj.message)
+                        }
+                        //window.location.replace( '/index/cart/shoppingCart.html')
                     },
                     error: function (xhr, status, error) {
                         showToast("Please enter the quantity of products")
@@ -384,7 +392,17 @@
                     },
                     data: JSON.stringify(params),
                     dataType: "json",
-                    success: function (response) {
+                    success: function (obj) {
+                        if (obj.status === 200 || obj.status === '200') {
+                            showToast("Successful")
+                            window.location.href = '../cart/shoppingCart';
+                        }else if (obj.status === 401 || obj.status === '401'){
+                            window.location.replace('../passport/logIn.html')
+                        }else {
+                            showToast(obj.message)
+                        }
+                        return;
+
                         resolve(response);
                         window.location.href = "./shoppingCart.html"
                     },