Customers.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <?php
  2. namespace app\admin\controller\qingdongams\statistic;
  3. use addons\qingdongams\model\Customer as CustomerModel;
  4. use addons\qingdongams\model\Event;
  5. use addons\qingdongams\model\Form;
  6. use addons\qingdongams\model\Quote;
  7. use addons\qingdongams\model\StaffSignIn;
  8. use app\admin\model\AuthGroup;
  9. use app\common\controller\Backend;
  10. use addons\qingdongams\model\Contract;
  11. use addons\qingdongams\model\Customer;
  12. use addons\qingdongams\model\Field;
  13. use addons\qingdongams\model\Receivables;
  14. use addons\qingdongams\model\Record;
  15. use addons\qingdongams\model\Staff;
  16. use fast\Tree;
  17. use think\Config;
  18. use think\Exception;
  19. /**
  20. * 客户分析
  21. */
  22. class Customers extends Backend
  23. {
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. try{
  28. \think\Db::execute("SET @@sql_mode='';");
  29. }catch (Exception $e){
  30. }
  31. $childrenGroupIds = $this->auth->getChildrenGroupIds(true);
  32. $groupList = collection(AuthGroup::where('id', 'in', $childrenGroupIds)->select())->toArray();
  33. Tree::instance()->init($groupList);
  34. $groupList = [];
  35. if ($this->auth->isSuperAdmin()) {
  36. $groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
  37. } else {
  38. $groups = $this->auth->getGroups();
  39. $groupIds = [];
  40. foreach ($groups as $m => $n) {
  41. if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) {
  42. continue;
  43. }
  44. $groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid'])));
  45. foreach ($groupList as $index => $item) {
  46. $groupIds[] = $item['id'];
  47. }
  48. }
  49. }
  50. $this->assign('groupdata', $groupList);
  51. $this->assign('typeList', [0 => '请选择', 1 => '部门', 2 => '员工']);
  52. }
  53. /**
  54. * 客户总量分析
  55. */
  56. public function index()
  57. {
  58. $time = strtotime(date('Y-m', strtotime('-1 year')));
  59. $auth = Staff::getMyStaffIds();
  60. $staff_id = implode(',', $auth); //权限
  61. //新增客户数
  62. $customers = CustomerModel::where([
  63. 'createtime' => [
  64. 'egt',
  65. $time
  66. ],
  67. 'owner_staff_id' => ['in', $staff_id]
  68. ])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,count(*) as c")->group('ctime')->select();
  69. $select = [];
  70. foreach ($customers as $v) {
  71. $select[$v['ctime']] = $v['c'];
  72. }
  73. //已成交客户数
  74. $usecustomers = CustomerModel::where([
  75. 'owner_staff_id' => ['in', $staff_id],
  76. 'createtime' => [
  77. 'egt',
  78. $time
  79. ],
  80. 'contract_status' => 1
  81. ])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,count(*) as c")->group('ctime')->select();
  82. $useselect = [];
  83. foreach ($usecustomers as $v) {
  84. $useselect[$v['ctime']] = $v['c'];
  85. }
  86. $toMonthTime = strtotime(date('Y-m'));
  87. $typedata = [];
  88. for ($time; $time <= $toMonthTime; $time = strtotime('+1 month', $time)) {
  89. $typedata['date'][] = date('Y-m', $time);
  90. $typedata['num'][] = $select[date('Y-m', $time)] ?? 0;
  91. $typedata['use'][] = $useselect[date('Y-m', $time)] ?? 0;
  92. }
  93. $where['status'] = 1;
  94. $staff = Staff::where($where)->field('id,name')->select();
  95. $customInfo = [];
  96. foreach ($staff as $k => $v) {
  97. $customInfo[$k]['name'] = $v['name'];
  98. //新增客户数
  99. $addcustomer = CustomerModel::where(array('owner_staff_id' => $v['id']))->count();
  100. $customInfo[$k]['addcustomer'] = $addcustomer;
  101. //成交客户数
  102. $usecustomer = CustomerModel::where(array('owner_staff_id' => $v['id'], 'contract_status' => 1))->count();
  103. $customInfo[$k]['usecustomer'] = $usecustomer;
  104. //客户成交率(%)
  105. $customInfo[$k]['userate'] = $addcustomer ? sprintf("%.2f", $usecustomer / $addcustomer) : 0;
  106. //合同总金额
  107. $contractMoney = Contract::where(array('owner_staff_id' => $v['id'], 'check_status' => 2))->sum('money');
  108. $customInfo[$k]['contractMoney'] = $contractMoney;
  109. //回款金额
  110. $reciveMoney = Receivables::where(array('owner_staff_id' => $v['id'], 'check_status' => 2))->sum('money');
  111. $customInfo[$k]['reciveMoney'] = $reciveMoney;
  112. //未回款金额
  113. $customInfo[$k]['noreciveMoney'] = $contractMoney - $reciveMoney;
  114. //回款完成率
  115. $customInfo[$k]['ratereciveMoney'] = $contractMoney ? sprintf("%.2f", $reciveMoney / $contractMoney) : 0;
  116. }
  117. $this->view->assign([
  118. 'customerdata' => $typedata,
  119. 'customInfo' => $customInfo
  120. ]);
  121. return $this->view->fetch();
  122. }
  123. /**
  124. * 客户跟进次数分析
  125. */
  126. public function record()
  127. {
  128. $time = strtotime(date('Y-m', strtotime('-1 year')));
  129. $auth = Staff::getMyStaffIds();
  130. $staff_id = implode(',', $auth); //权限修改
  131. //跟进客户数
  132. $customers = StaffSignIn::where([
  133. 'staff_id' => ['in', $staff_id],
  134. 'relation_type' => 0,
  135. 'createtime' => [
  136. 'egt',
  137. $time
  138. ]
  139. ])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,relation_id,count('*') as c")->group('relation_id,ctime')->select();
  140. $select = [];
  141. foreach ($customers as $v) {
  142. $select[$v['ctime']] = $v['c'];
  143. }
  144. //跟进次数
  145. $usecustomers = StaffSignIn::where([
  146. 'staff_id' => ['in', $staff_id],
  147. 'relation_type' => 0,
  148. 'createtime' => [
  149. 'egt',
  150. $time
  151. ]
  152. ])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,count(*) as c")->group('ctime')->select();
  153. $useselect = [];
  154. foreach ($usecustomers as $v) {
  155. $useselect[$v['ctime']] = $v['c'];
  156. }
  157. $toMonthTime = strtotime(date('Y-m'));
  158. $typedata = [];
  159. for ($time; $time <= $toMonthTime; $time = strtotime('+1 month', $time)) {
  160. $typedata['date'][] = date('Y-m', $time);
  161. $typedata['num'][] = $select[date('Y-m', $time)] ?? 0;
  162. $typedata['use'][] = $useselect[date('Y-m', $time)] ?? 0;
  163. }
  164. $where['status'] = 1;
  165. $staff = Staff::where($where)->field('id,name')->select();
  166. $customInfo = [];
  167. foreach ($staff as $k => $v) {
  168. $customInfo[$k]['name'] = $v['name'];
  169. //跟进客户数
  170. $addcustomer = StaffSignIn::where(array('staff_id' => $v['id'], 'relation_type' => 0))->group('relation_id')->count();
  171. $customInfo[$k]['addcustomer'] = $addcustomer;
  172. //跟进次数
  173. $usecustomer = StaffSignIn::where(array('staff_id' => $v['id'], 'relation_type' => 0))->count();
  174. $customInfo[$k]['usecustomer'] = $usecustomer;
  175. }
  176. $this->view->assign([
  177. 'customerdata' => $typedata,
  178. 'customInfo' => $customInfo
  179. ]);
  180. return $this->view->fetch();
  181. }
  182. /**
  183. * 客户跟进方式分析
  184. */
  185. public function recordtype()
  186. {
  187. //客户来源统计
  188. $time = strtotime(date('Y-m', strtotime('-1 year')));
  189. $auth = Staff::getMyStaffIds();
  190. $staff_id = implode(',', $auth); //权限修改
  191. $sources = Field::getField('客户来源');
  192. $customers = CustomerModel::where([
  193. 'owner_staff_id' => ['in', $staff_id],
  194. 'createtime' => [
  195. 'egt',
  196. $time
  197. ]
  198. ])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,source,count(*) as c")->group('source,ctime')->select();
  199. $select = [];
  200. foreach ($customers as $v) {
  201. $select[$v['source']][$v['ctime']] = $v['c'];
  202. }
  203. $toMonthTime = strtotime(date('Y-m'));
  204. $sourcedata = ['客户来源' => ['客户来源']];
  205. for ($time; $time <= $toMonthTime; $time = strtotime('+1 month', $time)) {
  206. $sourcedata['客户来源'][] = date('Y-m', $time);
  207. foreach ($sources as $v) {
  208. if (empty($sourcedata[$v])) {
  209. $sourcedata[$v][] = $v;
  210. }
  211. $sourcedata[$v][] = intval($select[$v][date('Y-m', $time)] ?? 0);
  212. }
  213. }
  214. $this->view->assign([
  215. 'customerdata' => array_values($sourcedata),
  216. ]);
  217. return $this->view->fetch();
  218. }
  219. /**
  220. * 客户成交率分析
  221. */
  222. public function ratio()
  223. {
  224. $type = input('type', 'bar');//bar 柱状图 pie 饼状图
  225. $row = input('row/a');
  226. if (isset($row['times']) && $row['times']) {
  227. $times = explode(' - ', $row['times']);
  228. } else {
  229. $times = [date('Y-01-01'), date('Y-m-d')];
  230. }
  231. $between = [strtotime($times[0]), strtotime($times[1]) + 86400 - 1];
  232. $group_id = $row['group_id'] ?? 0;
  233. $ids = [];
  234. if ($group_id) {//角色组
  235. $ids = Staff::getGroupStaffIds($group_id);
  236. }
  237. if (isset($row['staff_id']) && $row['staff_id']) {
  238. $ids = $staff_id = $row['staff_id'];
  239. } else {
  240. $staff_id = '';
  241. }
  242. $this->view->assign([
  243. 'customerdata' => [],
  244. 'times' => implode(' - ', $times),
  245. 'staff_id' => $staff_id,
  246. 'group_id' => $group_id,
  247. 'list' => [],
  248. 'type' => $type,
  249. ]);
  250. return $this->view->fetch();
  251. }
  252. /**
  253. * 客户自定义分析
  254. */
  255. public function customize()
  256. {
  257. $type = input('type', 'bar');//bar 柱状图 pie 饼状图
  258. $row = input('row/a');
  259. if (isset($row['times']) && $row['times']) {
  260. $times = explode(' - ', $row['times']);
  261. } else {
  262. $times = [date('Y-01-01'), date('Y-m-d')];
  263. }
  264. $between = [strtotime($times[0]), strtotime($times[1]) + 86400 - 1];
  265. $group_id = $row['group_id'] ?? 0;
  266. $ids = [];
  267. if ($group_id) {//角色组
  268. $ids = Staff::getGroupStaffIds($group_id);
  269. }
  270. if (isset($row['staff_id']) && $row['staff_id']) {
  271. $ids = $staff_id = $row['staff_id'];
  272. } else {
  273. $staff_id = '';
  274. }
  275. $customer = Form::getDataValue('customer');
  276. $fields = [];
  277. foreach ($customer as $v) {
  278. if ($v['component'] == 'select' && substr($v['id'], 0, 5) != 'other') {
  279. $content = $v['config']['content'];
  280. $label = [];
  281. foreach ($content as $ves) {
  282. $label[] = $ves['label'];
  283. }
  284. $fields[$v['id']] = ['id' => $v['id'], 'name' => $v['config']['label'],
  285. 'label' => $label, 'multiple' => $v['config']['multiple']];
  286. }
  287. }
  288. if (isset($row['field']) && $row['field']) {
  289. $field = html_entity_decode(trim($row['field']));
  290. if (empty($fields[$field])) {
  291. $this->error('没有可用的筛选项');
  292. }
  293. } else {
  294. if (empty($fields)) {
  295. $this->error('没有可用的筛选项');
  296. }
  297. $field = current($fields)['id'];
  298. }
  299. $where = [
  300. 'createtime' => [
  301. 'between',
  302. $between
  303. ]];
  304. if ($ids || !empty($group_id)) {
  305. $where['owner_staff_id'] = ['in', $ids];
  306. }
  307. if ($fields[$field]['multiple'] == false) {
  308. $customers = Customer::where($where)
  309. ->field("{$field},count(*) as c")
  310. ->group($field)->order('c desc')->select();
  311. $select = [];
  312. $total_count = 0;
  313. foreach ($customers as $v) {
  314. $total_count += $v['c'];
  315. $select[$v[$field]] = $v['c'];
  316. }
  317. } else {
  318. $select = [];
  319. $total_count = 0;
  320. //多选情况
  321. foreach ($fields[$field]['label'] as $label) {
  322. $where[$field] = ['like', "%{$label}%"];
  323. $count = Customer::where($where)->count();
  324. $select[$label] = $count;
  325. $total_count += $count;
  326. }
  327. }
  328. $sourcedata = [];
  329. $y = [];
  330. $list = [];
  331. $data = [];
  332. foreach ($fields[$field]['label'] as $label) {
  333. if (isset($select[$label])) {
  334. $list[] = [
  335. 'name' => $label,
  336. 'number' => $select[$label],
  337. 'ratio' => sprintf("%.2f", $select[$label] / $total_count * 100),
  338. ];
  339. $data[] = ['value' => $select[$label], 'name' => $label];
  340. $y[] = $select[$label];
  341. } else {
  342. $list[] = [
  343. 'name' => $label,
  344. 'number' => 0,
  345. 'ratio' => 0,
  346. ];
  347. $data[] = ['value' => 0, 'name' => $label];
  348. $y[] = 0;
  349. }
  350. }
  351. $sourcedata['x'] = $fields[$field]['label'];
  352. $sourcedata['y'] = $y;
  353. $sourcedata['title'] = $fields[$field]['name'];
  354. $sourcedata['data'] = $data;
  355. $sourcedata['type'] = $type;
  356. $this->view->assign([
  357. 'customerdata' => $sourcedata,
  358. 'times' => implode(' - ', $times),
  359. 'fields' => $fields,
  360. 'field' => $field,
  361. 'field_name' => $fields[$field]['name'],
  362. 'staff_id' => $staff_id,
  363. 'group_id' => $group_id,
  364. 'list' => $list,
  365. 'type' => $type,
  366. 'multiple' => $fields[$field]['multiple'],
  367. ]);
  368. return $this->view->fetch();
  369. }
  370. /**
  371. * 获取员工列表
  372. */
  373. public function getstaff()
  374. {
  375. $pageSize = input('pageSize');
  376. $pageNumber = input('pageNumber');
  377. $where = [];
  378. if ($keyValue = $this->request->request("keyValue")) {
  379. $where['id'] = ['in', $keyValue];
  380. } else {
  381. $where['id'] = ['in', Staff::getMyStaffIds()];
  382. }
  383. $name = input('name');
  384. if (!empty($name)) {
  385. $where['name'] = ['like', '%' . $name . '%'];
  386. }
  387. $staff = Staff::where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
  388. return json(['list' => $staff->items(), 'total' => $staff->total()]);
  389. }
  390. /**
  391. * 成交分析
  392. */
  393. public function deal()
  394. {
  395. list($where, $times, $row) = $this->getWhere();//获取where
  396. //到访
  397. $toWhere = array_merge($where, ['process' => 2]);
  398. $toResult = Event::where($toWhere)->field('count(*) as count,create_staff_id')->group('relation_id')->select();
  399. // 报价
  400. $quoteWhere = array_merge($where, ['check_status' => 2]);
  401. $quoteResult = Quote::where($quoteWhere)->field('count(*) as count,create_staff_id')->group('customer_id')->select();
  402. // 合同生效
  403. $contractWhere = array_merge($where, ['check_status' => 2]);
  404. $contractResult = Contract::where($contractWhere)->field('count(*) as count,create_staff_id')->group('customer_id')->select();
  405. // 表格
  406. $staffIds = array_unique(array_merge(array_column($toResult, 'create_staff_id'), array_column($quoteResult, 'create_staff_id'), array_column($contractResult, 'create_staff_id')));
  407. $staffList = Staff::where('id', 'in', $staffIds)->column('name', 'id');
  408. $toResult = $this->getArr($toResult, 'create_staff_id');
  409. $quoteResult = $this->getArr($quoteResult, 'create_staff_id');
  410. $contractResult = $this->getArr($contractResult, 'create_staff_id');
  411. $totalTo = array_sum($toResult);
  412. $totalQuote = array_sum($quoteResult);
  413. $totalContract = array_sum($contractResult);
  414. $table[] = [
  415. 'name' => '总计',
  416. 'to' => $totalTo,
  417. 'quote' => $totalQuote,
  418. 'contract' => $totalContract,
  419. ];
  420. $result = [
  421. ['value' => $totalTo, 'name' => '到访'],
  422. ['value' => $totalQuote, 'name' => '报价'],
  423. ['value' => $totalContract, 'name' => '合同'],
  424. ];
  425. foreach ($staffList as $key => $item) {
  426. $table[] = [
  427. 'name' => $staffList[$key],
  428. 'to' => isset($toResult[$key]) ? $toResult[$key] : 0,
  429. 'quote' => isset($quoteResult[$key]) ? $quoteResult[$key] : 0,
  430. 'contract' => isset($contractResult[$key]) ? $contractResult[$key] : 0,
  431. ];
  432. }
  433. $this->view->assign([
  434. 'result' => $result,
  435. 'table' => $table,
  436. 'row' => $row
  437. ]);
  438. $this->assignconfig('result', $result);
  439. $this->assignconfig('ids', $row['ids']);
  440. return $this->view->fetch();
  441. }
  442. /**
  443. * 跟进分析
  444. */
  445. public function follow()
  446. {
  447. list($where, $times, $row) = $this->getWhere(1);//获取where
  448. list($result, $table) = $this->getFollowList($where, $times);
  449. $this->view->assign([
  450. 'result' => $result,
  451. 'table' => $table,
  452. 'row' => $row
  453. ]);
  454. $this->assignconfig('result', $result);
  455. $this->assignconfig('ids', $row['ids']);
  456. return $this->view->fetch();
  457. }
  458. /**
  459. * 筛选条件
  460. */
  461. protected function getFollowList($where, $times)
  462. {
  463. // 员工跟进次数
  464. $result = StaffSignIn::where($where)
  465. ->field('count(*) as count,FROM_UNIXTIME(createtime,"%Y-%m-%d") as time')
  466. ->group('time,customer_id')->select();
  467. // 唠嗑跟进次数
  468. $trade_result = StaffSignIn::where($where)->where(['customer_status' => 1])//成交
  469. ->field('count(*) as count,FROM_UNIXTIME(createtime,"%Y-%m-%d") as time')
  470. ->group('time,customer_id')->select();
  471. $addCount = $this->getArr($result, 'time');
  472. $tradeCount = $this->getArr($trade_result, 'time');
  473. $dateList = getDateList($times[0], $times[1]);
  474. $result = [];
  475. foreach ($dateList as $date) {
  476. $result['date'][] = $date;
  477. $result['add_count'][] = $addCount[$date] ?? 0;
  478. $result['trade_count'][] = $tradeCount[$date] ?? 0;
  479. }
  480. // 表格跟进次数
  481. $tableTimes = StaffSignIn::where($where)
  482. ->field('count(*) as count,FROM_UNIXTIME(createtime,"%Y-%m-%d") as time,staff_id')
  483. ->group('staff_id,time')->select();
  484. // 跟进客户数
  485. $tablePeople = StaffSignIn::where($where)->where(['customer_status' => 1])//成交
  486. ->field('count(*) as count,FROM_UNIXTIME(createtime,"%Y-%m-%d") as time,staff_id')
  487. ->group('staff_id,customer_id')->select();
  488. $staffIds = array_unique(array_merge(array_column($tableTimes, 'staff_id'), array_column($tablePeople, 'staff_id')));
  489. $staffList = Staff::where('id', 'in', $staffIds)->column('name', 'id');
  490. $tableTimes = $this->getArr($tableTimes, 'staff_id');
  491. $tablePeople = $this->getArr($tablePeople, 'staff_id');
  492. $totalAdd = array_sum($tableTimes);
  493. $totalBook = array_sum($tablePeople);
  494. $table[] = [
  495. 'name' => '总计',
  496. 'add' => $totalAdd,
  497. 'book' => $totalBook,
  498. ];
  499. foreach ($staffList as $key => $item) {
  500. $table[] = [
  501. 'name' => $staffList[$key],
  502. 'add' => isset($tableTimes[$key]) ? $tableTimes[$key] : 0,// 跟进次数
  503. 'book' => isset($tablePeople[$key]) ? $tablePeople[$key] : 0,// 跟进客户数
  504. ];
  505. }
  506. return [$result, $table];
  507. }
  508. /**
  509. * 筛选条件
  510. */
  511. public function staffes()
  512. {
  513. if ($this->request->isPost()) {
  514. $type_id = input('typeid');
  515. $params = [];
  516. if ($type_id == 1) {
  517. $model = new AuthGroup();
  518. $groups = $model->where($params)->field('id,name')->select();
  519. $list = [];
  520. foreach ($groups as $v) {
  521. $list[$v['id']] = $v['name'];
  522. }
  523. } else {
  524. $model = new Staff();
  525. $params['status'] = 1;
  526. $list = $model->where($params)->column('name', 'id');
  527. }
  528. return json($list);
  529. }
  530. }
  531. /**
  532. * 筛选条件
  533. */
  534. protected function getWhere($type = 0)
  535. {
  536. $beforeDays = strtotime(date('Y-m-d', strtotime('-30 day', time())));
  537. $times = [$beforeDays, time()];
  538. $this->request->filter(['strip_tags']);
  539. $row['type_id'] = 0;
  540. $row['ids'] = 0;
  541. $where = [];
  542. if ($this->request->get()) {
  543. $params = $this->request->get('row/a');
  544. if (isset($params['times']) && !empty($params['times'])) {
  545. $timesArr = explode('-', $params['times']);
  546. if (count($timesArr) < 5) {
  547. $this->error('时间格式错误');
  548. }
  549. $times[0] = $timesArr[0] . '-' . $timesArr[1] . '-' . $timesArr[2];
  550. $times[1] = $timesArr[3] . '-' . $timesArr[4] . '-' . $timesArr[5];
  551. $times = [strtotime($times[0]), strtotime($times[1]) + 86400];
  552. }
  553. if(isset($params['type_id'])){
  554. $row['type_id'] = $params['type_id'];
  555. }
  556. if(isset($params['ids'])){
  557. $row['ids'] = $params['ids'] ?? 0;
  558. }
  559. if (isset($params['type_id']) && isset($params['ids']) && $params['type_id'] == 1 && $params['ids']) {
  560. $l_ids = Staff::getOneGroupStaffIds($params['ids']);
  561. if ($type == 1) {
  562. $where['staff_id'] = ['in', $l_ids];
  563. } else {
  564. $where['create_staff_id'] = ['in', $l_ids];
  565. }
  566. } elseif (isset($params['type_id']) && isset($params['ids']) && $params['type_id'] == 2 && $params['ids']) {
  567. if ($type == 1) {
  568. $where['staff_id'] = $params['ids'];
  569. } else {
  570. $where['create_staff_id'] = $params['ids'];
  571. }
  572. }
  573. }
  574. $row['times'] = implode(' - ', [date("Y-m-d", $times[0]), date("Y-m-d", $times[1])]);
  575. $where['createtime'] = ['between', $times];
  576. return [$where, $times, $row];
  577. }
  578. /**
  579. * 筛选条件
  580. */
  581. protected function getArr($data, $key)
  582. {
  583. $tradeCount = [];
  584. foreach ($data as $v) {
  585. $tradeCount[$v[$key]] = $v['count'];
  586. }
  587. return $tradeCount;
  588. }
  589. }