瀏覽代碼

未支付订单取消

zhangdehua 1 年之前
父節點
當前提交
ab6bd6bd97
共有 3 個文件被更改,包括 77 次插入5 次删除
  1. 25 0
      app/index/controller/Order.php
  2. 36 5
      app/index/view/user/orderDetails.html
  3. 16 0
      public/assets/index/css/orderDetails.css

+ 25 - 0
app/index/controller/Order.php

@@ -17,6 +17,7 @@ use app\index\model\Setting as SettingModel;
 use app\store\model\Express as ExpressModel;
 use app\common\enum\order\PayType as OrderPayTypeEnum;
 use cores\exception\BaseException;
+use think\facade\Session;
 use think\response\Json;
 
 /**
@@ -126,6 +127,30 @@ class Order extends Controller
     }
 
     /**
+     * 取消订单
+     * @return Json
+     * @throws BaseException
+     */
+    public function cancel(): Json
+    {
+        $userId = Session::get('user_id');
+        if (empty($userId)) {
+            return $this->renderJson(config('status.not_logged'), 'Log in please!');
+        }
+
+        $orderId = $this->request->param('orderId');
+        if (empty($orderId)){
+            return $this->renderError('Something error!');
+        }
+
+        $model = OrderModel::getDetail(intval($orderId));
+        if ($model->cancel()) {
+            return $this->renderSuccess('订单取消成功');
+        }
+        return $this->renderError($model->getError() ?: '订单取消失败');
+    }
+
+    /**
      * 确认收货
      * @param int $orderId
      * @return Json

+ 36 - 5
app/index/view/user/orderDetails.html

@@ -97,7 +97,10 @@
                     <div class="orderGoodsBox eleBox">
                         <div class="ogTeFlex">
                             <p class="ogTitle">Listing</p>
+                            {if $order['pay_status'] == 10 }
                             <div class="ogMarkButton">Pay With PayPal</div>
+                            <div class="ogCancelButton">Cancel</div>
+                            {/if}
                         </div>
                         <p class="ogTips">
                             Your goods will be shipped in 72 hours
@@ -347,11 +350,11 @@
 
         $("#loadingModel").hide(0);
         var orderId = "{$order['order_id']}";
-        var payStatus = "{$order['pay_status']}";
-        $('#ogMarkButton').hide(0)
-        if (payStatus === "10") {
-            $('#ogMarkButton').show(0)
-        }
+        //var payStatus = "{$order['pay_status']}";
+        // $('#ogMarkButton').hide(0)
+        // if (payStatus === "10") {
+        //     $('#ogMarkButton').show(0)
+        // }
 
         //触屏事件 || 点击事件
         const tap = "ontouchstart" in window ? "touchstart" : "click";
@@ -441,6 +444,34 @@
                 showToast(message)
             }
         });
+        //取消未支付的订单
+        $(".ogCancelButton").on(tap, async function () {
+            const dp = {
+                orderId: orderId
+            };
+            $.ajax({
+                url: "/index/order/cancel",
+                headers: {platform: 'H5'},
+                dataType: 'json',
+                data: JSON.stringify(dp),
+                type: "POST",
+                contentType: 'application/json',
+                success: function (obj) {
+                    //注册成功后进入
+                    if (obj.status === 200 || obj.status === '200') {
+                        showToast("Successful")
+                        setTimeout(function () {
+                                window.location.replace('/index/user/order.html')
+                            }
+                            , 3000)
+                    } else if (obj.status === 401 || obj.status === '401') {
+                        window.location.replace('../passport/logIn.html')
+                    } else {
+                        showToast('Something wrong,please try again later')
+                    }
+                }
+            })
+        });
 
         function fetchOrder(interId) {
             $.get('/index/order/detail?orderId=' + orderId, function (res) {

+ 16 - 0
public/assets/index/css/orderDetails.css

@@ -139,6 +139,22 @@ body{
     border-radius: .04rem;
     cursor: pointer;
 }
+
+.ogTeFlex .ogCancelButton{
+    padding: 0 .15rem;
+    min-width: .8rem;
+    height: .47rem;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    font-size: .16rem;
+    color: #333336;
+    background-color: rgba(188, 188, 197, 0.28);
+    border-radius: .04rem;
+    cursor: pointer;
+    margin-left: .08rem;
+}
+
 .orderGoodsBox .ogTips{
     word-break: break-all;
     line-height: 1.5;