售前绩效

This commit is contained in:
hant 2025-05-18 19:39:39 +08:00
parent 1cf64baf95
commit a314f791e7
5 changed files with 371 additions and 2 deletions

View File

@ -376,7 +376,6 @@ class Orderplan extends Backend
'admin_id',
'count(id) count',
])->group('admin_id')
->with('user')
->order('count', 'desc')
->limit(5)
->select();
@ -438,7 +437,6 @@ class Orderplan extends Backend
'item_id',
'count(id) count',
])->group('item_id')
->with('user')
->order('count', 'desc')
->limit(6)
->select();

View File

@ -0,0 +1,286 @@
<?php
namespace app\admin\controller;
use app\admin\model\Admin;
use app\common\controller\Backend;
use Carbon\Carbon;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\Loader;
use function Symfony\Component\Clock\now;
/**
*
*
* @icon fa fa-circle-o
*/
class Performance extends Backend
{
public function _initialize()
{
parent::_initialize();
}
public function presales()
{
//设置过滤方法
$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 = (new Admin())
->where($where)
->field(['id','nickname','mobile'])
->order($sort, $order)
->paginate($limit);
$data = $list->items();
$out = [];
foreach ($data as $datum){
$out[] = $datum->toArray();
}
$ids = array_column($out,'id');
// 默认本月
$build = new \app\admin\model\Order();
$start = (new Carbon())->startOfMonth()->format('Y-m-d 00:00:00');
$end_at = (new Carbon())->format('Y-m-d 23:29:59');
$filter ['daterange'] = json_decode(request()->get('filter','[]'),true)['daterange'] ?? [];
// dd($filter);
if (!empty($filter['daterange'])) {
$arr = explode(' - ', $filter['daterange']);
if (trim($arr[0])) {
$start = trim($arr[0]);
}
if (trim($arr[1])) {
$end_at = trim($arr[1]);
}
}
$build->whereBetween('create_time', [$start, $end_at]);
$data = $build->field([
'admin_id',
'count(id) total',
'count(if(status=60,1,null)) finish',
'sum(if(status=60,performance,null)) money',
])->group('admin_id')
->whereIn('admin_id',$ids)
->select();
$data_array = [];
foreach ($data as $datum){
$data_array [] = $datum->toArray();
}
$data_array_map = array_column($data_array,null,'admin_id');
foreach ($out as &$item){
$item['total'] = $data_array_map[$item['id']]['total'] ?? 0;
$item['finish'] = $data_array_map[$item['id']]['finish'] ?? 0;
$item['money'] = $data_array_map[$item['id']]['money'] ?? 0;
$item['rate'] = '3%';
$item['my_money'] = number_format($item['money'] * 0.03,2,'.','');
}
$result = ['total' => $list->total(), 'rows' => $out];
return json($result);
}
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 : [];
unset($filter['daterange']);
$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 (!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];
}
}

View File

@ -29,4 +29,10 @@ class Admin extends Model
});
}
public function myOrder()
{
return $this->hasMany(Order::class, 'admin_id', 'id');
}
}

View File

@ -0,0 +1,23 @@
<div class="panel panel-default panel-intro">
<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">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('phones/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('phones/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('phones/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('phones/edit')}"
data-operate-del="{:$auth->check('phones/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,56 @@
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
presales: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'performance/presales' + location.search,
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: false,
commonSearch:true,
visible: false,
showToggle: false,
showColumns: false,
showExport: true,
searchFormVisible:true,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'nickname', title: '名称', operate: 'LIKE'},
{field: 'mobile', title: '号码', operate: 'LIKE'},
{field: 'total', title: '派单数',searchable:false},
{field: 'money', title: '派单利润',searchable:false},
{field: 'rate', title: '提成比例',searchable:false},
{field: 'my_money', title: '提成',searchable:false},
{field: 'daterange', title: __('时间筛选'), addclass:'datetimerange',
autocomplete:false,
operate: "RANGE",
datetimeFormat: "YYYY-MM-DD",
data:'autocomplete="off" data-local={"format":"YYYY-MM-DD"}',
visible:false,
defaultValue: Config.default_daterange
},
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});