// +---------------------------------------------------------------------- declare(strict_types=1); namespace addon\haonav\model; use ywxapp\model\BaseModel; /** * 友链/广告 自助申请模型 * 访客在前台提交收录或广告合作申请,后台审核;通过的友链可一键写入 Links。 * 表在首次访问时由 BaseModel 自愈引擎 自愈建立,无需重跑 install.sql。 */ class Apply extends BaseModel { // 申请类型 const TYPE_LINK = 1; // 友链/收录申请 const TYPE_AD = 2; // 广告合作申请 // 审核状态 const STATUS_PENDING = 0; // 待审核 const STATUS_APPROVED = 1; // 已通过 const STATUS_REJECTED = 2; // 已拒绝 /** * 类型字典 */ public static function types(): array { return [ self::TYPE_LINK => '收录/友链', self::TYPE_AD => '广告合作', ]; } protected function getOptions(): array { return [ 'strict' => false, 'name' => 'haonav_apply', 'autoRelation' => [], 'createTime' => 'create_at', 'updateTime' => 'update_at', 'dateFormat' => 'Y-m-d H:i:s', ]; } /** * 同一 IP 限频:窗口期内最多 N 条(默认 1 小时 5 条) */ public static function ipOverLimit(string $ip, int $max = 5, int $window = 3600): bool { $count = self::where('ip', $ip)->where('create_at', '>=', time() - $window)->count(); return $count >= $max; } /** * 同 URL 去重:待审/已通过中已存在同地址申请则拒收 */ public static function urlExists(string $url): bool { return self::where('url', $url)->whereIn('status', [self::STATUS_PENDING, self::STATUS_APPROVED])->count() > 0; } }