1
0

PropertyOrderAnalysis.php 4.7 KB

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