Browse Source

预约单

lizhen_gitee 1 year ago
parent
commit
72aff51c2e
1 changed files with 99 additions and 0 deletions
  1. 99 0
      application/api/controller/company/Preorder.php

+ 99 - 0
application/api/controller/company/Preorder.php

@@ -0,0 +1,99 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use think\Db;
+
+/**
+ * 预约管理
+ */
+class Preorder extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+
+    //列表
+    public function lists(){
+        $pre_order_status = input('pre_order_status',1);
+        $where = [
+            'po.company_id' => $this->auth->company_id,
+            'po.pre_order_status' => $pre_order_status,
+        ];
+        $list = Db::name('pre_order')->alias('po')->field('po.*,servicetype.title')
+            ->join('servicetype','po.servicetype_id = servicetype.id','LEFT')
+            ->where($where)->order('po.id desc')->autopage()->select();
+        $this->success(1,$list);
+    }
+
+    //取消
+    public function cancel(){
+        $id = input('pre_order_id',0);
+        $cancel_reason = input('cancel_reason','');
+
+        $update = [
+            'cancel_reason' => $cancel_reason,
+            'cancel_time'   => time(),
+            'updatetime'    => time(),
+            'pre_order_status' => 0,
+        ];
+        Db::name('pre_order')->where('id',$id)->where('company_id',$this->auth->company_id)->update($update);
+
+        $this->success('取消成功');
+    }
+
+    //详情
+    public function info(){
+        $id = input('pre_order_id',0);
+        $info = Db::name('pre_order')->where('id',$id)->find();
+        $this->success(1,$info);
+    }
+
+    //预约开单 在线开单
+    public function submit_order(){
+        $pre_order_id = input('pre_order_id',0); //预约单id
+
+        $data = request_post_hub([
+            'user_name','user_car_number','user_mobile','user_address',
+            'servicetype_id','server_time','server_info','server_images','pay_fee'
+        ]);
+
+        //检查用户
+        $user_info = Db::name('user')->where('mobile',$data['user_mobile'])->find();
+        if(empty($user_info)){
+            $this->error('不存在的用户');
+        }
+        $data['user_id'] = $user_info['id'];
+
+        //预约单
+        $pre_order = [];
+        if($pre_order_id > 0){
+            $pre_order = Db::name('pre_order')->where('id',$pre_order_id)->find();
+            if(empty($pre_order)){
+                $this->error('不存在的预约单');
+            }else{
+                $data['pre_order_id'] = $pre_order_id;
+            }
+        }
+
+        //检索car_id,没必要了
+
+        //准备数据
+        $data['orderno']    = createUniqueNo('O',$this->auth->id);
+        $data['ordertype']    = ($pre_order_id > 0) ? 1 : 2;  //类型:1=预约下单,2=在线下单,3=套餐订单
+        $data['company_id'] = $this->auth->company_id;
+        $data['staff_id'] = $this->auth->id;
+
+        $data['createtime'] = time();
+
+        $order_id = Db::name('order')->insertGetId($data);
+        $this->success('下单完成',$order_id);
+    }
+
+    //查看预约单下的订单
+
+
+
+
+}