<?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 PlayerMoneyEditLog
 * @property int id 主键
 * @property int player_id 玩家id
 * @property int department_id 部门/渠道id
 * @property int type 类型
 * @property string action 操作
 * @property string tradeno 单号
 * @property string currency 币种
 * @property float money 金额
 * @property float origin_money 原始金额
 * @property float after_money 異動後金額
 * @property float inmoney 实际金额
 * @property float subsidy_money 辅助金额
 * @property float bet_multiple 流水倍数
 * @property float bet_num 流水
 * @property string remark 备注
 * @property int user_id 審核人員ID
 * @property string user_name 審核人員名稱
 * @property string created_at 创建时间
 * @property string updated_at 最后一次修改时间
 * @property string deleted_at 最后一次修改时间
 *
 * @property AdminUser $user 管理员
 * @property Player $player 玩家
 * @property Channel $channel 部门/渠道
 * @package addons\webman\model
 */
class PlayerMoneyEditLog extends Model
{
    use SoftDeletes, HasDateTimeFormatter, DataPermissions;

    //数据权限字段
    protected $dataAuth = ['department_id' => 'department_id'];

    const TYPE_DEDUCT = 0; // 扣点
    const TYPE_INCREASE = 1; // 加点

    const RECHARGE = 0; // 充值
    const VIP_RECHARGE = 1; // vip充值
    const OTHER = 2; // 其他
    const ACTIVITY_GIVE = 3; // 活動外贈
    const ADMIN_DEDUCT = 4; // 管理员扣点
    const ADMIN_INCREASE = 5; // 管理员加点

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setTable(plugin()->webman->config('database.player_money_edit_log_table'));
    }

    /**
     * 玩家信息
     * @return BelongsTo
     */
    public function player(): BelongsTo
    {
        return $this->BelongsTo(plugin()->webman->config('database.player_model'), 'player_id')->withTrashed();
    }

    /**
     * 渠道信息
     * @return BelongsTo
     */
    public function channel(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.channel_model'), 'department_id', 'department_id')->withTrashed();
    }

    /**
     * 管理员用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.user_model'), 'user_id')->withTrashed();
    }
}
