$userId, 'card_id'=>$cardId, ])->find(); $time *= 86400; if($data){ $endtime = ( $data['end_time'] > time() ? $data['end_time'] :time() ) + $time; self::where([ 'id'=>$data['id'] ])->update([ 'updatetime'=>time(), 'end_time'=>$endtime ]); }else{ $endtime = time() + $time; self::insert([ 'updatetime'=>time(), 'createtime'=>time(), 'end_time'=>$endtime, 'status'=>1, 'user_id'=>$userId, 'card_id'=>$cardId, 'uniacid'=>UNIACID ]); } return true; } /** * 获取用户VIP信息 * @param $userId * @return void */ public static function getUserVipInfo($userId){ $data = self::with(['card'])->where([ 'card_user.user_id'=>$userId, 'card_user.status'=>1, // 'card.status'=>1, 'card_user.end_time'=>['>',time()] ])->order('card_user.updatetime','desc')->find(); return $data; } /** * 获取用户VIP信息 * @param $userId * @return void */ public static function getUserAllVipInfo($userId){ $data = self::with(['card'])->where([ 'card_user.user_id'=>$userId, 'card_user.status'=>1, // 'card.status'=>1, 'card_user.end_time'=>['>',time()] ])->order('card_user.updatetime','desc')->select(); return $data; } public function card() { return $this->belongsTo('app\api\model\app\vip\Card', 'card_id', 'id', [], 'Right')->setEagerlyType(0); } }