PropertyGroupSettlementLists.php 2.3 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\group_activity\GroupSettlement;
  7. use app\common\model\property\PropertyHead;
  8. use app\common\model\works\GroupServiceWork;
  9. /**
  10. * 代理人结算列表
  11. * Class PropertyGroupSettlementLists
  12. * @package app\api\lists\property
  13. */
  14. class PropertyGroupSettlementLists extends BaseApiDataLists implements ListsSearchInterface, ListsExtendInterface
  15. {
  16. /**
  17. * @notes 设置搜索条件
  18. * @return \string[][]
  19. * @author likeadmin
  20. * @date 2024/07/07 18:37
  21. */
  22. public function setSearch(): array
  23. {
  24. return [
  25. '=' => [],
  26. ];
  27. }
  28. public function queryWhere()
  29. {
  30. // 指定用户
  31. $propertyHeadId = (int)PropertyHead::where('user_id',$this->userId)->value('id');
  32. $where[] = ['property_head_id', '=', $propertyHeadId];
  33. if (isset($this->params['start_time']) && !empty($this->params['start_time'])) {
  34. $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time'])));
  35. $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time'])));
  36. $where[] = ['create_time', 'between', [$monthStart, $monthEnd]];
  37. }
  38. $where[] = ['settlement_type', '=', 1];
  39. return $where;
  40. }
  41. /**
  42. * @notes 获取列表
  43. * @return array
  44. */
  45. public function lists(): array
  46. {
  47. $lists = GroupSettlement::where($this->queryWhere())
  48. ->order("id","desc")
  49. ->limit($this->limitOffset, $this->limitLength)
  50. ->select()
  51. ->toArray();
  52. foreach($lists as &$item) {
  53. $item['create_time'] = date('n月j日', strtotime($item['create_time']));
  54. }
  55. return $lists;
  56. }
  57. /**
  58. * @notes 获取数量
  59. * @return int
  60. */
  61. public function count(): int
  62. {
  63. return GroupSettlement::where($this->queryWhere())->count();
  64. }
  65. /**
  66. * @notes 统计结算总额
  67. * @return float
  68. */
  69. public function extend(): array
  70. {
  71. $settlementedTotal = GroupSettlement::where($this->queryWhere())->sum('settlement_amount');
  72. return ["total_amount" => $settlementedTotal];
  73. }
  74. }