User.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 会员管理
  7. *
  8. * @icon fa fa-user
  9. */
  10. class User extends Backend
  11. {
  12. /**
  13. * User模型对象
  14. * @var \app\admin\model\User
  15. */
  16. protected $model = null;
  17. protected $noNeedRight = ['selectpagenew'];
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\User;
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. $this->view->assign("noticeEmailList", $this->model->getNoticeEmailList());
  24. $this->view->assign("noticeWhatsappList", $this->model->getNoticeWhatsappList());
  25. $this->view->assign("isFirstList", $this->model->getIsFirstList());
  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(['userwallet'])
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as $row) {
  53. $row->getRelation('userwallet')->visible(['score']);
  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 updatescore(){
  64. $id = input('id');
  65. $info = Db::name('user_wallet')
  66. ->where('user_id',$id)
  67. ->find();
  68. if ($this->request->isPost()) {
  69. $user_id = input('user_id');
  70. $score = input('score');
  71. $remark = input('remark','后台调节');
  72. Db::startTrans();
  73. $rs = model('wallet')->lockChangeAccountRemain($user_id,'score',$score,1,$remark);
  74. if($rs['status'] === false){
  75. Db::rollback();
  76. $this->error($rs['msg']);
  77. }
  78. Db::commit();
  79. $this->success('充值完成');
  80. }
  81. $this->assign('row',$info);
  82. return $this->view->fetch();
  83. }
  84. public function selectpagenew()
  85. {
  86. $this->selectpageFields = 'id,username,nickname,firstname,lastname';
  87. return parent::selectpage_user();
  88. }
  89. }