| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%activity_wechat_room_goods}}".
- *
- * @property integer $id
- */
- class ActivityWechatRoomGoods extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%activity_wechat_room_goods}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
- public function rules()
- {
- return [
- [['id', 'goods_id', 'store_id', 'is_delete', 'activity_id', 'use_attr'], 'integer'],
- [['attr'], 'string'],
- [['price'], 'number'],
- [['created_at', 'updated_at'], 'safe']
- ];
- }
- public static function saveList($list = [], $activity_id = 0) {
- if($activity_id){
- //删除
- $oldList = self::find()->where(['activity_id' => $activity_id, 'is_delete' => 0])->all();
- foreach($oldList as $item){
- $continue = 0;
- foreach($list as $i){
- if($item->id == $i['id']){
- $continue = 1;
- break;
- }
- }
- if($continue){
- continue;
- }
- $item->is_delete = 1;
- $item->save();
- }
- }
- //修改、新增
- foreach($list as $item){
- $id = $item['id'];
- $model = $id ? self::findOne($id) : new self();
- $model->attributes = $item;
- $save = $model->save();
- if(!$save){
- \Yii::error([__METHOD__, $model->attributes]);
- return [
- 'code' => 1,
- 'msg' => '商品信息保存失败:' . json_encode($model->getFirstErrors()),
- ];
- }
- }
- return [
- 'code' => 0,
- 'msg' => 'ok',
- ];
- }
- }
|