from_store_id; $to_store_id = $this->to_store_id; $cat_id = $this->cat_id; foreach ($to_store_id as $store_id_item) { //商品分类 $this->handleGoodsCat($from_store_id, $store_id_item, $cat_id); } } private function handleGoodsCat($from_store_id, $to_store_id, $cat_id) { $cats = Cat::find()->where([ 'store_id' => $from_store_id, 'id' => $cat_id, ])->asArray()->all(); foreach ($cats as $cat) { $catC = $cat; //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT, 'from_id' => $cat['id'] ]); $c = Cat::findOne($storeSyncExtLog->to_id ?? 0) ?: new Cat(); //判断是否为当前商城同步过此商品 $storeSyncExtLogCatParent = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT, 'from_id' => $cat['parent_id'] ]); unset($catC['id']); $catC['store_id'] = $to_store_id; $c->setAttributes($catC, false); $c->parent_id = $storeSyncExtLogCatParent->to_id ?? 0; $c->save(); (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $cat['id'], $c->id, StoreSyncExtLog::TYPE_PRODUCT_CAT); } } }