User.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\User;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index()
  27. {
  28. //当前是否为关联查询
  29. $this->relationSearch = false;
  30. //设置过滤方法
  31. $this->request->filter(['strip_tags', 'trim']);
  32. if ($this->request->isAjax()) {
  33. //如果发送的来源是Selectpage,则转发到Selectpage
  34. if ($this->request->request('keyField')) {
  35. return $this->selectpage();
  36. }
  37. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  38. $list = $this->model
  39. ->with(['wallet'])
  40. ->where($where)
  41. ->order($sort, $order)
  42. ->paginate($limit);
  43. foreach ($list as $row) {
  44. $row->getRelation('wallet')->visible(['score']);
  45. }
  46. $result = array("total" => $list->total(), "rows" => $list->items());
  47. return json($result);
  48. }
  49. return $this->view->fetch();
  50. }
  51. /**
  52. * 增加积分
  53. */
  54. public function scoreadd(){
  55. $id = input('id',0);
  56. if($this->request->isAjax()){
  57. $score = input('score',0);
  58. $remark = input('remark','');
  59. if($score == 0){
  60. $this->error('积分不能为0');
  61. }
  62. if($score > 0){
  63. $logtype = 1;
  64. }else{
  65. $logtype = 2;
  66. }
  67. Db::startTrans();
  68. $rs_wallet = model('wallet')->lockChangeAccountRemain($id,'score',$score,$logtype,$remark,'admin',$this->auth->id);
  69. if($rs_wallet['status'] == false){
  70. Db::rollback();
  71. $this->error($rs_wallet['msg']);
  72. }
  73. Db::commit();
  74. $this->success('操作完成');
  75. }
  76. $row = Db::name('user')->where('id',$id)->find();
  77. $this->assign('row',$row);
  78. $this->assign('id',$id);
  79. return $this->view->fetch();
  80. }
  81. }