public static function getCloneWmIdUserList wmid null where bindValues

 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
public static function getCloneWmIdUserList($wmid = null)
{
$where = '1 = 1';
$bindValues = [
':add_by_webmoney' => Transaction::TYPE_ADD_BY_WEBMONEY,
':deduct_by_user' => Transaction::TYPE_DEDUCT_BY_USER,
];
// фильтруем клонов по WMID если он передан
if (!empty($wmid)) {
$where = 'wmid = :wmid';
$bindValues[':wmid'] = $wmid;
}
$addUnion = Yii::app()->db->createCommand()
->select("t_add.wmid, t_add.to_user_id AS user_id")
->from('transactions t_add')
->where('t_add.type = :add_by_webmoney AND t_add.wmid IS NOT NULL')
->text;
$deductUnion = Yii::app()->db->createCommand()
->select("t_deduct.wmid, t_deduct.from_user_id AS user_id")
->from('transactions t_deduct')
->where('t_deduct.type = :deduct_by_user AND t_deduct.wmid IS NOT NULL')
->text;
$allWmids = Yii::app()->db->createCommand()
->select("wmid, user_id")
->from('user_purse_history uph')
->union($addUnion)
->union($deductUnion)
->where('uph.wmid IS NOT NULL')
->text;
return Yii::app()->db->createCommand()
->select("wmid, COUNT(user_id) AS users, array_agg(user_id) AS users_id")
->from('('.$allWmids.') AS wu')
->where($where)
->group('wu.wmid')
->having('COUNT(user_id) > 1')
->bindValues($bindValues)
->queryAll();
}
/**
* Получение списка клонов в формате для отображения
*
* @param int $wmid WMID пользователя
*
* @return array
*/
public static function prepareCloneWmidList($wmid)
{
$usersWmIdClones = self::getCloneWmIdUserList($wmid);
$result = $wmidList = $allUsers = [];
foreach ($usersWmIdClones as $clone) {
$users = str_replace(["{", "}"], "", $clone['users_id']);
$users = explode(",", $users);
$result[$clone['wmid']] = $users;
$allUsers = array_merge($allUsers, $users);
}
$allUsersIds = array_unique($allUsers);
$usersInfo = Yii::app()->db->createCommand()
->select('u.id AS user_id, u.email, u.created, u.name, u.balance, u.banned')
->from('users u')
->where(['in', 'u.id', $allUsersIds])
->queryAll();
$usersInfo = ArrayHelper::listData($usersInfo, 'user_id');
foreach ($result as $wmid => $userList) {
foreach ($userList as $userId) {
$wmidList[$wmid][] = $usersInfo[$userId];
}
}
foreach ($wmidList as $key => $list) {
if (count($list) < 2) {
unset($wmidList[$key]);
}
}
return $wmidList;
}