-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthBeInvited.php
51 lines (47 loc) · 1.95 KB
/
authBeInvited.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
<?php
header("content-type:text/html;charset=utf-8");
include_once __DIR__ . "/common.php";
$data = initPostData();
$token = $data['token'];
$seccs = $data['scene'];
$con = pdo_database();
if ($token) {
[$openid, $identity, $nickName, $uid] = pdoCheckUserPrivilege($con, $token, true);
//var_dump([$token,$openid,$identity,$nickName]);
} else {
$con = null;
die('{"code":1002,"msg":"请登录后重试"}');
}
if ($openid && $identity == 'u') {
$identity = pdoCheckCatEditPrivilege($con, $openid, $id);
}
$ntime = date("Y-m-d H:i:s");
$sth = $con->prepare("SELECT * FROM invitepower WHERE secret_checksum = :seccs");
$sth->execute(array(':seccs' => $seccs));
$resu = $sth->fetch(PDO::FETCH_ASSOC);
if($resu){
if ($resu['invite_period_time']>$ntime && $resu['times_left'] > 0) {
$sthi = $con->prepare('INSERT IGNORE INTO userpower (catid,openid,power,auth_by) VALUES (:id, :openid, "e", :authby)', array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$result = $sthi->execute(array(':id' => $resu['catid'], ':openid' => $openid, ':authby' => $resu['inviter_openid']));
if($resu['times_left']>1){
$con->prepare("UPDATE invitepower SET times_left = times_left - 1 WHERE secret_checksum = :seccs ")->execute(array(':seccs' => $seccs));
} else {
$con->prepare("DELETE FROM invitepower WHERE secret_checksum = :seccs")->execute(array(':seccs' => $seccs));
}
} else {
$con->prepare("DELETE FROM invitepower WHERE secret_checksum = :seccs")->execute(array(':seccs' => $seccs));
$con = null;
die('{"code":1005,"msg":"邀请码已失效!"}');
}
if($result){
$redata['code'] = 10;
}
echo json_encode($redata, JSON_UNESCAPED_UNICODE);
// 邀请成功的消息
setNewMsg($con, $resu['inviter_openid'], 5, 0, $uid, $resu['catid'],
'{"content":"template_4"}');
$con = null;
}else{
$con = null;
die('{"code":1005,"msg":"邀请码已失效!"}');
}