98 lines
3.3 KiB
PHP
98 lines
3.3 KiB
PHP
<?php
|
||
|
||
namespace app\models;
|
||
|
||
use Yii;
|
||
|
||
/**
|
||
* This is the model class for table "{{%order_detail}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int $cx_mch_id 平台商户ID
|
||
* @property int $order_id 订单ID
|
||
* @property string $goods_id 商品ID
|
||
* @property int $num 购买商品数量
|
||
* @property float $unit_price 商品单价
|
||
* @property float $total_original_price 商品原总价(优惠前)
|
||
* @property float $total_price 商品总价(优惠后)
|
||
* @property string $goods_attr_info 购买商品信息
|
||
* @property int $is_delete 是否删除:0=否,1=是
|
||
* @property int $created_at 添加时间
|
||
* @property int $updated_at 更新时间
|
||
* @property int $deleted_at 删除时间
|
||
* @property int $is_refund 是否退款
|
||
* @property int $refund_status 售后状态:0=未售后,1=售后中,2=售后结束
|
||
* @property string $plugin_sign 插件标识
|
||
* @property string $serial_no 商品货号
|
||
* @property int $goods_type 商品类型
|
||
*/
|
||
class OrderDetail extends \yii\db\ActiveRecord
|
||
{
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%order_detail}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['goods_attr_info', 'plugin_sign', 'serial_no'], 'trim'],
|
||
[['cx_mch_id', 'order_id', 'num', 'is_delete', 'created_at', 'updated_at', 'deleted_at', 'is_refund', 'refund_status', 'goods_type'], 'integer'],
|
||
[['order_id', 'goods_id', 'num', 'unit_price', 'total_original_price', 'total_price', 'goods_attr_info', ], 'required'],
|
||
[['unit_price', 'total_original_price', 'total_price'], 'number'],
|
||
[['goods_attr_info'], 'string'],
|
||
[['plugin_sign'], 'string', 'max' => 255],
|
||
[['serial_no'], 'string', 'max' => 60],
|
||
[['goods_id'], 'string', 'max' => 20],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'order_id' => '订单ID',
|
||
'goods_id' => '商品ID',
|
||
'num' => '购买商品数量',
|
||
'unit_price' => '商品单价',
|
||
'total_original_price' => '商品原总价(优惠前)',
|
||
'total_price' => '商品总价(优惠后)',
|
||
'goods_attr_info' => '购买商品信息',
|
||
'is_delete' => '是否删除:0=否,1=是',
|
||
'created_at' => '添加时间',
|
||
'updated_at' => '更新时间',
|
||
'deleted_at' => '删除时间',
|
||
'is_refund' => '是否退款',
|
||
'refund_status' => '售后状态:0=未售后,1=售后中,2=售后结束',
|
||
'plugin_sign' => '插件标识',
|
||
'serial_no' => '商品货号',
|
||
'goods_type' => '商品类型',
|
||
];
|
||
}
|
||
|
||
|
||
public function beforeSave($insert) {
|
||
if(parent::beforeSave($insert)){
|
||
if($this->isNewRecord){
|
||
$this->created_at = time();
|
||
}
|
||
$this->updated_at = time();
|
||
if($this->is_delete == 1)
|
||
$this->deleted_at = time();
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
}
|