$this->id, 'type' => $this->type, 'to_id' => $this->to_id], 'queuePush.log'); $type = $this->type; $t = \Yii::$app->db->beginTransaction(); if (isset($type)) { $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value']; if(!$default) { return; } $default = json_decode($default, true); if (empty($default)) { return; } $fromStoreId = $default['store_id']; $imports = $default['type']; $toStoreIds = [$this->to_id]; } else { $item = StoreSyncLog::findOne($this->id); $syncItem = StoreSync::findOne($item->sync_id); $fromStoreId = $item->from_store_id; $toStoreIds = \json_decode($item->to_store_ids, true); $imports = json_decode($syncItem->imports, true); } debug_log(['from' => $fromStoreId, 'to_store_' => $toStoreIds, 'imports' => $imports], 'queuePush.log'); if (in_array('product', $imports) && !in_array('product_cat', $imports)) { array_push($imports, 'product_cat'); } foreach ($toStoreIds as $toId) { //配送规则 if (in_array('delivery_rules', $imports)) { list($deliveryRulesCache) = $this->syncDeliveryRules($fromStoreId, $toId); } // if (in_array('product_cat', $imports)) { // $cacheCat = $this->doGoodsCat($fromStoreId, $toId); // } if (in_array('product', $imports) && in_array('delivery_rules', $imports) && in_array('product_cat', $imports)) { //商品 分类 list($goodsCache, $cacheCat) = $this->syncGoods($fromStoreId, $toId, $deliveryRulesCache, $message); // if (!empty($message)) { // throw new \Exception($message); // } $cacheCat_ = $cacheCat; if (isset($item)) { $item->goods_info = json_encode(['goods_result' => $goodsCache, 'cat_result' => $cacheCat]); } //拼团 $ptCacheActivity = $ptCacheCat = $ptCache = []; if (in_array('pintuan', $imports)) { [$ptCacheActivity, $ptCacheBanner, $ptCacheCat, $ptCache, $ptCacheSetting] = $this->syncGroup($fromStoreId, $toId, $goodsCache); if (isset($item)) { $item->pintuan = json_encode(['cacheActivity' => $ptCacheActivity, 'cacheBanner' => $ptCacheBanner, 'cacheCat' => $ptCacheCat, 'cache' => $ptCache, 'cacheSetting' => $ptCacheSetting], JSON_UNESCAPED_UNICODE); } } //砍价 $cutPriceCacheActivity = $cutPriceCacheCat = $cutPriceCache = []; if (in_array('activityCutPrice', $imports)) { [$cutPriceCacheActivity, $cutPriceCacheBanner, $cutPriceCacheCat, $cutPriceCache] = $this->syncBargain($fromStoreId, $toId, $goodsCache); if (isset($item)) { $item->bargain = json_encode(['cacheActivity' => $cutPriceCacheActivity, 'cacheBanner' => $cutPriceCacheBanner, 'cacheCat' => $cutPriceCacheCat, 'cache' => $cutPriceCache], JSON_UNESCAPED_UNICODE); } } //秒杀 $seckillCacheActivity = $seckillCache = []; if (in_array('seckill', $imports)) { [$seckillCacheActivity, $seckillCache] = $this->seckill($fromStoreId, $toId, $goodsCache); if (isset($item)) { $item->seckill = json_encode(['cacheActivity' => $seckillCacheActivity, 'cache' => $seckillCache], JSON_UNESCAPED_UNICODE); } } //分销设置 if (in_array('shareConfig', $imports)) { [$result, $levelResult] = $this->shareConfig($fromStoreId, $toId, $goodsCache); if (isset($item)) { $item->shareConfig = json_encode(['config_result' => $result, 'level_result' => $levelResult], JSON_UNESCAPED_UNICODE); } } //股东设置 if (in_array('shareHolderConfig', $imports)) { [$result, $levelResult] = $this->shareHolderConfig($fromStoreId, $toId, $goodsCache); if (isset($item)) { $item->shareHolderConfig = json_encode(['config_result' => $result, 'level_result' => $levelResult], JSON_UNESCAPED_UNICODE); } } //短视频 if (in_array('videoGoods', $imports)) { [$goods_result, $goods_cat_result, $goods_setting_result, $goods_list_result] = $this->videoGoods($fromStoreId, $toId, $goodsCache); if (isset($item)) { $item->videoGoods = json_encode(['goods_result' => $goods_result, 'goods_cat_result' => $goods_cat_result, 'goods_setting_result' => $goods_setting_result, 'goods_list_result' => $goods_list_result], JSON_UNESCAPED_UNICODE); } } //积分商城 if (in_array('integralStore', $imports)) { [$goods_cat_result, $setting_result] = $this->integralStore($fromStoreId, $toId); if (isset($item)) { $item->integralStore = json_encode(['goods_cat_result' => $goods_cat_result, 'setting_result' => $setting_result], JSON_UNESCAPED_UNICODE); } } //上门服务 $worker_goods_cat_result = $worker_goods_result = $worker_cat_result = []; if (in_array('workerConfig', $imports)) { [$worker_goods_cat_result, $worker_goods_result, $worker_cat_result, $worker_level_result, $worker_setting] = $this->workerConfig($fromStoreId, $toId, $goodsCache); if (isset($item)) { $item->workerConfig = json_encode(['cat_result' => $worker_goods_cat_result, 'goods_result' => $worker_goods_result, 'worker_cat_result' => $worker_cat_result, 'worker_level_result' => $worker_level_result, 'worker_setting' => $worker_setting], JSON_UNESCAPED_UNICODE); } } //预约 $booking_goods_cat_cache = []; if (in_array('bookingGoods', $imports)) { [$booking_goods_cat_cache, $ext_result] = $this->bookingHome($fromStoreId, $toId, $goodsCache); } //装修 if (in_array('diy', $imports)) { $result = $this->syncDiy($fromStoreId, $toId, $goodsCache, $cacheCat_, [ 'ptCacheActivity' => $ptCacheActivity, 'ptCacheCat' => $ptCacheCat, 'ptCache' => $ptCache, 'cutPriceCacheActivity' => $cutPriceCacheActivity, 'cutPriceCacheCat' => $cutPriceCacheCat, 'cutPriceCache' => $cutPriceCache, 'seckillCacheActivity' => $seckillCacheActivity, 'seckillCache' => $seckillCache, 'worker_goods_cat_result' => $worker_goods_cat_result, 'worker_goods_result' => $worker_goods_result, 'worker_cat_result' => $worker_cat_result, 'booking_goods_cat_cache' => $booking_goods_cat_cache ]); if (isset($item)) { $item->diy = json_encode(['diy' => $result], JSON_UNESCAPED_UNICODE); } } } if (in_array('article', $imports)) { $result = $this->articleSetting($fromStoreId, $toId); if (isset($item)) { $item->article = json_encode(['result' => $result], JSON_UNESCAPED_UNICODE); } } if (in_array('topic', $imports)) { [$type_result, $result] = $this->topicSetting($fromStoreId, $toId); if (isset($item)) { $item->topic = json_encode(['type_result' => $type_result, 'result' => $result], JSON_UNESCAPED_UNICODE); } } } if (isset($item)) { $item->status = 1; $item->result = 1; $item->save(); } // $syncItem->status = 0; // $syncItem->save(); $t->commit(); } catch (\Throwable $e) { $logName = 'store_sync.log'; debug_log('任务ID => ' . $this->id, $logName); debug_log('异常消息 => ' . $e->getMessage(), $logName); debug_log('异常文件 => ' . $e->getFile(), $logName); debug_log('异常行数 => ' . $e->getLine(), $logName); debug_log($e->getTraceAsString(), $logName); debug_log('++++++++++++++++++++++++++++', $logName); $t->rollBack(); $item->status = 1; $item->result = 2; $item->save(); // $syncItem->status = 0; // $syncItem->save(); } } /** * 同步商城配送规则 */ private function syncDeliveryRules($from_store_id, $to_store_id) { //删除原来的配送规则 debug_log('开始同步', 'queuePush.log'); PostageRules::deleteAll(['store_id' => $to_store_id]); $PostageRulesList = PostageRules::find()->where([ 'store_id' => $from_store_id, 'is_delete' => 0, 'mch_id' => 0 ])->asArray()->all(); $rules_id_cache = []; foreach ($PostageRulesList as $item) { //判断是否为当前商城同步过此规则 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_POSTAGE_RULES, 'from_id' => $item['id'] ]); $rules_id_cache[$item['id']] = 0; $postageRules = PostageRules::findOne($storeSyncExtLog->to_id ?? 0) ?: new PostageRules(); $postageRules->attributes = $item; $postageRules->store_id = $to_store_id; $postageRules->mch_id = 0; if (!$postageRules->save()) { continue; } $rules_id_cache[$item['id']] = $postageRules->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $item['id'], $postageRules->id, StoreSyncExtLog::TYPE_POSTAGE_RULES); } debug_log($rules_id_cache, 'queuePush.log'); return $rules_id_cache; } /** 同步商品 start */ // 同步商品 private function syncGoods($from_store_id, $to_store_id, $deliveryRulesCache, &$message) { $goods_ids = Goods::find()->where(['store_id' => $to_store_id, 'is_delete' => 0, 'mch_id' => 0])->select('id')->column(); $message = null; $cloud_store_token = get_merchant_token(0, $to_store_id, $message); $cloud_goods_id = []; foreach ($goods_ids as $param) { $goods = Goods::findOne($param); if ($goods->cloud_goods_id && !intval($goods->is_wholesale)) { if (!$cloud_store_token) { $message = $message['msg']; return []; } $cloud_goods_id[] = $goods->cloud_goods_id; } } if ($cloud_goods_id) { $mch_set_submit_order_url = "/cloud/mch/delTransGoods"; $mch_set_submit_order_data = []; $mch_set_submit_order_data['access_token'] = $cloud_store_token; //获取供货商的token信息 $mch_set_submit_order_data['goods_id'] = implode(',', $cloud_goods_id); $domain = (new OptionSetting)->getCloudDomainName(); $mchSetSubmitOrderInfo = cloud_post( $domain . $mch_set_submit_order_url, $mch_set_submit_order_data); $mchSetSubmitOrderInfo = json_decode($mchSetSubmitOrderInfo,true); if($mchSetSubmitOrderInfo['code'] != 0){ $message = '删除转单商品' . $mchSetSubmitOrderInfo['msg']; return []; } else { CloudGoodsBind::updateAll(['is_delete' => 1], ['store_id' => $to_store_id, 'cloud_goods_id' => $cloud_goods_id, 'is_delete' => 0]); } } // 软删除商品 Goods::deleteAll(['store_id' => $to_store_id, 'is_delete' => 0, 'mch_id' => 0]); // 软删除规格组和规格 $attrGroups = AttrGroup::find()->where(['store_id' => $to_store_id, 'is_delete' => 0])->all(); foreach ($attrGroups as $attrGroup) { Attr::deleteAll(['attr_group_id' => $attrGroup->id, 'is_delete' => 0]); $attrGroup->is_delete = 1; $attrGroup->save(); } AttrGroup::deleteAll(['store_id' => $to_store_id]); // 删除商品关联分类 GoodsCat::deleteAll(['store_id' => $to_store_id, 'is_delete' => 0]); // 删除云仓商品绑定 CloudGoodsBind::updateAll(['is_delete' => 1], ['store_id' => $to_store_id, 'is_delete' => 0]); // 商品分类处理 $cacheCat = $this->doGoodsCat($from_store_id, $to_store_id); // 商品规格处理 $goodsList = Goods::find()->where([ 'store_id' => $from_store_id, 'is_delete' => 0, 'mch_id' => 0 ])->andWhere(['<=', 'md_food_id', 0])->orderBy(['id' => SORT_ASC])->asArray()->all(); $goodsCache = []; $store_cloud_id = StoreCloud::findOne(['store_id' => $to_store_id, 'is_delete' => 0]); foreach ($goodsList as $goods) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT, 'from_id' => $goods['id'] ]); $goods_id_cache = $goods['id']; $g = Goods::findOne($storeSyncExtLog->to_id ?? 0) ?: new Goods(); if (!empty($goods['attr'])) { $attrs = \json_decode($goods['attr'], true); list($attrGroupCache, $attrCache) = $this->doGoodsAttr($from_store_id, $to_store_id, $attrs); foreach ($attrs as &$attr) { if ($attr['attr_list']) { foreach ($attr['attr_list'] as &$att) { if (isset($att['attr_id']) && isset($attrCache[$att['attr_id']])) { $att['attr_id'] = $attrCache[$att['attr_id']]; } } } } $goods['attr'] = \json_encode($attrs); } unset($goods['id']); $goods['store_id'] = $to_store_id; $g->setAttributes($goods, false); $g->cloud_goods_id = $goods['cloud_goods_id']; $g->is_wholesale = $goods['is_wholesale']; $g->cloud_supplier_id = $goods['cloud_supplier_id']; $g->delivery_rules_id = $deliveryRulesCache[$goods['delivery_rules_id']] ?? 0; $g->save(); (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $goods_id_cache, $g->id, StoreSyncExtLog::TYPE_PRODUCT); $goodsCache[$goods_id_cache] = $g->id; if ($g->cloud_goods_id > 0 && !intval($g->is_wholesale)) { try { $form = new GoodsForm(); $form->id = $g->cloud_goods_id; $form->store_id = $to_store_id; $goodsInfo = $form->saveCloudGoods(); $merchantForm = new MerchantForm(); $merchantForm->token_stroe_cloud_id = $store_cloud_id ?? 0; $r = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'], $goodsInfo['goods_id'], $to_store_id); } catch (\Exception $e) { } } } // 商品分类处理 $goodsCats = GoodsCat::find()->where(['store_id' => $from_store_id, 'is_delete' => 0])->asArray()->all(); foreach ($goodsCats as $goodsCat) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_GOODS_CAT, 'from_id' => $goodsCat['id'] ]); if (isset($goodsCache[$goodsCat['goods_id']]) && isset($cacheCat[$goodsCat['cat_id']])) { $id = $goodsCat['id']; $cat = GoodsCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new GoodsCat(); $goodsCat['goods_id'] = $goodsCache[$goodsCat['goods_id']]; $goodsCat['cat_id'] = $cacheCat[$goodsCat['cat_id']]; $goodsCat['store_id'] = $to_store_id; unset($goodsCat['id']); $cat->setAttributes($goodsCat, false); $cat->save(); (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $cat->id, StoreSyncExtLog::TYPE_PRODUCT_GOODS_CAT); } } // 商品组图处理 $inGoodsIds = \array_keys($goodsCache); $goodsPic = GoodsPic::find()->where(['is_delete' => 0, 'goods_id' => $inGoodsIds])->asArray()->all(); foreach ($goodsPic as $pic) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_GOODS_PIC, 'from_id' => $pic['id'] ]); $newPic = GoodsPic::findOne($storeSyncExtLog->to_id ?? 0) ?: new GoodsPic(); $newPic->goods_id = $goodsCache[$pic['goods_id']]; $newPic->pic_url = $pic['pic_url']; $newPic->is_delete = 0; $newPic->save(); (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $pic['id'], $newPic->id, StoreSyncExtLog::TYPE_PRODUCT_GOODS_PIC); } // 云仓商品绑定 // $cloudGoodsBinds = CloudGoodsBind::find()->where(['is_delete' => 0, 'store_id' => $from_store_id, 'goods_id' => $inGoodsIds])->asArray()->all(); // foreach ($cloudGoodsBinds as $goodsBind) { // $cloudGoods = new CloudGoodsBind(); // $cloudGoods->cloud_goods_id = $goodsBind['cloud_goods_id']; // $cloudGoods->cloud_supplier_id = $goodsBind['cloud_supplier_id']; // $cloudGoods->store_id = $to_store_id; // $cloudGoods->goods_id = $goodsCache[$goodsBind['goods_id']]; // $cloudGoods->is_delete = 0; // $cloudGoods->created_at = time(); // $cloudGoods->save(); // } //重新选品 return [$goodsCache, $cacheCat]; } // 商品规格创建 private function doGoodsAttr($from_store_id, $to_store_id, $attrs = null) { $attr_id = []; if ($attrs) { $attrs = json_decode($attrs, true); foreach ($attrs as $attr_item) { $attr_id_item = array_column($attr_item['attr_list'], 'attr_id'); $attr_id = array_merge($attr_id, $attr_id_item); } } $attrGroupCache = $attrCache = []; if ($attr_id) { $attr_id = array_unique($attr_id); foreach ($attr_id as $attr_id_item) { $attrGroup = null; $old_attr = Attr::findOne($attr_id_item); if ($old_attr) { $old_attr_group = AttrGroup::findOne($old_attr->attr_group_id); //判断是否为当前商城同步过此商品 $storeSyncAttrGroupExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_ATTR_GROUP, 'from_id' => $old_attr_group->id ]); $attrGroup = AttrGroup::findOne($storeSyncAttrGroupExtLog->to_id ?? 0) ?: new AttrGroup(); $attrGroup->store_id = $to_store_id; $attrGroup->attr_group_name = $old_attr_group->attr_group_name; $attrGroup->is_delete = $old_attr_group->is_delete; $attrGroup->save(); $attrGroupCache[$old_attr_group->id] = $attrGroup->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $old_attr_group->id, $attrGroup->id, StoreSyncExtLog::TYPE_PRODUCT_ATTR_GROUP); } //判断是否为当前商城同步过此商品 $storeSyncAttrExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_ATTR, 'from_id' => $attr_id_item ]); $attr = Attr::findOne($storeSyncAttrExtLog->to_id ?? 0) ?: new Attr(); $attr->attr_group_id = $attrGroup->id ?? 0; $attr->attr_name = $old_attr->attr_name; $attr->is_delete = $old_attr->is_delete; $attr->is_default = 0; $attr->save(); $attrCache[$old_attr->id] = $attr->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $old_attr->id, $attr->id, StoreSyncExtLog::TYPE_PRODUCT_ATTR); } } return [$attrGroupCache, $attrCache]; } // 商品分类创建 private function doGoodsCat($from_store_id, $to_store_id) { Cat::deleteAll(['store_id' => $to_store_id, 'is_delete' => 0]); $cats = Cat::find()->where([ 'store_id' => $from_store_id, 'is_delete' => 0, 'parent_id' => 0, ])->asArray()->all(); $catCache = []; 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(); unset($catC['id']); $catC['store_id'] = $to_store_id; $c->setAttributes($catC, false); $c->save(); $catCache[$cat['id']] = $c->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $cat['id'], $c->id, StoreSyncExtLog::TYPE_PRODUCT_CAT); $cats1 = Cat::find()->where([ 'store_id' => $from_store_id, 'is_delete' => 0, 'parent_id' => $cat['id'], ])->asArray()->all(); foreach ($cats1 as $cat1) { $catC1 = $cat1; //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT, 'from_id' => $cat1['id'] ]); $c1 = Cat::findOne($storeSyncExtLog->to_id ?? 0) ?: new Cat(); unset($catC1['id']); $catC1['store_id'] = $to_store_id; $catC1['parent_id'] = $c->id; $c1->setAttributes($catC1, false); $c1->save(); $catCache[$cat1['id']] = $c1->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $cat1['id'], $c1->id, StoreSyncExtLog::TYPE_PRODUCT_CAT); $cats2 = Cat::find()->where([ 'store_id' => $from_store_id, 'is_delete' => 0, 'parent_id' => $cat1['id'], ])->asArray()->all(); foreach ($cats2 as $cat2) { $catC2 = $cat2; //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT, 'from_id' => $cat2['id'] ]); $c2 = Cat::findOne($storeSyncExtLog->to_id ?? 0) ?: new Cat(); unset($catC2['id']); $catC2['store_id'] = $to_store_id; $catC2['parent_id'] = $c1->id; $c2->setAttributes($catC2, false); $c2->save(); $catCache[$cat2['id']] = $c2->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $cat2['id'], $c2->id, StoreSyncExtLog::TYPE_PRODUCT_CAT); } } } return $catCache; } /** 同步商品 end */ /** 同步拼团 start */ // 同步拼团 private function syncGroup($from_store_id, $to_store_id, $cacheGoods) { $cacheActivity = $this->doCopyPt($from_store_id, $to_store_id); $cacheBanner = $this->doCopyPtBanner($from_store_id, $to_store_id); $cacheCat = $this->doCopyPtCat($from_store_id, $to_store_id); $cache = $this->doCopyPtGoods($from_store_id, $to_store_id, $cacheActivity, $cacheCat, $cacheGoods); $cacheSetting = $this->doCopyPtSetting($from_store_id, $to_store_id); return [$cacheActivity, $cacheBanner, $cacheCat, $cache, $cacheSetting]; } public function doCopyPtSetting($from_store_id, $to_store_id) { try { $article_ = AboutArticle::find()->where([ 'is_delete' => AboutArticle::IS_DELETE_NO, 'store_id' => $from_store_id, 'type' => 1 ])->select("desc")->asArray()->one(); if ($article_) { $article = AboutArticle::findOne(['is_delete' => AboutArticle::IS_DELETE_NO, 'store_id' => $to_store_id, 'type' => 1]); if (!$article) { $article = new AboutArticle(); } unset($article_['id']); $article->attributes = $article_; $article->store_id = $to_store_id; $article->name = $article_['name'] ?: ''; $article->created_at = time(); $article->updated_at = time(); $article->type = 1; if (!$article->save()) { throw new \Exception(json_encode($article->errors, JSON_UNESCAPED_UNICODE)); }; } return [ 'code' => 0, 'msg' => "同步成功" ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopyPt($from_store_id, $to_store_id) { try { PtActivity::deleteAll(['store_id' => $to_store_id]); $list = PtActivity::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; foreach ($list as $value) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PT, 'from_id' => $value['id'] ]); $id = $value['id']; $attr = $value->attributes; unset($attr['id']); $attr['store_id'] = $to_store_id; $attr['goods_ids'] = ''; $model = PtActivity::findOne($storeSyncExtLog->to_id ?? 0) ?: new PtActivity(); $model->setAttributes($attr, false); $model->save(); $cache[$id] = $model->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $value['id'], $model->id, StoreSyncExtLog::TYPE_PT); } return $cache; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopyPtBanner($from_store_id, $to_store_id) { try { PtActivityBanner::deleteAll(['store_id' => $to_store_id]); $list = PtActivityBanner::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; foreach ($list as $value) { $id = $value['id']; $attr = $value->attributes; unset($attr['id']); $attr['store_id'] = $to_store_id; $model = new PtActivityBanner(); $model->setAttributes($attr, false); $model->save(); $cache[$id] = $model->id; } return $cache; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopyPtCat($from_store_id, $to_store_id) { try { PtActivityGoodsCat::deleteAll(['store_id' => $to_store_id]); $list = PtActivityGoodsCat::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; foreach ($list as $value) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PT_GOODS_CAT, 'from_id' => $value['id'] ]); $id = $value['id']; $attr = $value->attributes; unset($attr['id']); $attr['store_id'] = $to_store_id; $model = PtActivityGoodsCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new PtActivityGoodsCat(); $model->setAttributes($attr, false); $model->save(); $cache[$id] = $model->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $model->id, StoreSyncExtLog::TYPE_PT_GOODS_CAT); } return $cache; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopyPtGoods($from_store_id, $to_store_id, $cacheActivity, $cacheCat, $cacheGoods) { try { debug_log($cacheActivity,'store_sync.log'); $old_activity_id = array_keys($cacheActivity); $list = PtActivityGoods::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, 'activity_id' => $old_activity_id ])->orderBy(['id' => SORT_ASC])->all(); PtActivityGoods::deleteAll(['store_id' => $to_store_id]); $cache = []; foreach ($list as $value) { $id = $value['id']; $attr = $value->attributes; if (!$cacheGoods[$attr['goods_id']]) { continue; } unset($attr['id']); $attr['store_id'] = $to_store_id; $attr['activity_id'] = $cacheActivity[$attr['activity_id']]; $cat = PtActivityGoodsCat::findOne(['id' => $attr['cat_id'], 'is_delete' => 0]); if (!$cat) { continue; } $attr['cat_id'] = $cacheCat[$attr['cat_id']]; $goods = Goods::findOne(['id' => $attr['goods_id'], 'is_delete' => 0, 'mch_id' => 0]); if (!$goods) { continue; } $attr['goods_id'] = $cacheGoods[$attr['goods_id']]; $agattr = json_decode($value['attr'], true); $goodsNew = Goods::findOne($attr['goods_id']); $gattrNew = json_decode($goodsNew->attr, true); $agattrNew = []; foreach($agattr as $k => $item){ $attrNames = array_column($item['attr_list'], 'attr_name'); // var_dump($attrNames); foreach($gattrNew as $v){ $attrNamesNew = array_column($v['attr_list'], 'attr_name'); // var_dump($attrNamesNew); if($attrNames === $attrNamesNew){ // var_dump('$attrNames == $attrNamesNew'); $item['attr_list'] = $v['attr_list']; } } $agattrNew[] = $item; } $attr['attr'] = json_encode($agattrNew, JSON_UNESCAPED_UNICODE); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PT_GOODS, 'from_id' => $value['id'] ]); $model = PtActivityGoods::findOne($storeSyncExtLog->to_id ?? 0) ?: new PtActivityGoods(); $model->setAttributes($attr, false); $model->save(); (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $value['id'], $model->id, StoreSyncExtLog::TYPE_PT_GOODS); $cache[$id] = $model->id; } return $cache; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步拼团 end */ /** 同步砍价 start */ // 同步砍价 private function syncBargain($from_store_id, $to_store_id, $cacheGoods) { $cacheActivity = $this->doCopyCutPrice($from_store_id, $to_store_id); $cacheBanner = $this->doCopyCutPriceBanner($from_store_id, $to_store_id); $cacheCat = $this->doCopyCutPriceCat($from_store_id, $to_store_id); $cache = $this->doCopyCutPriceGoods($from_store_id, $to_store_id, $cacheActivity, $cacheCat, $cacheGoods); return [$cacheActivity, $cacheBanner, $cacheCat, $cache]; } public function doCopyCutPrice($from_store_id, $to_store_id) { try { ActivityCutPrice::deleteAll(['store_id' => $to_store_id]); $list = ActivityCutPrice::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; foreach ($list as $value) { $id = $value['id']; $attr = $value->attributes; unset($attr['id']); $attr['store_id'] = $to_store_id; //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_ACTIVITY_CUT_PRICE, 'from_id' => $value['id'] ]); unset($attr['id']); $attr['store_id'] = $to_store_id; $attr['goods_ids'] = ''; $model = ActivityCutPrice::findOne($storeSyncExtLog->to_id ?? 0) ?: new ActivityCutPrice(); $model->setAttributes($attr, false); $model->save(); $cache[$id] = $model->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $model->id, StoreSyncExtLog::TYPE_ACTIVITY_CUT_PRICE); } return $cache; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopyCutPriceBanner($from_store_id, $to_store_id) { try { ActivityCutPriceBanner::deleteAll(['store_id' => $to_store_id]); $list = ActivityCutPriceBanner::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; foreach ($list as $value) { $id = $value['id']; $attr = $value->attributes; unset($attr['id']); $attr['store_id'] = $to_store_id; $model = new ActivityCutPriceBanner(); $model->setAttributes($attr, false); $model->save(); $cache[$id] = $model->id; } return $cache; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopyCutPriceCat($from_store_id, $to_store_id) { try { ActivityCutPriceCat::deleteAll(['store_id' => $to_store_id]); $list = ActivityCutPriceCat::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; foreach ($list as $value) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_ACTIVITY_CUT_PRICE_CAT, 'from_id' => $value['id'] ]); $id = $value['id']; $attr = $value->attributes; unset($attr['id']); $attr['store_id'] = $to_store_id; $model = ActivityCutPriceCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new ActivityCutPriceCat(); $model->setAttributes($attr, false); $model->save(); $cache[$id] = $model->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $model->id, StoreSyncExtLog::TYPE_ACTIVITY_CUT_PRICE_CAT); } return $cache; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopyCutPriceGoods($from_store_id, $to_store_id, $cacheActivity, $cacheCat, $cacheGoods) { try { $list = ActivityCutPriceGoods::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $goods = []; $cache = []; foreach ($list as $value) { $id = $value['id']; $attr = $value->attributes; unset($attr['id']); $attr['store_id'] = $to_store_id; $attr['activity_id'] = $cacheActivity[$attr['activity_id']]; $cat = Cat::findOne(['id' => $attr['cat_id'], 'is_delete' => 0]); if (!$cat) { continue; } $attr['cat_id'] = $cacheCat[$attr['cat_id']]; $goods = Goods::findOne(['id' => $attr['goods_id'], 'is_delete' => 0, 'mch_id' => 0]); if (!$goods) { continue; } $attr['goods_id'] = $cacheGoods[$attr['goods_id']]; $agattr = json_decode($value['attr'], true); $goodsNew = Goods::findOne($attr['goods_id']); $gattrNew = json_decode($goodsNew['attr'], true); $agattrNew = []; if ($agattr) { foreach($agattr as $k => $item){ $attrNames = array_column($item['attr_list'], 'attr_name'); // var_dump($attrNames); if ($gattrNew) { foreach($gattrNew as $v){ $attrNamesNew = array_column($v['attr_list'], 'attr_name'); // var_dump($attrNamesNew); if($attrNames === $attrNamesNew){ // var_dump('$attrNames == $attrNamesNew'); $item['attr_list'] = $v['attr_list']; } } } $agattrNew[] = $item; } } $attr['attr'] = json_encode($agattrNew, JSON_UNESCAPED_UNICODE); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_ACTIVITY_CUT_PRICE_GOODS, 'from_id' => $value['id'] ]); $model = ActivityCutPriceGoods::findOne($storeSyncExtLog->to_id ?? 0) ?: new ActivityCutPriceGoods(); $model->setAttributes($attr, false); $model->save(); $goods[$attr['activity_id']] = $goods[$attr['activity_id']] ?? []; array_push($goods[$attr['activity_id']], $attr['goods_id']); $cache[$id] = $model->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $model->id, StoreSyncExtLog::TYPE_ACTIVITY_CUT_PRICE_GOODS); } foreach($goods as $aid => $gids){ $ac = ActivityCutPrice::findOne($aid); $ac->goods_ids = implode(',', $gids); $ac->save(); } return $cache; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步砍价 end */ /** 同步DIY start */ // 同步DIY private function syncDiy($from_store_id, $to_store_id, $goodsCache, $cacheCat, $activity_cache) { try { // 首页 // Todo 同步其他页面 return $this->copyHome($from_store_id, $to_store_id, $goodsCache, $cacheCat, $activity_cache); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } // 处理DIY首页 private function copyHome($from_store_id, $to_store_id, $goodsCache, $cacheCat, $activity_cache) { try { // 取消原来的首页信息 // $oldIndex = NewDiyTemplate::findOne([ // 'is_delete' => 0, // 'is_index' => 1, // 'store_id' => $to_store_id, // 'name' => 'DIY', // ]); // if ($oldIndex) { // $oldIndex->is_index = 0; // $oldIndex->save(); // } // $fromIndex = NewDiyTemplate::findOne([ // 'is_delete' => 0, // 'is_index' => 1, // 'store_id' => $from_store_id, // 'name' => 'DIY', // ]); //20240509要同步其他diy页面 $fromList = NewDiyTemplate::find()->where([ 'is_delete' => 0, 'store_id' => $from_store_id, 'name' => ['DIY', 'system'], 'is_index' => 0 ])->all(); // if (!$fromList) { //// return; // } $diyCache = []; if ($fromList) { NewDiyTemplate::deleteAll([ 'is_delete' => 0, 'store_id' => $to_store_id, 'name' => ['DIY', 'system'], 'is_index' => 0 ]); foreach ($fromList as $fromIndex) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_DIY, 'from_id' => $fromIndex->id ]); $template = \json_decode($fromIndex->template, true); if (!$template) { return; } foreach ($template['templates'] as &$item) { $item = $this->diyHandleCommon($item, $goodsCache, $cacheCat, [], $activity_cache); } $toIndex = NewDiyTemplate::findOne($storeSyncExtLog->to_id ?? 0) ?: new NewDiyTemplate(); $toIndex->store_id = $to_store_id; $toIndex->template = json_encode($template, JSON_UNESCAPED_UNICODE); $toIndex->addtime = time(); $toIndex->name = $fromIndex->name; $toIndex->is_index = $fromIndex->is_index; $toIndex->type = $fromIndex->type; $toIndex->is_delete = $fromIndex->is_delete; if (!$toIndex->save()) { throw new \Exception(json_encode($toIndex->errors, JSON_UNESCAPED_UNICODE)); } $diyCache[$fromIndex->id] = $toIndex->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $fromIndex->id, $toIndex->id, StoreSyncExtLog::TYPE_DIY); } } $fromIndex_ = NewDiyTemplate::findOne([ 'is_delete' => 0, 'is_index' => 1, 'store_id' => $from_store_id, 'name' => 'DIY', ]); $template = \json_decode($fromIndex_->template, true); if ($template) { NewDiyTemplate::deleteAll([ 'is_delete' => 0, 'is_index' => 1, 'store_id' => $to_store_id, 'name' => 'DIY', ]); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_DIY, 'from_id' => $fromIndex_->id ]); foreach ($template['templates'] as &$index_item) { $index_item = $this->diyHandleCommon($index_item, $goodsCache, $cacheCat, $diyCache, $activity_cache); } $toIndex = NewDiyTemplate::findOne($storeSyncExtLog->to_id ?? 0) ?: new NewDiyTemplate(); $toIndex->store_id = $to_store_id; $toIndex->template = json_encode($template, JSON_UNESCAPED_UNICODE); $toIndex->addtime = time(); $toIndex->name = $fromIndex_->name; $toIndex->is_index = $fromIndex_->is_index; $toIndex->type = $fromIndex_->type; $toIndex->is_delete = $fromIndex->is_delete; if (!$toIndex->save()) { throw new \Exception(json_encode($toIndex->errors, JSON_UNESCAPED_UNICODE)); } $diyCache[$fromIndex_->id] = $toIndex->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $fromIndex_->id, $toIndex->id, StoreSyncExtLog::TYPE_DIY); } $controls = NewDiyTemplate::findOne([ 'store_id' => $from_store_id, 'is_delete' => 0, 'name' => 'controls' ]); $template = \json_decode($controls->template, true); if ($template) { NewDiyTemplate::deleteAll([ 'is_delete' => 0, 'name' => 'controls', 'store_id' => $to_store_id, ]); $data = $template; foreach ($data as &$data_item) { if (!empty($data_item['params']['navList'])) { foreach ($data_item['params']['navList'] as &$item) { $item = $this->replaceLink($item, $goodsCache, $cacheCat, $diyCache); } debug_log($data_item['params']['navList'], 'controls.log'); } } //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_DIY, 'from_id' => $controls->id ]); $toControls = NewDiyTemplate::findOne($storeSyncExtLog->to_id ?? 0) ?: new NewDiyTemplate(); $toControls->store_id = $to_store_id; $toControls->template = json_encode($data, JSON_UNESCAPED_UNICODE); $toControls->addtime = time(); $toControls->name = $controls->name; $toControls->is_index = $controls->is_index; $toControls->type = $controls->type; $toControls->is_delete = $fromIndex->is_delete; if (!$toControls->save()) { throw new \Exception(json_encode($toControls->errors, JSON_UNESCAPED_UNICODE)); } (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $controls->id, $toControls->id, StoreSyncExtLog::TYPE_DIY); } return [ 'code' => 0, 'msg' => '执行成功', 'data' => $diyCache ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() . $e->getLine() ]; } } //处理装修公用部分 public function diyHandleCommon($template, $goodsCache, $cacheCat, $diyCache = [], $activity_cache = []) { // 头部导航 if ($template['type'] == 'fastNav') { $template = $this->replaceFastNav($template, $goodsCache, $cacheCat); } // 图片轮播 if ($template['type'] == 'banner') { debug_log('1处理装修公用部分','store_sync.log'); $template = $this->replaceBanner($template, $goodsCache, $cacheCat, $diyCache); } // 魔方导航 if ($template['type'] == 'cubeNav') { debug_log('2处理装修公用部分','store_sync.log'); $template = $this->replaceCubeNav($template, $goodsCache, $cacheCat, $diyCache); } // 魔方图片 if ($template['type'] == 'container') { debug_log('3处理装修公用部分','store_sync.log'); $template = $this->replaceContainer($template, $goodsCache, $cacheCat, $diyCache); } // 产品展示 if ($template['type'] == 'productShow') { debug_log('4处理装修公用部分','store_sync.log'); $template = $this->replaceProductShow($template, $goodsCache, $cacheCat, $diyCache); } //产品分类 if ($template['type'] == 'productClassify') { debug_log('5处理装修公用部分','store_sync.log'); $template = $this->replaceProductClassify($template, $goodsCache, $cacheCat, $diyCache); } // 倒计时 if ($template['type'] == 'marketCountDown') { $template = $this->replaceMarketCountDown($template, $goodsCache, $cacheCat, $diyCache); } //图片 if ($template['type'] == 'images') { $template = $this->replaceImages($template, $goodsCache, $cacheCat, $diyCache); } // 首页推荐 if ($template['type'] == 'indexRecommend') { // Todo 该模块数据有误,后期解决 $template = $this->replaceIndexRecommend($template, $goodsCache, $cacheCat, $diyCache); debug_log($template, '20250328.log'); } //秒杀 if ($template['type'] == 'productSeckill') { $template = $this->replaceProductSeckill($template, $activity_cache['seckillCacheActivity'], $activity_cache['seckillCache'], $diyCache); } //上门服务 if ($template['type'] == 'serviceHome') { $template = $this->replaceServiceHome($template, $activity_cache['worker_goods_cat_result'], $activity_cache['worker_goods_result'], $activity_cache['worker_cat_result'], $goodsCache, $diyCache); } //拼团 if ($template['type'] == 'ptProductShow') { $template = $this->replacePtProductShow($template, $activity_cache['ptCacheActivity'], $activity_cache['ptCacheCat'], $activity_cache['ptCache'], $goodsCache, $diyCache); } //预约 if ($template['type'] == 'bookingHome') { $template = $this->replaceBookingHome($template, $goodsCache, $activity_cache['booking_goods_cat_cache'], $diyCache); } return $template; } // 替换头部导航 private function replaceFastNav($data, $goodsCache, $cacheCat) { if (!empty($data['params']['list'])) { foreach ($data['params']['list'] as &$item) { $item = $this->replaceLink($item, $goodsCache, $cacheCat); } } return $data; } // 替换图片轮播 private function replaceBanner($data, $goodsCache, $cacheCat, $diyCache) { if (!empty($data['params']['bannerList'])) { foreach ($data['params']['bannerList'] as &$item) { $item = $this->replaceLink($item, $goodsCache, $cacheCat, $diyCache); } } return $data; } // 替换魔方导航 private function replaceCubeNav($data, $goodsCache, $cacheCat, $diyCache) { if (!empty($data['params']['list'])) { foreach ($data['params']['list'] as &$item) { $item = $this->replaceLink($item, $goodsCache, $cacheCat, $diyCache); } } return $data; } // 替换魔方图片 private function replaceContainer($data, $goodsCache, $cacheCat, $diyCache) { debug_log('——替换魔方图片','store_sync.log'); if (!empty($data['params']['cubeCoverList'])) { debug_log('替换魔方图片——','store_sync.log'); foreach ($data['params']['cubeCoverList'] as &$item) { $item = $this->replaceLink($item, $goodsCache, $cacheCat, $diyCache); } } return $data; } // 替换产品展示 private function replaceProductShow($data, $goodsCache, $cacheCat, $diyCache) { // 替换分类id if (isset($data['params']['classifyData']) && isset($cacheCat[$data['params']['classifyData']])) { $data['params']['classifyData'] = $cacheCat[$data['params']['classifyData']]; } // 替换分类商品id if (isset($data['params']['classifyArr'])) { foreach ($data['params']['classifyArr'] as &$item) { if (isset($goodsCache[$item['id']])) { $item['id'] = $goodsCache[$item['id']]; } } } // 替换商品id if (isset($data['params']['selectData'])) { foreach ($data['params']['selectData'] as &$select_item) { if (isset($goodsCache[$select_item['id']])) { $select_item['id'] = $goodsCache[$select_item['id']]; } } } $data['params'] = $this->replaceLink($data['params'], $goodsCache, $cacheCat, $diyCache); return $data; } // 替换产品分类 private function replaceProductClassify($data, $goodsCache, $cacheCat, $diyCache) { if (!empty($data['params']['classifyList'])) { $data['params']['classifyList'] = (array)$data['params']['classifyList']; foreach ($data['params']['classifyList'] as &$item) { // 替换分类 if (!empty($item['classifyId']) && isset($cacheCat[$item['classifyId']])) { $item['id'] = $cacheCat[$item['classifyId']]; $item['classifyId'] = $cacheCat[$item['classifyId']]; } if (!empty($item['data'])) { // 替换商品id foreach ($item['data'] as &$value) { if (isset($goodsCache[$value['id']])) { $value['id'] = $goodsCache[$value['id']]; } } } } } return $data; } //秒杀 private function replaceProductSeckill($template, $seckillCacheActivity, $seckillCache, $diyCache) { if (!empty($template['params'])) { $template['params']['activeId'] = (string)$seckillCacheActivity[$template['params']['activeId']]; } return $template; } //上门服务 private function replaceServiceHome($template, $worker_goods_cat_result, $worker_goods_result, $worker_cat_result, $goodsCache, $diyCache) { if (!empty($template['params'])) { $template['params']['classifyData'] = $worker_goods_cat_result[$template['params']['classifyData']]; if (!empty($template['params']['classifyArr'])) { foreach ($template['params']['classifyArr'] as &$worker_goods_item) { $worker_goods_item['id'] = $goodsCache[$worker_goods_item['id']]; } } } return $template; } //拼团 private function replacePtProductShow($template, $ptCacheActivity, $ptCacheCat, $ptCache, $goodsCache, $diyCache) { if (!empty($template['params'])) { $template['params']['classifyData'] = $ptCacheCat[$template['params']['classifyData']]; if (!empty($template['params']['classifyArr'])) { foreach ($template['params']['classifyArr'] as &$pt_classify_goods_item) { $pt_classify_goods_item['id'] = $goodsCache[$pt_classify_goods_item['id']]; } } if (!empty($template['params']['selectData'])) { foreach ($template['params']['selectData'] as &$pt_goods_item) { $pt_goods_item['id'] = $goodsCache[$pt_goods_item['id']]; } } } return $template; } //砍价 private function replaceCutPrice($data, $cutPriceCacheActivity, $cutPriceCacheCat, $cutPriceCache, $goodsCache, $diyCache) { if (!empty($data['params']['classifyList'])) { foreach ((array)$data['params']['classifyList'] as &$item) { // 替换分类 if (!empty($item['classifyId']) && isset($cacheCat[$item['classifyId']])) { $item['id'] = $cacheCat[$item['classifyId']]; $item['classifyId'] = $cacheCat[$item['classifyId']]; } if (!empty($item['data'])) { // 替换商品id foreach ($item['data'] as &$value) { if (isset($goodsCache[$value['id']])) { $value['id'] = $goodsCache[$value['id']]; } } } } } return $data; } //装修预约商品 private function replaceBookingHome($template, $goodsCache, $booking_goods_cat_cache) { try { if (!empty($template['params'])) { $template['params']['classifyData'] = $booking_goods_cat_cache[$template['params']['classifyData']]; if (!empty($template['params']['selectData'])) { foreach ($template['params']['selectData'] as &$booking_goods_item) { $booking_goods_item['id'] = $goodsCache[$booking_goods_item['id']]; } } } return $template; } catch (\Exception $e) { return $template; } } // 替换倒计时 private function replaceMarketCountDown($data, $goodsCache, $cacheCat, $diyCache) { $data['params'] = $this->replaceLink($data['params'], $goodsCache, $cacheCat, $diyCache); return $data; } // 替换图片链接 private function replaceImages($data, $goodsCache, $cacheCat, $diyCache) { if (isset($data['params']['current'])) { $data['params']['current'] = $this->replaceLink($data['params']['current'], $goodsCache, $cacheCat, $diyCache); } else { if (isset($data['params'])) { $data['params'] = $this->replaceLink($data['params'], $goodsCache, $cacheCat, $diyCache); } } return $data; } //替换首页推荐 private function replaceIndexRecommend($template, $goodsCache, $cacheCat, $diyCache) { try { foreach ($template['params']['list'] as &$item) { foreach ($item['pics']['link'] as &$link_item) { if (!isset($link_item['link'])) { continue; } // 处理分类id if ( strpos($link_item['link'], '/pages/cat/cat?cat_id=') !== false && $link_item['params'][0]['value'] != '' && isset($cacheCat[$link_item['params'][0]['value']]) ) { $link_item['link'] = '/pages/cat/cat?cat_id=' . $cacheCat[$link_item['params'][0]['value']]; $link_item['params'][0]['value'] = $cacheCat[$cacheCat[$link_item['params'][0]['value']]]; } // 处理商品列表 if ( strpos($link_item['link'], '/other/list/list?cat_id=') !== false && $link_item['params'][0]['value'] != '' && isset($cacheCat[$link_item['params'][0]['value']]) ) { $link_item['link'] = '/other/list/list?cat_id=' . $cacheCat[$link_item['params'][0]['value']]; $link_item['params'][0]['value'] = $cacheCat[$link_item['params'][0]['value']]; } // 处理商品详情 if ( strpos($link_item['link'], '/goods/goods/goods?id=') !== false && $link_item['params'][0]['value'] != '' && isset($goodsCache[$link_item['params'][0]['value']]) ) { $link_item['link'] = '/goods/goods/goods?id=' . $goodsCache[$link_item['params'][0]['value']]; $link_item['params'][0]['value'] = $goodsCache[$link_item['params'][0]['value']]; } if ( strpos($link_item['link'], '/pages/diy/diy?id=') !== false && isset($diyCache[$link_item['id']]) ) { $link_item['link'] = '/pages/diy/diy?id=' . $diyCache[$link_item['id']]; $link_item['id'] = $diyCache[$link_item['id']]; } } } return $template; } catch (\Exception $e) { return $template; } } private function replaceLink($item, $goodsCache, $cacheCat, $diyCache = []) { debug_log('——开始替换','store_sync.log'); if (!isset($item['link']['link'])) { return $item; } debug_log('开始替换_','store_sync.log'); // 处理分类id if ( strpos($item['link']['link'], '/pages/cat/cat?cat_id=') !== false && $item['link']['params'][0]['value'] != '' && isset($cacheCat[$item['link']['params'][0]['value']]) ) { $item['link']['link'] = '/pages/cat/cat?cat_id=' . $cacheCat[$item['link']['params'][0]['value']]; $item['link']['params'][0]['value'] = $cacheCat[$item['link']['params'][0]['value']]; } // 处理商品列表 if (strpos($item['link']['link'], '/other/list/list?cat_id=') !== false) { debug_log('处理分类替换', 'store_sync.log'); debug_log(['cacheCat' => $cacheCat], 'store_sync.log'); debug_log(['item' => $item], 'store_sync.log'); } if ( strpos($item['link']['link'], '/other/list/list?cat_id=') !== false && $item['link']['params'][0]['value'] != '' && isset($cacheCat[$item['link']['params'][0]['value']]) ) { $item['link']['link'] = '/other/list/list?cat_id=' . $cacheCat[$item['link']['params'][0]['value']]; $item['link']['params'][0]['value'] = $cacheCat[$item['link']['params'][0]['value']]; } // 处理商品详情 if ( strpos($item['link']['link'], '/goods/goods/goods?id=') !== false && $item['link']['params'][0]['value'] != '' && isset($goodsCache[$item['link']['params'][0]['value']]) ) { $item['link']['link'] = '/goods/goods/goods?id=' . $goodsCache[$item['link']['params'][0]['value']]; $item['link']['params'][0]['value'] = $goodsCache[$item['link']['params'][0]['value']]; } debug_log('开始替换','store_sync.log'); if ( strpos($item['link']['link'], '/pages/diy/diy?id=') !== false && isset($diyCache[$item['link']['id']]) ) { $item['link']['link'] = '/pages/diy/diy?id=' . $diyCache[$item['link']['id']]; $item['link']['id'] = $diyCache[$item['link']['id']]; } debug_log($item,'store_sync.log'); debug_log('结束替换','store_sync.log'); return $item; } /** 同步DIY end */ /** 同步秒杀 start */ private function seckill($from_store_id, $to_store_id, $goodsCache) { //同步活动 $cacheActivity = $this->doCopySeckill($from_store_id, $to_store_id); //同步产品 $cache = $this->doCopySeckillGoods($from_store_id, $to_store_id, $cacheActivity, $goodsCache); return [$cacheActivity, $cache]; } public function doCopySeckill($from_store_id, $to_store_id) { try { SeckillActivity::deleteAll(['store_id' => $to_store_id]); $list = SeckillActivity::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; foreach ($list as $value) { $id = $value['id']; $attr = $value->attributes; //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_SECKILL, 'from_id' => $id ]); unset($attr['id']); $attr['store_id'] = $to_store_id; $model = SeckillActivity::findOne($storeSyncExtLog->to_id ?? 0) ?: new SeckillActivity(); $model->setAttributes($attr, false); $model->save(); (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $model->id, StoreSyncExtLog::TYPE_SECKILL); $cache[$id] = $model->id; } return $cache; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function doCopySeckillGoods($from_store_id, $to_store_id, $cacheActivity, $cacheGoods) { try { $old_activity_id = array_keys($cacheActivity); $list = SeckillActivityGoods::find() ->where([ 'store_id' => $from_store_id, 'is_delete' => 0, 'activity_id' => $old_activity_id ])->orderBy(['id' => SORT_ASC])->all(); $cache = []; SeckillActivityGoods::deleteAll(['store_id' => $to_store_id]); foreach ($list as $value) { $id = $value['id']; $attr = $value->attributes; if (!$cacheGoods[$attr['goods_id']]) { continue; } unset($attr['id']); $attr['store_id'] = $to_store_id; $attr['activity_id'] = $cacheActivity[$attr['activity_id']]; $attr['goods_id'] = $cacheGoods[$attr['goods_id']]; $attr['sale_num'] = 0; $agattr = json_decode($value['attr'], true); $goodsNew = Goods::findOne($attr['goods_id']); $gattrNew = json_decode($goodsNew['attr'], true); $agattrNew = []; foreach($agattr as $k => $item){ $attrNames = array_column($item['attr_list'], 'attr_name'); // var_dump($attrNames); if ($gattrNew) { foreach($gattrNew as $v){ $attrNamesNew = array_column($v['attr_list'], 'attr_name'); // var_dump($attrNamesNew); if($attrNames === $attrNamesNew){ // var_dump('$attrNames == $attrNamesNew'); $item['attr_list'] = $v['attr_list']; } } } $agattrNew[] = $item; } $attr['attr'] = json_encode($agattrNew, JSON_UNESCAPED_UNICODE); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_SECKILL_GOODS, 'from_id' => $id ]); $model = SeckillActivityGoods::findOne($storeSyncExtLog->to_id ?? 0) ?: new SeckillActivityGoods(); $model->setAttributes($attr, false); $model->save(); $cache[$id] = $model->id; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $model->id, StoreSyncExtLog::TYPE_SECKILL_GOODS); } return $cache; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步秒杀 end */ /** 同步分销start **/ private function shareConfig($from_store_id, $to_store_id, $goodsCache) { //同步配置 基础配置 佣金配置 推广海报 $result = $this->shareBasicConfig($from_store_id, $to_store_id); //同步等级 $levelResult = $this->shareLevel($from_store_id, $to_store_id); return [ $result, $levelResult ]; } //同步配置 基础配置 佣金配置 推广海报 private function shareBasicConfig($from_store_id, $to_store_id) { try { $share_basic_setting = Option::get('share_basic_setting', $from_store_id, OptionSetting::SHARE_GROUP_NAME)['value']; try { $share_basic_setting = json_decode($share_basic_setting, true); if (isset($share_basic_setting['share_goods_id']['value'])) { $ids = \explode(',', $share_basic_setting['share_goods_id']['value']); $arr = []; foreach ($ids as $id) { $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT, 'from_id' => $id, ]); if ($storeSyncExtLog) { $arr[] = $storeSyncExtLog->to_id; } } $share_basic_setting['share_goods_id']['value'] = \implode(',', $arr); } $share_basic_setting = json_encode($share_basic_setting, JSON_UNESCAPED_UNICODE); Option::set('share_basic_setting', $share_basic_setting, $to_store_id, OptionSetting::SHARE_GROUP_NAME); } catch (Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } $share_basic_setting = Option::get('share_money_setting', $from_store_id, OptionSetting::SHARE_GROUP_NAME)['value']; try { Option::set('share_money_setting', $share_basic_setting, $to_store_id, OptionSetting::SHARE_GROUP_NAME); } catch (Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } $qrcode = Qrcode::findOne(['store_id' => $from_store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_SHARE]); $qrcode_ = Qrcode::findOne(['store_id' => $to_store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_SHARE]); if (!$qrcode_) { $qrcode_ = new Qrcode(); } unset($qrcode['id']); $qrcode_->attributes = $qrcode->attributes; $qrcode_->store_id = $to_store_id; $qrcode_->created_at = time(); $qrcode_->updated_at = time(); if (!$qrcode_->save()) { return [ 'code' => 1, 'msg' => json_encode($qrcode_->errors, JSON_UNESCAPED_UNICODE) ]; } return [ 'code' => 0, 'msg' => '操作成功' ]; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //同步等级 private function shareLevel($from_store_id, $to_store_id) { try { $shareLevelList = ShareLevel::find()->where(['store_id' => $from_store_id, 'is_delete' => 0])->asArray()->all(); foreach ($shareLevelList as $item) { $share_level = ShareLevel::findOne(['store_id' => $to_store_id, 'is_delete' => 0, 'level' => $item['level']]); if (!$share_level) { $share_level = new ShareLevel(); } $id = $item['id']; unset($item['id']); $share_level->attributes = $item; $share_level->store_id = $to_store_id; if (!$share_level->save()) { return [ 'code' => 1, 'msg' => json_encode($share_level->errors, JSON_UNESCAPED_UNICODE) ]; }; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $share_level->id, StoreSyncExtLog::TYPE_SHARE_CONFIG); } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步分销end **/ /** 同步股东start **/ private function shareHolderConfig($from_store_id, $to_store_id, $goodsCache) { //页面设置 申请设置 $basic_result = $this->shareHolderBasicConfig($from_store_id, $to_store_id); //等级同步 $level_result = $this->shareHolderLevelConfig($from_store_id, $to_store_id, $goodsCache); return [$basic_result, $level_result]; } //页面设置 申请设置 private function shareHolderBasicConfig($from_store_id, $to_store_id) { try { Option::set('cycle', Option::get('cycle', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('is_open_share', Option::get('is_open_share', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('is_open_range', Option::get('is_open_range', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('team_num', Option::get('team_num', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('qrcode', Option::get('qrcode', $from_store_id, 'bonus_pool', '')['value'], $to_store_id, 'bonus_pool'); Option::set('range_name', Option::get('range_name', $from_store_id, 'bonus_pool', '')['value'], $to_store_id, 'bonus_pool'); Option::set('holder_name', Option::get('holder_name', $from_store_id, 'bonus_pool', '')['value'], $to_store_id, 'bonus_pool'); Option::set('area_name', Option::get('area_name', $from_store_id, 'bonus_pool', '')['value'], $to_store_id, 'bonus_pool'); Option::set('old_range_name', Option::get('old_range_name', $from_store_id, 'bonus_pool', '')['value'], $to_store_id, 'bonus_pool'); Option::set('direct_range_name', Option::get('direct_range_name', $from_store_id, 'bonus_pool', '')['value'], $to_store_id, 'bonus_pool'); Option::set('old_add_holder_name', Option::get('old_add_holder_name', $from_store_id, 'bonus_pool', '')['value'], $to_store_id, 'bonus_pool'); Option::set('is_open_area', Option::get('is_open_area', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderProfit', Option::get('shareHolderProfit', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderPriceMin', Option::get('shareHolderPriceMin', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderCashProfit', Option::get('shareHolderCashProfit', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderLevel', Option::get('shareHolderLevel', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderNumber', Option::get('shareHolderNumber', $from_store_id, 'bonus_pool', '0,0')['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderHasCheck', Option::get('shareHolderHasCheck', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('pay_wechat', Option::get('pay_wechat', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('pay_alipay', Option::get('pay_alipay', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('bank', Option::get('bank', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('cash_max_day', Option::get('cash_max_day', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('cash_max_single_day', Option::get('cash_max_single_day', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('min_money', Option::get('min_money', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('auto_money', Option::get('auto_money', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('dividends_condition', Option::get('dividends_condition', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderProfitSwitch', Option::get('shareHolderProfitSwitch', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); Option::set('shareHolderHighProfit', Option::get('shareHolderHighProfit', $from_store_id, 'bonus_pool', 0)['value'], $to_store_id, 'bonus_pool'); //申请设置 Option::set('holder_agreement', Option::get('holder_agreement', $from_store_id, 'store', '')['value'], $to_store_id, 'store'); Option::set('holder_banner', Option::get('holder_banner', $from_store_id, 'store', '')['value'], $to_store_id, 'store'); Option::set('holder_audit', Option::get('holder_audit', $from_store_id, 'store', '')['value'], $to_store_id, 'store'); return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //等级同步 private function shareHolderLevelConfig($from_store_id, $to_store_id, $goodsCache) { try { $shareHolderLevelList = ShareHolderLevel::find()->where(['store_id' => $from_store_id, 'is_delete' => 0])->orderBy(['level' => 'ASC'])->asArray()->all(); $level_cache = []; foreach ($shareHolderLevelList as $item) { $share_holder_level = ShareHolderLevel::findOne(['store_id' => $to_store_id, 'is_delete' => 0, 'level' => $item['level']]); $share_holder_level_id = $item['id']; if (!$share_holder_level) { $share_holder_level = new ShareHolderLevel(); } unset($item['id']); $share_holder_level->attributes = $item; $share_holder_level->store_id = $to_store_id; if ($share_holder_level->save()) { $level_cache[$item['id']] = $share_holder_level->id; } $condition = json_decode($share_holder_level->condition, true); if ($condition) { foreach ($condition as $condition_index => $condition_item) { //商品升级 if ($condition_index === 'goods') { if ($condition_item['value']['id']) { $id = []; if ($condition_item['value']['id']) { if (is_array($condition_item['value']['id'])) { foreach ($condition_item['value']['id'] as $goods_id_item) { $id[] = $goodsCache[$goods_id_item]; } } else { $id = [$condition_item['value']['id']]; } } $condition[$condition_index]['value']['id'] = $id; } } if ($condition_index === 'shareholder') { if ($condition_item['from_level_id']) { $condition[$condition_index]['from_level_id'] = $level_cache[$condition_item['from_level_id']]; } if ($condition_item['to_level_id']) { $condition[$condition_index]['to_level_id'] = $level_cache[$condition_item['to_level_id']]; } } } } $share_holder_level->condition = json_encode($condition, JSON_UNESCAPED_UNICODE); $share_holder_level->save(); (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $share_holder_level_id, $share_holder_level->id, StoreSyncExtLog::TYPE_SHARE_HOLDER_CONFIG); } return [ 'code' => 0, 'msg' => '同步成功', 'data' => [ 'level_cache' => $level_cache ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步股东end **/ /** 同步短视频start **/ private function videoGoods($fromStoreId, $toId, $goodsCache) { //同步商品 $goods_result = $this->videoGoodsCopy($fromStoreId, $toId, $goodsCache); //同步分类 $goods_cat_result = $this->videoGoodsCatCopy($fromStoreId, $toId); $video_cat_cache = []; if ($goods_cat_result['code'] === 0) { $video_cat_cache = $goods_cat_result['data']['video_cat_cache']; } //同步设置 $goods_setting_result = $this->videoGoodsConfigCopy($fromStoreId, $toId); //同步视频 $goods_list_result = $this->videoCopy($fromStoreId, $toId, $goodsCache, $video_cat_cache); return [$goods_result, $goods_cat_result, $goods_setting_result, $goods_list_result]; } //同步商品 private function videoGoodsCopy($fromStoreId, $toId, $goodsCache) { try { $video_goods_list = VideoGoods::find()->where(['store_id' => $fromStoreId, 'is_delete' => 0])->asArray()->all(); VideoGoods::deleteAll(['store_id' => $toId]); foreach ($video_goods_list as $video_goods_item) { if (!$goodsCache[$video_goods_item['goods_id']]) { continue; } $video_goods_id = $video_goods_item['id']; unset($video_goods_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_VIDEO_GOODS, 'from_id' => $video_goods_id ]); $video_goods = VideoGoods::findOne($storeSyncExtLog->to_id ?? 0) ?: new VideoGoods(); $video_goods->store_id = $toId; $video_goods->status = $video_goods_item['status']; $video_goods->goods_id = $goodsCache[$video_goods_item['goods_id']]; $video_goods->created_at = time(); $video_goods->updated_at = time(); $video_goods->save(); (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $video_goods_id, $video_goods->id, StoreSyncExtLog::TYPE_VIDEO_GOODS); } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //同步短视频分类 private function videoGoodsCatCopy($fromStoreId, $toId) { try { $video_cat_cache = []; $video_goods_list = VideoGoodsCat::find()->where(['store_id' => $fromStoreId, 'is_delete' => 0])->asArray()->all(); VideoGoodsCat::deleteAll(['store_id' => $toId]); foreach ($video_goods_list as $video_goods_item) { $id = $video_goods_item['id']; unset($video_goods_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_VIDEO_GOODS_CAT, 'from_id' => $id ]); $video_goods_cat = VideoGoodsCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new VideoGoodsCat(); $video_goods_cat->attributes = $video_goods_item; $video_goods_cat->store_id = $toId; $video_goods_cat->created_at = time(); $video_goods_cat->updated_at = time(); if (!$video_goods_cat->save()) { throw new \Exception(json_encode($video_goods_cat, JSON_UNESCAPED_UNICODE)); } $video_cat_cache[$id] = $video_goods_cat->id; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $video_goods_cat->id, StoreSyncExtLog::TYPE_VIDEO_GOODS_CAT); } return [ 'code' => 0, 'msg' => '同步成功', 'data' => [ 'video_cat_cache' => $video_cat_cache ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //同步短视频分类 private function videoGoodsConfigCopy($fromStoreId, $toId) { try { $video_goods_setting_ = VideoGoodsSetting::find()->where(['store_id' => $fromStoreId])->asArray()->one(); unset($video_goods_setting_['id']); $video_goods_setting = VideoGoodsSetting::findOne(['store_id' => $toId]); if (!$video_goods_setting) { $video_goods_setting = new VideoGoodsSetting(); } $video_goods_setting->attributes = $video_goods_setting_; $video_goods_setting->store_id = $toId; $video_goods_setting->created_at = time(); $video_goods_setting->updated_at = time(); if (!$video_goods_setting->save()) { throw new \Exception(json_encode($video_goods_setting->errors, JSON_UNESCAPED_UNICODE)); } $video_analyze_345_ = Option::get('video_analyze_345', $fromStoreId, 'saas')['value']; Option::set('video_analyze_345', $video_analyze_345_, $toId, 'saas'); return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } private function videoCopy($fromStoreId, $toId, $goodsCache, $video_cat_cache) { try { $video_goods_list = VideoGoodsList::find()->where(['store_id' => $fromStoreId, 'is_delete' => 0])->asArray()->all(); VideoGoodsList::deleteAll(['store_id' => $toId]); foreach ($video_goods_list as $video_goods_item) { $integral_cat = new VideoGoodsList(); unset($video_goods_item['id']); $integral_cat->attributes = $video_goods_item; $goodsList = json_decode($video_goods_item['goods_id'], true); $ids = []; if ($goodsList) { foreach ($goodsList as $goods_id) { $ids[] = $goodsCache[$goods_id]; } } $integral_cat->goods_id = json_encode($ids); $integral_cat->cat_id = $video_cat_cache[$video_goods_item['cat_id']]; $integral_cat->store_id = $toId; $integral_cat->user_id = 0; $integral_cat->created_at = time(); $integral_cat->updated_at = time(); if (!$integral_cat->save()) { throw new \Exception(json_encode($integral_cat->errors, JSON_UNESCAPED_UNICODE)); } } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步短视频end **/ /** 同步积分商城start **/ private function integralStore($fromStoreId, $toId) { //商品分类 $goods_cat_result = $this->integralGoodsCatCopy($fromStoreId, $toId); //设置 $setting_result = $this->integralSettingCopy($fromStoreId, $toId); return [$goods_cat_result, $setting_result]; } //商品分类 private function integralGoodsCatCopy($fromStoreId, $toId) { try { $integral_cat_list = NewIntegralCat::find()->where(['store_id' => $fromStoreId, 'is_delete' => 0])->asArray()->all(); $integral_cat_arr = []; NewIntegralCat::deleteAll(['store_id' => $toId]); $goods_id = Goods::find()->where(['store_id' => $toId, 'is_delete' => 0, 'product_type' => Goods::GOODS_TYPE_INTEGRAL, 'mch_id' => 0]) ->select('id')->asArray()->column(); foreach ($integral_cat_list as $integral_cat_item) { $id = $integral_cat_item['id']; unset($integral_cat_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_INTEGRAL_STORE_CAT, 'from_id' => $id ]); $integral_cat = NewIntegralCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new NewIntegralCat(); $integral_cat->attributes = $integral_cat_item; $integral_cat->store_id = $toId; $integral_cat->created_at = time(); $integral_cat->updated_at = time(); if (!$integral_cat->save()) { throw new \Exception(json_encode($integral_cat->errors, JSON_UNESCAPED_UNICODE)); } $integral_cat_arr[$id] = $integral_cat->id; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $integral_cat->id, StoreSyncExtLog::TYPE_INTEGRAL_STORE_CAT); $goods_cat_list = GoodsCat::find()->where(['goods_id' => $goods_id, 'cat_id' => $integral_cat_item['id'], 'is_delete' => 0, 'store_id' => $toId]) ->asArray()->all(); foreach ($goods_cat_list as $goods_cat_item) { $goods_cat = GoodsCat::findOne($goods_cat_item['id']); $goods_cat->cat_id = $integral_cat->id; if (!$goods_cat->save()) { throw new \Exception(json_encode($goods_cat->errors, JSON_UNESCAPED_UNICODE)); } } } return [ 'code' => 0, 'msg' => '同步完成', 'data' => [ 'integral_cat_arr' => $integral_cat_arr ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } private function integralSettingCopy($fromStoreId, $toId) { try { //签到积分设置 $integral_setting_ = IntegralSetting::find()->where(['store_id' => $fromStoreId])->asArray()->one(); if ($integral_setting_) { $integral_setting = IntegralSetting::findOne(['store_id' => $toId]); if (!$integral_setting) { $integral_setting = new IntegralSetting(); } unset($integral_setting_['id']); $integral_setting->attributes = $integral_setting_; $integral_setting->store_id = $toId; if (!$integral_setting->save()) { throw new \Exception(json_encode($integral_setting->errors, JSON_UNESCAPED_UNICODE)); } } //积分商城设置 $new_integral_setting_ = NewIntegralSetting::find()->where(['store_id' => $fromStoreId])->asArray()->one(); if ($new_integral_setting_) { $new_integral_setting = NewIntegralSetting::findOne(['store_id' => $toId]); if (!$new_integral_setting) { $new_integral_setting = new NewIntegralSetting(); } $new_integral_setting->store_id = $toId; $new_integral_setting->polling_img = $new_integral_setting_['polling_img']; $new_integral_setting->explain = $new_integral_setting_['explain']; $new_integral_setting->created_at = time(); if (!$new_integral_setting->save()) { throw new \Exception(json_encode($new_integral_setting->errors, JSON_UNESCAPED_UNICODE)); } } return [ 'code' => 0, 'msg' => '同步完成' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() . $e->getFile() . $e->getLine() ]; } } /** 同步积分商城end **/ /** 同步上门服务start **/ private function workerConfig($fromStoreId, $toId, $goodsCache) { //商品分类 $cat_cache = $this->workerGoodsCat($fromStoreId, $toId); //商品列表 $goods_result = $this->workerGoods($fromStoreId, $toId, $cat_cache, $goodsCache); //服务分类 $worker_cat_result = $this->workerCat($fromStoreId, $toId); //服务等级 $worker_level_result = $this->workerLevel($fromStoreId, $toId); //功能设置 $worker_setting = $this->workerSetting($fromStoreId, $toId); return [$cat_cache, $goods_result, $worker_cat_result, $worker_level_result, $worker_setting]; } //预约 private function bookingHome($fromStoreId, $toId, $goodsCache) { //预约分类 $cat_cache = $this->bookingHomeGoodsCat($fromStoreId, $toId); //预约商品与预约分类修改绑定关系 $ext_result = $this->bookingHomeGoodsCatBind($fromStoreId, $toId, $goodsCache, $cat_cache); return [$cat_cache, $ext_result]; } //预约商品分类 private function bookingHomeGoodsCat($fromStoreId, $toId) { try { $goodsCatCache = []; $goods_cat_ = BookingGoodsCat::find()->where(['store_id' => $fromStoreId, 'is_delete' => 0])->asArray()->all(); BookingGoodsCat::deleteAll(['store_id' => $toId]); foreach ($goods_cat_ as $goods_cat_item) { $id = $goods_cat_item['id']; unset($goods_cat_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_BOOKING_GOODS_CAT, 'from_id' => $id ]); $goods_cat = BookingGoodsCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new BookingGoodsCat(); $goods_cat->attributes = $goods_cat_item; $goods_cat->store_id = $toId; $goods_cat->name = $goods_cat_item['name']; $goods_cat->pic_url = $goods_cat_item['pic_url']; $goods_cat->sort = $goods_cat_item['sort']; $goods_cat->is_show = $goods_cat_item['is_show']; if (!$goods_cat->save()) { throw new \Exception(json_encode($goods_cat->errors, JSON_UNESCAPED_UNICODE)); } $goodsCatCache[$id] = $goods_cat->id; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $goods_cat->id, StoreSyncExtLog::TYPE_BOOKING_GOODS_CAT); } return $goodsCatCache; } catch (\Exception $e) { return []; } } //预约商品与预约分类修改绑定关系 private function bookingHomeGoodsCatBind($fromStoreId, $toId, $goodsCache, $cat_cache) { try { $goodsExt = BookingGoodsExt::find()->where(['store_id' => $fromStoreId])->asArray()->all(); BookingGoodsExt::deleteAll(['store_id' => $toId]); foreach ($goodsExt as $ext_item) { //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_BOOKING_GOODS, 'from_id' => $ext_item['id'] ]); $id = $ext_item['id']; unset($ext_item['id']); $goods_ext = BookingGoodsExt::findOne($storeSyncExtLog->to_id ?? 0) ?: new BookingGoodsExt(); $goods_ext->store_id = $toId; $goods_ext->goods_id = $goodsCache[$ext_item['goods_id']]; $goods_ext->cat_id = $cat_cache[$ext_item['cat_id']]; if (!$goods_ext->save()) { throw new \Exception(json_encode($goods_ext->errors, JSON_UNESCAPED_UNICODE)); } (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $goods_ext->id, StoreSyncExtLog::TYPE_BOOKING_GOODS); } return [ 'code' => 0, 'msg' => 'success' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //商品分类 private function workerGoodsCat($fromStoreId, $toId) { try { $cat_cache = []; $goods_cat_ = WorkerGoodsCat::find()->where(['store_id' => $fromStoreId, 'is_delete' => 0])->asArray()->all(); WorkerGoodsCat::deleteAll(['store_id' => $toId]); foreach ($goods_cat_ as $goods_cat_item) { $id = $goods_cat_item['id']; unset($goods_cat_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_WORKER_CONFIG_GOODS_CAT, 'from_id' => $id ]); $goods_cat = WorkerGoodsCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new WorkerGoodsCat(); $goods_cat->attributes = $goods_cat_item; $goods_cat->store_id = $toId; $goods_cat->created_at = time(); $goods_cat->updated_at = time(); $goods_cat->name = $goods_cat_item['name']; $goods_cat->pic_url = $goods_cat_item['pic_url']; $goods_cat->is_show = $goods_cat_item['is_show']; $goods_cat->big_pic_url = $goods_cat_item['big_pic_url']; $goods_cat->advert_pic = $goods_cat_item['advert_pic']; $goods_cat->advert_url = $goods_cat_item['advert_url']; if (!$goods_cat->save()) { throw new \Exception(json_encode($goods_cat->errors, JSON_UNESCAPED_UNICODE)); } $cat_cache[$id] = $goods_cat->id; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $goods_cat->id, StoreSyncExtLog::TYPE_WORKER_CONFIG_GOODS_CAT); } return $cat_cache; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } private function workerGoods($fromStoreId, $toId, $cat_cache, $goodsCache) { $t = \Yii::$app->db->beginTransaction(); try { $workGoodsCache = []; $worker_goods_list = WorkerGoodsExt::find()->where(['store_id' => $fromStoreId])->asArray()->all(); WorkerGoodsExt::deleteAll(['store_id' => $toId]); foreach ($worker_goods_list as $goods_item) { $goods_id = $goodsCache[$goods_item['goods_id']]; $cat_id = $cat_cache[$goods_item['cat_id']]; if (!empty($goods_id) && !empty($cat_id)) { $workGoodsId = $goods_item['id']; $workGoodsCache[$workGoodsId] = 0; unset($goods_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_WORKER_CONFIG_GOODS, 'from_id' => $workGoodsId ]); $worker_goods = WorkerGoodsExt::findOne($storeSyncExtLog->to_id ?? 0) ?: new WorkerGoodsExt(); $worker_goods->attributes = $goods_item; $worker_goods->payment_type = $goods_item['payment_type']; $worker_goods->profit_base = $goods_item['profit_base']; $worker_goods->profit_max = $goods_item['profit_max']; $worker_goods->final_profit = $goods_item['profit_max']; $worker_goods->desc = $goods_item['desc']; $worker_goods->warn = $goods_item['warn']; $worker_goods->bind_worker = $goods_item['bind_worker']; $worker_goods->goods_id = $goods_id; $worker_goods->cat_id = $cat_id; $worker_goods->store_id = $toId; if (!$worker_goods->save()) { throw new \Exception(json_encode($worker_goods->errors, JSON_UNESCAPED_UNICODE)); } $workGoodsCache[$workGoodsId] = $worker_goods->id; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $workGoodsId, $worker_goods->id, StoreSyncExtLog::TYPE_WORKER_CONFIG_GOODS); } } $t->commit(); return $workGoodsCache; } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } private function workerCat($fromStoreId, $toId) { try { $workerCatCache = []; $worker_cat_list = WorkerCat::find()->where(['store_id' => $fromStoreId, 'is_delete' => 0])->asArray()->all(); WorkerCat::deleteAll(['store_id' => $toId, 'is_delete' => 0]); foreach ($worker_cat_list as $item) { $workerCatId = $item['id']; $workerCatCache[$workerCatId] = 0; unset($item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_WORKER_CONFIG_CAT, 'from_id' => $workerCatId ]); $worker_cat = WorkerCat::findOne($storeSyncExtLog->to_id ?? 0) ?: new WorkerCat(); $worker_cat->attributes = $item; $worker_cat->store_id = $toId; $worker_cat->created_at = time(); $worker_cat->updated_at = time(); if (!$worker_cat->save()) { throw new \Exception(json_encode($worker_cat->errors, JSON_UNESCAPED_UNICODE)); } $workerCatCache[$workerCatId] = $worker_cat->id; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $workerCatId, $worker_cat->id, StoreSyncExtLog::TYPE_WORKER_CONFIG_CAT); } return $workerCatCache; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //同步等级 private function workerLevel($from_store_id, $to_store_id) { try { $workerLevelList = WorkerLevel::find()->where(['store_id' => $from_store_id, 'is_delete' => 0])->asArray()->all(); foreach ($workerLevelList as $item) { $workerLevelId = $item['id']; //判断是否为当前商城同步过此商品 $worker_level = WorkerLevel::findOne(['store_id' => $to_store_id, 'is_delete' => 0, 'level' => $item['level']]); if (!$worker_level) { $worker_level = new WorkerLevel(); } unset($item['id']); $worker_level->attributes = $item; $worker_level->store_id = $to_store_id; if (!$worker_level->save()) { return [ 'code' => 1, 'msg' => json_encode($worker_level->errors, JSON_UNESCAPED_UNICODE) ]; }; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $workerLevelId, $worker_level->id, StoreSyncExtLog::TYPE_WORKER_CONFIG_LEVEL); } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //同步短视频分类 private function workerSetting($fromStoreId, $toId) { try { $worker_setting_ = WorkerSetting::find()->where(['store_id' => $fromStoreId])->asArray()->one(); unset($worker_setting_['id']); $worker_setting = WorkerSetting::findOne(['store_id' => $toId]); if (!$worker_setting) { $worker_setting = new WorkerSetting(); } $worker_setting->store_id = $toId; $worker_setting->order_space = $worker_setting_['order_space'] ?: 999; $worker_setting->fee_road = $worker_setting_['fee_road'] ?? ''; $worker_setting->form_apply = $worker_setting_['form_apply'] ?? ''; $worker_setting->tag = $worker_setting_['tag'] ?? ''; $worker_setting->created_at = time(); $worker_setting->updated_at = time(); $worker_setting->starting_price = $worker_setting_['starting_price'] ?? '0.00'; $worker_setting->additional_charge = $worker_setting_['additional_charge'] ?? '0.00'; $worker_setting->banner = $worker_setting_['banner'] ?? ''; if (!$worker_setting->save()) { throw new \Exception(json_encode($worker_setting->errors, JSON_UNESCAPED_UNICODE)); } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步上门服务end **/ /** 同步文章start **/ private function articleSetting($fromStoreId, $toId) { try { $article_list = AboutArticle::find()->where(['is_delete' => 0, 'store_id' => $fromStoreId])->andWhere(['<>', 'type', 1])->asArray()->all(); debug_log(AboutArticle::find()->where(['is_delete' => 0, 'store_id' => $fromStoreId])->andWhere(['<>', 'type', 1])->createCommand()->getRawSql(), 'store_sync.log'); AboutArticle::deleteAll(['store_id' => $toId, 'is_delete' => 0]); 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']; 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 **/ /** 同步专题start **/ private function topicSetting($fromStoreId, $toId) { $type_result = $this->topicTypeSetting($fromStoreId, $toId); $typeCache = []; if ($type_result['code'] === 0) { $typeCache = $type_result['data']['typeCache']; } $result = $this->topicContentSetting($fromStoreId, $toId, $typeCache); return [$type_result, $result]; } private function topicTypeSetting($fromStoreId, $toId) { try { $topic_type_list = TopicType::find()->where(['is_delete' => TopicType::IS_DELETE_NO, 'store_id' => $fromStoreId])->orderBy('sort desc, id desc')->asArray()->all(); TopicType::deleteAll(['store_id' => $toId, 'is_delete' => 0]); $typeCache = []; foreach ($topic_type_list as $topic_type_item) { $id = $topic_type_item['id']; unset($topic_type_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_TOPIC_TYPE, 'from_id' => $id ]); $TopicType = TopicType::findOne($storeSyncExtLog->to_id ?? 0) ?: new TopicType(); $TopicType->attributes = $topic_type_item; $TopicType->store_id = $toId; if (!$TopicType->save()) { throw new \Exception(json_encode($TopicType->errors, JSON_UNESCAPED_UNICODE)); }; $typeCache[$id] = $TopicType->id; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $TopicType->id, StoreSyncExtLog::TYPE_TOPIC_TYPE); } return [ 'code' => 0, 'msg' => '同步成功', 'data' => [ 'typeCache' => $typeCache ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } private function topicContentSetting($fromStoreId, $toId, $typeCache) { try { $topic_list = Topic::find()->where(['is_delete' => 0, 'store_id' => $fromStoreId])->orderBy('sort desc, id desc')->asArray()->all(); Topic::updateAll(['is_delete' => 0], ['store_id' => $toId, 'is_delete' => 0]); foreach ($topic_list as $topic_item) { $id = $topic_item['id']; unset($topic_item['id']); //判断是否为当前商城同步过此商品 $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $fromStoreId, 'to_store_id' => $toId, 'type' => StoreSyncExtLog::TYPE_TOPIC, 'from_id' => $id ]); $Topic = Topic::findOne($storeSyncExtLog->to_id ?? 0) ?: new Topic(); $Topic->attributes = $topic_item; $Topic->store_id = $toId; $Topic->type = $typeCache[$topic_item['type']]; if (!$Topic->save()) { throw new \Exception(json_encode($Topic->errors, JSON_UNESCAPED_UNICODE)); }; (new StoreSyncExtLog())::handleData($fromStoreId, $toId, $id, $Topic->id, StoreSyncExtLog::TYPE_TOPIC); } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步专题end **/ }