setTable(plugin()->webman->config('database.channel_table')); } /** * 部门 * @return BelongsTo */ public function department(): BelongsTo { return $this->belongsTo(plugin()->webman->config('database.department_model'), 'department_id')->withTrashed(); } /** * 管理员用户 * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(plugin()->webman->config('database.user_model'), 'user_id')->withTrashed(); } /** * 管理员用户 * @return hasMany */ public function player(): hasMany { return $this->hasMany(plugin()->webman->config('database.player_model'), 'department_id', 'department_id'); } /** * 管理员用户 * @return hasManyThrough */ public function wallet(): hasManyThrough { return $this->hasManyThrough(plugin()->webman->config('database.player_platform_cash_model'), plugin()->webman->config('database.player_model'), 'department_id', 'player_id', 'department_id', 'id'); } /** * 模型的 "booted" 方法 * * @return void */ protected static function booted() { static::created(function (Channel $channel) { $cacheKey = "channel_" . $channel->site_id; Cache::set($cacheKey, $channel->toArray()); // 创建渠道系统配置 SystemSetting::insert([ [ 'department_id' => $channel->department_id, 'feature' => 'marquee', 'created_at' => date('Y-m-d H:i:s'), ], [ 'department_id' => $channel->department_id, 'feature' => 'machine_marquee', 'created_at' => date('Y-m-d H:i:s'), ] ]); }); static::deleted(function (Channel $channel) { $cacheKey = "channel_" . $channel->site_id; Cache::delete($cacheKey); }); static::updated(function (Channel $channel) { $cacheKey = "channel_" . $channel->site_id; Cache::set($cacheKey, $channel->toArray()); }); } }