PropertyServiceWorkLists.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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,a.work_amount,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['work_total'] = bcsub($item['work_total'], $item['work_amount'], 2);
  57. $item['appointment_time'] = date('n月j日', strtotime($item['appointment_time']));
  58. }
  59. return $lists;
  60. }
  61. /**
  62. * @notes 获取数量
  63. * @return int
  64. */
  65. public function count(): int
  66. {
  67. return GroupServiceWork::alias('a')
  68. ->leftJoin('group_order b','a.group_order_id=b.id')
  69. ->where($this->queryWhere())
  70. ->count();
  71. }
  72. /**
  73. * @notes 统计工单总收益
  74. * @return float
  75. */
  76. public function extend(): array
  77. {
  78. $totalWorkTotal = GroupServiceWork::alias('a')
  79. ->leftJoin('group_order b','a.group_order_id=b.id')
  80. ->where($this->searchWhere)
  81. ->where($this->queryWhere())
  82. ->sum('a.work_total');
  83. $totalWorkAmount = GroupServiceWork::alias('a')
  84. ->leftJoin('group_order b','a.group_order_id=b.id')
  85. ->where($this->searchWhere)
  86. ->where($this->queryWhere())
  87. ->sum('a.work_amount');
  88. return ["total_amount" => bcsub($totalWorkTotal, $totalWorkAmount, 2)];
  89. }
  90. }