<?php

namespace app\model;

use think\Model;

class GameImproveRtpUsersGlobalModel extends Model
{
    // 设置表名
    protected $name = 'improve_rtp_users_global_control';
    // 设置主键
    protected $pk = 'id';

    protected $connection = 'fortue_tiger';


    // 设置自动时间戳
    protected $autoWriteTimestamp = 'int';

    // 设置字段类型
    protected $type = [
        'id' => 'int',
        'app_id' => 'int', // 商户ID
        'user_id' => 'int', // 用户ID
        'bet_amount' => 'decimal', // 点控期间 下注总分数
        'bet_count' => 'int', // 点控期间 下单总数量
        'total_win_amount' => 'decimal', // 点控期间总输赢
        'winning_score' => 'decimal',
        'status' => 'int', // 状态 1 正常，0 取消
        'round_status' => 'int', // 轮开始 1 开始， 2 已满足
        'round_count' => 'int',
        'open_status_time' => 'int', // 每轮开始的时间
        'create_time' => 'int',
        'update_time' => 'int',
        'end_time' => 'int',
    ];

    public static function getUserInfo($app_id, $user_id)
    {
        $where = ['app_id' => $app_id, 'user_id' => $user_id];
        $info = self::where($where)->find();
        if (empty($info)) {
            self::create($where);
            $info = self::where($where)->find();
        }
        return $info;
    }
}