diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 778397c..705fbec 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -12,6 +12,7 @@ use app\common\controller\Backend; use app\common\Logic\OrderLogic; use fast\Tree; use think\Db; +use think\Exception; use think\exception\DbException; use think\exception\PDOException; use think\exception\ValidateException; @@ -387,6 +388,8 @@ class Order extends Backend $orderDispatch = new OrderDispatch(); $orderDispatch->allowField(true)->save($insert); $order->status = \app\admin\model\Order::STATUS_DISPATCHED; + $order->dispatch_time = date('Y-m-d H:i:s'); + $order->dispatch_admin_id = $this->auth->id; $order->save(); //日志 diff --git a/application/admin/controller/orders/Dispatch.php b/application/admin/controller/orders/Dispatch.php index 6e94dac..2e1cc12 100644 --- a/application/admin/controller/orders/Dispatch.php +++ b/application/admin/controller/orders/Dispatch.php @@ -153,6 +153,8 @@ class Dispatch extends Backend $result = $this->model->allowField(true)->save($insert); $order->status = Order::STATUS_DISPATCHED; + $order->dispatch_time = date('Y-m-d H:i:s'); + $order->dispatch_admin_id = $this->auth->id; $order->save(); //order log diff --git a/application/admin/controller/statistics/Dispatcher.php b/application/admin/controller/statistics/Dispatcher.php new file mode 100644 index 0000000..02da9ff --- /dev/null +++ b/application/admin/controller/statistics/Dispatcher.php @@ -0,0 +1,99 @@ +model = new \app\admin\model\Order(); + } + + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + /** + * 查看 + * + * @return string|Json + * @throws \think\Exception + * @throws DbException + */ + public function index() + { + + + $this->chart(); + + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + //如果发送的来源是 Selectpage,则转发到 Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } + + //图表统计 + public function chart(){ + + $filter = $this->request->param('filter/a',[]); + + $orderValid = implode(',',$this->model->tabStatus(Order::TAB_VALID)); + + //"COUNT(CASE WHEN status IN (".$orderValid.") THEN 1 END) AS ing_num", + $fields = [ + 'dispatch_admin_id', + "COUNT(CASE WHEN status = 60 THEN 1 END) AS finish_num", //完成数 + "COUNT(CASE WHEN status IN (".$orderValid.") THEN 1 END) AS count_num", //总订单数 (排除取消 和草稿) + "SUM(CASE WHEN status = 60 THEN total END) AS total", //成效额 + "SUM(CASE WHEN status = 60 THEN total END) AS performance", //业绩 + "SUM(CASE WHEN status = 60 THEN (refund_amount + worker_refund_amount) END) AS refund_total", //退款总数 + "COUNT(CASE WHEN refund_amount > 0 OR worker_refund_amount > 0 THEN 1 END) AS refund_count", //退款订单数量 + "AVG(CASE WHEN status > 10 THEN UNIX_TIMESTAMP(dispatch_time) - UNIX_TIMESTAMP(create_time) END) AS avg_time_diff", //派单时效 + // "SUM(CASE WHEN status = 60 THEN (field1 + field2) END) AS performance", + ]; + + $data = $this->model + ->field($fields) + ->group('dispatch_admin_id') + ->select(); + dump($data);exit; + } + + +} diff --git a/application/admin/lang/zh-cn/statistics/dispatcher.php b/application/admin/lang/zh-cn/statistics/dispatcher.php new file mode 100644 index 0000000..3b32427 --- /dev/null +++ b/application/admin/lang/zh-cn/statistics/dispatcher.php @@ -0,0 +1,70 @@ + 'ID', + 'Order_no' => '订单号', + 'Customer' => '客户姓名', + 'Tel' => '客户电话', + 'Status' => '订单状态', + 'Status 0' => '草稿', + 'Set status to 0' => '设为草稿', + 'Status 10' => '未派单', + 'Set status to 10' => '设为未派单', + 'Status 20' => '已派单', + 'Set status to 20' => '设为已派单', + 'Status 30' => '进行中', + 'Set status to 30' => '设为进行中', + 'Status 40' => '待验收', + 'Set status to 40' => '设为待验收', + 'Status 50' => '待财务审核', + 'Set status to 50' => '设为待财务审核', + 'Status 60' => '已完成', + 'Set status to 60' => '设为已完成', + 'Status -10' => '取消', + 'Set status to -10' => '设为取消', + 'Area_id' => '地域', + 'Address' => '详细地址', + 'Lng' => '经度', + 'Lat' => '纬度', + 'Work_tel_id' => '工作机', + 'Source_shop' => '来源店铺', + 'Source' => '订单来源', + 'Source_uid' => '来源UID', + 'Item_id' => '服务ID', + 'Item_title' => '服务名称', + 'Detail' => '订单详情', + 'Remark' => '订单备注', + 'Images' => '图片', + 'Plan_time' => '客户预约时间', + 'Admin_id' => '录单员ID', + 'Coupon_id' => '优惠码id', + 'Total' => '总收款', + 'Online_amount' => '线上收款', + 'Offline_amount' => '线下尾款', + 'Online_amount_last' => '线上尾款', + 'Offline_amount_type' => '线下尾款类型', + 'Offline_amount_type 1' => '师傅收', + 'Offline_amount_type 2' => '公司收', + 'Discount_amount' => '优惠抵扣', + 'Refund_amount' => '公司款额', + 'Worker_refund_amount' => '师傅退款', + 'Real_amount' => '实际收款', + 'Cost' => '师傅成本', + 'Material_cost' => '材料成本', + 'Performance' => '预计利润', + 'Cancel_reason_id' => '取消原因', + 'Cancel_detail' => '取消详情', + 'Audit_remark' => '审核备注', + 'Audit_admin_id' => '审核员', + 'Create_time' => '录单时间', + 'Update_time' => '更新时间', + 'Delete_time' => '删除时间', + 'Dispatch_type' => '1 手动派单 2自动排单', + 'Receive_type' => '1 定金 2全款', + 'Revisit_id' => '回访ID', + 'Dispatch_admin_id' => '派单员', + 'Dispatch_admin_user' => '派单员', + 'Dispatch_time' => '派单时间', + 'Aftersale_id' => '售后ID', + 'Amount_images' => '收款凭据' +]; diff --git a/application/admin/validate/Dispatcherorder.php b/application/admin/validate/Dispatcherorder.php new file mode 100644 index 0000000..5147b99 --- /dev/null +++ b/application/admin/validate/Dispatcherorder.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/validate/Staorder.php b/application/admin/validate/Staorder.php new file mode 100644 index 0000000..75c7104 --- /dev/null +++ b/application/admin/validate/Staorder.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/statistics/dispatcher/add.html b/application/admin/view/statistics/dispatcher/add.html new file mode 100644 index 0000000..b49bd11 --- /dev/null +++ b/application/admin/view/statistics/dispatcher/add.html @@ -0,0 +1,313 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ {foreach name="statusList" item="vo"} + + {/foreach} +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+ + +
+ +
+
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + + + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    +
    + +
    + + +
    + +
    +
      +
      +
      + +
      diff --git a/application/admin/view/statistics/dispatcher/edit.html b/application/admin/view/statistics/dispatcher/edit.html new file mode 100644 index 0000000..6b3b94c --- /dev/null +++ b/application/admin/view/statistics/dispatcher/edit.html @@ -0,0 +1,313 @@ +
      + +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      + {foreach name="statusList" item="vo"} + + {/foreach} +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      +
      + +
      + + +
      + +
      +
        +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + + + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        + +
        +
        +
        + +
        +
        + +
        + + +
        + +
        +
          +
          +
          + +
          diff --git a/application/admin/view/statistics/dispatcher/index.html b/application/admin/view/statistics/dispatcher/index.html new file mode 100644 index 0000000..25676e8 --- /dev/null +++ b/application/admin/view/statistics/dispatcher/index.html @@ -0,0 +1,46 @@ +
          + +
          + {:build_heading(null,FALSE)} + +
          + + +
          +
          +
          +
          +
          + + {:__('Add')} + {:__('Edit')} + {:__('Delete')} + + + + + +
          + +
          +
          +
          + +
          +
          +
          diff --git a/public/assets/js/backend/statistics/dispatcher.js b/public/assets/js/backend/statistics/dispatcher.js new file mode 100644 index 0000000..572fb87 --- /dev/null +++ b/public/assets/js/backend/statistics/dispatcher.js @@ -0,0 +1,99 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'statistics/dispatcher/index' + location.search, + add_url: 'statistics/dispatcher/add', + edit_url: 'statistics/dispatcher/edit', + del_url: 'statistics/dispatcher/del', + multi_url: 'statistics/dispatcher/multi', + import_url: 'statistics/dispatcher/import', + table: 'order', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + fixedColumns: true, + fixedRightNumber: 1, + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'order_no', title: __('Order_no'), operate: 'LIKE'}, + {field: 'customer', title: __('Customer'), operate: 'LIKE'}, + {field: 'tel', title: __('Tel'), operate: 'LIKE'}, + {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"10":__('Status 10'),"20":__('Status 20'),"30":__('Status 30'),"40":__('Status 40'),"50":__('Status 50'),"60":__('Status 60'),"-10":__('Status -10')}, formatter: Table.api.formatter.status}, + {field: 'area_id', title: __('Area_id'), operate: 'LIKE'}, + {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'lng', title: __('Lng'), operate:'BETWEEN'}, + {field: 'lat', title: __('Lat'), operate:'BETWEEN'}, + {field: 'work_tel_id', title: __('Work_tel_id')}, + {field: 'source_shop', title: __('Source_shop'), operate: 'LIKE'}, + {field: 'source', title: __('Source')}, + {field: 'source_uid', title: __('Source_uid'), operate: 'LIKE'}, + {field: 'item_id', title: __('Item_id')}, + {field: 'item_title', title: __('Item_title'), operate: 'LIKE'}, + {field: 'detail', title: __('Detail'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images}, + {field: 'plan_time', title: __('Plan_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {field: 'admin_id', title: __('Admin_id')}, + {field: 'coupon_id', title: __('Coupon_id')}, + {field: 'total', title: __('Total'), operate:'BETWEEN'}, + {field: 'online_amount', title: __('Online_amount'), operate:'BETWEEN'}, + {field: 'offline_amount', title: __('Offline_amount'), operate:'BETWEEN'}, + {field: 'online_amount_last', title: __('Online_amount_last'), operate:'BETWEEN'}, + {field: 'offline_amount_type', title: __('Offline_amount_type'), searchList: {"1":__('Offline_amount_type 1'),"2":__('Offline_amount_type 2')}, formatter: Table.api.formatter.normal}, + {field: 'discount_amount', title: __('Discount_amount'), operate:'BETWEEN'}, + {field: 'refund_amount', title: __('Refund_amount'), operate:'BETWEEN'}, + {field: 'worker_refund_amount', title: __('Worker_refund_amount'), operate:'BETWEEN'}, + {field: 'real_amount', title: __('Real_amount'), operate:'BETWEEN'}, + {field: 'cost', title: __('Cost'), operate:'BETWEEN'}, + {field: 'material_cost', title: __('Material_cost'), operate:'BETWEEN'}, + {field: 'performance', title: __('Performance'), operate:'BETWEEN'}, + {field: 'cancel_reason_id', title: __('Cancel_reason_id')}, + {field: 'cancel_detail', title: __('Cancel_detail'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'audit_remark', title: __('Audit_remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'audit_admin_id', title: __('Audit_admin_id')}, + {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {field: 'delete_time', title: __('Delete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {field: 'dispatch_type', title: __('Dispatch_type')}, + {field: 'receive_type', title: __('Receive_type')}, + {field: 'revisit_id', title: __('Revisit_id')}, + {field: 'dispatch_admin_id', title: __('Dispatch_admin_id')}, + {field: 'dispatch_admin_user', title: __('Dispatch_admin_user'), operate: 'LIKE'}, + {field: 'dispatch_time', title: __('Dispatch_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {field: 'aftersale_id', title: __('Aftersale_id')}, + {field: 'amount_images', title: __('Amount_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images}, + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + edit: function () { + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +});