goods_id; $status = $this->status; // 是否删除 $goods = Goods::findOne(['id' => $goods_id, 'md_food_id' => 0]); if ($goods) { if ($status) { GoodsCat::updateAll(['is_delete' => 1], ['old_goods_id' => $goods_id]); } else { $md_list = Md::find()->where(['store_id' => $goods->store_id, 'is_delete' => 0, 'is_single' => 1]) ->select('id')->asArray()->all(); foreach ($md_list as $item) { $goods_ = Goods::findOne(['md_food_id' => $item['id'], 'is_delete' => 0, 'old_goods_id' => $goods_id]); $status_ = $goods->status; if ($goods_) { $status_ = $goods_->status; } $goods_ = $goods_ ?? new Goods(); $goods_->attributes = $goods; $goods_->old_goods_id = $goods_id; $goods_->status = $status_; if ($goods_->save()) { //同步分类 $goods_cat = GoodsCat::find()->where(['goods_id' => $goods_id, 'is_delete' => 0])->asArray()->all(); GoodsCat::updateAll(['is_delete' => 1], ['goods_id' => $goods_->id, 'is_delete' => 0]); foreach ($goods_cat as $cat) { $goods_cat_ = new GoodsCat(); $goods_cat_->attributes = $cat; $goods_cat_->goods_id = $goods_->id; $goods_cat_->save(); } //同步满减 $goods_full_minus = GoodsFullMinus::find()->where(['goods_id' => $goods_id, 'is_delete' => 0])->asArray()->all(); GoodsFullMinus::updateAll(['is_delete' => 1], ['goods_id' => $goods_->id, 'is_delete' => 0]); foreach ($goods_full_minus as $cat) { $goods_full_minus_ = new GoodsFullMinus(); $goods_full_minus_->attributes = $cat; $goods_full_minus_->goods_id = $goods_->id; $goods_full_minus_->save(); } //同步商品图片 $goods_pic = GoodsPic::find()->where(['goods_id' => $goods_id, 'is_delete' => 0])->asArray()->all(); GoodsPic::updateAll(['is_delete' => 1], ['goods_id' => $goods_->id, 'is_delete' => 0]); foreach ($goods_pic as $cat) { $goods_pic_ = new GoodsPic(); $goods_pic_->attributes = $cat; $goods_pic_->goods_id = $goods_->id; $goods_pic_->save(); } } } } } } catch (\Exception $e) { debug_log('门店同步商品处理:' . $e->getMessage() . $e->getLine() . $e->getFile(),'md_goods.log'); } } }