from_store_id; $to_store_id = $this->to_store_id; foreach ($to_store_id as $store_id_item) { //等级同步 $level_result = $this->shareHolderLevelConfig($from_store_id, $store_id_item); } } //等级同步 private function shareHolderLevelConfig($from_store_id, $to_store_id) { 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']]); if (!$share_holder_level) { $share_holder_level = new ShareHolderLevel(); } $share_holder_level_id = $item['id']; 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) { $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT, 'from_id' => $goods_id_item ]); if ($storeSyncExtLog && !$storeSyncExtLog->to_id) { continue; } $id[] = $storeSyncExtLog->to_id; } } 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() ]; } } }