PropertyOrderAnalysis.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * @notes 获取列表
  56. * @return array
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @author likeadmin
  61. * @date 2024/09/19 14:48
  62. */
  63. public function lists(): array
  64. {
  65. $res = Db::name('property_order')->alias('a')
  66. ->field(['c.id','c.head_name','c.property_name','c.village_name',
  67. 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')
  68. ])
  69. ->leftJoin('service_work b', 'a.work_id = b.id')
  70. ->leftJoin('property_head c', 'a.property_head_id = c.id')
  71. ->where([['b.work_pay_status','=',2],['b.approval','=',1]])
  72. ->where('b.finished_time','>',0)
  73. ->where($this->queryWhere())
  74. ->group('a.property_head_id,month_format')
  75. ->limit($this->limitOffset, $this->limitLength)
  76. ->select()->toArray();
  77. return $res;
  78. }
  79. /**
  80. * @notes 获取数量
  81. * @return int
  82. * @author likeadmin
  83. * @date 2024/09/19 14:48
  84. */
  85. public function count(): int
  86. {
  87. return ServiceWork::where([['work_pay_status','=',2],['approval','=',1]])
  88. ->where('finished_time','>',0)
  89. ->where('user_id','>',0)
  90. ->where($this->queryWhere())
  91. ->count();
  92. }
  93. }