SaleMasterWorkerLists.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\sale;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\master_worker_register\MasterWorkerRegister;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\sale\Sale;
  19. use think\facade\Db;
  20. /**
  21. * Sale列表
  22. * Class SaleLists
  23. * @package app\adminapi\lists
  24. */
  25. class SaleMasterWorkerLists extends BaseAdminDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 设置搜索条件
  29. * @return \string[][]
  30. * @author likeadmin
  31. * @date 2024/12/15 10:53
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '=' => ['sale_id'],
  37. ];
  38. }
  39. public function queryWhere()
  40. {
  41. $where = [];
  42. if(isset($this->params['time_range']) && $this->params['time_range']){
  43. $startDateTime = strtotime($this->params['time_range'][0]);
  44. $endDateTime = strtotime($this->params['time_range'][1])+86400-1;
  45. $where[] = ['create_time','BETWEEN',[$startDateTime,$endDateTime]];
  46. }
  47. return $where;
  48. }
  49. /**
  50. * 获取数据权限
  51. * $this->adminInfo['data_rules']
  52. * province city admin_id sale_group_id sale_id property_head_id
  53. */
  54. public function queryDataWhere(){
  55. $where = [];
  56. $data_rules = $this->adminInfo['data_rules'];
  57. if (isset($data_rules['province']) && !empty($data_rules['province'])) {
  58. $where[] = ['province','in' ,$data_rules['province']];
  59. }
  60. if (isset($data_rules['city']) && !empty($data_rules['city'])) {
  61. $where[] = ['city','in' ,$data_rules['city']];
  62. }
  63. if (isset($data_rules['sale_group_id']) && !empty($data_rules['sale_group_id'])) {
  64. $sale_ids = Sale::where('sale_group_id','in',$data_rules['sale_group_id'])->column('id')??[];
  65. $where[] = ['sale_id','in' ,$sale_ids];
  66. }
  67. if (isset($data_rules['sale_id']) && !empty($data_rules['sale_id'])) {
  68. $where[] = ['sale_id','in' ,$data_rules['sale_id']];
  69. }
  70. return $where;
  71. }
  72. /**
  73. * @notes 获取列表
  74. * @return array
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @author likeadmin
  79. * @date 2024/12/15 10:53
  80. */
  81. public function lists(): array
  82. {
  83. return MasterWorkerRegister::with(['sale'])
  84. ->where('sale_id','>',0)
  85. ->where($this->searchWhere)
  86. ->where($this->queryWhere())
  87. ->where($this->queryDataWhere())
  88. ->field([
  89. 'sale_id',
  90. Db::raw("COUNT(id) AS register_count,SUM(CASE WHEN worker_id > 0 THEN 1 ELSE 0 END) AS settled_count"),
  91. Db::raw("'".($this->params['time_range'][0]??'')."' AS start_date"),
  92. Db::raw("'".($this->params['time_range'][1]??'')."' AS end_date"),
  93. ])
  94. ->group('sale_id')
  95. ->limit($this->limitOffset, $this->limitLength)
  96. ->select()->toArray();
  97. }
  98. /**
  99. * @notes 获取数量
  100. * @return int
  101. * @author likeadmin
  102. * @date 2024/12/15 10:53
  103. */
  104. public function count(): int
  105. {
  106. return MasterWorkerRegister::with(['sale'])
  107. ->where('sale_id','>',0)
  108. ->where($this->searchWhere)
  109. ->where($this->queryWhere())
  110. ->where($this->queryDataWhere())
  111. ->field(['sale_id'])
  112. ->group('sale_id')
  113. ->count();
  114. }
  115. public function setExcelComplexFields(): array
  116. {
  117. $zh_cn_fields = [
  118. '销售人员','所属组','注册数','入驻数','开始日期', '结束日期'
  119. ];
  120. $data_fields = [
  121. function($row){ return $row['sale']['sale_name']??''; },
  122. function($row){ return $row['sale']['saleGroupInfo']['sale_name']??''; },
  123. 'register_count','settled_count','start_date','end_date'
  124. ];
  125. return [
  126. 'zh_cn_fields' => $zh_cn_fields,
  127. 'data_fields' => $data_fields
  128. ];
  129. }
  130. }