RefundRecordLists.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\finance;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\enum\RefundEnum;
  17. use app\common\lists\ListsExtendInterface;
  18. use app\common\lists\ListsSearchInterface;
  19. use app\common\model\refund\RefundRecord;
  20. use app\common\service\FileService;
  21. /**
  22. * 退款记录列表
  23. * Class RefundRecordLists
  24. * @package app\adminapi\lists\product
  25. */
  26. class RefundRecordLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
  27. {
  28. /**
  29. * @notes 查询条件
  30. * @return \string[][]
  31. * @author 段誉
  32. * @date 2023/3/1 9:51
  33. */
  34. public function setSearch(): array
  35. {
  36. return [
  37. '=' => ['r.sn', 'r.order_sn', 'r.refund_type'],
  38. ];
  39. }
  40. /**
  41. * @notes 查询条件
  42. * @param bool $flag
  43. * @return array
  44. * @author 段誉
  45. * @date 2023/3/1 9:51
  46. */
  47. public function queryWhere($flag = true)
  48. {
  49. $where = [];
  50. if (!empty($this->params['user_info'])) {
  51. $where[] = ['u.sn|u.nickname|u.mobile|u.account', 'like', '%' . $this->params['user_info'] . '%'];
  52. }
  53. if (!empty($this->params['start_time'])) {
  54. $where[] = ['r.create_time', '>=', strtotime($this->params['start_time'])];
  55. }
  56. if (!empty($this->params['end_time'])) {
  57. $where[] = ['r.create_time', '<=', strtotime($this->params['end_time'])];
  58. }
  59. if ($flag == true) {
  60. if (isset($this->params['refund_status']) && $this->params['refund_status'] != '') {
  61. $where[] = ['r.refund_status', '=', $this->params['refund_status']];
  62. }
  63. }
  64. return $where;
  65. }
  66. /**
  67. * @notes 获取列表
  68. * @return array
  69. * @author 段誉
  70. * @date 2023/3/1 9:51
  71. */
  72. public function lists(): array
  73. {
  74. $lists = (new RefundRecord())->alias('r')
  75. ->field('r.*,u.nickname,u.avatar')
  76. ->join('user u', 'u.id = r.user_id')
  77. ->order(['r.id' => 'desc'])
  78. ->where($this->searchWhere)
  79. ->where($this->queryWhere())
  80. ->limit($this->limitOffset, $this->limitLength)
  81. ->append(['refund_type_text', 'refund_status_text', 'refund_way_text'])
  82. ->select()
  83. ->toArray();
  84. foreach ($lists as &$item) {
  85. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  86. }
  87. return $lists;
  88. }
  89. /**
  90. * @notes 获取数量
  91. * @return int
  92. * @author 段誉
  93. * @date 2023/3/1 9:51
  94. */
  95. public function count(): int
  96. {
  97. return (new RefundRecord())->alias('r')
  98. ->join('user u', 'u.id = r.user_id')
  99. ->where($this->searchWhere)
  100. ->where($this->queryWhere())
  101. ->count();
  102. }
  103. /**
  104. * @notes 额外参数
  105. * @return mixed|null
  106. * @author 段誉
  107. * @date 2023/3/1 9:51
  108. */
  109. public function extend()
  110. {
  111. $count = (new RefundRecord())->alias('r')
  112. ->join('user u', 'u.id = r.user_id')
  113. ->field([
  114. 'count(r.id) as total',
  115. 'count(if(r.refund_status='.RefundEnum::REFUND_ING.', true, null)) as ing',
  116. 'count(if(r.refund_status='.RefundEnum::REFUND_SUCCESS.', true, null)) as success',
  117. 'count(if(r.refund_status='.RefundEnum::REFUND_ERROR.', true, null)) as error',
  118. ])
  119. ->where($this->searchWhere)
  120. ->where($this->queryWhere(false))
  121. ->select()->toArray();
  122. return array_shift($count);
  123. }
  124. }