Userwallet.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 updatemoney(){
  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');
  71. Db::startTrans();
  72. $rs = model('wallet')->lockChangeAccountRemain($user_id,'gold',$gold,1);
  73. if($rs['status'] === false){
  74. Db::rollback();
  75. $this->error($rs['msg']);
  76. }
  77. Db::commit();
  78. $this->success('充值完成');
  79. }
  80. $this->assign('row',$info);
  81. return $this->view->fetch();
  82. }
  83. /**
  84. * 充值VIP
  85. */
  86. public function updatevip(){
  87. $id = input('id');
  88. $info = Db::name('user_wallet')->where('id',$id)->find();
  89. if ($this->request->isPost()) {
  90. $user_id = input_post('user_id');
  91. $vip_endtime = strtotime(input_post('vip_endtime'));
  92. Db::startTrans();
  93. $info = Db::name('user_wallet')->where('user_id',$user_id)->update(['vip_endtime'=>$vip_endtime]);
  94. if($info === false){
  95. Db::rollback();
  96. $this->error('修改失败');
  97. }
  98. Db::commit();
  99. $this->success('充值完成');
  100. }
  101. $this->assign('row',$info);
  102. return $this->view->fetch();
  103. }
  104. }