| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /**
- * MdGroupActivitiesGoods.php
- * todo 文件描述
- * Created on 2024/3/19 11:08
- * @author: hankaige
- */
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%md}}".
- * @property integer $id
- * @property integer $activities_id
- * @property integer $goods_id
- * @property integer $use_attr
- * @property string $attr
- * @property float $price
- * @property integer $sale_num
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer $is_delete
- */
- class MdGroupActivitiesGoods extends \yii\db\ActiveRecord
- {
- public static function tableName()
- {
- return '{{%md_group_activities_goods}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
- ]
- ]
- ];
- }
- public function rules()
- {
- return [
- [
- [
- 'activities_id',
- 'goods_id',
- 'attr'
- ],
- 'required'
- ],
- [
- [
- 'activities_id',
- 'goods_id',
- 'use_attr',
- 'sale_num'
- ],
- 'integer'
- ],
- [
- ['price'],
- 'number'
- ],
- [
- ['attr'],
- 'string'
- ],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'activities_id' => '活动ID',
- 'goods_id' => '商品ID',
- 'use_attr' => '是否使用规格',
- 'attr' => '规格信息',
- 'price' => '单规格活动价格',
- 'sale_num' => '活动销售数量',
- ];
- }
- public function getGoods()
- {
- return $this->hasOne(Goods::className(),['id'=>'goods_id']);
- }
- /**
- * 修改活动销售数量
- * @param $id
- * @param $type
- * @author: hankaige
- * @Time: 2024/3/19 11:21
- */
- public static function setSaleNum($id, $type = 1)
- {
- $model = self::findOne($id);
- if ($type == 1) {
- $model->sale_num++;
- } else {
- $model->sale_num--;
- }
- $model->save();
- }
- }
|