cxfoot/models/integral/mall/IntegralMallGoods.php
2023-10-27 14:25:12 +08:00

83 lines
2.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\models\integral\mall;
use Yii;
use app\models\Goods;
use app\models\GoodsAttr;
/**
* This is the model class for table "{{%integral_mall_goods}}".
*
* @property int $id ID
* @property int $cx_mch_id 平台商户ID
* @property int $goods_id 商品ID
* @property int $integral_num 所需积分
* @property int $created_at 添加时间
* @property int $updated_at 更新时间
* @property int $is_delete 是否删除0=否1=是
* @property int $deleted_at 删除时间
*/
class IntegralMallGoods extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return '{{%integral_mall_goods}}';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['cx_mch_id', 'goods_id', 'integral_num', 'created_at', 'updated_at', 'is_delete', 'deleted_at'], 'integer'],
[['goods_id', 'integral_num'], 'required'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'cx_mch_id' => '平台商户ID',
'goods_id' => '商品ID',
'integral_num' => '所需积分',
'created_at' => '添加时间',
'updated_at' => '更新时间',
'is_delete' => '是否删除0=否1=是',
'deleted_at' => '删除时间',
];
}
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;
}
}
public function getAttr()
{
return $this->hasMany(GoodsAttr::className(), ['goods_id' => 'goods_id']);
}
public function getGoods()
{
return $this->hasOne(Goods::className(), ['id' => 'goods_id']);
}
}