/** * 生成邀请码,必要权限检查 * * @JSON * @Authorization */ public function create() { $user = User::getUserByUserId(User::getCurrent()->uid); $result = array('error' => 1, 'message' => '创建邀请码失败,您没有再次创建邀请码的次数了。当然,你可以用流量购买次数。(10GB/个)'); if ($user->invite_num > 0) { $invite = InviteModel::addInvite($user->uid, 'A', false); $result = array('error' => 0, 'message' => '创建邀请码成功,刷新后可见', 'invite_num' => $user->invite_num - 1, 'invite' => $invite); $user->invite_num = $user->invite_num - 1; $user->save(); } return $result; }
/** * 添加一个邀请码 * @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; }
public function userAddInvite() { global $user; $result = array('error' => 1, 'message' => '添加邀请码失败'); if (!$user) { $result = array('error' => 1, 'message' => '没有权限'); } if ($user->getFlow() > 10) { $invite = InviteModel::addInvite($user->uid); if ($invite != null) { $result = array('error' => 0, 'message' => '添加成功,邀请码为:' . $invite . " ,您可以稍后在列表内查看到您新增的邀请码"); } } else { $result = array('error' => 1, 'message' => '您的流量不足'); } echo json_encode($result); exit; }
public function addInvite() { global $user; $user = User::GetUserByUserId($user->uid); Invite::addInvite($user->uid, 'VIP'); echo 'add ok'; exit; }