123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- // +----------------------------------------------------------------------
- // | Yzncms [ 御宅男工作室 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018 http://yzncms.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 御宅男 <530765310@qq.com>
- // +----------------------------------------------------------------------
-
- // +----------------------------------------------------------------------
- // | 会员管理
- // +----------------------------------------------------------------------
- namespace app\admin\controller\member;
-
- use app\admin\model\member\Member as MemberModel;
- use app\common\controller\Adminbase;
- use app\member\service\User;
-
- class Member extends Adminbase
- {
- protected $searchFields = 'id,username,nickname';
- //初始化
- protected function initialize()
- {
- parent::initialize();
- $this->modelClass = new MemberModel;
- $this->UserService = User::instance();
- $this->groupCache = cache("Member_Group"); //会员模型
- }
-
- /**
- * 会员列表
- */
- public function index()
- {
- $this->relationSearch = true;
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($page, $limit, $where) = $this->buildTableParames();
- $_list = $this->modelClass
- ->withJoin('group')
- ->where($where)
- ->page($page, $limit)
- ->select();
- $total = $this->modelClass
- ->withJoin('group')
- ->where($where)
- ->count();
- $result = ["code" => 0, "count" => $total, "data" => $_list];
- return json($result);
- }
- return $this->fetch();
- }
-
- /**
- * 审核会员
- */
- public function userverify()
- {
- if ($this->request->isAjax()) {
- list($page, $limit, $where) = $this->buildTableParames();
- $_list = $this->modelClass->where($where)->where('status', '<>', 1)->page($page, $limit)->select();
- $total = $this->modelClass->where($where)->where('status', '<>', 1)->count();
- $result = ["code" => 0, "count" => $total, "data" => $_list];
- return json($result);
-
- }
- return $this->fetch();
- }
-
- /**
- * 会员增加
- */
- public function add()
- {
- if ($this->request->isPost()) {
- $data = $this->request->post();
- $result = $this->validate($data, 'app\admin\validate\member\Member');
- if (true !== $result) {
- return $this->error($result);
- }
- $data['overduedate'] = $data['overduedate'] ? strtotime($data['overduedate']) : null;
- if ($this->UserService->userRegister($data['username'], $data['password'], $data['email'], $data['mobile'], $data)) {
- $this->success("添加会员成功!", url("index"));
- } else {
- //$this->UserService->delete($memberinfo['userid']);
- $this->error($this->UserService->getError() ?: '添加会员失败!');
- }
- } else {
- foreach ($this->groupCache as $_key => $_value) {
- $groupCache[$_key] = $_value['name'];
- }
- $this->assign('groupCache', $groupCache);
- return $this->fetch();
- }
- }
-
- /**
- * 会员编辑
- */
- public function edit()
- {
- if ($this->request->isPost()) {
- $userid = $this->request->param('id/d', 0);
- $data = $this->request->post();
- $result = $this->validate($data, 'app\admin\validate\member\Member.edit');
- if (true !== $result) {
- return $this->error($result);
- }
- //获取用户信息
- $userinfo = MemberModel::get($userid);
- if (empty($userinfo)) {
- $this->error('该会员不存在!');
- }
- //修改基本资料
- if ($userinfo['username'] != $data['username'] || !empty($data['password']) || $userinfo['email'] != $data['email']) {
- $res = $this->modelClass->userEdit($userinfo['username'], '', $data['password'], $data['email'], 1);
- if (!$res) {
- $this->error($this->modelClass->getError());
- }
- }
- unset($data['username'], $data['password'], $data['email']);
- $data['overduedate'] = $data['overduedate'] ? strtotime($data['overduedate']) : null;
- //更新除基本资料外的其他信息
- if (false === $this->modelClass->allowField(true)->save($data, ['id' => $userid])) {
- $this->error('更新失败!');
- }
- $this->success("更新成功!", url("index"));
-
- } else {
- $userid = $this->request->param('id/d', 0);
- $data = $this->modelClass->get($userid);
- if (empty($data)) {
- $this->error("该会员不存在!");
- }
- foreach ($this->groupCache as $_key => $_value) {
- $groupCache[$_key] = $_value['name'];
- }
- $this->assign('groupCache', $groupCache);
- $this->assign("data", $data);
- return $this->fetch();
- }
- }
-
- /**
- * 会员删除
- */
- public function del()
- {
- $ids = $this->request->param('id/a', null);
- if (empty($ids)) {
- $this->error('请选择需要删除的会员!');
- }
- if (!is_array($ids)) {
- $ids = [0 => $ids];
- }
- foreach ($ids as $uid) {
- $this->UserService->delete($uid);
- }
- $this->success("删除成功!");
-
- }
-
- /**
- * 审核会员
- */
- public function pass()
- {
- $ids = $this->request->param('id/a', null);
- if (empty($ids)) {
- $this->error('请选择需要审核的会员!');
- }
- if (!is_array($ids)) {
- $ids = [0 => $ids];
- }
- foreach ($ids as $uid) {
- $info = MemberModel::where('id', $uid)->update(['status' => 1]);
- }
- $this->success("审核成功!");
- }
-
- }
|