PropertyServiceWorkLists.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\api\lists\property;
  3. use app\api\lists\BaseApiDataLists;
  4. use app\common\lists\ListsExtendInterface;
  5. use app\common\lists\ListsSearchInterface;
  6. use app\common\model\property\PropertyHead;
  7. use app\common\model\works\GroupServiceWork;
  8. use app\common\model\group_activity\GroupUserOrder;
  9. /**
  10. * 代理人完结工单列表
  11. * Class PropertyServiceWorkLists
  12. * @package app\api\lists\property
  13. */
  14. class PropertyServiceWorkLists extends BaseApiDataLists implements ListsSearchInterface, ListsExtendInterface
  15. {
  16. /**
  17. * @notes 设置搜索条件
  18. * @return \string[][]
  19. * @author likeadmin
  20. * @date 2024/07/07 18:37
  21. */
  22. public function setSearch(): array
  23. {
  24. return [
  25. '=' => [],
  26. ];
  27. }
  28. public function queryWhere()
  29. {
  30. // 指定用户
  31. $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
  32. $where[] = ['b.property_head_id', '=', $propertyHeadId];
  33. if (isset($this->params['start_time']) && !empty($this->params['start_time'])) {
  34. $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time'])));
  35. $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time'])));
  36. $where[] = ['b.create_time', 'between', [$monthStart, $monthEnd]];
  37. }
  38. // $where[] = ['a.service_status', '=', 3];
  39. return $where;
  40. }
  41. /**
  42. * @notes 获取列表
  43. * @return array
  44. */
  45. public function lists(): array
  46. {
  47. $lists = GroupServiceWork::alias('a')
  48. ->leftJoin('group_order b','a.group_order_id=b.id')
  49. ->field('a.id,a.work_total,a.address,a.mobile,a.real_name,b.create_time')
  50. ->where($this->queryWhere())
  51. ->limit($this->limitOffset, $this->limitLength)
  52. ->order('b.create_time', 'desc')
  53. ->select()
  54. ->toArray();
  55. return $lists;
  56. }
  57. /**
  58. * @notes 获取数量
  59. * @return int
  60. */
  61. public function count(): int
  62. {
  63. return GroupServiceWork::alias('a')
  64. ->leftJoin('group_order b','a.group_order_id=b.id')
  65. ->where($this->queryWhere())
  66. ->count();
  67. }
  68. /**
  69. * @notes 统计工单总收益
  70. * @return float
  71. */
  72. public function extend(): array
  73. {
  74. $totalWorkTotal = GroupUserOrder::alias('a')
  75. ->leftJoin('group_order b', 'a.group_order_id = b.id')
  76. ->leftJoin('group_service_work c', 'a.id = c.group_user_order_id')
  77. ->where($this->queryWhere())
  78. ->sum('c.work_total');
  79. $totalWorkAmount = GroupUserOrder::alias('a')
  80. ->leftJoin('group_order b', 'a.group_order_id = b.id')
  81. ->leftJoin('group_service_work c', 'a.id = c.group_user_order_id')
  82. ->where($this->queryWhere())
  83. ->sum('c.work_amount');
  84. return ["total_amount" => $totalWorkTotal - $totalWorkAmount];
  85. }
  86. }