RechargeLists.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\lists\recharge;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\lists\ListsSearchInterface;
  23. use app\common\model\RechargeOrder;
  24. use app\common\service\FileService;
  25. /**
  26. * 充值记录列表
  27. * Class RecharLists
  28. * @package app\adminapi\lists
  29. */
  30. class RechargeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
  31. {
  32. /**
  33. * @notes 导出字段
  34. * @return array
  35. * @author Tab
  36. * @date 2021/9/22 18:20
  37. */
  38. public function setExcelFields(): array
  39. {
  40. return [
  41. 'sn' => '充值单号',
  42. 'nickname' => '用户昵称',
  43. 'order_amount' => '充值金额',
  44. 'give_money' => '赠送余额',
  45. 'pay_way' => '支付方式',
  46. 'pay_time' => '支付时间',
  47. 'pay_status' => '订单状态',
  48. 'create_time' => '下单时间',
  49. ];
  50. }
  51. /**
  52. * @notes 导出表名
  53. * @return string
  54. * @author Tab
  55. * @date 2021/9/22 18:20
  56. */
  57. public function setFileName(): string
  58. {
  59. return '充值记录';
  60. }
  61. /**
  62. * @notes 设置搜索
  63. * @return \string[][]
  64. * @author Tab
  65. * @date 2021/8/11 16:09
  66. */
  67. public function setSearch(): array
  68. {
  69. return [
  70. '=' => ['ro.sn', 'u.mobile', 'ro.pay_way', 'ro.pay_status'],
  71. '%like%' => ['u.nickname']
  72. ];
  73. }
  74. /**
  75. * @notes 附加搜索条件
  76. * @author Tab
  77. * @date 2021/8/11 16:11
  78. */
  79. public function attachWhere()
  80. {
  81. // 用户编号
  82. if(isset($this->params['user_sn']) && !empty($this->params['user_sn'])) {
  83. $this->searchWhere[] = ['u.sn', '=', $this->params['user_sn']];
  84. }
  85. // 支付时间
  86. if(isset($this->params['type_time']) && $this->params['type_time'] == 1 && isset($this->params['start_time']) && isset($this->params['end_time'])) {
  87. $this->searchWhere[] = ['ro.pay_time', 'between', [$this->startTime, $this->endTime]];
  88. }
  89. // 下单时间
  90. if(isset($this->params['type_time']) && $this->params['type_time'] == 2 && isset($this->params['start_time']) && isset($this->params['end_time'])) {
  91. $this->searchWhere[] = ['ro.create_time', 'between', [$this->startTime, $this->endTime]];
  92. }
  93. }
  94. /**
  95. * @notes 充值记录列表
  96. * @return array
  97. * @author Tab
  98. * @date 2021/8/11 16:30
  99. */
  100. public function lists(): array
  101. {
  102. // 附加搜索
  103. $this->attachWhere();
  104. $field = 'ro.sn,ro.order_amount,ro.pay_way,ro.pay_time,ro.pay_status,ro.create_time,ro.award';
  105. $field .= ',u.avatar,u.nickname';
  106. $lists = RechargeOrder::alias('ro')
  107. ->leftJoin('user u', 'u.id = ro.user_id')
  108. ->field($field)
  109. ->where($this->searchWhere)
  110. ->order('ro.id', 'desc')
  111. ->limit($this->limitOffset, $this->limitLength)
  112. ->select()
  113. ->toArray();
  114. foreach($lists as &$item) {
  115. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  116. $item['give_money'] = $this->giveMoney($item);
  117. $item['pay_time'] = empty($item['pay_time']) ? '' : date('Y-m-d H:i:s', $item['pay_time']) ;
  118. }
  119. return $lists;
  120. }
  121. /**
  122. * @notes 充值记录数量
  123. * @return int
  124. * @author Tab
  125. * @date 2021/8/11 16:30
  126. */
  127. public function count(): int
  128. {
  129. // 附加搜索
  130. $this->attachWhere();
  131. $count = RechargeOrder::alias('ro')
  132. ->leftJoin('user u', 'u.id = ro.user_id')
  133. ->where($this->searchWhere)
  134. ->count();
  135. return $count;
  136. }
  137. /**
  138. * @notes 充值赠送金额
  139. * @param $item
  140. * @return int|mixed|string
  141. * @author Tab
  142. * @date 2021/8/11 15:49
  143. */
  144. public function giveMoney($item)
  145. {
  146. if(!isset($item['award']) || empty($item['award'])) {
  147. return 0;
  148. }
  149. foreach($item['award'] as $subItem) {
  150. if(isset($subItem['give_money'])) {
  151. return clear_zero($subItem['give_money']);
  152. }
  153. }
  154. return 0;
  155. }
  156. }