User.php 5.4 KB

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