Userwallet.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 会员钱包管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Userwallet extends Backend
  11. {
  12. /**
  13. * Userwallet模型对象
  14. * @var \app\admin\model\Userwallet
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Userwallet;
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = true;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $list = $this->model
  47. ->with(['user'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. foreach ($list as $row) {
  52. $row->getRelation('user')->visible(['username']);
  53. }
  54. $result = array("total" => $list->total(), "rows" => $list->items());
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. /**
  60. * 充值金币
  61. */
  62. public function updatejewel(){
  63. $user_id = input('user_id');
  64. $info = Db::name('user_wallet')
  65. ->where('user_id',$user_id)
  66. ->find();
  67. if ($this->request->isPost()) {
  68. $user_id = input('user_id');
  69. $jewel = input('jewel');
  70. Db::startTrans();
  71. $mode = '+';
  72. if($jewel < 0){
  73. $mode = '-';
  74. }
  75. $rs = model('wallet')->lockChangeAccountRemain($user_id,$jewel,$mode,0,'后台变动',0,'jewel');
  76. if($rs['status'] === false){
  77. Db::rollback();
  78. $this->error($rs['msg']);
  79. }
  80. Db::commit();
  81. $this->success('充值完成');
  82. }
  83. $this->assign('row',$info);
  84. return $this->view->fetch();
  85. }
  86. /**
  87. * 充值海钻
  88. */
  89. public function updatemoney(){
  90. $user_id = input('user_id');
  91. $info = Db::name('user_wallet')
  92. ->where('user_id',$user_id)
  93. ->find();
  94. if ($this->request->isPost()) {
  95. $user_id = input('user_id');
  96. $money = input('money');
  97. Db::startTrans();
  98. $mode = '+';
  99. if($money < 0){
  100. $mode = '-';
  101. }
  102. $rs = model('wallet')->lockChangeAccountRemain($user_id,$money,$mode,0,'后台变动',100,'money');
  103. if($rs['status'] === false){
  104. Db::rollback();
  105. $this->error($rs['msg']);
  106. }
  107. Db::commit();
  108. $this->success('充值完成');
  109. }
  110. $this->assign('row',$info);
  111. return $this->view->fetch();
  112. }
  113. }