PropertyHeadAnalysisLists.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\sale\Sale;
  17. use app\common\lists\ListsSearchInterface;
  18. use think\facade\Db;
  19. /**
  20. * Sale列表
  21. * Class SaleLists
  22. * @package app\adminapi\lists
  23. */
  24. class PropertyHeadAnalysisLists extends BaseAdminDataLists implements ListsSearchInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author likeadmin
  30. * @date 2024/12/15 10:53
  31. */
  32. public function setSearch(): array
  33. {
  34. return [
  35. '=' => ['a.sale_group_id', 'a.property_head_id','a.sale_type', 'a.sale_id'],
  36. ];
  37. }
  38. public function queryWhere()
  39. {
  40. $where = [];
  41. if(isset($this->params['time_range']) && $this->params['time_range']){
  42. $startDateTime = strtotime($this->params['time_range'][0]);
  43. $endDateTime = strtotime($this->params['time_range'][1])+86400-1;
  44. $where[] = ['b.finished_time','BETWEEN',[$startDateTime,$endDateTime]];
  45. }
  46. return $where;
  47. }
  48. /**
  49. * 获取数据权限
  50. * $this->adminInfo['data_rules']
  51. * province city admin_id sale_group_id sale_id property_head_id
  52. */
  53. public function queryDataWhere(){
  54. $where = [];
  55. $data_rules = $this->adminInfo['data_rules'];
  56. if (isset($data_rules['province']) && !empty($data_rules['province'])) {
  57. $where[] = ['b.province','in' ,$data_rules['province']];
  58. }
  59. if (isset($data_rules['city']) && !empty($data_rules['city'])) {
  60. $where[] = ['b.city','in' ,$data_rules['city']];
  61. }
  62. if (isset($data_rules['sale_group_id']) && !empty($data_rules['sale_group_id'])) {
  63. $where[] = ['a.sale_group_id','in' ,$data_rules['sale_group_id']];
  64. }
  65. if (isset($data_rules['sale_id']) && !empty($data_rules['sale_id'])) {
  66. $where[] = ['a.sale_id','in' ,$data_rules['sale_id']];
  67. }
  68. if (isset($data_rules['property_head_id']) && !empty($data_rules['property_head_id'])) {
  69. $where[] = ['a.property_head_id','in' ,$data_rules['property_head_id']];
  70. }
  71. return $where;
  72. }
  73. /**
  74. * @notes 获取列表
  75. * @return array
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. * @author likeadmin
  80. * @date 2024/12/15 10:53
  81. */
  82. public function lists(): array
  83. {
  84. return Db::name('property_order')->alias('a')
  85. ->leftJoin('service_work b', 'a.work_id = b.id')
  86. ->leftJoin('property_head c', 'a.property_head_id = c.id')
  87. ->leftJoin('sale d', 'a.sale_id = d.id')
  88. ->field([
  89. 'a.property_head_id','c.property_name','c.village_name','c.address','c.head_name','c.head_mobile','d.sale_name',
  90. Db::raw("COUNT(a.work_id) AS work_count,SUM(b.work_amount) AS total_sales_amount")
  91. ])
  92. ->where('a.sale_type', 'in', [1, 2])
  93. ->where($this->searchWhere)
  94. ->where($this->queryWhere())
  95. ->where($this->queryDataWhere())
  96. ->where('b.service_status', 3)
  97. ->group('a.property_head_id')
  98. ->limit($this->limitOffset, $this->limitLength)
  99. ->select()->toArray();
  100. }
  101. /**
  102. * @notes 获取数量
  103. * @return int
  104. * @author likeadmin
  105. * @date 2024/12/15 10:53
  106. */
  107. public function count(): int
  108. {
  109. return Db::name('property_order')->alias('a')
  110. ->leftJoin('service_work b', 'a.work_id = b.id')
  111. ->leftJoin('sale c', 'a.sale_id = c.id')
  112. ->field([
  113. 'a.property_head_id','c.sale_name','c.mobile',
  114. Db::raw("COUNT(a.work_id) AS work_count,SUM(b.work_amount) AS total_sales_amount")
  115. ])
  116. ->where('a.sale_type', 'in', [1, 2])
  117. ->where('a.order_status', 3)
  118. ->where($this->queryDataWhere())
  119. ->group('a.property_head_id')
  120. ->count();
  121. }
  122. }