MdGroupActivitiesGoods.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * MdGroupActivitiesGoods.php
  4. * todo 文件描述
  5. * Created on 2024/3/19 11:08
  6. * @author: hankaige
  7. */
  8. namespace app\models;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%md}}".
  13. * @property integer $id
  14. * @property integer $activities_id
  15. * @property integer $goods_id
  16. * @property integer $use_attr
  17. * @property string $attr
  18. * @property float $price
  19. * @property integer $sale_num
  20. * @property integer $created_at
  21. * @property integer $updated_at
  22. * @property integer $is_delete
  23. */
  24. class MdGroupActivitiesGoods extends \yii\db\ActiveRecord
  25. {
  26. public static function tableName()
  27. {
  28. return '{{%md_group_activities_goods}}';
  29. }
  30. public function behaviors()
  31. {
  32. return [
  33. [
  34. 'class' => TimestampBehavior::class,
  35. 'attributes' => [
  36. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  37. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  38. ]
  39. ]
  40. ];
  41. }
  42. public function rules()
  43. {
  44. return [
  45. [
  46. [
  47. 'activities_id',
  48. 'goods_id',
  49. 'attr'
  50. ],
  51. 'required'
  52. ],
  53. [
  54. [
  55. 'activities_id',
  56. 'goods_id',
  57. 'use_attr',
  58. 'sale_num'
  59. ],
  60. 'integer'
  61. ],
  62. [
  63. ['price'],
  64. 'number'
  65. ],
  66. [
  67. ['attr'],
  68. 'string'
  69. ],
  70. ];
  71. }
  72. public function attributeLabels()
  73. {
  74. return [
  75. 'activities_id' => '活动ID',
  76. 'goods_id' => '商品ID',
  77. 'use_attr' => '是否使用规格',
  78. 'attr' => '规格信息',
  79. 'price' => '单规格活动价格',
  80. 'sale_num' => '活动销售数量',
  81. ];
  82. }
  83. public function getGoods()
  84. {
  85. return $this->hasOne(Goods::className(),['id'=>'goods_id']);
  86. }
  87. /**
  88. * 修改活动销售数量
  89. * @param $id
  90. * @param $type
  91. * @author: hankaige
  92. * @Time: 2024/3/19 11:21
  93. */
  94. public static function setSaleNum($id, $type = 1)
  95. {
  96. $model = self::findOne($id);
  97. if ($type == 1) {
  98. $model->sale_num++;
  99. } else {
  100. $model->sale_num--;
  101. }
  102. $model->save();
  103. }
  104. }