Browse Source

维保订单接口

lizhen_gitee 9 months ago
parent
commit
bf9341e6c9
3 changed files with 177 additions and 3 deletions
  1. 20 1
      application/api/controller/Demo.php
  2. 155 0
      application/api/controller/Maintain.php
  3. 2 2
      application/common.php

+ 20 - 1
application/api/controller/Demo.php

@@ -40,7 +40,26 @@ class Demo extends Api
      */
     public function test()
     {
-        $this->success('返回成功', $this->request->param());
+        $data = [
+            [
+                'type' => 'video',
+                'url'  => '/upload/20240712/aaaaa.mp4',
+            ],
+            [
+                'type' => 'img',
+                'url'  => '/upload/20240712/bbbbb.jpg',
+            ],
+            [
+                'type' => 'video',
+                'url'  => '/upload/20240712/ccccc.mp4',
+            ],
+            [
+                'type' => 'img',
+                'url'  => '/upload/20240712/ddddd.png',
+            ],
+        ];
+
+        echo json_encode($data);
     }
 
     /**

+ 155 - 0
application/api/controller/Maintain.php

@@ -0,0 +1,155 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 保修
+ */
+class Maintain extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    public function addone()
+    {
+        $info     = input('info','');
+        $filedata = input('filedata','','htmlspecialchars_decode');
+        $mobile   = input('mobile','');
+        $address  = input('address','');
+
+        //视频类型追加缩略图
+        $filedata = json_decode($filedata,true);
+        foreach($filedata as $key => $file){
+            if($file['type'] == 'video'){
+                $file_url = explode('.', $file['url']);
+                unset($file_url[count($file_url) - 1]);
+                $file['images_thumb'] = implode('.', $file_url) . '_0.jpg';
+            }else{
+                $file['images_thumb'] = $file['url'];
+            }
+            $filedata[$key] = $file;
+        }
+        $filedata = json_encode($filedata);
+
+        //写入
+        $data = [
+            'orderno' => createUniqueNo('',''),
+            'user_id' => $this->auth->id,
+            'company_id' => $this->auth->company_id,
+            'createtime' => time(),
+            'updatetime' => time(),
+            'info' => $info,
+            'filedata' => $filedata,
+            'mobile' => $mobile,
+            'address' => $address,
+            'status' => 0,
+        ];
+
+        $order_id = Db::name('maintain')->insertGetId($data);
+        $this->success('保修成功请等待审核', $order_id);
+    }
+
+    public function lists(){
+        $status = input('status',0); //默认待审核
+
+        $map = [
+            'user_id' => $this->auth->id,
+            'status'  => $status,
+        ];
+        $list = Db::name('maintain')->field('id,orderno,createtime,info,filedata,status')
+            ->where($map)->order('id desc')
+            ->autopage()->select();
+        if(!empty($list)){
+            $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');//负责人的电话
+
+            foreach($list as $key => $val){
+                $list[$key]['header_mobile'] = $header_mobile;
+                $list[$key]['status_text'] = $this->status_data($val['status']);
+            }
+        }
+
+        $this->success(1,$list);
+    }
+
+    public function info(){
+        $id = input('id',0);
+
+        $map = [
+            'user_id' => $this->auth->id,
+            'id'      => $id,
+        ];
+
+        $info = Db::name('maintain')
+            ->where($map)
+            ->find();
+        $info['status_text'] = $this->status_data($info['status']);
+
+        $this->success(1, $info);
+    }
+
+    //报价单里列表
+    public function baojia_info(){
+        $order_id = input('order_id',0);
+        $lists = Db::name('maintain_baojia')
+            ->field('id,name,price,number,price_total')
+            ->where('order_id',$order_id)->order('id asc')->select();
+
+        $baojia_sum = Db::name('maintain')
+            ->where('id',$order_id)
+            ->value('baojia_sum');
+
+        $rs = [
+            'list' => $lists,
+            'baojia_sum' => $baojia_sum
+        ];
+
+        $this->success(1,$rs);
+    }
+
+    //取消上报
+    public function cancel(){
+        $id = input('id',0);
+
+        $map = [
+            'user_id' => $this->auth->id,
+            'id'      => $id,
+        ];
+
+        $info = Db::name('maintain')
+            ->where($map)
+            ->find();
+
+        if($info['status'] != 0){
+            $this->error('现在已经不能取消了');
+        }
+
+        $nowtime = time();
+        $update = [
+            'status' => 3,
+            'canceltime' => $nowtime,
+            'finishtime' => $nowtime,
+            'updatetime' => $nowtime,
+        ];
+        $rs = Db::name('maintain')
+            ->where($map)->update($update);
+
+        $this->success('取消成功');
+    }
+
+    //状态枚举
+    private function status_data($status){
+        $data = [
+            0  => '待审核',
+            3  => '已取消',
+            10 => '待报价',
+            20 => '报价审核',
+            30 => '待维修',
+            40 => '已完成',
+        ];
+        return $data[$status];
+    }
+
+
+}

+ 2 - 2
application/common.php

@@ -670,7 +670,7 @@ if (!function_exists('get_rand_nick_name')) {
 
     }
 }
-if (!function_exists('get_rand_nick_name')) {
+if (!function_exists('createUniqueNo')) {
     //创建订单号
     function createUniqueNo($prifix = 'P',$id = 0)
     {
@@ -680,7 +680,7 @@ if (!function_exists('get_rand_nick_name')) {
 
         $ms = substr($ms, 2, 6); //获取微妙
 
-        $rt = $prifix.date('YmdHis', $s).$ms.rand(10, 99).$id; //年月日时分秒.用户id对10取余.微秒
+        $rt = $prifix.date('YmdHis', $s).$ms.rand(10, 99).$id; //前缀.年月日时分秒.微秒.随机2位.用户id
 
         return $rt;
     }