PropertySurplusLogLists.php 2.4 KB

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