User.php 5.3 KB

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