common.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
<?php
function handleOrder($orderInfo) {
try {
$orderInfo['other'] = json_decode($orderInfo['other'], true);
if($orderInfo['type'] == 1) { // 打赏
$user = new \app\api\model\User();
$userInfo = $user->infoAndLockById($orderInfo['other']['user_id']);
if(!$userInfo) {
return false;
}
$insertData = [
'user_id' => $orderInfo['other']['user_id'],
'money' => $orderInfo['other']['money'],
'memo' => '收到打赏',
'createtime' => time(),
];
$userMoneyLog = new \app\api\model\UserMoneyLog();
$res = $userMoneyLog->addOne($insertData);
if(!$res) {
return false;
}
$updateData = [
'money' => bcadd($userInfo['money'], $orderInfo['other']['money'], 2)
];
$res = $user->updateOne($orderInfo['other']['user_id'], $updateData);
if(!$res) {
return false;
}
return true;
} elseif ($orderInfo['type'] == 2) { // 购买vip
$student = new \app\api\model\Student();
$studentInfo = $student->infoByUserIdCanShow($orderInfo['other']['user_id']);
if(!$student) {
return false;
}
if($studentInfo['vip_endtime']) {
if($studentInfo['vip_level'] == $orderInfo['other']['vip_level']) {
if($studentInfo['vip_endtime'] >= time()) {
$vipEndTime = bcadd($studentInfo['vip_endtime'], bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), 0);
} else {
$vipEndTime = bcadd(bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), time(), 0);
}
} else {
$vipEndTime = bcadd(bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), time(), 0);
}
} else {
$vipEndTime = bcadd(bcmul($orderInfo['other']['keep'], bcmul(3600, 24, 0), 0), time(), 0);
}
//添加明细
$insertData = [
'user_id' => $orderInfo['other']['user_id'],
'money' => $orderInfo['other']['money'],
'memo' => '购买VIP',
'createtime' => time()
];
$userMoneyLog = new \app\api\model\UserMoneyLog();
$res1 = $userMoneyLog->addOne($insertData);
$updateData = [
'vip_level' => $orderInfo['other']['vip_level'],
'vip_endtime' => $vipEndTime,
];
$res = $student->updateOne($studentInfo['user_id'], $updateData);
if(!$res) {
return false;
}
return true;
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
}