diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index ea65065..f9d7f7d 100755 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -42,7 +42,29 @@ class Index extends Backend } $order = new \app\admin\model\Order(); - $to_dispatch = $order->where('status',\app\admin\model\Order::STATUS_DISPATCHING)->count(); + $user = \model('admin')->find($this->auth->id); + + $group = \model('auth_group_access')->where('uid',$this->auth->id)->find()->group_id ?? 0; + + if ($group == 2 || $group == 6) { + // 生成 SQL 语句 + $ids = $user->area_ids??''; + if ($ids == ''){ + $to_dispatch = 0; + }else{ + $ids = explode(',',$ids); + $area_codes = $this->filterAreaCodes($ids); + + $order->where(function ($q) use ($area_codes) { + foreach ($area_codes as $area_code) { + $q->whereOr('area_id', 'like', $area_code . '%'); + } + }); + $to_dispatch = $order->where('status',\app\admin\model\Order::STATUS_DISPATCHING)->count(); + } + }else{ + $to_dispatch = $order->where('status',\app\admin\model\Order::STATUS_DISPATCHING)->count(); + } //待跟进 $to_follow = OrderDispatch::where('follow',0)->auth($this->auth)->count(); diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 9114478..a083958 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -19,6 +19,7 @@ use think\exception\DbException; use think\exception\PDOException; use think\exception\ValidateException; use think\Hook; +use think\Loader; use think\Model; use function Symfony\Component\Clock\now; @@ -119,7 +120,7 @@ class Order extends Backend public function index() { $this->request->filter(['strip_tags', 'trim']); - $group = \model('auth_group_access')->find($this->auth->id)->group_id ?? 0; + $group = \model('auth_group_access')->where('uid',$this->auth->id)->find()->group_id ?? 0; $user = \model('admin')->find($this->auth->id); @@ -144,6 +145,13 @@ class Order extends Backend 'aftersale_id' ]) ->where($where); + $filter = (array)json_decode(input()['filter'] ?? '', true); + $admin_filter = $filter['user.nickname'] ?? false; + + if ($admin_filter){ + $admin_ids = Admin::where('nickname','like','%'.$admin_filter.'%')->column('id'); + $build->whereIn('admin_id',$admin_ids); + } if ($type == 1){ $build->where('status','>=', 0); @@ -152,10 +160,15 @@ class Order extends Backend if ($type == 2){ $build->where('status','<', 0); } - - if ($group == 2) { + if ($group == 2 || $group == 6) { // 生成 SQL 语句 - $area_codes = $this->filterAreaCodes(explode(',', $user->area_ids)); + $ids = $user->area_ids??''; + if ($ids == ''){ + return ['total' => 0, 'rows' => []]; + } + $ids = explode(',',$ids); + $area_codes = $this->filterAreaCodes($ids); + $build->where(function ($q) use ($area_codes) { foreach ($area_codes as $area_code) { $q->whereOr('area_id', 'like', $area_code . '%'); @@ -356,7 +369,7 @@ class Order extends Backend } - private function autoDispatch($order) + public function autoDispatch($order) { // // if ($order->dispatch_type != 2) { @@ -643,36 +656,6 @@ class Order extends Backend } - private function filterAreaCodes(array $area_codes) - { - // 提取所有两位区号 - $prefix_2_digits = []; - foreach ($area_codes as $code) { - if (strlen($code) == 2) { - $prefix_2_digits[] = $code; - } - } - - // 过滤数组 - $filtered_codes = array_filter($area_codes, function ($code) use ($prefix_2_digits) { - // 如果是两位区号,直接保留 - if (strlen($code) == 2) { - return true; - } - // 检查是否有对应的两位前缀,如果有,则排除四位区号 - foreach ($prefix_2_digits as $prefix) { - if (strpos($code, $prefix) === 0) { - return false; - } - } - // 如果没有匹配的两位前缀,则保留 - return true; - }); - - // 重新索引数组 - return array_values($filtered_codes); - } - /** * 编辑 * @@ -734,4 +717,185 @@ class Order extends Backend return null; // 如果找不到返回 null } + + protected function buildparams($searchfields = null, $relationSearch = null) + { + $searchfields = is_null($searchfields) ? $this->searchFields : $searchfields; + $relationSearch = is_null($relationSearch) ? $this->relationSearch : $relationSearch; + $search = $this->request->get("search", ''); + $filter = $this->request->get("filter", ''); + $op = $this->request->get("op", '', 'trim'); + $sort = $this->request->get("sort", !empty($this->model) && $this->model->getPk() ? $this->model->getPk() : 'id'); + $order = $this->request->get("order", "DESC"); + $offset = max(0, $this->request->get("offset/d", 0)); + $limit = max(0, $this->request->get("limit/d", 0)); + $limit = $limit ?: 999999; + //新增自动计算页码 + $page = $limit ? intval($offset / $limit) + 1 : 1; + if ($this->request->has("page")) { + $page = max(0, $this->request->get("page/d", 1)); + } + $this->request->get([config('paginate.var_page') => $page]); + $filter = (array)json_decode($filter, true); + $op = (array)json_decode($op, true); + $filter = $filter ? $filter : []; + $where = []; + $alias = []; + $bind = []; + $name = ''; + $aliasName = ''; + if (!empty($this->model) && $relationSearch) { + $name = $this->model->getTable(); + $alias[$name] = Loader::parseName(basename(str_replace('\\', '/', get_class($this->model)))); + $aliasName = $alias[$name] . '.'; + } + $sortArr = explode(',', $sort); + foreach ($sortArr as $index => & $item) { + $item = stripos($item, ".") === false ? $aliasName . trim($item) : $item; + } + unset($item); + $sort = implode(',', $sortArr); + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + $where[] = [$aliasName . $this->dataLimitField, 'in', $adminIds]; + } + if ($search) { + $searcharr = is_array($searchfields) ? $searchfields : explode(',', $searchfields); + foreach ($searcharr as $k => &$v) { + $v = stripos($v, ".") === false ? $aliasName . $v : $v; + } + unset($v); + $where[] = [implode("|", $searcharr), "LIKE", "%{$search}%"]; + } + $index = 0; + + foreach ($filter as $k => $v) { + if ($k == 'user.nickname') continue; + if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $k)) { + continue; + } + $sym = $op[$k] ?? '='; + if (stripos($k, ".") === false) { + $k = $aliasName . $k; + } + $v = !is_array($v) ? trim($v) : $v; + $sym = strtoupper($op[$k] ?? $sym); + //null和空字符串特殊处理 + if (!is_array($v)) { + if (in_array(strtoupper($v), ['NULL', 'NOT NULL'])) { + $sym = strtoupper($v); + } + if (in_array($v, ['""', "''"])) { + $v = ''; + $sym = '='; + } + } + + switch ($sym) { + case '=': + case '<>': + $where[] = [$k, $sym, (string)$v]; + break; + case 'LIKE': + case 'NOT LIKE': + case 'LIKE %...%': + case 'NOT LIKE %...%': + $where[] = [$k, trim(str_replace('%...%', '', $sym)), "%{$v}%"]; + break; + case '>': + case '>=': + case '<': + case '<=': + $where[] = [$k, $sym, intval($v)]; + break; + case 'FINDIN': + case 'FINDINSET': + case 'FIND_IN_SET': + $v = is_array($v) ? $v : explode(',', str_replace(' ', ',', $v)); + $findArr = array_values($v); + foreach ($findArr as $idx => $item) { + $bindName = "item_" . $index . "_" . $idx; + $bind[$bindName] = $item; + $where[] = "FIND_IN_SET(:{$bindName}, `" . str_replace('.', '`.`', $k) . "`)"; + } + break; + case 'IN': + case 'IN(...)': + case 'NOT IN': + case 'NOT IN(...)': + $where[] = [$k, str_replace('(...)', '', $sym), is_array($v) ? $v : explode(',', $v)]; + break; + case 'BETWEEN': + case 'NOT BETWEEN': + $arr = array_slice(explode(',', $v), 0, 2); + if (stripos($v, ',') === false || !array_filter($arr, function ($v) { + return $v != '' && $v !== false && $v !== null; + })) { + continue 2; + } + //当出现一边为空时改变操作符 + if ($arr[0] === '') { + $sym = $sym == 'BETWEEN' ? '<=' : '>'; + $arr = $arr[1]; + } elseif ($arr[1] === '') { + $sym = $sym == 'BETWEEN' ? '>=' : '<'; + $arr = $arr[0]; + } + $where[] = [$k, $sym, $arr]; + break; + case 'RANGE': + case 'NOT RANGE': + $v = str_replace(' - ', ',', $v); + $arr = array_slice(explode(',', $v), 0, 2); + if (stripos($v, ',') === false || !array_filter($arr)) { + continue 2; + } + //当出现一边为空时改变操作符 + if ($arr[0] === '') { + $sym = $sym == 'RANGE' ? '<=' : '>'; + $arr = $arr[1]; + } elseif ($arr[1] === '') { + $sym = $sym == 'RANGE' ? '>=' : '<'; + $arr = $arr[0]; + } + $tableArr = explode('.', $k); + if (count($tableArr) > 1 && $tableArr[0] != $name && !in_array($tableArr[0], $alias) + && !empty($this->model) && $this->relationSearch) { + //修复关联模型下时间无法搜索的BUG + $relation = Loader::parseName($tableArr[0], 1, false); + $alias[$this->model->$relation()->getTable()] = $tableArr[0]; + } + $where[] = [$k, str_replace('RANGE', 'BETWEEN', $sym) . ' TIME', $arr]; + break; + case 'NULL': + case 'IS NULL': + case 'NOT NULL': + case 'IS NOT NULL': + $where[] = [$k, strtolower(str_replace('IS ', '', $sym))]; + break; + default: + break; + } + $index++; + } + if (!empty($this->model)) { + $this->model->alias($alias); + } + $model = $this->model; + $where = function ($query) use ($where, $alias, $bind, &$model) { + if (!empty($model)) { + $model->alias($alias); + $model->bind($bind); + } + foreach ($where as $k => $v) { + if (is_array($v)) { + call_user_func_array([$query, 'where'], $v); + } else { + $query->where($v); + } + } + }; + return [$where, $sort, $order, $offset, $limit, $page, $alias, $bind]; + } + } diff --git a/application/admin/controller/workers/Worker.php b/application/admin/controller/workers/Worker.php index 849c654..31a9da7 100644 --- a/application/admin/controller/workers/Worker.php +++ b/application/admin/controller/workers/Worker.php @@ -87,7 +87,7 @@ class Worker extends Backend $q->withField(['id','username']); }]) ->where($where) - ->field('worker.id,admin_id,type,name,tel,area_id,create_time,deposit_amount,update_time,status,star') + ->field('worker.id,admin_id,type,name,tel,area_id,create_time,deposit_amount,update_time,status,star,rate,rate_remark,remark,images') ->order($sort, $order); if ($keyword) { $build->where(function ($q) use ($keyword) { diff --git a/application/admin/model/Order.php b/application/admin/model/Order.php index ad9560b..d656580 100644 --- a/application/admin/model/Order.php +++ b/application/admin/model/Order.php @@ -254,7 +254,7 @@ class Order extends Model */ public function scopeAreaauth($query,Auth $auth,string $area_id_field='area_id'){ if(!$auth->isSuperAdmin()){ - $areaIds = array_unique(array_filter(explode(',',trim($auth->area_ids)))); + $areaIds = array_unique(array_filter(explode(',',trim($auth->area_ids??'')))); if(!in_array('*',$areaIds)){ $query->whereIn('fa_order.'.$area_id_field,$areaIds); } diff --git a/application/admin/view/workers/worker/add.html b/application/admin/view/workers/worker/add.html index cc75356..8be80d2 100644 --- a/application/admin/view/workers/worker/add.html +++ b/application/admin/view/workers/worker/add.html @@ -13,20 +13,6 @@ - -
- -
- -
-
-
- -
- -
-
-
@@ -57,7 +43,7 @@
- +
diff --git a/application/admin/view/workers/worker/edit.html b/application/admin/view/workers/worker/edit.html index a8c1fbe..dd35d03 100644 --- a/application/admin/view/workers/worker/edit.html +++ b/application/admin/view/workers/worker/edit.html @@ -16,19 +16,6 @@
-
- -
- -
-
-
- -
- -
-
-
@@ -74,7 +61,7 @@
- +
diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index 45bf392..67e9d79 100755 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -664,4 +664,34 @@ class Backend extends Controller return $formattedTree; } + + public function filterAreaCodes(array $area_codes) + { + // 提取所有两位区号 + $prefix_2_digits = []; + foreach ($area_codes as $code) { + if (strlen($code) == 2) { + $prefix_2_digits[] = $code; + } + } + + // 过滤数组 + $filtered_codes = array_filter($area_codes, function ($code) use ($prefix_2_digits) { + // 如果是两位区号,直接保留 + if (strlen($code) == 2) { + return true; + } + // 检查是否有对应的两位前缀,如果有,则排除四位区号 + foreach ($prefix_2_digits as $prefix) { + if (strpos($code, $prefix) === 0) { + return false; + } + } + // 如果没有匹配的两位前缀,则保留 + return true; + }); + + // 重新索引数组 + return array_values($filtered_codes); + } } diff --git a/public/assets/css/select.css b/public/assets/css/select.css index 6c82287..20d366d 100644 --- a/public/assets/css/select.css +++ b/public/assets/css/select.css @@ -43,6 +43,7 @@ top: 0; text-align: center; color: #c0c4cc; + cursor: pointer; } .zd-input__suffix-inner { diff --git a/public/assets/js/backend/orders/dispatch.js b/public/assets/js/backend/orders/dispatch.js index 05fb492..b7c65b8 100644 --- a/public/assets/js/backend/orders/dispatch.js +++ b/public/assets/js/backend/orders/dispatch.js @@ -352,7 +352,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layer', 'cascader'], // console.log(data,allPathData); $('#item_id').data('myvalue', data.value); }, - defaultValue:$('#item_id_name').val() + defaultValue:$('#item_id_name').val(), + clear:true, + clickParent:true }); // 为表格绑定事件 diff --git a/public/assets/js/backend/statistics/aftersale.js b/public/assets/js/backend/statistics/aftersale.js index 26705eb..6f55b9c 100644 --- a/public/assets/js/backend/statistics/aftersale.js +++ b/public/assets/js/backend/statistics/aftersale.js @@ -270,7 +270,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'addtabs' onChange: function ($this, data, allPathData) { // console.log(data,allPathData); $('#item_id_value').val(data.value); - } + }, + clear:true, + clickParent: true }); }, } diff --git a/public/assets/js/backend/workers/worker.js b/public/assets/js/backend/workers/worker.js index fe67b77..88b958b 100644 --- a/public/assets/js/backend/workers/worker.js +++ b/public/assets/js/backend/workers/worker.js @@ -60,8 +60,18 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], //{field: 'lng', title: __('Lng'), operate:'BETWEEN'}, //{field: 'lat', title: __('Lat'), operate:'BETWEEN'}, {field: 'area.short_merge_name', title: __('Area.short_merge_name'), searchable: false}, + {field: 'rate', title: '分成'}, + {field: 'rate_remark', title: '分成备注'}, + {field: 'remark', title: '备注'}, {field: 'deposit_amount', title: __('Deposit_amount'), operate: 'BETWEEN'}, {field: 'star', title: __('Star'), operate: 'BETWEEN'}, + { + field: 'images', + title: __('Images'), + operate: false, + events: Table.api.events.image, + formatter: Table.api.formatter.images + }, { field: 'create_time', title: __('Create_time'), diff --git a/public/assets/js/cascader.js b/public/assets/js/cascader.js index 1416d66..3f9a47a 100644 --- a/public/assets/js/cascader.js +++ b/public/assets/js/cascader.js @@ -51,6 +51,8 @@ data: null, //支持格式[{value:"",label:"",children:[{value:"",label:""}]}] range: ' / ', //分割符 search: true, //搜索 + clickParent: false, //是否可以选中父级 + clear: false, //是否可以关闭 onChange: function (data) {} } @@ -71,13 +73,13 @@ this.$container = this.$el.wrap(`
`) .wrap(`
`).addClass(this.CLASS.input).prop('readonly', !this.options.search).closest('.' + this.CLASS.wrap); - this.$closeBtn = $(` - + if (this.options.clear){ + this.$closeBtn = $(` - +`).insertAfter(this.$el); + } - `).insertAfter(this.$el); //文本框右侧图标 this.$arrow = $(` @@ -114,9 +116,15 @@ this.$container.removeClass(this.CLASS.checkClass.wrapFocus); }, this)); - this.$container.on('click.item', '.' + this.CLASS.menuNode, $.proxy(this._nodeClick, this)) - .on('click.item', '.' + 'zd-input__close', $.proxy(this._clear, this)) - .on('dblclick.item', '.' + this.CLASS.menuNode, $.proxy(this._nodeDoubleClick, this)); + if (this.options.clickParent){ + this.$container.on('click.item', '.' + this.CLASS.menuNode, $.proxy(this._nodeClick, this)) + .on('click.item', '.' + 'zd-input__close', $.proxy(this._clear, this)) + .on('dblclick.item', '.' + this.CLASS.menuNode, $.proxy(this._nodeDoubleClick, this)); + }else { + this.$container.on('click.item', '.' + this.CLASS.menuNode, $.proxy(this._nodeClick, this)) + .on('click.item', '.' + 'zd-input__close', $.proxy(this._clear, this)); + } + this.$el.on('keyup.wrap', $.proxy(this._keyup, this));