colly_wyx
2018-04-28 d50ec1d43fd3b57305425d38ecc7c84f201e74cf
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
 * 用户业务类
 */
class Domain_User {
 
    public function __construct(){
        $this->model = new Model_User();
    }
 
    /**
     * 注册
     * @param  [type] $regUserInfo [description]
     * @return [type]              [description]
     */
    public function register($regUserInfo) {
        return $this->model->register($regUserInfo);
    }
 
    /**
     * 验证手机
     * @param  [type] $phone [description]
     * @return [type]        [description]
     */
    public function checkPhone($phone){
        $user = $this->getUserInfoByPhone($phone);
        return $user?false:true;
    }
 
    /**
     * 验证用户是否可用
     * @param  [type] $phone [description]
     * @return [type]        [description]
     */
    public function checkUserStatus($phone){
        $user = $this->getUserInfoByPhone($phone);
        if($user && $user['is_lock'] == 0){
            return true;
        }
        else{
            return false;
        }
    }
 
    /**
     * 通过手机号查询用户信息
     * @param  [type] $phone [description]
     * @return [type]        [description]
     */
    public function getUserInfoByPhone($phone){
        return $this->model->get(array('phone' => $phone));
    }
 
    /**
     * 用户登录
     * @return [type] [description]
     */
    public function login($phone, $password){
        $user = $this->getUserInfoByPhone($phone);
        if($user){
            if(md5(md5($password).$user['encrypt']) == $user['password']){
                return true;
            }
            else{
                return false;
            }
        }
        else{
            return false;
        }
    }
 
    /**
     * 重置密码
     * @param  [type] $phone  [description]
     * @param  [type] $newPwd [description]
     * @return [type]         [description]
     */
    public function resetPwd($phone, $newPwd){
        $user = $this->getUserInfoByPhone($phone);
        if($user && $user['is_lock'] == 0){
            $data['password'] = md5(md5($newPwd).$user['encrypt']);
            $result = $this->model->update($data, array('_id' => $user['_id']));
            if($result){
                return 0;
            }
            else{
                return 2;
            }
        }
        else{
            return 1;
        }
    }
 
    /**
     * 更新用户信息
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public function updateUserInfo($data){
        if(isset($data['_id']) && !empty($data['_id'])){
            $id = $data['_id'];
            $user = $this->model->get(array('_id' => $id)); 
            unset($data['_id']);
            if($user && $user['is_lock'] == 0){
                $result = $this->model->update($data, array('_id' => $id));
                if($result){
                    return 0;
                }
                else{
                    return 1;
                }
            }
            else{
                return 2;
            }
        }
        else{
            return 3;
        }
 
    }
 
}