to_store_id; $from_store_id = $this->from_store_id; $delivery_rules_id = $this->delivery_rules_id; $postageRulesArr = PostageRules::find()->where(['id' => $delivery_rules_id])->all(); if ($postageRulesArr) { foreach ($to_store_id as $store_id_item) { $this->handle($from_store_id, $store_id_item, $postageRulesArr); } } } private function handle($from_store_id, $to_store_id, $postageRulesArr) { foreach ($postageRulesArr as $postageRules) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_POSTAGE_RULES, 'from_id' => $postageRules->id ]); if (intval($postageRules->is_enable)) { PostageRules::updateAll(['is_enable' => 0], ['is_delete' => 0, 'store_id' => $to_store_id]); } $toPostageRules = PostageRules::findOne($storeSyncExtLog->to_id ?? 0) ?: new PostageRules(); $toPostageRules->attributes = $postageRules->attributes; $toPostageRules->store_id = $to_store_id; $toPostageRules->mch_id = 0; if ($toPostageRules->save()) { (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $postageRules->id, $toPostageRules->id, StoreSyncExtLog::TYPE_POSTAGE_RULES); } } } }