RechargeLists.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\shopapi\lists;
  20. use app\common\enum\PayEnum;
  21. use app\common\model\RechargeOrder;
  22. use app\common\model\RechargeTemplate;
  23. /**
  24. * 充值记录列表
  25. * Class RechargeLists
  26. * @package app\shopapi\lists
  27. */
  28. class RechargeLists extends BaseShopDataLists
  29. {
  30. /**
  31. * @notes 充值成功记录列表
  32. * @return array
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @author Tab
  37. * @date 2021/8/11 15:14
  38. */
  39. public function lists(): array
  40. {
  41. $lists = RechargeOrder::field('order_amount,award,create_time')
  42. ->where([
  43. 'user_id' => $this->userId,
  44. 'pay_status' => PayEnum::ISPAID
  45. ])
  46. ->order('id', 'desc')
  47. ->select()
  48. ->toArray();
  49. foreach($lists as &$item) {
  50. $item['tips'] = $this->getTips($item);
  51. }
  52. return $lists;
  53. }
  54. /**
  55. * @notes 充值成功记录数
  56. * @return int
  57. * @author Tab
  58. * @date 2021/8/11 15:15
  59. */
  60. public function count(): int
  61. {
  62. $count = RechargeOrder::field('order_amount,award,create_time')
  63. ->where([
  64. 'user_id' => $this->userId,
  65. 'pay_status' => PayEnum::ISPAID
  66. ])
  67. ->count();
  68. return $count;
  69. }
  70. /**
  71. * @notes 获取充值赠送提示语
  72. * @param $item
  73. * @return string
  74. * @author Tab
  75. * @date 2021/8/11 10:13
  76. */
  77. public function getTips(&$item)
  78. {
  79. if(empty($item['award']) || !is_array($item['award'])) {
  80. return '充值' . clear_zero($item['order_amount']) . '元';
  81. }
  82. foreach($item['award'] as $subItem) {
  83. if (isset($subItem['give_money']) && $subItem['give_money'] > 0) {
  84. $tips = '充' . clear_zero($item['order_amount']) . '送' . clear_zero($subItem['give_money']) . '元';
  85. } else {
  86. $tips = '充值' . clear_zero($item['order_amount']) . '元';
  87. }
  88. $item['order_amount'] += $subItem['give_money'];
  89. return $tips;
  90. }
  91. }
  92. }