Userwallet.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use app\common\model\wallet;
  6. /**
  7. * 用户钱包
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Userwallet extends Backend
  12. {
  13. /**
  14. * Userwallet模型对象
  15. * @var \app\admin\model\Userwallet
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\Userwallet;
  22. }
  23. public function import()
  24. {
  25. parent::import();
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 查看
  34. */
  35. public function index()
  36. {
  37. //当前是否为关联查询
  38. $this->relationSearch = true;
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. if ($this->request->isAjax()) {
  42. //如果发送的来源是Selectpage,则转发到Selectpage
  43. if ($this->request->request('keyField')) {
  44. return $this->selectpage();
  45. }
  46. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  47. $list = $this->model
  48. ->with(['user'])
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as $row) {
  53. $row->getRelation('user')->visible(['username','nickname','mobile']);
  54. }
  55. $result = array("total" => $list->total(), "rows" => $list->items());
  56. return json($result);
  57. }
  58. return $this->view->fetch();
  59. }
  60. /**
  61. * 充值金币
  62. */
  63. public function updategold(){
  64. $id = input('id');
  65. $info = Db::name('user_wallet')
  66. ->where('id',$id)
  67. ->find();
  68. if ($this->request->isPost()) {
  69. $user_id = input_post('user_id');
  70. $gold = input_post('gold', 0, 'intval');
  71. $user_info = Db::name('user')->find($user_id);
  72. if (!$user_info) {
  73. $this->error('用户不存在');
  74. }
  75. if ($gold > 0) {
  76. $is_pay_get = 1;
  77. } else {
  78. $is_pay_get = 0;
  79. }
  80. Db::startTrans();
  81. $rs = model('wallet')->lockChangeAccountRemain($user_id,0,'gold',$gold,1, '系统调节','',0, $is_pay_get);
  82. if($rs['status'] === false){
  83. Db::rollback();
  84. $this->error($rs['msg']);
  85. }
  86. //若有上级,给上级返利
  87. if ($user_info['intro_uid'] && $gold > 0) {
  88. //获取返利比率
  89. $agent_info = Db::name('user')->where(['id' => $user_info['intro_uid']])->field('is_agent,h_intro_recharge_rebate_rate')->find();
  90. $intro_recharge_rebate_rate = ($agent_info['is_agent'] == 1) ? $agent_info['h_intro_recharge_rebate_rate'] : (int)config('site.intro_recharge_rebate_rate');
  91. if ($intro_recharge_rebate_rate > 0 && $intro_recharge_rebate_rate <= 100) {
  92. // 添加赠送用户余额
  93. $money_to_gold = config('site.money_to_gold');
  94. $money = bcdiv($gold,$money_to_gold,2);
  95. //上级获得金额数量
  96. $intro_uid_money = number_format($money * $intro_recharge_rebate_rate / 100, 2, '.', '');
  97. if ($intro_uid_money > 0) {
  98. $intro_result = model('wallet')->lockChangeAccountRemain($user_info['intro_uid'],$user_id,'money',$intro_uid_money,65,'邀请人充值奖励');
  99. if($intro_result['status']===false)
  100. {
  101. Db::rollback();
  102. $this->error($intro_result['msg']);
  103. }
  104. }
  105. }
  106. }
  107. Db::commit();
  108. $this->success('充值完成');
  109. }
  110. $this->assign('row',$info);
  111. return $this->view->fetch();
  112. }
  113. /**
  114. * 充值积分
  115. */
  116. public function updatemoney(){
  117. $id = input('id');
  118. $info = Db::name('user_wallet')
  119. ->where('id',$id)
  120. ->find();
  121. if ($this->request->isPost()) {
  122. $user_id = input_post('user_id');
  123. $money = input_post('money', 0, 'intval');
  124. $user_info = Db::name('user')->find($user_id);
  125. if (!$user_info) {
  126. $this->error('用户不存在');
  127. }
  128. Db::startTrans();
  129. $rs = model('wallet')->lockChangeAccountRemain($user_id,0,'money',$money,2, '系统调节','',0, 0);
  130. if($rs['status'] === false){
  131. Db::rollback();
  132. $this->error($rs['msg']);
  133. }
  134. Db::commit();
  135. $this->success('充值完成');
  136. }
  137. $this->assign('row',$info);
  138. return $this->view->fetch();
  139. }
  140. /**
  141. * 充值钻石
  142. */
  143. public function updatejewel(){
  144. $id = input('id');
  145. $info = Db::name('user_wallet')
  146. ->where('id',$id)
  147. ->find();
  148. if ($this->request->isPost()) {
  149. $user_id = input_post('user_id');
  150. $jewel = input_post('jewel', 0, 'intval');
  151. $user_info = Db::name('user')->find($user_id);
  152. if (!$user_info) {
  153. $this->error('用户不存在');
  154. }
  155. Db::startTrans();
  156. $rs = model('wallet')->lockChangeAccountRemain($user_id,0,'jewel',$jewel,3, '系统调节','',0, 0);
  157. if($rs['status'] === false){
  158. Db::rollback();
  159. $this->error($rs['msg']);
  160. }
  161. Db::commit();
  162. $this->success('充值完成');
  163. }
  164. $this->assign('row',$info);
  165. return $this->view->fetch();
  166. }
  167. }