/**
* 添加一个邀请码
* @JSON
*/
public function update()
{
$result = array('error' => -1, 'message' => 'Request failed');
$user = User::getCurrent();
if ($_POST['invite'] == null) {
$result = array('error' => 0, 'message' => '添加成功,刷新可见');
$plan = 'A';
$add_uid = -1;
$inviteNumber = 1;
if ($_POST['plan'] != null) {
$plan = $_POST['plan'];
}
if ($_POST['add_uid'] != null) {
$add_uid = trim($_POST['add_uid']);
if ($add_uid != $user->uid && $add_uid != -1) {
if (!User::getUserByUserId($add_uid)) {
$result['error'] = 1;
$result['message'] = "此UID: " . $add_uid . " 的用户不存在,添加失败";
return $result;
}
}
}
if ($_POST['number'] != null) {
$inviteNumber = $_POST['number'];
}
if ($inviteNumber > 1) {
for ($i = 0; $i < $inviteNumber; $i++) {
InviteModel::addInvite($add_uid, $plan);
}
} else {
InviteModel::addInvite($add_uid, $plan);
}
$result['inviteNumber'] = $inviteNumber;
$result['plan'] = $plan;
} else {
if ($_POST['invite'] != null) {
$invite = InviteModel::getInviteByInviteCode(trim($_POST['invite']));
if ($invite != null) {
$invite->dateLine = time();
$invite->expiration = $_POST['expiration'];
$invite->plan = $_POST['plan'];
$invite->save();
$result = array('error' => 0, 'message' => '更新邀请码成功');
}
}
}
return $result;
}