<?php

/**
 * 注册成员管理类
 *
 * @author 杨金球
 */
class UserAction extends CommonAction {

    public function index() {
        $status = false; //表示没有搜索
        if (isset($_GET['username']) && !empty($_GET['username'])) {
            $map['name'] = array('LIKE', '%' . rawurldecode($_GET['username']) . '%');
            $status = true;
        }

        if (isset($_GET['status']) && $_GET['status'] != 2) { //2表示全部
            $map['user_status'] = $_GET['status'];
            $status = true;
        }

        if (!$status) {   //判断有没有搜索
            $map = 1;
        }

        $user = M('user');

        import("ORG.Util.Page");
        $count = $user->where($map)->count();
        $page = new Page($count, 20);
        $show = $page->show();

        $user_list = $user->where($map)->limit($page->firstRow . ',' . $page->listRows)->select();

        $this->assign('user_list', $user_list);
        $this->assign('page', $show);
        $this->display();
    }

    //禁用成员
    public function forbidden_user() {
        $map['id'] = intval($_GET['id']);
        $map['user_status'] = 0;

        $user = M('user');

        if (!$user->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //取消禁用成员
    public function open_user() {
        $map['id'] = intval($_GET['id']);
        $map['user_status'] = 1;

        $user = M('user');

        if (!$user->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //多个禁用
    public function forbidden_users() {
        $map['id'] = array('IN', $_GET['id']);
        $map['user_status'] = 0;

        $user = M('user');

        if (!$user->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //删除成员
    public function del_user() {
        $map['id'] = intval($_GET['id']);

        $user = M('user');

        if (!$user->where($map)->delete()) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //修改成员密码
    public function chgpwd() {
        $map['id'] = intval($_GET['id']);
        $map['pwd'] = md5($_GET['pwd']);

        $user = M('user');

        if (!$user->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

}

?>
