瀏覽代碼

del cabinet box

ayHaru 4 年之前
父節點
當前提交
29a1617b6f
共有 3 個文件被更改,包括 39 次插入0 次删除
  1. 14 0
      application/index/controller/Cabinet.php
  2. 24 0
      application/index/model/CabinetModel.php
  3. 1 0
      route/route.php

+ 14 - 0
application/index/controller/Cabinet.php

@@ -73,6 +73,20 @@ class Cabinet extends Base
             json_success([]);
         }
     }
+    public function DelCabinet(){
+        $id = input('param.id');
+        $cabinet = $this->get_cabinet($id);
+        if(empty($cabinet)){
+            return json(json_error_exception(1008));
+        }
+        $CabinetModel = new CabinetModel();
+        $ret = $CabinetModel->DelCabinetBox($id);
+        if($ret == false){
+            return json(json_error_exception(1006));
+        }else{
+            json_success([]);
+        }
+    }
 
     public function OpenBox()
     {

+ 24 - 0
application/index/model/CabinetModel.php

@@ -71,4 +71,28 @@ class CabinetModel extends Model{
         return $this->count();
     }
 
+    public function DelCabinetBox($cabinet_number){
+        try {
+            $this->startTrans();
+            $ret = $this->where('id' , $cabinet_number)->delete($cabinet_number);
+            if(false === $ret){
+                $this->rollback();
+                return msg(-1, '', $this->getError());
+            }else{
+                $BoxModel = new BoxModel();
+                $ret = $BoxModel->where('cabinet_number' , $cabinet_number)->delete();
+                if(false === $ret){
+                    $this->rollback();
+                    return msg(-1, '', $this->getError());
+                }else{
+                    $this->commit();
+                    return msg(1, '', '删除成功');
+                }
+            }
+        }catch(PDOException $e){
+            $this->rollback();
+            return msg(-2, '', $e->getMessage());
+        }
+    }
+
 }

+ 1 - 0
route/route.php

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