PropertyServiceWorkLists.php 3.1 KB

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