<?php

namespace common\models;

/**
 * This is the model class for table "{{%SHOP_GOODS}}".
 *
 * @property string $ID
 * @property string $GOODS_NAME 商品名称
 * @property string $CATE_ID 所属分类ID
 * @property string $TYPE 商品来源
 * @property string $GIFT_TYPE 商品类型
 * @property string $CATEGORY_TYPE 商品分类
 * @property string $SELL_TYPE 允许购买方式
 * @property int $GOODS_NO 商品编号
 * @property string $UNIT 单位
 * @property string $COVER 商品封面
 * @property int $IMAGES 商品图片
 * @property string $CONTENT 商品内容
 * @property string $SELL_PRICE 销售价格
 * @property string $SELL_PRICE_STANDARD 标准价格
 * @property string $MARKET_PRICE 市场价格
 * @property int $PRICE_PV 价格PV
 * @property string $TAX_RATE 税率
 * @property int $POINT 兑换积分
 * @property int $STORE_NUMS 库存
 * @property int $IS_DEL 是否删除
 * @property int $CREATED_AT 创建时间
 * @property int $UPDATED_AT 更新时间
 * @property int $DELETED_AT 删除时间
 * @property int $STATUS 状态
 * @property string $SORT 排序
 */
class ShopGoods extends \common\components\ActiveRecord
{
    const SALE_TYPE = [
        1 => [
            'id' => 1,
            'name' => 'Account Balance', //余额购买
            'label' => 'cash',
        ],
//        2 => [
//            'id' => 2,
//            'name' => '复消兑换',
//        ],
//        3 => [
//            'id' => 3,
//            'name' => '兑换点数',
//            'label' => 'exchange',
//        ],
        4 => [
            'id' => 4,
            'name' => 'Travel Bonus',
            'label' => 'tourism_points',
        ],
        5 => [
            'id' => 5,
            'name' => 'Car Fund',
            'label' => 'garage_points',
        ],
        6 => [
            'id' => 6,
            'name' => 'Villa Fund',
            'label' => 'villa_points',
        ],
        7 => [
            'id' => 7,
            'name' => 'PayStack',
            'label' => 'pay_stack',
        ],
    ];

    const GOODS_TYPE = [
        1 =>[
            'name'=>'国内商品',//国内商品
            'discount'=>'50',
        ],
        2 =>[
            'name'=>'进口商品',//进口商品
            'discount'=>'60',
        ],
    ];
    const GIFT_TYPE = [
        1 =>[
            'name'=>'1st Purchase',//报单区
        ],
        2 =>[
            'name'=>'Repeat Purchase',//复消区
        ],
        3 =>[
            'name'=>'Office Entry area',//工作室报单
        ],
        4 =>[
            'name'=>'Office Reselling area',//工作室复消
        ],
    ];
    const STATUS_NAME = [
        1 => 'On sale',//已上架
        0 => 'Sold out',//已下架
    ];
    const CATEGORY_TYPE = [
        [
            'id' => 1,
            'name' => 'Standard Products',//普通商品
            'sell_type' => [
                self::SALE_TYPE[1],
//                self::SALE_TYPE[3],
                self::SALE_TYPE[7],
            ]
        ],
//        [
//            'id' => 4,
//            'name' => 'Travel bonus products',//旅游积分商品
//            'sell_type' => [
//                self::SALE_TYPE[4]
//            ]
//        ],
        [
            'id' => 5,
            'name' => 'Car Fund Products',
            'sell_type' => [
                self::SALE_TYPE[5]
            ]
        ],
        [
            'id' => 6,
            'name' => 'Villa Fund Products',
            'sell_type' => [
                self::SALE_TYPE[6]
            ]
        ],
    ];
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%SHOP_GOODS}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['SELL_DISCOUNT','GOODS_NAME', 'CATE_ID','GIFT_TYPE', 'GOODS_NO', 'SELL_PRICE','MARKET_PRICE','PRICE_PV','STORE_NUMS', 'SELL_TYPE', 'CATEGORY_TYPE', 'SELL_PRICE_STANDARD', 'TAX_RATE'], 'required'],
            [['STORE_NUMS'], 'integer'],
            [['SELL_PRICE','MARKET_PRICE','PRICE_PV','POINT',/* 'SELL_TYPE',*/ 'CATEGORY_TYPE' ,'SELL_PRICE_STANDARD', 'TAX_RATE'], 'number'],
            [['ID','CATE_ID', 'GOODS_NO','GIFT_TYPE'], 'string', 'max' => 32],
            [['UNIT'], 'string', 'max' => 16],
            [['COVER', 'GOODS_NAME'], 'string', 'max' => 255],
            [['IMAGES','CONTENT'], 'string', 'max' => 4000],
            [['GOODS_NAME'], 'unique'],
            [['ID'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'GOODS_NAME' => '商品名称',
            'CATE_ID' => '所属分类ID',
            // 'TYPE' => '商品来源',
            'SELL_DISCOUNT' => '会员折扣',
            'GIFT_TYPE' => '商品类型',
            'CATEGORY_TYPE' => '商品分类',
            'SELL_TYPE' => '出售方式',
            'GOODS_NO' => '商品编号',
            'UNIT' => '商品单位',
            'COVER' => '商品封面',
            'IMAGES' => '商品图片',
            'CONTENT' => '商品内容',
            'SELL_PRICE' => '销售价格',
            'SELL_PRICE_STANDARD' => 'US price($)',
            'MARKET_PRICE' => '市场价格',
            'PRICE_PV' => '价格PV',
            'TAX_RATE' => '税率',
            'TAX_AMOUNT' => '税额',
//            'POINT' => '兑换积分',
            'STORE_NUMS' => '库存',
            'STATUS' => '是否上架',
            'IS_DEL' => '是否删除',
            'CREATED_AT' => '创建时间',
            'UPDATED_AT' => '更新时间',
            'DELETED_AT' => '更新时间',
            'SORT' => '排序',
        ];
    }

    /**
     * 判断提现状态
     * @param $nowStatus
     * @param $toStatus
     * @return string
     */
    public static function chkAuditStatus($nowStatus, $toStatus) {
        $statusName = self::STATUS_NAME;
        $msg = 'The current product status is【' . $statusName[$nowStatus] . '】，cannot be set to【' . $statusName[$toStatus] . '】';// 当前商品状态为    无法设置为
        switch ($toStatus) {
            // 下架
            case 0:
                if ($nowStatus == 1) {
                    $msg = '';
                }
                break;
            //上架
            case 1:
                if ($nowStatus == 0) {
                    $msg = '';
                }
                break;
            default:
        }
        return $msg;
    }

    /**
     * 支付方式
     * @return array
     */
    public static function payTypes(){
        return [
            'cash'=>[
                'name'=>'Ecoin' //余额支付
            ],
//            'point'=>[
//                'name'=>'积分支付' //积分支付
//            ],
//            'exchange' => [
//                'name' => '积分点数'
//            ],
//            'tourism_points'=>[
//                'name'=>'Travel Bonus'
//            ],
            'garage_points' => [
                'name' => 'Car Fund'
            ],
            'villa_points' => [
                'name' => 'Villa Fund'
            ],
            'pay_stack' => [
                'name' => 'PayStack'
            ],
        ];
    }

}
