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. 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. public function add()
  67. {
  68. if (!$this->request->isPost()) {
  69. return $this->view->fetch();
  70. }
  71. $firstname = input('firstname');
  72. $lastname = input('lastname');
  73. $countrycode = input('countrycode',65,'intval');
  74. $mobile = input('mobile','');
  75. $email = input('email');
  76. $password = input('password');
  77. if (!$firstname || !$lastname || !$email || !$password) {
  78. $this->error(__('Invalid parameters'));
  79. }
  80. if ($email && !Validate::is($email, "email")) {
  81. $this->error(__('Email is incorrect'));
  82. }
  83. $fullmobile = $countrycode.$mobile;
  84. $extend = [
  85. 'firstname' => $firstname,
  86. 'lastname' => $lastname,
  87. 'simplemobile' => $mobile,
  88. 'birthday' => strtotime(input('birthday','')),
  89. 'height' => input('height',''),
  90. 'weight' => input('weight',''),
  91. 'age' => input('age',''),
  92. 'residential' => input('residential',''),
  93. 'health' => input('health',''),
  94. 'emergency' => input('emergency',''),
  95. 'emergency_phone' => input('emergency_phone',''),
  96. 'knowus' => input('knowus',''),
  97. // 'is_first' => input('is_first',''),
  98. 'notice_email' => input('notice_email',0),
  99. 'notice_whatsapp' => input('notice_whatsapp',0),
  100. 'notice_phonecall' => input('notice_phonecall',0),
  101. 'whatsapp' => input('whatsapp',''),
  102. ];
  103. $auth = new \app\common\library\Auth;
  104. $ret = $auth->register('',$password, $email, $fullmobile, $extend);
  105. if ($ret) {
  106. $this->success('注册完成');
  107. } else {
  108. $this->error($auth->getError());
  109. }
  110. }
  111. /**
  112. * 充值积分
  113. */
  114. public function updatescore(){
  115. $id = input('id');
  116. $info = Db::name('user_wallet')
  117. ->where('user_id',$id)
  118. ->find();
  119. if ($this->request->isPost()) {
  120. $user_id = input('user_id');
  121. $score = input('score');
  122. $remark = input('remark','线下修改');
  123. $remark_en = input('remark_en','Offline modification');
  124. Db::startTrans();
  125. if($score != 0){
  126. $rs = model('wallet')->lockChangeAccountRemain($user_id,'score',$score,1,$remark,'admin',$this->auth->id,$remark_en);
  127. if($rs['status'] === false){
  128. Db::rollback();
  129. $this->error($rs['msg']);
  130. }
  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,email';
  141. return parent::selectpage_user();
  142. }
  143. }