Browse Source

订单日志

tincey 3 years ago
parent
commit
e7ac8b161b

+ 91 - 1
application/admin/controller/Order.php

@@ -3,6 +3,8 @@
 namespace app\admin\controller;
 
 use app\common\controller\Backend;
+use think\exception\PDOException;
+use think\exception\ValidateException;
 use think\Session;
 use think\Db;
 
@@ -19,11 +21,13 @@ class Order extends Backend
      * @var \app\admin\model\Order
      */
     protected $model = null;
+    protected $logmodel = null;
 
     public function _initialize()
     {
         parent::_initialize();
         $this->model = new \app\admin\model\Order;
+        $this->logmodel = new \app\admin\model\OrderLog;
         $this->view->assign("statusList", $this->model->getStatusList());
     }
 
@@ -89,7 +93,6 @@ class Order extends Backend
         if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
             $params[$this->dataLimitField] = $this->auth->id;
         }
-//        halt($params);die;
         $result = false;
         Db::startTrans();
         try {
@@ -100,6 +103,11 @@ class Order extends Backend
                 $this->model->validateFailException()->validate($validate);
             }
             $result = $this->model->allowField(true)->save($params);
+            $arr['oid'] = $this->model->getLastInsID();
+            $arr['userid'] = $user_info['id'];
+            $arr['username'] = $user_info['nickname'];
+            $arr['type'] = 1;
+            $this->logmodel->save($arr);
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
             Db::rollback();
@@ -110,6 +118,88 @@ class Order extends Backend
         }
         $this->success();
     }
+
+    public function edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $params = $this->preExcludeFields($params);
+        $result = false;
+        Db::startTrans();
+        try {
+            //是否采用模型验证
+            if ($this->modelValidate) {
+                $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                $row->validateFailException()->validate($validate);
+            }
+            $arr = [];
+            foreach ($params as $k=>$v){
+                if($v!=$row[$k]) {
+                    if ($k == 'no') {
+                        $arr['field'] = '编号';
+                    } elseif ($k == 'customer') {
+                        $arr['field'] = '订货单位';
+                    } elseif ($k == 'product') {
+                        $arr['field'] = '品名';
+                    } elseif ($k == 'specs') {
+                        $arr['field'] = '包装规格';
+                    } elseif ($k == 'unit') {
+                        $arr['field'] = '单位';
+                    } elseif ($k == 'number') {
+                        $arr['field'] = '数量';
+                    } elseif ($k == 'price') {
+                        $arr['field'] = '单价';
+                    } elseif ($k == 'delivery_date') {
+                        $arr['field'] = '交货期';
+                    } elseif ($k == 'remark') {
+                        $arr['field'] = '备注';
+                    } elseif ($k == 'date') {
+                        $arr['field'] = '日期';
+                    } elseif ($k == 'user_name') {
+                        $arr['field'] = '经办';
+                    } elseif ($k == 'examine') {
+                        $arr['field'] = '审核';
+                    } elseif ($k == 'status') {
+                        $arr['field'] = '状态';
+                    }
+                    $user_info = Session::get('admin');
+                    $arr['userid'] = $user_info['id'];
+                    $arr['username'] = $user_info['nickname'];
+                    $arr['oid'] = $row['id'];
+                    $arr['type'] = 2;
+                    $res[]=$arr;
+                }
+            }
+            $this->logmodel->saveAll($res);
+
+            $result = $row->allowField(true)->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+             Db::rollback();
+             $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $this->success();
+    }
+
+
     //生产作业票
     public function task(){
         $ids = input('ids');

+ 140 - 0
application/admin/controller/OrderLog.php

@@ -0,0 +1,140 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+
+/**
+ * 订单日志
+ *
+ * @icon fa fa-circle-o
+ */
+class OrderLog extends Backend
+{
+
+    /**
+     * @var \app\admin\model\OrderLog
+     */
+    protected $model = null;
+    protected $childrenGroupIds = [];
+    protected $childrenAdminIds = [];
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = model('OrderLog');
+
+        $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
+        $this->childrenGroupIds = $this->auth->getChildrenGroupIds(true);
+
+//        $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds)
+//            ->column('id,name');
+
+//        $this->view->assign('groupdata', $groupName);
+    }
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+//        halt();
+        //当前是否为关联查询
+        $this->relationSearch = true;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+            $list = $this->model
+                ->where($where)
+                ->with(['order'])
+//                ->where('admin_id', 'in', $this->childrenAdminIds)
+                ->order($sort, $order)
+                ->paginate($limit);
+
+            foreach ($list as $row) {
+                $row->visible(['id','username','updatetime','field','type']);
+                $row->visible(['order']);
+                $row->getRelation('order')->visible(['no']);
+            }
+            $result = array("total" => $list->total(), "rows" => $list->items());
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    /**
+     * 详情
+     */
+    public function detail($ids)
+    {
+        $row = $this->model->get(['id' => $ids]);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        $this->view->assign("row", $row->toArray());
+        return $this->view->fetch();
+    }
+
+    /**
+     * 添加
+     * @internal
+     */
+    public function add()
+    {
+        $this->error();
+    }
+
+    /**
+     * 编辑
+     * @internal
+     */
+    public function edit($ids = null)
+    {
+        $this->error();
+    }
+
+    /**
+     * 删除
+     */
+    public function del($ids = "")
+    {
+        if (!$this->request->isPost()) {
+            $this->error(__("Invalid parameters"));
+        }
+        $ids = $ids ? $ids : $this->request->post("ids");
+        if ($ids) {
+            $adminList = $this->model->where('id', 'in', $ids)->where('admin_id', 'in', $this->childrenAdminIds)->select();
+            if ($adminList) {
+                $deleteIds = [];
+                foreach ($adminList as $k => $v) {
+                    $deleteIds[] = $v->id;
+                }
+                if ($deleteIds) {
+                    $this->model->destroy($deleteIds);
+                    $this->success();
+                }
+            }
+        }
+        $this->error();
+    }
+
+    /**
+     * 批量更新
+     * @internal
+     */
+    public function multi($ids = "")
+    {
+        // 管理员禁止批量操作
+        $this->error();
+    }
+
+    public function selectpage()
+    {
+        return parent::selectpage();
+    }
+}

+ 10 - 0
application/admin/lang/zh-cn/order_log.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'Order No'      => '订单号',
+    'Field'         => '字段',
+    'Create time'   => '操作时间',
+    'Type 1'        => '新增',
+    'Type 2'        => '修改',
+    'Username'      => '操作人'
+];

+ 51 - 0
application/admin/model/OrderLog.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class OrderLog extends Model
+{
+
+
+
+
+
+    // 表名
+    protected $name = 'order_log';
+
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'datetime';
+    protected $dateFormat ='Y-m-d H:i:s';
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+    ];
+
+
+
+    public function getStatusList()
+    {
+        return ['1' => __('Type 1'), '2' => __('Type 2')];
+    }
+
+
+    public function getTypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+    public function order()
+    {
+        return $this->belongsTo('Order', 'oid', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+}

+ 21 - 0
application/admin/view/order_log/index.html

@@ -0,0 +1,21 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        {:build_toolbar('refresh')}
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-detail=""
+                           data-operate-del=""
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 65 - 0
public/assets/js/backend/order_log.js

@@ -0,0 +1,65 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'order_log/index',
+                    add_url: '',
+                    edit_url: '',
+                    del_url: 'order_log/del',
+                    multi_url: 'order_log/multi',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                fixedColumns: true,
+                fixedRightNumber: 1,
+                columns: [
+                    [
+                        {field: 'state', checkbox: true,},
+                        {field: 'id', title: 'ID', operate: false},
+                        {field: 'order.no', title: __('Order No'), formatter: Table.api.formatter.search},
+                        {field: 'username', title: __('Username'), operate: 'LIKE %...%'},
+                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.status},
+                        {field: 'field', title: __('Field'), operate: 'RANGE'},
+                        // {field: 'ip', title: __('IP'), events: Table.api.events.ip, formatter: Table.api.formatter.search},
+                        // {field: 'browser', title: __('Browser'), operate: false, formatter: Controller.api.formatter.browser},
+                        {field: 'updatetime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
+                        // {
+                        //     field: 'operate', title: __('Operate'), table: table,
+                        //     events: Table.api.events.operate,
+                        //     buttons: [{
+                        //         name: 'detail',
+                        //         text: __('Detail'),
+                        //         icon: 'fa fa-list',
+                        //         classname: 'btn btn-info btn-xs btn-detail btn-dialog',
+                        //         url: 'order_log/detail'
+                        //     }],
+                        //     formatter: Table.api.formatter.operate
+                        // }
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            },
+            formatter: {
+                browser: function (value, row, index) {
+                    return '<a class="btn btn-xs btn-browser">' + row.useragent.split(" ")[0] + '</a>';
+                },
+            },
+        }
+    };
+    return Controller;
+});