Kaynağa Gözat

Merge branch 'test' of 39.97.239.116:gyfl/apisongcan into test

stanley-king 4 yıl önce
ebeveyn
işleme
9349b92d0f
2 değiştirilmiş dosya ile 34 ekleme ve 2 silme
  1. 33 2
      application/index/controller/Cabinet.php
  2. 1 0
      route/route.php

+ 33 - 2
application/index/controller/Cabinet.php

@@ -40,18 +40,36 @@ class Cabinet extends Base
         $number = $param['number'];
         $login_key = $param['login_key'];
         if($count < 0 || empty($url)) {
-            return json(json_error_exception('1006','参数不正确'));
+            return json(json_error_exception(1007,'参数不正确'));
         }
 
         $CabinetModel = new CabinetModel();
         $flag = $CabinetModel->insertCabinet($url,$alias,$count,$number,$login_key);
         if($flag['code'] != 1){
-            return json(json_error_exception('1006',$flag['msg']));
+            return json(json_error_exception(1006,$flag['msg']));
         }
         $this->action_log();
         json_success([]);
     }
 
+    public function AddBox(){
+        $cabinet_number = input('param.cabinet_number');
+        $BoxModel = new BoxModel();
+        $last_box = $BoxModel->where('cabinet_number' , $cabinet_number)->order('box_number desc')->find();
+        if(empty($last_box)){
+            $data['box_number'] = 1;
+        }else{
+            $data['box_number'] = intval($last_box['box_number'] + 1);
+        }
+        $data['cabinet_number'] = $cabinet_number;
+        $ret = $BoxModel->save($data);
+        if($ret == false){
+            return json(json_error_exception(1006));
+        }else{
+            json_success([]);
+        }
+    }
+
     public function OpenBox()
     {
         $params['id']                 = $this->getid();
@@ -77,6 +95,8 @@ class Cabinet extends Base
             json_error(2000);
         } else {
             $this->action_log();
+            $model = new BoxModel();
+            $model->editData(['cabinet_number' => $cabinet_code , 'box_number' => $box_number] , ['box_status' => 0]);
             json_success($result['data']);
         }
     }
@@ -103,6 +123,7 @@ class Cabinet extends Base
             json_error(2000);
         } else {
             $this->action_log();
+            $this->CabinetStatusChange($cabinet_code , 2);
             json_success($result['data']);
         }
     }
@@ -129,6 +150,7 @@ class Cabinet extends Base
             json_error(2000);
         } else {
             $this->action_log();
+            $this->CabinetStatusChange($cabinet_code , 1);
             json_success($result['data']);
         }
     }
@@ -452,6 +474,15 @@ class Cabinet extends Base
         return $BoxModel->editData($where,$update);
     }
 
+    private function CabinetStatusChange($cabinet_number , $status){
+        $cabinet = $this->get_cabinet($cabinet_number);
+        if($cabinet['cabinet_status'] == $status){
+            return true;
+        }
+        $CabinetModel = new CabinetModel();
+        $CabinetModel->save(['cabinet_status' => $status] , ['id' => $cabinet_number]);
+    }
+
     public function test(){
         pre(1);
     }

+ 1 - 0
route/route.php

@@ -8,6 +8,7 @@
         'EditPwd'                   => 'index/user/EditPwd',
 
         'AddCabinet'                => 'index/cabinet/AddCabinet',
+        'AddBox'                    => 'index/cabinet/AddBox',
 
         'OpenBox'                   => 'index/cabinet/OpenBox',
         'LockCabinet'               => 'index/cabinet/LockCabinet',