Quellcode durchsuchen

订单取消和完成

lizhen_gitee vor 1 Jahr
Ursprung
Commit
7baeee10fd

+ 96 - 1
application/admin/controller/Order.php

@@ -84,7 +84,7 @@ class Order extends Backend
      * 在线开单
      */
     public function submitordernew(){
-        if(!$this->request->post()){
+        if(!$this->request->isPost()){
             $this->assign('staff_id',$this->auth->staff_id);
             return $this->view->fetch();
         }
@@ -130,4 +130,99 @@ class Order extends Backend
         $this->success('下单完成',$order_id);
     }
 
+    /**
+     * 取消
+     */
+    public function cancel(){
+
+        $id = input('id',0);
+        if(!$this->request->ispost()){
+            $this->assign('id',$id);
+            return $this->view->fetch();
+        }
+
+        $reason = input('reason','');
+
+        $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
+        if($info['status'] == 4){
+            $this->error('当前订单已经取消');
+        }
+        if($info['status'] != 0 && $info['status'] != 2){
+            $this->error('当前订单状态不能取消');
+        }
+        if($info['ordertype'] == 3){
+            $this->error('套餐订单不能取消');
+        }
+        $time = time();
+        //同步到预约单
+        if (!empty($info['pre_order_id'])) {
+            $preOrderWhere['id'] = $info['pre_order_id'];
+            $preOrder = Db::name('pre_order')->where($preOrderWhere)->find();
+            if (!empty($preOrder) && $preOrder['pre_order_status'] != 0) {
+                $preOrderData = ['pre_order_status'=>0,'cancel_time'=>$time,'cancel_reason'=>$reason];
+                $preOrderRes = Db::name('pre_order')->where($preOrderWhere)->update($preOrderData);
+                if (!$preOrderRes) {
+                    $this->error('预约单取消失败');
+                }
+            }
+        }
+        //取消
+        $rs = Db::name('order')->where('id',$id)->update(['status'=>4,'cancel_time'=>time(),'finish_time'=>time(),'cancel_reason'=>$reason]);
+
+        if($rs === false){
+            $this->error('取消失败');
+        }
+        //订单取消发送消息
+        $userService = new UserService();
+        $params['order_id'] = $id;
+        $userService->msgOrder($params);
+        $this->success('取消成功');
+
+    }
+
+    /**
+     * 完成
+     */
+    public function finish(){
+        $id = input('id',0);
+
+        Db::startTrans();
+        $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->company_id)->lock(true)->find();
+        if($info['status'] != 2){
+            Db::rollback();
+            $this->error('当前订单不能完成');
+        }
+
+        //完成
+        $time = time();
+        $updateData = ['status'=>3,'finish_time'=>time(),'staff_id'=>$this->auth->id];
+        if (empty($info['hexiao_time'])) {
+            $updateData['hexiao_time'] = $time;
+        }
+        $rs = Db::name('order')->where('id',$id)->update($updateData);
+        if($rs === false){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+
+        //给门店加钱
+        if($info['ordertype'] == 3 && $info['paytype'] == 3 && $info['pay_fee'] > 0){
+            $wallet_rs = model('walletcompany')->lockChangeAccountRemain($this->auth->company_id,'money',$info['pay_fee'],203,$remark='套餐订单完成服务','order',$id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+        }
+
+        Db::commit();
+        //订单取消发送消息
+        $userService = new UserService();
+        $params['order_id'] = $id;
+        $userService->msgOrder($params);
+        //是否弹出保养
+        $baoyang_switch = Db::name('servicetype')->where('id',$info['servicetype_id'])->value('baoyang_switch');
+
+        $this->success('操作成功',$baoyang_switch);
+    }
+
 }

+ 2 - 0
application/admin/view/order/index.html

@@ -36,6 +36,8 @@
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                            data-operate-edit="{:$auth->check('order/edit')}"
                            data-operate-del="{:$auth->check('order/del')}"
+                           data-operate-cancel="{:$auth->check('order/cancel')}"
+                           data-operate-finish="{:$auth->check('order/finish')}"
                            width="100%">
                     </table>
                 </div>

+ 9 - 3
public/assets/js/backend/order.js

@@ -31,6 +31,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'id', title: __('Id')},
                         {field: 'orderno', title: __('Orderno'), operate: 'LIKE'},
                         {field: 'ordertype', title: __('Ordertype'), searchList: {"1":__('Ordertype 1'),"2":__('Ordertype 2'),"3":__('Ordertype 3')}, formatter: Table.api.formatter.normal},
+                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                         {field: 'company_id', title: __('Company_id')},
                         {field: 'company.name', title: __('Company.name'), operate: 'LIKE'},
 //                        {field: 'staff_id', title: __('Staff_id'), operate:false, visible:false},
@@ -52,7 +53,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'server_info', title: __('Server_info'), operate: 'LIKE'},
                         {field: 'server_images', title: __('Server_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
 //                        {field: 'package_id', title: __('Package_id'), operate:false, visible:false},
-                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                         {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'paytype', title: __('Paytype'), searchList: {"1":__('Paytype 1'),"2":__('Paytype 2'),"3":__('Paytype 3')}, formatter: Table.api.formatter.normal},
                         {field: 'pay_fee', title: __('Pay_fee'), operate:'BETWEEN'},
@@ -78,7 +78,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     target:'_self',
                                     extend: 'data-area=["90%","90%"]',
                                 },
-                                /*{
+                                {
                                     name:'cancel',
                                     text:'取消',
                                     title:'取消',
@@ -87,6 +87,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     url:'order/cancel/order_id/{ids}?dialog=1',
                                     target:'_self',
                                     extend: 'data-area=["90%","90%"]',
+                                    hidden:function($row){
+                                        if($row['ordertype'] != 3 && $row['status'] == 2){
+                                            return false;
+                                        }
+                                        return true;
+                                    }
                                 },
                                 {
                                     name:'finish',
@@ -97,7 +103,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     url:'order/finish/order_id/{ids}?dialog=1',
                                     target:'_self',
                                     extend: 'data-area=["90%","90%"]',
-                                },*/
+                                },
 
                             ],
                             events: Table.api.events.operate, formatter: Table.api.formatter.operate}