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(); } }