<?php

namespace addons\webman\model;

use addons\webman\traits\DataPermissions;
use addons\webman\traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ChannelRechargeSetting
 * @property int id 主键
 * @property int department_id 所属部门
 * @property int method_id 充值方式id
 * @property int user_id 管理员id
 * @property int user_name 管理员名称
 * @property int title 标题
 * @property int status 状态(0:禁用,1:启用)
 * @property int type 充值类型
 * @property float chip_multiple 打码倍数
 * @property float coins_num coins数量
 * @property float gift_coins 赠送coins
 * @property float money 充值金额
 * @property string deleted_at 删除时间
 * @property string created_at 创建时间
 * @property string updated_at 最后一次修改时间
 *
 * @property AdminDepartment department
 * @property AdminUser user
 * @property ChannelRechargeMethod channel_recharge_method
 * @package addons\webman\model
 */
class ChannelRechargeSetting extends Model
{
    use HasDateTimeFormatter, SoftDeletes, DataPermissions;

    const TYPE_REGULAR = 1; // 普通充值
    const TYPE_ACTIVITY = 2; // 活动充值
    //数据权限字段
    protected $dataAuth = ['department_id' => 'department_id'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->setTable(plugin()->webman->config('database.channel_recharge_setting_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 BelongsTo
     */
    public function channel_recharge_method(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.channel_recharge_method_model'), 'method_id')->withTrashed();
    }
}
