<?php

namespace App\Models;

class Bet extends BaseModel
{
    protected $table = 'bets';
    protected $fillable = ['issue_no', 'keywords', 'amount', 'odds', 'status', 'profit', 'issue_id', 'member_id', 'user_id'];
    protected $hidden = [];
    const STATUS_STAY = 1;
    const STATUS_SETTLED = 2;
    const STATUS_CANCEL = 3;

    function pcIssue()
    {
        return $this->belongsTo(PcIssue::class, 'issue_no', 'issue_no');
    }

    function issue()
    {
        return $this->belongsTo(Issue::class, 'issue_no', 'issue_no');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'member_id', 'member_id')
            ->select(['id', 'member_id', 'username', 'first_name', 'admin_note', 'status', 'phone', 'visitor_id', 'register_ip']);
    }


    public static $STATUS = [
        1 => '待结算',
        2 => '已结算',
        3 => '取消',
    ];

    public static function getStatus($val = -1)
    {
        $array = self::$STATUS;
        if ($val < 0) {
            $arr = [];
            foreach ($array as $k => $v) {
                $item = [];
                $item['id'] = $k;
                $item['title'] = $v;
                $arr[] = $item;
            }
            return $arr;
        } else {
            return $array[$val];
        }
    }
}