<?php

namespace common\models\ars;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "ats_order".
 *
 * @property int $id
 * @property int $user_id 用户id
 * @property string $order_sn 订单号
 * @property string $invoice_id 发票单号
 * @property int $status 状态
 * @property int $type 类型
 * @property int $goods_count 商品数量
 * @property int $goods_amount 商品金额
 * @property int $shipping_amount 物流金额
 * @property int $shipping_type 物流类型
 * @property string $consignee 收件人
 * @property string $phone 手机号码
 * @property string $province 省份
 * @property string $city 城市
 * @property string $area 区域
 * @property int $taking_site 自提点
 * @property int $pay_type 支付方式
 * @property int $pay_at 支付时间
 * @property string $payment_sn 付款单号
 * @property int $payment_amount 支付金额
 * @property int $receivables 应收款
 * @property string $remarks 备注
 * @property int $discount_amount 折扣金额
 * @property string $discount_decription 折扣说明
 * @property int $updated_at 更新时间
 * @property int $created_at 创建时间
 */
class Order extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'ats_order';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id'], 'required'],
            [['user_id', 'status', 'type', 'goods_count', 'goods_amount', 'shipping_amount', 'shipping_type', 'taking_site', 'pay_type', 'pay_at', 'payment_amount', 'receivables', 'discount_amount'], 'integer'],
            [['discount_decription'], 'string'],
            [['order_sn', 'invoice_id'], 'string', 'max' => 64],
            [['consignee', 'phone'], 'string', 'max' => 20],
            [['province', 'city', 'area'], 'string', 'max' => 10],
            [['payment_sn'], 'string', 'max' => 120],
            [['remarks'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'id',
            'user_id' => '用户id',
            'order_sn' => '订单号',
            'invoice_id' => '发票单号',
            'status' => '状态',
            'type' => '类型',
            'goods_count' => '商品数量',
            'goods_amount' => '商品金额',
            'shipping_amount' => '物流金额',
            'shipping_type' => '物流类型',
            'consignee' => '收件人',
            'phone' => '手机号码',
            'province' => '省份',
            'city' => '城市',
            'area' => '区域',
            'taking_site' => '自提点',
            'pay_type' => '支付方式',
            'pay_at' => '支付时间',
            'payment_sn' => '付款单号',
            'payment_amount' => '支付金额',
            'receivables' => '应收款',
            'remarks' => '备注',
            'discount_amount' => '折扣金额',
            'discount_decription' => '折扣说明',
            'updated_at' => '更新时间',
            'created_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();
                },
            ],
        ];
    }
}