from_store_id; $to_store_id = $this->to_store_id; foreach ($to_store_id as $store_id_item) { $result = $this->articleSetting($from_store_id, $store_id_item); } } /** 同步文章start **/ private function articleSetting($fromStoreId, $toId) { try { $article_list = AboutArticle::find()->where(['store_id' => $fromStoreId])->andWhere(['<>', 'type', 1])->asArray()->all(); foreach ($article_list as $article_item) { $id = $article_item['id']; unset($article_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_ARTICLE, 'from_id' => $id ]); $aboutArticle = AboutArticle::findOne($storeSyncExtLog->to_id ?? 0) ?: new AboutArticle(); $aboutArticle->attributes = $article_item; $aboutArticle->store_id = $toId; $aboutArticle->type = $article_item['type']; $aboutArticle->is_delete = $article_item['is_delete']; if (!$aboutArticle->save()) { throw new \Exception(json_encode($aboutArticle->errors, JSON_UNESCAPED_UNICODE)); }; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $aboutArticle->id, StoreSyncExtLog::TYPE_ARTICLE); } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步文章end **/ }