PropertyOrderLists.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\PropertyCommission;
  7. use app\common\model\property\PropertyHead;
  8. use app\common\model\property\PropertyOrder;
  9. use app\common\model\property\PropertySurplusLog;
  10. use app\common\model\works\ServiceWork;
  11. use DateTime;
  12. /**
  13. * 订单列表
  14. */
  15. class PropertyOrderLists extends BaseApiDataLists implements ListsSearchInterface,ListsExtendInterface
  16. {
  17. public function setSearch(): array
  18. {
  19. return [
  20. '=' => ['id','order_status'],
  21. ];
  22. }
  23. public function queryWhere()
  24. {
  25. // 指定用户
  26. $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
  27. $where[] = ['property_head_id', '=', $propertyHeadId];
  28. return $where;
  29. }
  30. public function lists(): array
  31. {
  32. $lists = PropertyOrder::with(['propertyHead','propertyUser','propertyWork'])->where($this->searchWhere)
  33. ->where($this->queryWhere())
  34. ->limit($this->limitOffset, $this->limitLength)
  35. ->field(['id','property_head_id','property_user_id','remark','order_status','work_id','create_time','update_time'])
  36. ->order('create_time desc')
  37. ->select()
  38. ->toArray();
  39. foreach ($lists as &$item){
  40. $item['householder_name'] = $item['propertyUser']?$item['propertyUser']['householder_name']:'';
  41. $item['householder_mobile'] = $item['propertyUser']?$item['propertyUser']['householder_name']:'';
  42. $item['work_address'] = $item['propertyWork']?$item['propertyWork']['address']:'';
  43. $item['work_create_time'] = $item['propertyWork']?$item['propertyWork']['create_time']:'';
  44. }
  45. return $lists;
  46. }
  47. /**
  48. * @notes 获取数量
  49. * @return int
  50. */
  51. public function count(): int
  52. {
  53. return PropertyOrder::where($this->searchWhere)->where($this->queryWhere())->count();
  54. }
  55. /**
  56. * @notes 返回扩展数据
  57. * @return array|int
  58. */
  59. public function extend(): array
  60. {
  61. $workIds = PropertyOrder::where('order_status',3)->where($this->queryWhere())->column('work_id');
  62. if(empty($workIds)){
  63. return ['month_amount' => 0,'month_num' => 0];
  64. }
  65. $startDateTime = strtotime(date('Y-m-01'));
  66. if(isset($this->params['start_month']) && $this->params['start_month']){
  67. $startDateTime = strtotime($this->params['start_month']);
  68. }
  69. $endDateTime = strtotime('+1 month', strtotime($startDateTime))-1;
  70. $serviceWork = ServiceWork::where([['id','in',$workIds],['work_pay_status','=',2],['approval','=',1]])
  71. ->where('user_id',$this->userId)
  72. ->where('create_time','BETWEEN',[$startDateTime,$endDateTime]);
  73. return [
  74. 'month_amount' =>$serviceWork->sum('work_amount'),
  75. 'month_num' => $serviceWork->count('id')
  76. ];
  77. }
  78. }