<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class InviteUser extends BaseModel
{
    use HasFactory;
    protected $table = 'invite_user';

    /**
     * 插入邀请信息
     * @param $invite_user_id
     * @param $user_id
     */
    public function insertInviteData($invite_user_id,$user_id){
        if($invite_user_id){
            $invite_info = InviteUser::where('invite_user_id',$invite_user_id)
                ->where('user_id',$user_id)->exists();
            //无需重复插入
            if(!$invite_info){
                self::create([
                    'invite_user_id' => $invite_user_id,
                    'user_id' => $user_id
                ]);
            }
        }

    }
}
