PropertyHeadAnalysisLists.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. * @notes 获取列表
  50. * @return array
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. * @author likeadmin
  55. * @date 2024/12/15 10:53
  56. */
  57. public function lists(): array
  58. {
  59. return Db::name('property_order')->alias('a')
  60. ->leftJoin('service_work b', 'a.work_id = b.id')
  61. ->leftJoin('property_head c', 'a.property_head_id = c.id')
  62. ->leftJoin('sale d', 'a.sale_id = d.id')
  63. ->field([
  64. 'a.property_head_id','c.property_name','c.village_name','c.address','c.head_name','c.head_mobile','d.sale_name',
  65. Db::raw("COUNT(a.work_id) AS work_count,SUM(b.work_amount) AS total_sales_amount")
  66. ])
  67. ->where('a.sale_type', 'in', [1, 2])
  68. ->where($this->searchWhere)
  69. ->where($this->queryWhere())
  70. ->where('b.service_status', 3)
  71. ->group('a.property_head_id')
  72. ->limit($this->limitOffset, $this->limitLength)
  73. ->select()->toArray();
  74. }
  75. /**
  76. * @notes 获取数量
  77. * @return int
  78. * @author likeadmin
  79. * @date 2024/12/15 10:53
  80. */
  81. public function count(): int
  82. {
  83. return Db::name('property_order')->alias('a')
  84. ->leftJoin('service_work b', 'a.work_id = b.id')
  85. ->leftJoin('sale c', 'a.sale_id = c.id')
  86. ->field([
  87. 'a.property_head_id','c.sale_name','c.mobile',
  88. Db::raw("COUNT(a.work_id) AS work_count,SUM(b.work_amount) AS total_sales_amount")
  89. ])
  90. ->where('a.sale_type', 'in', [1, 2])
  91. ->where('a.order_status', 3)
  92. ->group('a.property_head_id')
  93. ->count();
  94. }
  95. }