User.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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("oldstatusList", $this->model->getOldStatusList());
  24. $this->view->assign("noticeEmailList", $this->model->getNoticeEmailList());
  25. $this->view->assign("noticeWhatsappList", $this->model->getNoticeWhatsappList());
  26. $this->view->assign("isFirstList", $this->model->getIsFirstList());
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. //当前是否为关联查询
  39. $this->relationSearch = true;
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if ($this->request->isAjax()) {
  43. //如果发送的来源是Selectpage,则转发到Selectpage
  44. if ($this->request->request('keyField')) {
  45. return $this->selectpage();
  46. }
  47. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48. $list = $this->model
  49. ->with(['userwallet'])
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. foreach ($list as $row) {
  54. $row->getRelation('userwallet')->visible(['score']);
  55. }
  56. $result = array("total" => $list->total(), "rows" => $list->items());
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. /**
  62. * 注册会员
  63. *
  64. * @ApiMethod (POST)
  65. * @param string $username 用户名
  66. * @param string $password 密码
  67. * @param string $email 邮箱
  68. * @param string $mobile 手机号
  69. * @param string $code 验证码
  70. */
  71. public function add()
  72. {
  73. $firstname = input('firstname');
  74. $lastname = input('lastname');
  75. $countrycode = input('countrycode',65,'intval');
  76. $mobile = input('mobile');
  77. $email = input('email');
  78. $password = input('password');
  79. if (!$firstname || !$lastname || !$mobile || !$email || !$password) {
  80. $this->error(__('Invalid parameters'));
  81. }
  82. if ($email && !Validate::is($email, "email")) {
  83. $this->error(__('Email is incorrect'));
  84. }
  85. $fullmobile = $countrycode.$mobile;
  86. $extend = [
  87. 'firstname' => $firstname,
  88. 'lastname' => $lastname,
  89. 'simplemobile' => $mobile,
  90. 'birthday' => strtotime(input('birthday','')),
  91. 'height' => input('height',''),
  92. 'weight' => input('weight',''),
  93. 'age' => input('age',''),
  94. 'residential' => input('residential',''),
  95. 'health' => input('health',''),
  96. 'emergency' => input('emergency',''),
  97. 'emergency_phone' => input('emergency_phone',''),
  98. 'knowus' => input('knowus',''),
  99. 'is_first' => input('is_first',''),
  100. 'notice_email' => input('notice_email',0),
  101. 'notice_whatsapp' => input('notice_whatsapp',0),
  102. 'notice_phonecall' => input('notice_phonecall',0),
  103. 'whatsapp' => input('whatsapp',''),
  104. ];
  105. $auth = new \app\common\library\auth;
  106. $ret = $auth->register('',$password, $email, $fullmobile, $extend);
  107. if ($ret != true) {
  108. $this->success('注册完成');
  109. } else {
  110. $this->error($auth->getError());
  111. }
  112. }
  113. /**
  114. * 充值积分
  115. */
  116. public function updatescore(){
  117. $id = input('id');
  118. $info = Db::name('user_wallet')
  119. ->where('user_id',$id)
  120. ->find();
  121. if ($this->request->isPost()) {
  122. $user_id = input('user_id');
  123. $score = input('score');
  124. $remark = input('remark','后台调节');
  125. Db::startTrans();
  126. $rs = model('wallet')->lockChangeAccountRemain($user_id,'score',$score,1,$remark);
  127. if($rs['status'] === false){
  128. Db::rollback();
  129. $this->error($rs['msg']);
  130. }
  131. Db::commit();
  132. $this->success('充值完成');
  133. }
  134. $this->assign('row',$info);
  135. return $this->view->fetch();
  136. }
  137. public function selectpagenew()
  138. {
  139. $this->selectpageFields = 'id,username,nickname,firstname,lastname';
  140. return parent::selectpage_user();
  141. }
  142. }