心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MemberController.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2019年10月05日
  7. * 会员控制器
  8. */
  9. namespace app\admin\controller\member;
  10. use core\basic\Controller;
  11. use app\admin\model\member\MemberModel;
  12. class MemberController extends Controller
  13. {
  14. private $model;
  15. public function __construct()
  16. {
  17. $this->model = new MemberModel();
  18. }
  19. // 会员列表
  20. public function index()
  21. {
  22. if ((! ! $id = get('id', 'int')) && $result = $this->model->getMember($id)) {
  23. $this->assign('more', true);
  24. $this->assign('fields', $this->model->getFields());
  25. $this->assign('member', $result);
  26. } else {
  27. $this->assign('list', true);
  28. if (! ! ($field = get('field', 'var')) && ! ! ($keyword = get('keyword', 'vars'))) {
  29. $result = $this->model->findMember($field, $keyword);
  30. } else {
  31. $result = $this->model->getList();
  32. }
  33. // 会员等级
  34. $this->assign('groups', model('admin.member.MemberGroup')->getSelect());
  35. $this->assign('members', $result);
  36. }
  37. $this->display('member/member.html');
  38. }
  39. // 会员增加
  40. public function add()
  41. {
  42. if ($_POST) {
  43. // 获取数据
  44. $ucode = get_auto_code($this->model->getLastCode(), 1);
  45. $username = post('username');
  46. $useremail = post('useremail');
  47. $usermobile = post('usermobile');
  48. $nickname = post('nickname');
  49. $password = post('password');
  50. $headpic = post('headpic');
  51. $status = post('status') ?: 1;
  52. $gid = post('gid');
  53. $score = post('score');
  54. $register_time = get_datetime();
  55. if (! $username) {
  56. alert_back('用户账号不能为空!');
  57. }
  58. if (! preg_match('/^[\w\@\.]+$/', $username)) {
  59. alert_back('用户账号含有不允许的特殊字符!');
  60. }
  61. if ($useremail && ! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $useremail)) {
  62. alert_back('邮箱账号格式不正确!');
  63. }
  64. if ($usermobile && ! preg_match('/^1[0-9]{10}$/', $usermobile)) {
  65. alert_back('手机号码格式不正确!');
  66. }
  67. if ($username && $this->model->checkMember("username='$username' OR useremail='$username' OR usermobile='$username'")) {
  68. alert_back('用户名已经存在!');
  69. }
  70. if ($useremail && $this->model->checkMember("username='$useremail' OR useremail='$useremail' OR usermobile='$useremail'")) {
  71. alert_back('邮箱账号已经存在!');
  72. }
  73. if ($usermobile && $this->model->checkMember("username='$usermobile' OR useremail='$usermobile' OR usermobile='$usermobile'")) {
  74. alert_back('手机号码已经存在!');
  75. }
  76. if (! $password) {
  77. alert_back('密码不能为空!');
  78. } else {
  79. $password = md5(md5($password));
  80. }
  81. // 构建数据
  82. $data = array(
  83. 'ucode' => $ucode,
  84. 'username' => $username,
  85. 'useremail' => $useremail,
  86. 'usermobile' => $usermobile,
  87. 'nickname' => $nickname,
  88. 'password' => $password,
  89. 'headpic' => $headpic,
  90. 'status' => $status,
  91. 'gid' => $gid,
  92. 'wxid' => '',
  93. 'qqid' => '',
  94. 'wbid' => '',
  95. 'activation' => 1,
  96. 'score' => $score,
  97. 'register_time' => $register_time,
  98. 'login_count' => 0,
  99. 'last_login_ip' => 0,
  100. 'last_login_time' => 0
  101. );
  102. // 执行添加
  103. if ($this->model->addMember($data)) {
  104. $this->log('新增会员成功!');
  105. if (! ! $backurl = get('backurl')) {
  106. success('新增成功!', base64_decode($backurl));
  107. } else {
  108. success('新增成功!', url('/admin/Member/index'));
  109. }
  110. } else {
  111. $this->log('新增会员失败!');
  112. error('新增失败!', - 1);
  113. }
  114. }
  115. }
  116. // 会员删除
  117. public function del()
  118. {
  119. // 执行批量删除
  120. if ($_POST) {
  121. if (! ! $list = post('list')) {
  122. if ($this->model->delMemberList($list)) {
  123. $this->log('批量删除会员成功!');
  124. success('删除成功!', - 1);
  125. } else {
  126. $this->log('批量删除会员失败!');
  127. error('删除失败!', - 1);
  128. }
  129. } else {
  130. alert_back('请选择要删除的会员!');
  131. }
  132. }
  133. if (! $id = get('id', 'int')) {
  134. error('传递的参数值错误!', - 1);
  135. }
  136. if ($this->model->delMember($id)) {
  137. $this->log('删除会员' . $id . '成功!');
  138. success('删除成功!', - 1);
  139. } else {
  140. $this->log('删除会员' . $id . '失败!');
  141. error('删除失败!', - 1);
  142. }
  143. }
  144. // 会员修改
  145. public function mod()
  146. {
  147. if (! ! $submit = post('submit')) {
  148. switch ($submit) {
  149. case 'verify1':
  150. $list = post('list');
  151. if (! $list) {
  152. alert_back('请选择要操作的会员!');
  153. }
  154. if ($this->model->modMemberList($list, "status=1")) {
  155. $this->log('会员批量启用成功!');
  156. success('启用成功!', - 1);
  157. } else {
  158. alert_back('启用失败!');
  159. }
  160. break;
  161. case 'verify0':
  162. $list = post('list');
  163. if (! $list) {
  164. alert_back('请选择要操作的会员!');
  165. }
  166. if ($this->model->modMemberList($list, "status=0")) {
  167. $this->log('会员批量禁用成功!');
  168. success('禁用成功!', - 1);
  169. } else {
  170. alert_back('禁用失败!');
  171. }
  172. break;
  173. }
  174. }
  175. if (! $id = get('id', 'int')) {
  176. error('传递的参数值错误!', - 1);
  177. }
  178. // 单独修改状态
  179. if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
  180. if ($this->model->modMember($id, "$field='$value'")) {
  181. location(- 1);
  182. } else {
  183. alert_back('修改失败!');
  184. }
  185. }
  186. // 修改操作
  187. if ($_POST) {
  188. // 获取数据
  189. $username = post('username');
  190. $useremail = post('useremail');
  191. $usermobile = post('usermobile');
  192. $nickname = post('nickname');
  193. $password = post('password');
  194. $headpic = post('headpic');
  195. $status = post('status') ?: 1;
  196. $gid = post('gid');
  197. $score = post('score');
  198. if (! $username) {
  199. alert_back('用户账号不能为空!');
  200. }
  201. if (! preg_match('/^[\w\@\.]+$/', $username)) {
  202. alert_back('用户账号含有不允许的特殊字符!');
  203. }
  204. if ($useremail && ! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $useremail)) {
  205. alert_back('邮箱账号格式不正确!');
  206. }
  207. if ($usermobile && ! preg_match('/^1[0-9]{10}$/', $usermobile)) {
  208. alert_back('手机号码格式不正确!');
  209. }
  210. if ($username && $this->model->checkMember("(username='$username' OR useremail='$username' OR usermobile='$username') AND id<>$id")) {
  211. alert_back('用户名已经存在!');
  212. }
  213. if ($useremail && $this->model->checkMember("(username='$useremail' OR useremail='$useremail' OR usermobile='$useremail') AND id<>$id")) {
  214. alert_back('邮箱账号已经存在!');
  215. }
  216. if ($usermobile && $this->model->checkMember("(username='$usermobile' OR useremail='$usermobile' OR usermobile='$usermobile') AND id<>$id")) {
  217. alert_back('手机号码已经存在!');
  218. }
  219. // 构建数据
  220. $data = array(
  221. 'username' => $username,
  222. 'useremail' => $useremail,
  223. 'usermobile' => $usermobile,
  224. 'nickname' => $nickname,
  225. 'headpic' => $headpic,
  226. 'status' => $status,
  227. 'gid' => $gid,
  228. 'score' => $score
  229. );
  230. if ($password) {
  231. $data['password'] = md5(md5($password));
  232. }
  233. // 执行添加
  234. if ($this->model->modMember($id, $data)) {
  235. $this->log('修改会员成功!');
  236. if (! ! $backurl = get('backurl')) {
  237. success('修改成功!', base64_decode($backurl));
  238. } else {
  239. success('修改成功!', url('/admin/Member/index'));
  240. }
  241. } else {
  242. $this->log('修改会员失败!');
  243. error('修改失败!', - 1);
  244. }
  245. } else {
  246. // 调取修改内容
  247. $this->assign('mod', true);
  248. if (! $result = $this->model->getMember($id)) {
  249. error('编辑的内容已经不存在!', - 1);
  250. }
  251. // 会员等级
  252. $this->assign('groups', model('admin.member.MemberGroup')->getSelect());
  253. $this->assign('member', $result);
  254. $this->display('member/member.html');
  255. }
  256. }
  257. }