RetentionMoneyLogLists.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\adminapi\lists\finance;
  3. use app\adminapi\lists\BaseAdminDataLists;
  4. use app\common\lists\ListsSearchInterface;
  5. use app\common\lists\ListsExtendInterface;
  6. use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
  7. /**
  8. * 质保金流水列表
  9. * Class RetentionMoneyLogLists
  10. * @package app\adminapi\lists\finance
  11. */
  12. class RetentionMoneyLogLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
  13. {
  14. /**
  15. * @notes 搜索条件
  16. * @return array
  17. */
  18. public function setSearch(): array
  19. {
  20. return [
  21. '=' => ['l.status','l.action'],
  22. ];
  23. }
  24. /**
  25. * @notes 搜索条件
  26. */
  27. public function queryWhere()
  28. {
  29. $where = [];
  30. if (!empty($this->params['worker'])) {
  31. $where[] = ['w.real_name|w.mobile', 'like', '%' . $this->params['worker'] . '%'];
  32. }
  33. if (!empty($this->params['start_time'])) {
  34. $where[] = ['l.create_time', '>=', strtotime($this->params['start_time'])];
  35. }
  36. if (!empty($this->params['end_time'])) {
  37. $where[] = ['l.create_time', '<=', strtotime($this->params['end_time'])];
  38. }
  39. return $where;
  40. }
  41. /**
  42. * @notes 获取列表
  43. * @return array
  44. */
  45. public function lists(): array
  46. {
  47. $field = 'w.real_name,w.mobile,l.*';
  48. $lists = MasterWorkerRetentionMoneyLog::alias('l')
  49. ->join('master_worker w', 'w.id = l.worker_id')
  50. ->field($field)
  51. ->where($this->searchWhere)
  52. ->where($this->queryWhere())
  53. ->order('l.id', 'desc')
  54. ->limit($this->limitOffset, $this->limitLength)
  55. ->select()
  56. ->toArray();
  57. foreach ($lists as &$item) {
  58. $symbol = $item['action'] == 1 ? '+' : '-';
  59. $item['amount'] = $symbol . $item['amount'];
  60. }
  61. return $lists;
  62. }
  63. /**
  64. * @notes 获取数量
  65. * @return int
  66. */
  67. public function count(): int
  68. {
  69. return MasterWorkerRetentionMoneyLog::alias('l')
  70. ->join('master_worker w', 'w.id = l.worker_id')
  71. ->where($this->queryWhere())
  72. ->where($this->searchWhere)
  73. ->count();
  74. }
  75. /**
  76. * @notes 额外参数
  77. * @return mixed|null
  78. */
  79. public function extend()
  80. {
  81. $count = (new MasterWorkerRetentionMoneyLog())->alias('l')
  82. ->join('master_worker w', 'w.id = l.worker_id')
  83. ->field([
  84. 'count(l.id) as total',
  85. 'count(if(l.action=1, true, null)) as ing',
  86. 'count(if(l.action=2, true, null)) as success',
  87. ])
  88. ->where($this->searchWhere)
  89. ->where($this->queryWhere(false))
  90. ->select()->toArray();
  91. return array_shift($count);
  92. }
  93. }