colly_wyx
2018-03-30 5b00b28782f2c773aa9b63ac61584b70a366526c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
 
class Service_User extends System_Service_Base{
 
    public function __construct(){
        $this->user_model = new UserModel();
    }
 
    /**
     * 根据条件获取用户列表
     * @param  array   $query  [description]
     * @param  array   $fields [description]
     * @param  array   $sort   [description]
     * @param  integer $limit  [description]
     * @param  integer $skip   [description]
     * @return [type]          [description]
     */
    public function getUserList($query=array(),$fields=array(),$sort=array(),$limit=0,$skip=0){
        return $this->user_model->getList($query, $fields, $sort, $limit, $skip);
    }
 
    /**
     * 根据条件获取数量
     * @param  array   $query [description]
     * @param  integer $limit [description]
     * @param  integer $skip  [description]
     * @return [type]         [description]
     */
    public function getUserListTotal($query=array(),$limit=0,$skip=0){
        return $this->user_model->count($query, $limit, $skip);
    }
 
    /**
     * 添加用户
     * @param [type] $data [description]
     */
    public function add($data){
        return $this->user_model->add($data);
    }
 
    /**
     * 更新用户信息
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public function update($data, $query = array()){
        return $this->user_model->update($data, $query);
    }
 
    /**
     * 根据条件,获取用户信息
     * @param  array  $query [description]
     * @param  array  $field [description]
     * @return [type]        [description]
     */
    public function getUserInfo($query = array(), $field = array()){
        return $this->user_model->get($query, $field);
    }
 
     /**
     * 后台用户登录
     * @param  [type] $username [description]
     * @param  [type] $password [description]
     * @return [type]           [description]
     */
     public function login($phone, $password){
         $user = $this->valid($phone, $password);
         if(!$user){
             $this->error('用户名或密码不正确');
             return false;
         }
         else{
             $role_service = new Service_Role();
             $user_role = $role_service->getRoleInfo(array('_id' => $user['role']));
             $session = Yaf_Session::getInstance();
             $user_info = array(
                 'nickname' => $user['nickname'],
                 'user_id' => $user['_id'],
                 'role_id' => $user['role'],
                 'role_name' => $user_role['name']
             );
             $session->user = $user_info;
             return true;
         }
 
     }
 
     /**
      * 检测用户名与密码
      * @param  [type] $username [description]
      * @param  [type] $password [description]
      * @return [type]           [description]
      */
     public function valid($phone, $password){
         $user = $this->user_model->getInfoByPhone($phone);
         if($user && $user['password'] == md5(md5($password).$user['encrypt'])){
             return $user;
         }
         return false;
     }
}