RefundRecordLists.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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\orders\RechargeOrder;
  20. use app\common\model\refund\RefundRecord;
  21. use app\common\service\FileService;
  22. /**
  23. * 退款记录列表
  24. * Class RefundRecordLists
  25. * @package app\adminapi\lists\product
  26. */
  27. class RefundRecordLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
  28. {
  29. /**
  30. * @notes 查询条件
  31. * @return \string[][]
  32. * @author 段誉
  33. * @date 2023/3/1 9:51
  34. */
  35. public function setSearch(): array
  36. {
  37. return [
  38. '=' => ['r.sn', 'r.order_sn', 'r.refund_type'],
  39. ];
  40. }
  41. /**
  42. * @notes 查询条件
  43. * @param bool $flag
  44. * @return array
  45. * @author 段誉
  46. * @date 2023/3/1 9:51
  47. */
  48. public function queryWhere($flag = true)
  49. {
  50. $where = [];
  51. if (isset($this->params['work_id']) && !empty($this->params['work_id'])) {
  52. $order_ids = RechargeOrder::where('work_id', $this->params['work_id'])->column('id')?:[0];
  53. if($order_ids){
  54. $where[] = ['r.order_type', '=', 'order'];
  55. $where[] = ['r.order_id', 'IN', $order_ids];
  56. }
  57. }
  58. if (!empty($this->params['user_info'])) {
  59. $where[] = ['u.sn|u.nickname|u.mobile|u.account', 'like', '%' . $this->params['user_info'] . '%'];
  60. }
  61. if (!empty($this->params['start_time'])) {
  62. $where[] = ['r.create_time', '>=', strtotime($this->params['start_time'])];
  63. }
  64. if (!empty($this->params['end_time'])) {
  65. $where[] = ['r.create_time', '<=', strtotime($this->params['end_time'])];
  66. }
  67. if ($flag == true) {
  68. if (isset($this->params['refund_status']) && $this->params['refund_status'] != '') {
  69. $where[] = ['r.refund_status', '=', $this->params['refund_status']];
  70. }
  71. }
  72. return $where;
  73. }
  74. /**
  75. * @notes 获取列表
  76. * @return array
  77. * @author 段誉
  78. * @date 2023/3/1 9:51
  79. */
  80. public function lists(): array
  81. {
  82. $lists = (new RefundRecord())->alias('r')
  83. ->field('r.*,u.nickname,u.avatar')
  84. ->join('user u', 'u.id = r.user_id')
  85. ->order(['r.id' => 'desc'])
  86. ->where($this->searchWhere)
  87. ->where($this->queryWhere())
  88. ->limit($this->limitOffset, $this->limitLength)
  89. ->append(['refund_type_text', 'refund_status_text', 'refund_way_text'])
  90. ->select()
  91. ->toArray();
  92. foreach ($lists as &$item) {
  93. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  94. }
  95. return $lists;
  96. }
  97. /**
  98. * @notes 获取数量
  99. * @return int
  100. * @author 段誉
  101. * @date 2023/3/1 9:51
  102. */
  103. public function count(): int
  104. {
  105. return (new RefundRecord())->alias('r')
  106. ->join('user u', 'u.id = r.user_id')
  107. ->where($this->searchWhere)
  108. ->where($this->queryWhere())
  109. ->count();
  110. }
  111. /**
  112. * @notes 额外参数
  113. * @return mixed|null
  114. * @author 段誉
  115. * @date 2023/3/1 9:51
  116. */
  117. public function extend()
  118. {
  119. $count = (new RefundRecord())->alias('r')
  120. ->join('user u', 'u.id = r.user_id')
  121. ->field([
  122. 'count(r.id) as total',
  123. 'count(if(r.refund_status='.RefundEnum::REFUND_ING.', true, null)) as ing',
  124. 'count(if(r.refund_status='.RefundEnum::REFUND_SUCCESS.', true, null)) as success',
  125. 'count(if(r.refund_status='.RefundEnum::REFUND_ERROR.', true, null)) as error',
  126. ])
  127. ->where($this->searchWhere)
  128. ->where($this->queryWhere(false))
  129. ->select()->toArray();
  130. return array_shift($count);
  131. }
  132. }