zhangdehua пре 1 година
родитељ
комит
f360a14099

+ 10 - 6
app/index/controller/Passport.php

@@ -13,9 +13,7 @@ declare (strict_types=1);
 namespace app\index\controller;
 
 use app\api\service\passport\Login as LoginService;
-use think\facade\Cookie;
 use think\facade\Session;
-use think\response\Redirect;
 
 /**
  * 用户认证模块
@@ -50,14 +48,20 @@ class Passport extends Controller
         Session::set('access_token',$token);
         Session::set('user_id',$userInfo['user_id']);
 
-//        $indexContr = new Index($this->app);
-//        return $indexContr->index();
-//        $url = url('index/index/index');
-
         return $this->renderSuccess([
             'userId' => (int)$userInfo['user_id'],
             'token' => $LoginService->getToken((int)$userInfo['user_id'])
         ], '登录成功');
     }
 
+    /**
+     * 退出登录
+     * @return \think\response\View
+     */
+    public function logout()
+    {
+        Session::clear();
+        return view('logIn');
+    }
+
 }

+ 15 - 18
app/index/view/cart/shoppingCart.html

@@ -373,7 +373,11 @@
             postalCode: "{$zipCode}"
         }
         // 是否已填写过地址
-        let isAddress = true
+        if (addressId){
+            var isAddress = true
+        }else {
+            var isAddress = false
+        }
 
         //初始化地址模块标签显示隐藏
         function initAddressLabel() {
@@ -522,7 +526,7 @@
             console.log(params)
             return new Promise(function (resolve, reject) {
                 $.ajax({
-                    url: "/index/checkout/submit?payType=30&mode=cart&address_id=2",
+                    url: "/index/checkout/submit?payType=30&mode=cart&address_id=" + addressId,
                     method: "POST",
                     data: JSON.stringify(params),
                     headers: {
@@ -546,7 +550,7 @@
             console.log(params)
             return new Promise(function (resolve, reject) {
                 $.ajax({
-                    url: "/index/checkout/submit?payType=50&mode=cart&address_id=2",
+                    url: "/index/checkout/submit?payType=50&mode=cart&address_id=" + addressId,
                     method: "POST",
                     data: JSON.stringify(params),
                     headers: {
@@ -645,36 +649,33 @@
                         } else {
                             showToast(obj.message)
                         }
-                        return;
-
-                        resolve(response);
-                        window.location.href = "./shoppingCart.html"
                     },
                     error: function (xhr, status, error) {
                         reject(error);
                     }
                 });
-                return
             }
         }
 
         //支付
         $(".payPalButton").on(tap, async function () {
             console.log("paypaing")
-            let addressId
             $("#loadingModel").show(0)
             // 支付之前先判断是否有默认地址
-            if (!isAddress) {
+            if (!addressId) {
+                showToast('No address')
+                return
+
                 // 先添加地址
-                const res = await addAddress()
-                addressId = res
+                // const res = await addAddress()
+                // addressId = res
             }
 
 
             const params = {
                 //"cartIds": "10002",
                 "delivery": 10,
-                "address_id": 2
+                "address_id": addressId
             }
             console.log(params)
             const res = await orderPayment(params)
@@ -694,7 +695,7 @@
             console.log("points")
             const params = {
                 "delivery": 10,
-                "address_id": 2
+                "address_id": addressId
             }
             $("#loadingModel").show(0)
             const res = await orderPaymentPoints(params)
@@ -735,10 +736,6 @@
         //前往购物车
         $(".shoppingCartIcon").on(tap, function () {
             window.location.href = "./shoppingCart.html"
-
-            // const state = isLogin()
-            // if (state) {
-            // }
         });
     })
 </script>

+ 13 - 38
app/index/view/index/productDetails.html

@@ -51,9 +51,9 @@
                 </div>
             </a>
             <!-- 收藏 -->
-<!--            <div class="headIconItem collectIcon">-->
-<!--                <img src="/assets/index/asstes/icon/collect.png" alt="collect" tabindex="collect">-->
-<!--            </div>-->
+            <!--            <div class="headIconItem collectIcon">-->
+            <!--                <img src="/assets/index/asstes/icon/collect.png" alt="collect" tabindex="collect">-->
+            <!--            </div>-->
             <!-- 个人中心 -->
 
             <a href="/index/user/order.html">
@@ -97,9 +97,9 @@
             <a href="/index/cart/shoppingCart.html">
                 <h2 class="menuItemTitle shoppingCartIcon">Shopping Cart</h2>
             </a>
-<!--            <div class="mobileMenuItem">-->
-<!--                <h2 class="menuItemTitle collectIcon">Collect</h2>-->
-<!--            </div>-->
+            <!--            <div class="mobileMenuItem">-->
+            <!--                <h2 class="menuItemTitle collectIcon">Collect</h2>-->
+            <!--            </div>-->
             <div class="mobileMenuItem">
                 <a href="/index/user/personal.html">
                     <h2 class="menuItemTitle userIcon">Personal</h2>
@@ -310,11 +310,6 @@
         //触屏事件 || 点击事件
         const tap = "ontouchstart" in window ? "touchstart" : "click";
 
-        //用户存储token名
-        const VAPES_TOKEN = "PHPSESSID"
-
-        var vapesToken = '';
-
         var goodsId = {$goods.goods_id};
         var goodsSkuId = {$goods['skuList'][0]['goods_sku_id']};
 
@@ -324,20 +319,6 @@
         }
 
         /**
-         * 登录校验点击
-         * @param state 是否需要跳转登录页
-         * @returns
-         */
-        const isLogin = (state) => {
-            vapesToken = sessionStorage.getItem(VAPES_TOKEN);
-            state = state || true;
-            if (!vapesToken || vapesToken === 'undefined' || vapesToken === "" && state) {
-                window.location.href = "../passport/login.html?return=1"
-            }
-            return vapesToken && vapesToken !== "";
-        }
-
-        /**
          * 添加购物车
          * @param number 数量
          * @returns
@@ -354,7 +335,7 @@
             }
             $.ajax({
                 url: "/index/cart/add",
-                headers: {platform: 'H5', "Access-Token": vapesToken},
+                headers: {platform: 'H5'},
                 dataType: 'json',
                 data: JSON.stringify(dp),
                 type: "POST",
@@ -365,9 +346,9 @@
                         showToast("Successful")
                         window.location.href = '/index/cart/shoppingCart.html';
                         return
-                    }else if (obj.status === 401 || obj.status === '401'){
+                    } else if (obj.status === 401 || obj.status === '401') {
                         window.location.replace('../passport/logIn.html')
-                    }else {
+                    } else {
                         showToast(obj.message)
                     }
                 }
@@ -421,20 +402,14 @@
 
         //上面的添加按钮
         $(".addToCart").on(tap, function () {
-            const state = isLogin()
-            if (state) {
-                const number = $('#numberInput').val();
-                addCart(number)
-            }
+            const number = $('#numberInput').val();
+            addCart(number)
         });
 
         //悬浮模块的添加按钮
         $(".fPrAddToCart").on(tap, function () {
-            const state = isLogin()
-            if (state) {
-                const number = $('#fPrNumberInput').val();
-                addCart(number)
-            }
+            const number = $('#fPrNumberInput').val();
+            addCart(number)
         });
         initRichText()
     });