fuc/src/Models/InviteUp.php
2025-02-23 13:30:57 +08:00

43 lines
897 B
PHP
Executable File

<?php
declare(strict_types=1);
namespace App\Models;
use App\Utils\Tools;
use Illuminate\Database\Query\Builder;
/**
* @property int $id 记录ID
* @property string $code 邀请码
* @property int $user_id 用户ID
*
* @mixin Builder
*/
final class InviteUp extends Model
{
protected $connection = 'default';
protected $table = 'invite_up';
public function add(string $code, int $type = 0, int $checkIp = 0): string
{
$ip = $_SERVER['REMOTE_ADDR'];
if ($checkIp == 1) {
$iCountByIp = InviteUp::where('ip', $ip)->count();
if ($iCountByIp != 0) {
return 'no';
}
}
$this->code = $code;
$this->type = $type;
$this->date = date("Y-m-d");
$this->ip = $ip;
$this->save();
return $this->code;
}
}