PropertySurplusLogLists.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\PropertySurplusLog;
  9. use app\common\model\works\ServiceWork;
  10. use DateTime;
  11. /**
  12. * 订单列表
  13. */
  14. class PropertySurplusLogLists extends BaseApiDataLists implements ListsSearchInterface,ListsExtendInterface
  15. {
  16. public function setSearch(): array
  17. {
  18. return [
  19. '=' => ['status','property_head_id'],
  20. ];
  21. }
  22. public function queryWhere()
  23. {
  24. // 指定用户
  25. $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
  26. $where[] = ['property_head_id', '=', $propertyHeadId];
  27. isset($this->params['in_out']) && $this->params['in_out'] && $where[] = ['in_out', '=', $this->params['in_out']];
  28. if(isset($this->params['start_time']) && $this->params['start_time']){
  29. $startDateTime = $this->params['start_time'];
  30. $date = new DateTime($startDateTime);
  31. $date->modify('+1 month');
  32. $startDateTime = strtotime($startDateTime);
  33. $endDateTime = strtotime($date->format('Y-m'))-1;
  34. $where[] = ['create_time', 'BETWEEN', [$startDateTime, $endDateTime]];
  35. }
  36. return $where;
  37. }
  38. public function lists(): array
  39. {
  40. $lists = PropertySurplusLog::with(['propertyHead'])->where($this->searchWhere)
  41. ->where($this->queryWhere())
  42. ->limit($this->limitOffset, $this->limitLength)
  43. ->field(['id','in_out','property_commission_id','amount','status','remark','create_time','update_time','property_head_id'])
  44. ->order('create_time desc')
  45. ->select()
  46. ->toArray();
  47. foreach ($lists as &$item){
  48. if($item['property_commission_id']){
  49. $work_id = PropertyCommission::where('id',$item['property_commission_id'])->value('work_id');
  50. $item['work_title'] = ServiceWork::where('id',$work_id)->value('title');
  51. }
  52. $item['surplus_sn'] = date('YmdHis',strtotime($item['create_time']));
  53. $item['head_bank_card'] = $item['propertyHead']?$item['propertyHead']['head_bank_card']:'';
  54. }
  55. return $lists;
  56. }
  57. /**
  58. * @notes 获取数量
  59. * @return int
  60. */
  61. public function count(): int
  62. {
  63. return PropertySurplusLog::where($this->searchWhere)->where($this->queryWhere())->count();
  64. }
  65. /**
  66. * @notes 返回扩展数据
  67. * @return array|int
  68. */
  69. public function extend(): array
  70. {
  71. return [
  72. 'month_amount' => PropertySurplusLog::where($this->searchWhere)->where($this->queryWhere())->sum('amount')
  73. ];
  74. }
  75. }