Ver Fonte

订单地址的bug

zhangdehua há 1 ano atrás
pai
commit
95e4eb26d3
2 ficheiros alterados com 39 adições e 19 exclusões
  1. 12 4
      app/index/controller/Cart.php
  2. 27 15
      app/index/view/cart/shoppingCart.html

+ 12 - 4
app/index/controller/Cart.php

@@ -53,7 +53,14 @@ class Cart extends Controller
             $temp = bcmul(strval($item['goods_num']), $item['goods']['goods_price_min'], 2);
             $cartMoney = bcadd($cartMoney, $temp, 2);
         }
-        $res = ['list' => $list, 'cartTotal' => $cartTotal, 'cartMoney' => $cartMoney, 'points' => $user['points']];
+
+        $payPoints = intval(bcmul($cartMoney, '100', 0));//订单所需积分
+        $payByPoints = false;
+        if (intval($user['points']) >= $payPoints) {
+            $payByPoints = true;
+        }
+
+        $res = ['list' => $list, 'cartTotal' => $cartTotal, 'cartMoney' => $cartMoney, 'points' => $user['points'], 'payByPoints' => $payByPoints];
         $res['address_id'] = 0;
         $res['full'] = '';
         $res['zip_code'] = '';
@@ -63,21 +70,22 @@ class Cart extends Controller
         $res['email'] = '';
 
         $regList = RegionModel::getCacheAll();
-        $states50 = array_slice($regList,2);
+        $states50 = array_slice($regList, 2);
         $res['states50'] = $states50;
 
         if (!empty($user['address_id'])) {
             $addr = UserAddress::detail($user['address_id']);
-            if ($addr){
+            if ($addr) {
                 $res['addressId'] = $addr['address_id'];
                 $res['full'] = $addr['detail'] . ',' . $addr['region']['region'] . '(' . $addr['zip_code'] . '),US';
                 $res['zipCode'] = $addr['zip_code'];
                 $res['name'] = $addr['name'];
                 $res['lastName'] = $addr['last_name'];
-                $res['fullName'] = $addr['name'].' '.$addr['last_name'];
+                $res['fullName'] = $addr['name'] . ' ' . $addr['last_name'];
                 $res['phone'] = $addr['phone'];
                 $res['email'] = $addr['email'];
                 $res['regionId'] = $addr['region_id'];
+                $res['detail'] = $addr['detail'];
             }
         }
 

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

@@ -239,6 +239,16 @@
                     <p class="totalT">Total</p>
                     <p class="totalVal">${$cartMoney}</p>
                 </div>
+                <div class="mbItem">
+                    <div class="windInfoBox freeshipping">
+                        {if $payByPoints}
+                        <p class="key">You can redeem this order for free through points!</p>
+                        {/if}
+                    </div>
+                    <div class="windInfoBox">
+                        <p class="key">Your Points:{$points}</p>
+                    </div>
+                </div>
                 <div class="payPalButton">
                     <span>PayPal</span>
                 </div>
@@ -359,8 +369,9 @@
 <script src="/assets/index/js/jquery.lazyload.js"></script>
 <script>
     $(document).ready(function () {
-
         var addressId = {$addressId};
+        var payByPoints = "{$payByPoints}";
+        //console.log(payByPoints, payByPoints)
 
         //默认地址
         const defaultAddressInfo = {
@@ -368,14 +379,14 @@
             lastName: "{$lastName}",
             phoneNumber: "{$phone}",
             areaSelect: "{$regionId}",
-            address: "{$full}",
+            address: "{$detail}",
             mailbox: "{$email}",
             postalCode: "{$zipCode}"
         }
         // 是否已填写过地址
-        if (addressId){
+        if (addressId) {
             var isAddress = true
-        }else {
+        } else {
             var isAddress = false
         }
 
@@ -393,7 +404,7 @@
 
         //初始化表单
         function initAddressForm() {
-            const {userName, lastName,phoneNumber, areaSelect, address, mailbox, postalCode} = defaultAddressInfo || {}
+            const {userName, lastName, phoneNumber, areaSelect, address, mailbox, postalCode} = defaultAddressInfo || {}
             userName && $("#userName").val(userName)
             lastName && $("#lastName").val(lastName)
             phoneNumber && $("#phoneNumber").val(phoneNumber)
@@ -518,7 +529,6 @@
 
         //支付方法
         const orderPayment = (params) => {
-            console.log(params)
             return new Promise(function (resolve, reject) {
                 $.ajax({
                     url: "/index/checkout/submit?payType=30&mode=cart&address_id=" + addressId,
@@ -542,7 +552,6 @@
         }
 
         const orderPaymentPoints = (params) => {
-            console.log(params)
             return new Promise(function (resolve, reject) {
                 $.ajax({
                     url: "/index/checkout/submit?payType=50&mode=cart&address_id=" + addressId,
@@ -565,7 +574,6 @@
             });
         }
 
-
         /**
          * 商品操作方法
          * @param _this $(this)
@@ -578,7 +586,7 @@
             const goodsId = _this.closest(".productItem").attr("goods-id");
             const goodsSkuId = _this.closest(".productItem").attr("goods-sku-id");
             let goodsNum = parseInt(_this.closest(".productItem").attr("data-goods-num"));
-            console.log(productId, goodsId, goodsSkuId)
+            //console.log(productId, goodsId, goodsSkuId)
             //商品增加
             if (type === "add" || type === "reduce") {
                 if (type === "add") {
@@ -586,7 +594,6 @@
                 } else {
                     goodsNum -= 1
                 }
-                console.log("商品增加")
                 $.ajax({
                     url: "/index/cart/update?goodsId=" + goodsId + "&goodsSkuId=" + goodsSkuId + "&goodsNum=" + goodsNum,
                     method: "POST",
@@ -676,9 +683,9 @@
             const {status, message, data} = res || {}
             if (status === 200 || status === "200") {
                 window.open(data.payment.approval_link, "_blank");
-                var interId =  setInterval(function (){
+                var interId = setInterval(function () {
                     fetchOrder(data.orderId, interId);
-                },2000)
+                }, 2000)
             } else if (status === 401 || status === "401") {
                 window.location.replace('../passport/logIn.html')
             } else {
@@ -686,10 +693,10 @@
             }
         });
 
-        function fetchOrder(orderId, interId){
-            $.get('/index/order/detail?orderId='+ orderId,function (res){
+        function fetchOrder(orderId, interId) {
+            $.get('/index/order/detail?orderId=' + orderId, function (res) {
                 console.log(res.data.order.pay_status);
-                if (res.status == 200 && res.data.order.pay_status == 20){
+                if (res.status == 200 && res.data.order.pay_status == 20) {
                     clearInterval(interId);
                     $("#loadingModel").hide(0);
                     window.location.replace('/index/user/orderDetails.html?orderId=' + orderId)
@@ -700,6 +707,11 @@
 
         //支付
         $(".checkoutButton").on(tap, async function () {
+            if (payByPoints !== '1'){
+                showToast('Insufficient points!')
+                return;
+            }
+
             console.log("points")
             const params = {
                 "delivery": 10,