-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdonateBonus.php
175 lines (137 loc) · 5.24 KB
/
donateBonus.php
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
header('Content-type: application/json');
if(empty($_POST)) {
$response = array(
'status' => 110
);
echo json_encode($response);
exit();
}
ob_start(); //Do not delete this line
require_once("include/bittorrent.php");
dbconn();
loggedinorreturn();
$amount = (int) $_POST['amount'];
$now = date('Y-m-d H:i:s');
$donater = $CURUSER['username'];
$donaterId = $CURUSER['id'];
$objectType = $_POST['type'];
$status = 0;
if(!empty($CURUSER['username'])) {
if($CURUSER['seedbonus'] < $amount) {
$status = 1; // Not enough bonus
} else if($objectType === 'torrent'
|| $objectType === 'topic') {
$validAmount = false;
if($objectType == 'torrent') {
$objectId = (int) $_POST['torrent_id'];
$result = sql_query('SELECT owner, name, anonymous FROM torrents WHERE id='.$objectId);
$torrentInfo = _mysql_fetch_assoc($result);
$receiverId = $torrentInfo['owner'];
$objectName = $torrentInfo['name'];
$anonymous = $torrentInfo['anonymous'];
$validAmount = in_array($amount, array(64, 128, 256, 512, 1024));
} else {
$objectId = (int) $_POST['topicid'];
$result = sql_query('SELECT userid, subject, forumid, locked FROM topics WHERE id='.$objectId) or sqlerr();
$topicInfo = _mysql_fetch_assoc($result);
$receiverId = $topicInfo['userid'];
$objectName = $topicInfo['subject'];
$anonymous = 'no';
$forumid = $topicInfo['forumid'];
if ($topicInfo['locked'] == 'yes') {
unset($objectId);
}
$validAmount = in_array($amount, array(8, 16, 32, 64, 128));
}
if(empty($objectId)) {
$status = 2; // No such torrent
} else if(empty($receiverId)) {
$status = 3; // No such user
} else if(!$validAmount) {
$status = 4; // Involid amount of donate
} else if($receiverId == $donaterId) {
$status = 5; // Donate to someone self
}else {
$sqlCheckDonate = 'SELECT donater_id FROM donate_bonus WHERE object_id='.$objectId.' AND donater_id='.$donaterId.' AND `type`="'.$objectType.'"';
$result = sql_query($sqlCheckDonate);
$donated = _mysql_fetch_assoc($result);
if(!empty($donated)) {
$status = 6; // Already donated
} else {
$amount_after_tax = $amount - ($amount / 8); // Tax is required, 1/8
$message = sqlesc($_POST['message']);
$sqlAddLog = 'INSERT INTO donate_bonus'
.' (`donater_id`, `donater`, `receiver_id`, `type`, `object_id`, `amount`, `amount_after_tax`, `message`)'
.' VALUES'
." ({$donaterId}, '{$donater}', {$receiverId}, '{$objectType}', {$objectId}, {$amount}, {$amount_after_tax}, '')";
sql_query($sqlAddLog);
if(_mysql_affected_rows()) {
$status = 7; // Loged the donate
// Update the user details of donater |->
$receiver = get_user_row($receiverId)['username'];
$dotanerBonusComment = date("Y-m-d")." - {$amount} Points as donate to {$receiver} on {$objectType} {$objectId}.\n";
// End update the user details of donater
if (update_user($donaterId, "seedbonus=seedbonus-?, bonuscomment=CONCAT(?, bonuscomment)", [$amount, $dotanerBonusComment])) {
$status = 8; // Reduced the bonus from donater
$receiverBonusComment = date("Y-m-d")." + {$amount_after_tax} Points (after tax) as donate from {$donater} on {$objectType} {$objectId}.\n";
if (update_user($receiverId, "seedbonus=seedbonus+?, bonuscomment=CONCAT(?, bonuscomment)", [$amount_after_tax, $receiverBonusComment])) {
$status = 9; // Successful
}
}
}
}
}
} else {
$status = 6; // Undefined object type
}
}
if($status == 9) {
// send private message ||->
if($objectType == 'torrent') {
$poster = '发布者';
$object = '种子';
$pageType = '种子页面';
} else if($objectType == 'topic') {
$poster = '楼主';
$object = '帖子';
$pageType = '论坛主题页面';
}
$pageLink = '[' . $objectType . '=' . $objectId . ']';
$receiverSubject = "{$donater} 在{$pageType}给你捐赠了 {$amount} 魔力值";
if($anonymous === 'yes') {
$donaterSubject = "你在{$pageType}向种子发布者捐赠了 {$amount} 魔力值";
} else {
$donaterSubject = "你在{$pageType}向 {$receiver} 捐赠了 {$amount} 魔力值";
}
$donaterLink = "[user={$donaterId}]";
if($anonymous == 'yes') {
$receiverLink = "种子发布者(用户已匿名)";
} else {
$receiverLink = "[user={$receiverId}]";
}
$donaterMessage = <<<MESSAGE
你在{$pageType} {$pageLink} 向 {$receiverLink} 捐赠了[b]{$amount}[/b] 魔力值。
谢谢你对{$poster}的支持!
MESSAGE;
$receiverMessage = <<<MESSAGE
用户 {$donaterLink} 在{$pageType} {$pageLink} 给你捐赠了[b]{$amount}[/b] 魔力值,税后你将获得 [b]{$amount_after_tax}[/b] 魔力值。
谢谢你发布{$object},祝愉快~
MESSAGE;
// Send PM to receiver |->
send_pm(0, $receiverId, $receiverSubject, $receiverMessage);
// End send PM to receiver ||
// End send private message. ||
// Update memcache sign
$Cache->delete_value("update_donate_bonus_{$objectType}_{$objectId}");
}
//var_dump($query_name);die(); // debug
$response = array(
'status' => $status,
'amount' => $amount,
'donater' => $donater,
'message' => '',
// 'message' => $status < 9 ? '' : 'I love the movie~'
'date' => $now
);
echo json_encode($response);