Model\Invite::getInviteByInviteCode PHP Method

getInviteByInviteCode() public static method

Get a invite object by inviteCode
public static getInviteByInviteCode ( $invite ) : mixed
$invite
return mixed
    public static function getInviteByInviteCode($invite)
    {
        $statement = DB::getInstance()->prepare("SELECT * FROM invite AS t1 WHERE t1.invite=? LIMIT 0,1");
        $statement->bindValue(1, $invite, DB::PARAM_STR);
        $statement->execute();
        return $statement->fetchObject(__CLASS__);
    }

Usage Example

Beispiel #1
0
 /**
  * 添加一个邀请码
  * @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;
 }
All Usage Examples Of Model\Invite::getInviteByInviteCode