<?php


namespace app\model;

/**
 *
 * @property int $id
 * @property int $stock_code
 * @property string $stock_name
 * @property int stock_type
 * @property int $tape
 * @property int $status
 * @property float $price
 * @property int $min
 * @property int $total
 * @property float $rate
 * @property string $had_get_num
 * @property string $start_time
 * @property string $end_time
 * @property string $get_time
 * @property string $open_time
 * @property int $limit_get_num
 * @property int $open_status
 * @property int $sign_status
 * @property string $create_time
 * @property string $update_time
 * @property int $is_delete
 * @property string $company_reg_amount
 * @property string $company_open_time
 * @property string $company_info
 * @property string $logo
 */
class PreFundStockModel extends BaseModel
{
    protected $name = 'pre_fund_stock';
    protected $pk = 'id';

    // 上市状态
    const OPEN_STATUS_NO = 1; // 未上市
    const OPEN_STATUS_HAD = 2; // 已上市
    const OPEN_STATUS_OUT = 3; // 退市

    // 删除
    const IS_DELETE_NO = 1;
    const IS_DELETE_YES = 2;

    // 股票类型
    const STOCK_TYPE_ONE = 1;
    const STOCK_TYPE_TWO = 2;

    // 周期单位
    const DAY = 1;
    const MONTH = 2;
    const YEAR = 3;

    //
    const ONE_TIME_PRINCIPAL_INTEREST = 1;

    public static $stockTypeList = [
        self::STOCK_TYPE_ONE => '固定收益',
    ];

    public static $stockTypeEnList = [
        self::STOCK_TYPE_ONE => 'FIXED INCOME', //固定收益
    ];

    public static $openStatusList = [
        self::OPEN_STATUS_NO => '未上市',
        self::OPEN_STATUS_HAD => '已上市',
        self::OPEN_STATUS_OUT => '退市',
    ];

    public static $openStatusEnList = [
        self::OPEN_STATUS_NO => 'Unlisted',
        self::OPEN_STATUS_HAD => 'BE LISTED',
        self::OPEN_STATUS_OUT => 'BE DELISTED',
    ];

    public static $cycleTypeList = [
        self::DAY => '天',
//        self::MONTH => '月',
//        self::YEAR => '年',
    ];

    public static $interestTypeList = [
        self::ONE_TIME_PRINCIPAL_INTEREST => '一次性本息',
    ];

    public function getStockTypeTextAttr($value, $data)
    {
        $status = PreFundStockModel::$stockTypeList[$data['stock_type']];
        return $status;
    }

    public function getStockTypeEnTextAttr($value, $data)
    {
        $status = PreFundStockModel::$stockTypeEnList[$data['stock_type']];
        return $status;
    }

    public function getOpenStatusTextAttr($value, $data)
    {
        $status = PreFundStockModel::$openStatusList[$data['open_status']];
        return $status;
    }

    public function getOpenStatusEnTextAttr($value, $data)
    {
        $status = PreFundStockModel::$openStatusEnList[$data['open_status']];
        return $status;
    }

    public function history()
    {
        return $this->belongsTo(HistoryFundStockModel::class, 'stock_code', 'stock_code');
    }
}