FoodGoods.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\food\models;
  8. use yii\db\ActiveRecord;
  9. use yii\behaviors\TimestampBehavior;
  10. /**
  11. * Class Goods
  12. * @package app\modules\common\models
  13. * @property integer $id
  14. * @property integer $store_id
  15. * @property string $name
  16. * @property string $subtitle
  17. * @property string $price
  18. * @property string $original_price
  19. * @property string $detail
  20. * @property string $cat_id
  21. * @property integer $status
  22. * @property integer $is_delete
  23. * @property string $attr
  24. * @property integer $sort
  25. * @property integer $virtual_sales
  26. * @property integer $is_recommend
  27. * @property string $cover_pic
  28. * @property string $material_id
  29. * @property string $created_at
  30. * @property string $updated_at
  31. */
  32. class FoodGoods extends ActiveRecord
  33. {
  34. const STATUS_NORMAL = 1; // 上架
  35. const STATUS_DISABLE = 0; // 下架
  36. public static function tableName()
  37. {
  38. return '{{%food_goods}}';
  39. }
  40. public function behaviors()
  41. {
  42. return [
  43. [
  44. // 自动更新创建和更新时间
  45. 'class' => TimestampBehavior::class,
  46. 'value' => time()
  47. ]
  48. ];
  49. }
  50. public function rules()
  51. {
  52. return [
  53. [['store_id', 'name', 'detail', 'attr'], 'required', 'on' => self::whenSave()],
  54. [['store_id', 'cat_id', 'status', 'is_delete', 'created_at', 'updated_at',
  55. 'sort', 'virtual_sales', 'is_recommend'], 'integer', 'on' => self::whenSave()],
  56. [['price', 'original_price'], 'number', 'on' => self::whenSave()],
  57. [['detail', 'attr', 'cover_pic', 'subtitle'], 'string', 'on' => self::whenSave()],
  58. [['name', 'material_id'], 'string', 'max' => 255, 'on' => self::whenSave()],
  59. [['status', 'cat_id', 'store_id'], 'integer', 'on' => self::whenList()],
  60. [['name'], 'string', 'max' => 60, 'on' => self::whenList()],
  61. ];
  62. }
  63. public function attributeLabels()
  64. {
  65. return [
  66. 'id' => 'ID',
  67. 'store_id' => 'Store ID',
  68. 'name' => '商品名称',
  69. 'subtitle' => '副标题',
  70. 'price' => '售价',
  71. 'original_price' => '原价(只做显示用)',
  72. 'detail' => '商品详情,图文',
  73. 'cat_id' => '商品类别',
  74. 'status' => '上架状态:0=下架,1=上架',
  75. 'is_delete' => 'Is Delete',
  76. 'attr' => '规格的库存及价格',
  77. 'sort' => '排序 升序',
  78. 'virtual_sales' => '虚拟销量',
  79. 'is_recommend' => '是否推荐',
  80. 'cover_pic' => '商品缩略图',
  81. 'material_id' => '图片物料id',
  82. 'created_at' => '创建时间',
  83. 'updated_at' => '更新时间',
  84. ];
  85. }
  86. public static function whenSave ()
  87. {
  88. return 'save';
  89. }
  90. public static function whenList ()
  91. {
  92. return 'list';
  93. }
  94. }