TransferLists.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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\model\User;
  21. use app\common\model\UserTransfer;
  22. /**
  23. * 转账记录列表
  24. * Class TransferLists
  25. * @package app\shopapi\lists
  26. */
  27. class TransferLists extends BaseShopDataLists
  28. {
  29. /**
  30. * @notes 设置搜索条件
  31. * @return void
  32. * @author lbzy
  33. * @datetime 2023-12-15 11:19:09
  34. */
  35. public function setSearch()
  36. {
  37. switch ($this->params['type'] ?? '') {
  38. // 转入
  39. case 'in':
  40. $this->searchWhere[] = [ 'ut.transfer_in', '=', $this->userId ];
  41. break;
  42. // 转出
  43. case 'out':
  44. $this->searchWhere[] = [ 'ut.transfer_out', '=', $this->userId ];
  45. break;
  46. // 转入 + 转出
  47. default:
  48. $this->searchWhere[] = [ 'ut.transfer_out|ut.transfer_in', '=', $this->userId ];
  49. break;
  50. }
  51. $this->searchWhere[] = [ 'u.user_delete', '=', 0 ];
  52. }
  53. /**
  54. * @notes 转账列表
  55. * @return array
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. * @author Tab
  60. * @date 2021/8/12 14:14
  61. */
  62. public function lists(): array
  63. {
  64. // 设置搜索
  65. $this->setSearch();
  66. $lists = User::alias('u')
  67. ->field('ut.id,ut.transfer_in,ut.transfer_out,ut.money,ut.money as money_desc,ut.create_time,u.nickname,u.avatar,u.sn')
  68. ->where($this->searchWhere)
  69. ->join('user_transfer ut', 'u.id=ut.transfer_out or u.id=ut.transfer_in')
  70. ->group('ut.id')
  71. ->limit($this->limitOffset, $this->limitLength)
  72. ->order('ut.id', 'desc')
  73. ->select()
  74. ->toArray();
  75. foreach($lists as &$item) {
  76. $this->format($item);
  77. }
  78. return $lists;
  79. }
  80. /**
  81. * @notes 转账记录数量
  82. * @return int
  83. * @author Tab
  84. * @date 2021/8/12 14:14
  85. */
  86. public function count(): int
  87. {
  88. // 设置搜索
  89. $this->setSearch();
  90. $count = User::alias('u')
  91. ->join('user_transfer ut', 'u.id=ut.transfer_out or u.id=ut.transfer_in')
  92. ->group('ut.id')
  93. ->where($this->searchWhere)
  94. ->count();
  95. return $count;
  96. }
  97. /**
  98. * @notes notes
  99. * @param $item
  100. * @return void
  101. * @author lbzy
  102. * @datetime 2023-12-15 11:14:12
  103. */
  104. public function format(&$item)
  105. {
  106. // 转入
  107. if($item['transfer_in'] == $this->userId) {
  108. $item['money_desc'] = '+' . $item['money'];
  109. }
  110. // 转出
  111. if($item['transfer_out'] == $this->userId) {
  112. $item['money_desc'] = '-' . $item['money'];
  113. }
  114. $item['nickname'] = '转账-' . $item['nickname'];
  115. }
  116. }