FreeQueueGoods.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\behaviors\TimestampBehavior;
  9. use yii\db\ActiveRecord;
  10. /**
  11. * This is the model class for table "{{%activity_new_user_goods}}".
  12. *
  13. * @property integer $id
  14. * @property integer $activity_id
  15. * @property integer $goods_id
  16. * @property string $attr
  17. * @property integer $virtual_sales
  18. * @property float $price
  19. * @property integer $store_id
  20. * @property integer $is_delete
  21. * @property integer $created_at
  22. * @property integer $updated_at
  23. * @property integer $use_attr
  24. * @property integer $sale_num
  25. */
  26. class FreeQueueGoods extends \yii\db\ActiveRecord
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%free_queue_goods}}';
  34. }
  35. public function behaviors()
  36. {
  37. return [
  38. [
  39. 'class' => TimestampBehavior::class,
  40. 'attributes' => [
  41. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  42. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  43. ]
  44. ]
  45. ];
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function rules()
  51. {
  52. return [
  53. [['id', 'goods_id', 'virtual_sales', 'store_id', 'is_delete', 'activity_id', 'use_attr', 'sale_num'], 'integer'],
  54. [['attr'], 'string'],
  55. [['price'], 'number'],
  56. [['created_at', 'updated_at'], 'safe']
  57. ];
  58. }
  59. /**
  60. * @inheritdoc
  61. */
  62. public function attributeLabels()
  63. {
  64. return [
  65. 'id' => 'ID',
  66. 'activity_id' => '活动ID',
  67. 'goods_id' => '商品ID',
  68. 'attr' => '商品规格',
  69. 'virtual_sales' => '虚拟销量',
  70. 'price' => '活动价格',
  71. 'store_id' => 'Store Id',
  72. 'is_delete' => 'Is Delete',
  73. 'created_at' => '创建时间',
  74. 'updated_at' => '修改时间',
  75. 'use_attr' => '是否使用规格',
  76. ];
  77. }
  78. public static function saveAll($list, $activity_id)
  79. {
  80. // 删除旧数据
  81. self::deleteAll(['activity_id' => $activity_id]);
  82. // 添加新数据
  83. foreach ($list as $item) {
  84. $model = new self();
  85. $model->attributes = $item;
  86. $model->save();
  87. }
  88. }
  89. }