ayHaru 4 سال پیش
والد
کامیت
170bc88bdf

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

@@ -1,6 +1,7 @@
 <?php
 namespace app\index\controller;
 
+use app\index\model\ActionLogModel;
 use think\Controller;
 
 class Base extends Controller{
@@ -19,4 +20,17 @@ class Base extends Controller{
             }
         }
     }
+
+    protected function action_log(){
+        $control = lcfirst(request()->controller());
+        $action = lcfirst(request()->action());
+
+        $ActionLogModel = new ActionLogModel();
+        $params['admin_id']             = session('id');
+        $params['username']             = session('username');
+        $params['content']              = $control . '/' . $action;
+        $params['ip']                   = request()->ip();
+        $params['date']                 = date("Y-m-d H:i:s");
+        $ActionLogModel->save($params);
+    }
 }

+ 0 - 43
application/index/controller/Box.php

@@ -1,43 +0,0 @@
-<?php
-
-namespace app\index\controller;
-
-use app\index\model\BoxModel;
-
-class Box extends Base{
-
-    /**
-     * 自提柜箱子修改状态
-     */
-    public function change_box_status(){
-        $cabinet_number     = input('param.cabinet_number');
-        $box_number         = input('param.box_number');
-        $status             = input('param.status');
-        $BoxModel = new BoxModel();
-        $box = $BoxModel->getOneCabinetBox($cabinet_number,$box_number);
-        if(empty($cabinet)){
-            return json(json_error_exception(1008));
-        }
-        if($box['status'] == $status){
-            json_success('','success');
-        }
-    }
-
-    /**
-     * 自提柜箱子绑定订单号
-    */
-    public function box_bind_order(){
-        $where['cabinet_number']    = input('param.cabinet_number');
-        $where['box_number']        = input('param.box_number');
-
-        $update['enter_time']       = date('Y-m-d H:i:s');
-        $update['order_sn']         = input('param.order_sn');
-
-        $BoxModel = new BoxModel();
-        $result = $BoxModel->editData($where,$update);
-        if($result['code'] != 1){
-            return json(json_error_exception('1006',$result['msg']));
-        }
-        json_return(200,[],'success');
-    }
-}

+ 49 - 1
application/index/controller/Cabinet.php

@@ -6,9 +6,11 @@ define('BASE_ROOT_PATH',str_replace('/application/index/controller','',dirname(_
 require_once(BASE_ROOT_PATH . '/extend/queue.php');
 require_once(BASE_ROOT_PATH . '/extend/queue.logic.php');
 
+use app\index\model\ActionLogModel;
 use app\index\model\BoxActionModel;
 use app\index\model\CabinetModel;
 use app\index\model\BoxModel;
+use app\index\model\MsgModel;
 use app\index\model\OrderModel;
 use app\index\model\UserModel;
 use think\App;
@@ -46,6 +48,7 @@ class Cabinet extends Base
         if($flag['code'] != 1){
             return json(json_error_exception('1006',$flag['msg']));
         }
+        $this->action_log();
         json_success([]);
     }
 
@@ -73,7 +76,8 @@ class Cabinet extends Base
         if($result == false) {
             json_error(2000);
         } else {
-            json_success($result);
+            $this->action_log();
+            json_success($result['data']);
         }
     }
 
@@ -98,6 +102,7 @@ class Cabinet extends Base
         if($result == false) {
             json_error(2000);
         } else {
+            $this->action_log();
             json_success($result);
         }
     }
@@ -213,6 +218,7 @@ class Cabinet extends Base
         }
         $return['total'] = $CabinetModel->getAllCabinets();  //总数量
         $return['rows'] = $selectResult;
+        $this->action_log();
         json_success($return);
     }
 
@@ -231,6 +237,7 @@ class Cabinet extends Base
         }
         $return['total'] = $BoxModel->getAllCounts();  //总数量
         $return['rows'] = $selectResult;
+        $this->action_log();
         json_success($return);
     }
     public function BoxActionList(){
@@ -253,6 +260,47 @@ class Cabinet extends Base
         }
         $return['total'] = $BoxActionModel->getAllCounts($where);  //总数量
         $return['rows'] = $selectResult;
+        $this->action_log();
+        json_success($return);
+    }
+    public function MsgList(){
+        $param = input('param.');
+        if(empty($param['cabinet_number']) || empty($param['box_number'])){
+            json_error(1007 , '柜子号码或箱子号码不能为空');
+        }
+        $where['cabinet_number'] = $param['cabinet_number'];
+        $where['box_number'] = $param['box_number'];
+        $limit = isset($param['pageSize']) ? $param['pageSize'] : 10;
+        $param['pageNumber'] = isset($param['pageNumber']) ? $param['pageNumber'] : 1;
+        $offset = ($param['pageNumber'] - 1) * $limit;
+
+        $MsgModel = new MsgModel();
+        $selectResult = $MsgModel->getMsgsByWhere($where , $offset, $limit);
+        $status = ['1' => '存入上报' , '2' => '取走上报'];
+        // 拼装参数
+        foreach($selectResult as $key=>$vo){
+            $selectResult[$key]['status_text'] = $status[$vo['type']];
+        }
+        $return['total'] = $MsgModel->getAllCounts($where);  //总数量
+        $return['rows'] = $selectResult;
+        $this->action_log();
+        json_success($return);
+    }
+    public function ActionLogList(){
+        $param = input('param.');
+        $limit = isset($param['pageSize']) ? $param['pageSize'] : 10;
+        $param['pageNumber'] = isset($param['pageNumber']) ? $param['pageNumber'] : 1;
+        $offset = ($param['pageNumber'] - 1) * $limit;
+
+        $ActionLogModel = new ActionLogModel();
+        $selectResult = $ActionLogModel->getActionLogsByWhere($offset, $limit);
+        // 拼装参数
+        foreach($selectResult as $key=>$vo){
+
+        }
+        $return['total'] = $ActionLogModel->getAllCounts();  //总数量
+        $return['rows'] = $selectResult;
+        $this->action_log();
         json_success($return);
     }
 

+ 14 - 1
application/index/controller/Order.php

@@ -5,6 +5,7 @@ namespace app\index\controller;
 use app\index\model\BoxActionModel;
 use app\index\model\BoxModel;
 use app\index\model\CabinetModel;
+use app\index\model\MsgModel;
 use app\index\model\OrderModel;
 use think\Controller;
 
@@ -62,6 +63,7 @@ class Order extends Base
             $msg = "{$alias}柜门{$trunk}箱门,密码信息{$code}";
             $result = request_post(self::base_url . '/deliver' , ['orderCode' => $order_sn,"boxMsg" => $msg]);
             //todo 存储到消息记录表里面。
+            $this->CreateMsg($cabinet_number,$trunk,$msg,$order_sn,1);
             json_success();
         }
     }
@@ -106,7 +108,8 @@ class Order extends Base
         $order_sn = $Box['order_sn'];
         $result = request_post(self::base_url . '/receive' , ['orderCode' => $Box['order_sn']]);
         //todo 存消息
-
+        $msg = "{$cabinet['alias']}柜门{$trunk}箱门";
+        $this->CreateMsg($cabinet_number,$trunk,$msg,$order_sn,2);
         $this->box_action_record($cabinet_number , $trunk , 2 , $cabinet ,$cabinet['alias']);
         json_success();
     }
@@ -137,6 +140,16 @@ class Order extends Base
         return !empty($box);
     }
 
+    private function CreateMsg($cabinet_number , $box_number , $msg , $order_sn , $type){
+        $MsgModel = new MsgModel();
+        $params['cabinet_number']       = $cabinet_number;
+        $params['box_number']           = $box_number;
+        $params['order_sn']             = $order_sn;
+        $params['msg']                  = $msg;
+        $params['type']                 = $type;
+        $params['datetime']             = date("Y-m-d H:i:s");
+        $MsgModel->save($params);
+    }
     /**
      * 生成订单并绑定箱子
     */

+ 20 - 0
application/index/model/ActionLogModel.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace app\index\model;
+
+use think\Model;
+
+class ActionLogModel extends Model {
+
+    // 确定链接表名
+    protected $name = 'action_log';
+
+    public function getActionLogsByWhere( $offset , $limit)
+    {
+        return $this->limit($offset, $limit)->order('id desc')->select();
+    }
+    public function getAllCounts()
+    {
+        return $this->count();
+    }
+}

+ 0 - 8
application/index/model/BoxActionModel.php

@@ -9,19 +9,11 @@ class BoxActionModel extends Model {
     // 确定链接表名
     protected $name = 'box_action_record';
 
-    /**
-     * 根据搜索条件获取箱子列表信息
-     * @param $offset
-     * @param $limit
-     */
     public function getBoxActionsByWhere($where , $offset , $limit)
     {
         return $this->where($where)->limit($offset, $limit)->order('box_number asc')->select();
     }
 
-    /**
-     * 根据搜索条件获取所有的箱子数量
-     */
     public function getAllCounts($where)
     {
         return $this->where($where)->count();

+ 20 - 0
application/index/model/MsgModel.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace app\index\model;
+
+use think\Model;
+
+class MsgModel extends Model {
+
+    // 确定链接表名
+    protected $name = 'msg';
+
+    public function getMsgsByWhere($where , $offset , $limit)
+    {
+        return $this->where($where)->limit($offset, $limit)->order('id desc')->select();
+    }
+    public function getAllCounts($where)
+    {
+        return $this->where($where)->count();
+    }
+}

+ 2 - 0
route/route.php

@@ -23,7 +23,9 @@
 
         'CabinetList'               => 'index/cabinet/CabinetList',
         'BoxList'                   => 'index/cabinet/BoxList',
+        'MsgList'                   => 'index/cabinet/MsgList',
         'BoxActionList'             => 'index/cabinet/BoxActionList',
+        'ActionLogList'             => 'index/cabinet/ActionLogList',
         'OrderList'                 => 'index/order/OrderList',
 
         'GetCabinetsBoxs'           => 'index/cabinet/GetCabinetsBoxs',

+ 0 - 11
tests/LoginTest.php

@@ -1,11 +0,0 @@
-<?php
-
-namespace tests;
-
-use PHPUnit\Framework\TestCase;
-
-class LoginTest extends TestCase
-{
-
-
-}