| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- /**
- * Material.php
- * todo 文件描述
- * Created on 2025/1/11 上午9:53
- * @author: hankaige
- */
- namespace app\models\material;
- use app\models\Goods;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%material}}".
- * @property integer $id
- * @property integer $store_id
- * @property integer $material_category_id
- * @property integer $type
- * @property string $promotion
- * @property integer $status
- * @property integer $is_top
- * @property integer $sort
- * @property integer $browsing_number
- * @property integer $goods_id
- * @property integer $resource_model
- * @property integer $download_number
- * @property string $promotion_image
- * @property string $promotion_image_f
- */
- class Material extends \yii\db\ActiveRecord
- {
- const RESOURCE_MODEL_IMAGE = 1;
- const RESOURCE_MODEL_VIDEO = 2;
- const RESOURCE_MODEL_TEXT = [
- self::RESOURCE_MODEL_IMAGE => '图片',
- self::RESOURCE_MODEL_VIDEO => '视频'
- ];
- const TYPE_SYSTEM = 1;
- const TYPE_CUSTOM = 2;
- const STATUS_ON = 1;
- const STATUS_OFF = 0;
- const IS_TOP_ON = 1;
- const IS_TOP_OFF = 0;
- public static function tableName():string
- {
- return '{{%material}}';
- }
- public function behaviors():array
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- \yii\db\BaseActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
- \yii\db\BaseActiveRecord::EVENT_BEFORE_UPDATE => ['update_time'],
- ],
- 'createdAtAttribute' => 'create_time',
- 'updatedAtAttribute' => 'update_time',
- 'value' => function(){
- return date('Y-m-d H:i:s');
- }
- ],
- ];
- }
- public function rules():array
- {
- return [
- [['store_id','material_category_id','type','status','sort','is_top','browsing_number','download_number','resource_model'],'integer'],
- [['promotion','promotion_image_f'],'string'],
- [['store_id','material_category_id','type','promotion','promotion_image'],'required'],
- ['browsing_number','default', 'value' => 0]
- ];
- }
- public function attributeLabels():array
- {
- return [
- 'store_id' => '店铺ID',
- 'material_category_id' => '素材分类ID',
- 'type' => '素材类型',
- 'promotion' => '素材推广',
- 'status' => '状态',
- 'is_top' => '是否置顶',
- 'sort' => '排序',
- 'browsing_number' => '浏览次数',
- 'promotion_image' => '推广图',
- 'promotion_image_f' => '推广方图'
- ];
- }
- public function getMaterialCategory()
- {
- return $this->hasOne(MaterialCategory::class, ['id' => 'material_category_id']);
- }
- public function getMaterialResource(){
- return $this->hasMany(MaterialResource::class, ['material_id' => 'id']);
- }
- public function getGoods(){
- return $this->hasOne(Goods::class,['id'=>'goods_id'])->select('id,name,cover_pic,price');
- }
- }
|