UserBillRepository.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\user;
  12. use app\common\dao\BaseDao;
  13. use app\common\dao\user\UserBillDao;
  14. use app\common\repositories\BaseRepository;
  15. use crmeb\jobs\SendTemplateMessageJob;
  16. use think\facade\Queue;
  17. use think\Model;
  18. /**
  19. * Class UserBillRepository
  20. * @package app\common\repositories\user
  21. * @author xaboy
  22. * @day 2020-05-07
  23. * @mixin UserBillDao
  24. */
  25. class UserBillRepository extends BaseRepository
  26. {
  27. /**
  28. * @var UserBillDao
  29. */
  30. protected $dao;
  31. const TYPE_INFO = [
  32. 'presell' => '支付预售尾款',
  33. 'pay_product' => '购买商品',
  34. 'order_one' => '获得一级推广佣金',
  35. 'order_two' => '获得二级推广佣金',
  36. 'refund_one' => '退回一级推广佣金',
  37. 'refund_two' => '退回二级推广佣金',
  38. 'refund' => '商品退款',
  39. 'recharge' => '余额充值',
  40. 'sys_inc_money' => '系统增加余额',
  41. 'sys_dec_money' => '系统减少余额',
  42. 'brokerage' => '佣金转入余额',
  43. ];
  44. /**
  45. * UserBillRepository constructor.
  46. * @param UserBillDao $dao
  47. */
  48. public function __construct(UserBillDao $dao)
  49. {
  50. $this->dao = $dao;
  51. }
  52. public function userList($where, $uid, $page, $limit)
  53. {
  54. $where['uid'] = $uid;
  55. $query = $this->dao->search($where)->order('create_time DESC');
  56. $count = $query->count();
  57. $list = $query->setOption('field', [])->field('bill_id,pm,title,number,balance,mark,create_time,status')->page($page, $limit)->select();
  58. return compact('count', 'list');
  59. }
  60. public function getList($where, $page, $limit)
  61. {
  62. $query = $this->dao->searchJoin($where)->order('a.create_time DESC');
  63. $count = $query->count();
  64. $list = $query->page($page, $limit)->select();
  65. return compact('count', 'list');
  66. }
  67. /**
  68. * @param int $uid
  69. * @param string $category
  70. * @param string $type
  71. * @param int $pm
  72. * @param array $data
  73. * @return BaseDao|Model
  74. * @author xaboy
  75. * @day 2020-05-07
  76. */
  77. public function bill(int $uid, string $category, string $type, int $pm, array $data)
  78. {
  79. $data['category'] = $category;
  80. $data['type'] = $type;
  81. $data['uid'] = $uid;
  82. $data['pm'] = $pm;
  83. $bill = $this->dao->create($data);
  84. if($category == 'now_money'){
  85. $tempData = ['tempCode' => 'USER_BALANCE_CHANGE','id' => $bill->bill_id];
  86. Queue::push(SendTemplateMessageJob::class,$tempData);
  87. }
  88. return $bill;
  89. }
  90. /**
  91. * @param int $uid
  92. * @param string $category
  93. * @param string $type
  94. * @param array $data
  95. * @return BaseDao|Model
  96. * @author xaboy
  97. * @day 2020-05-07
  98. */
  99. public function incBill(int $uid, string $category, string $type, array $data)
  100. {
  101. return $this->bill($uid, $category, $type, 1, $data);
  102. }
  103. /**
  104. * @param int $uid
  105. * @param string $category
  106. * @param string $type
  107. * @param array $data
  108. * @return BaseDao|Model
  109. * @author xaboy
  110. * @day 2020-05-07
  111. */
  112. public function decBill(int $uid, string $category, string $type, array $data)
  113. {
  114. return $this->bill($uid, $category, $type, 0, $data);
  115. }
  116. public function type()
  117. {
  118. $data = [];
  119. foreach (self::TYPE_INFO as $type => $title) {
  120. $data[] = compact('type', 'title');
  121. }
  122. return $data;
  123. }
  124. }