<?php

namespace  backend\modules\shop\models\ars;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "ats_cart".
 *
 * @property int $id
 * @property int $user_id 用户id
 * @property int $goods_id 商品id
 * @property string $goods_name 商品名称
 * @property int $goods_img 商品图片
 * @property int $goods_price 商品售价
 * @property int $sku_id 商品sku的id
 * @property int $goods_count 商品数量
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class Cart extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'ats_cart';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id', 'goods_id', 'goods_name', 'sku_id'], 'required'],
            [['user_id', 'goods_id', 'goods_img', 'goods_price', 'sku_id', 'goods_count'], 'integer'],
            [['goods_name'], 'string', 'max' => 120],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'id',
            'user_id' => '用户id',
            'goods_id' => '商品id',
            'goods_name' => '商品名称',
            'goods_img' => '商品图片',
            'goods_price' => '商品售价',
            'sku_id' => '商品sku的id',
            'goods_count' => '商品数量',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }
   

    /**
    * @author linyao
    * @email 602604991@qq.com
    * @created Nov 8, 2019
    *
    * 行为存储创建时间和更新时间
    */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at',
                'value' => function() {
                    return time();
                },
            ],
        ];
    }
}