rcube_platform_users.php
2.1 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
<?php
/**
* 接入平台的用户
* @author:dc
* @time 2022/7/22 14:10
* Class rcube_platform_users
*/
class rcube_platform_users{
private $db;
/**
* 表
* @var string
*/
public $table;
/**
* rcube_platform constructor.
* @param null $db
*/
public function __construct($db = null)
{
$this->db = $db ? $db : rcube::get_instance()->get_dbh();
$this->table = $this->db->table_name('platform_users',true);
}
public function firstByPlatformUserId($platform_user_id)
{
// 查询数据
$result = $this->db->query("select * from ". $this->table ." where `platform_user_id` = ?",$platform_user_id);
return $this->db->fetch_assoc($result);
}
public function firstById($id){
// 查询数据
$result = $this->db->query("select * from ". $this->table ." where `id` = ?",$id);
return $this->db->fetch_assoc($result);
}
/**
* 创建用户,平台用户
* @param $platform_id
* @param $user_id
* @param $platform_user_id
* @author:dc
* @time 2022/7/23 14:21
*/
public function create($platform_id,$user_id,$platform_user_id){
// 存在,就直接返回
$result = $this->db->query("select `id`,`platform_id`,`user_id`,`platform_user_id` from {$this->table} where `platform_id` = ? and `user_id` = ? and `platform_user_id` = ? limit 1",$platform_id,$user_id,$platform_user_id);
$row = $this->db->fetch_assoc($result);
if($row){
return $row;
}
// 使用参数绑定一样要按照?所排列的字段来,不然会混乱
// 不存在,则新增
$insert = $this->db->query("insert into {$this->table} set `platform_id` = ? , `user_id` = ? , `platform_user_id` = ? , `created_at` = ?",$platform_id,$user_id,$platform_user_id,date('Y-m-d H:i:s'));
if ($insert && $this->db->affected_rows($insert) && ($id = $this->db->insert_id('platform_users'))) {
return $this->firstById($id);
}else{
return false;
}
}
}