MemberModel.php
2.9 KB
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
<?php
/**
* Created by PhpStorm.
* User: 29925
* Date: 2018/8/9
* Time: 11:01
*/
namespace app\member\model;
use think\Model;
use think\Db;
use think\Session;
class MemberModel extends Model
{
protected $autoWriteTimestamp = true;
/**
* 编辑用户
*/
public function editMember($data) {
$this->allowField(true)->data($data,true)->isUpdate(true)->save();
return $this;
}
public function doMobile($user)
{
$userQuery = Db::name("Member");
$result = $userQuery->where('mobile', $user['mobile'])->find();
if (!empty($result)) {
$hookParam =[
'user'=>$user
];
hook_one("user_login_start",$hookParam);
$code_where = [
'mobile' => $user['mobile'],
'code' => $user['code'],
'is_used' => 0
];
$code_check = Db::name('Code')->where($code_where)->find();
if($code_check) {
Db::name('Code')->where($code_where)->update(['is_used'=>1]);
session('user', $result);
session('baby_age','');
$data = [
'last_login_time' => time(),
'last_login_ip' => get_client_ip(0, true),
];
$userQuery->where('id', $result["id"])->update($data);
return 0;
}
return 1;
}
$hookParam =[
'user'=>$user
];
hook_one("user_login_start",$hookParam);
return 2;
}
public function registerMobile($user)
{
$result = Db::name("Member")->where('mobile', $user['mobile'])->find();
if (empty($result)) {
$data = [
'mobile' => $user['mobile'],
'baby_name' => $user['baby_name'],
'baby_birth' => $user['baby_birth'],
'parent_name' => $user['parent_name'],
'parent_status' => $user['parent_status'],
'is_member' => $user['is_member'],
// 'user_pass' => cmf_password($user['user_pass']),
'last_login_ip' => get_client_ip(0, true),
'create_time' => time(),
'last_login_time' => time(),
// 'user_status' => $userStatus,
// "user_type" => 2,//会员
];
// 是否为渠道注册
$channel_id = Session::pull('channel');
if(!empty($channel_id)) {
$data['channel_id'] = $channel_id;
}
$userId = Db::name("Member")->insertGetId($data);
$data = Db::name("Member")->where('id', $userId)->find();
cmf_update_current_user($data);
session('baby_age',null);
return 0;
}
return 1;
}
}