Material.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Material.php
  4. * todo 文件描述
  5. * Created on 2025/1/11 上午9:53
  6. * @author: hankaige
  7. */
  8. namespace app\models\material;
  9. use app\models\Goods;
  10. use yii\behaviors\TimestampBehavior;
  11. /**
  12. * This is the model class for table "{{%material}}".
  13. * @property integer $id
  14. * @property integer $store_id
  15. * @property integer $material_category_id
  16. * @property integer $type
  17. * @property string $promotion
  18. * @property integer $status
  19. * @property integer $is_top
  20. * @property integer $sort
  21. * @property integer $browsing_number
  22. * @property integer $goods_id
  23. * @property integer $resource_model
  24. * @property integer $download_number
  25. * @property string $promotion_image
  26. * @property string $promotion_image_f
  27. */
  28. class Material extends \yii\db\ActiveRecord
  29. {
  30. const RESOURCE_MODEL_IMAGE = 1;
  31. const RESOURCE_MODEL_VIDEO = 2;
  32. const RESOURCE_MODEL_TEXT = [
  33. self::RESOURCE_MODEL_IMAGE => '图片',
  34. self::RESOURCE_MODEL_VIDEO => '视频'
  35. ];
  36. const TYPE_SYSTEM = 1;
  37. const TYPE_CUSTOM = 2;
  38. const STATUS_ON = 1;
  39. const STATUS_OFF = 0;
  40. const IS_TOP_ON = 1;
  41. const IS_TOP_OFF = 0;
  42. public static function tableName():string
  43. {
  44. return '{{%material}}';
  45. }
  46. public function behaviors():array
  47. {
  48. return [
  49. [
  50. 'class' => TimestampBehavior::class,
  51. 'attributes' => [
  52. \yii\db\BaseActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
  53. \yii\db\BaseActiveRecord::EVENT_BEFORE_UPDATE => ['update_time'],
  54. ],
  55. 'createdAtAttribute' => 'create_time',
  56. 'updatedAtAttribute' => 'update_time',
  57. 'value' => function(){
  58. return date('Y-m-d H:i:s');
  59. }
  60. ],
  61. ];
  62. }
  63. public function rules():array
  64. {
  65. return [
  66. [['store_id','material_category_id','type','status','sort','is_top','browsing_number','download_number','resource_model'],'integer'],
  67. [['promotion','promotion_image_f'],'string'],
  68. [['store_id','material_category_id','type','promotion','promotion_image'],'required'],
  69. ['browsing_number','default', 'value' => 0]
  70. ];
  71. }
  72. public function attributeLabels():array
  73. {
  74. return [
  75. 'store_id' => '店铺ID',
  76. 'material_category_id' => '素材分类ID',
  77. 'type' => '素材类型',
  78. 'promotion' => '素材推广',
  79. 'status' => '状态',
  80. 'is_top' => '是否置顶',
  81. 'sort' => '排序',
  82. 'browsing_number' => '浏览次数',
  83. 'promotion_image' => '推广图',
  84. 'promotion_image_f' => '推广方图'
  85. ];
  86. }
  87. public function getMaterialCategory()
  88. {
  89. return $this->hasOne(MaterialCategory::class, ['id' => 'material_category_id']);
  90. }
  91. public function getMaterialResource(){
  92. return $this->hasMany(MaterialResource::class, ['material_id' => 'id']);
  93. }
  94. public function getGoods(){
  95. return $this->hasOne(Goods::class,['id'=>'goods_id'])->select('id,name,cover_pic,price');
  96. }
  97. }