WorkerAccountLogLists.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\tenantapi\lists\finance;
  3. use app\tenantapi\lists\BaseAdminDataLists;
  4. use app\common\enum\worker\WorkerAccountLogEnum;
  5. use app\common\lists\ListsSearchInterface;
  6. use app\common\model\master_worker\MasterWorkerAccountLog;
  7. use app\common\model\user\UserAccountLog;
  8. use app\common\service\FileService;
  9. /**
  10. * 账记流水列表
  11. * Class WorkerAccountLogLists
  12. * @package app\tenantapi\lists\finance
  13. */
  14. class WorkerAccountLogLists extends BaseAdminDataLists implements ListsSearchInterface
  15. {
  16. /**
  17. * @notes 搜索条件
  18. * @return array
  19. */
  20. public function setSearch(): array
  21. {
  22. return [
  23. '=' => ['al.change_type','worker_number'],
  24. ];
  25. }
  26. /**
  27. * @notes 搜索条件
  28. */
  29. public function queryWhere()
  30. {
  31. $where = [];
  32. // 用户余额
  33. if (isset($this->params['type']) && $this->params['type'] == 'um') {
  34. $where[] = ['change_type', 'in', WorkerAccountLogEnum::getUserMoneyChangeType()];
  35. }
  36. if (!empty($this->params['user_info'])) {
  37. $where[] = ['u.sn|u.nickname|u.mobile|u.account', 'like', '%' . $this->params['user_info'] . '%'];
  38. }
  39. if (!empty($this->params['start_time'])) {
  40. $where[] = ['al.create_time', '>=', strtotime($this->params['start_time'])];
  41. }
  42. if (!empty($this->params['end_time'])) {
  43. $where[] = ['al.create_time', '<=', strtotime($this->params['end_time'])];
  44. }
  45. return $where;
  46. }
  47. /**
  48. * @notes 获取列表
  49. * @return array
  50. */
  51. public function lists(): array
  52. {
  53. $field = 'u.nickname,u.account,u.sn,u.avatar,u.mobile,al.action,al.change_amount,al.left_amount,al.change_type,al.work_sn,al.create_time';
  54. $lists = MasterWorkerAccountLog::alias('al')
  55. ->with(['serviceWork'])
  56. ->join('master_worker u', 'u.id = al.worker_id and u.tenant_id = ' . $this->adminInfo['tenant_id'])
  57. ->field($field)
  58. ->where($this->searchWhere)
  59. ->where($this->queryWhere())
  60. ->order('al.id', 'desc')
  61. ->limit($this->limitOffset, $this->limitLength)
  62. ->select()
  63. ->toArray();
  64. foreach ($lists as &$item) {
  65. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  66. $item['change_type_desc'] = WorkerAccountLogEnum::getChangeTypeDesc($item['change_type']);
  67. $symbol = $item['action'] == WorkerAccountLogEnum::INC ? '+' : '-';
  68. $item['change_amount'] = $symbol . $item['change_amount'];
  69. $item['total_amount'] = bcadd($item['left_amount'], $item['change_amount'], 2);
  70. }
  71. return $lists;
  72. }
  73. /**
  74. * @notes 获取数量
  75. * @return int
  76. */
  77. public function count(): int
  78. {
  79. return MasterWorkerAccountLog::alias('al')
  80. ->join('master_worker u', 'u.id = al.worker_id and u.tenant_id = ' . $this->adminInfo['tenant_id'])
  81. ->where($this->queryWhere())
  82. ->where($this->searchWhere)
  83. ->count();
  84. }
  85. }