syncAppearanceTemplates($appearanceId,$distId); } /* * 得到独立页的模版数组 */ public static function getLandingPageTemplateOptions() { $distInfo = DistAdminDistributor::getInfo(); $distId = $distInfo->id; $appearanceId = $distInfo->appearance_id; $model = new Model(); $result = $model->where('appearance_id', $appearanceId)->where('dist_id', $distId)->select('file_name')->get(); $options = ['pages_detail.liquid'=>config('dictionary.landing_page_default_template')]; foreach ($result as $key => $value) { // 检查字符串是否以 "pages_sp_" 开头 if (strpos($value->file_name, 'pages_sp_') === 0) { // 提取 "xxxx" 部分 // $part = str_replace('pages_sp_', '', $value->file_name); // $part = str_replace('.liquid', '', $part); $part = $value->file_name; $options[$part] = $part; } } return $options; } public static function previewSave($data) { //echo $data;exit; $distInfo = DistAdminDistributor::getInfo(); $distId = $distInfo->id; $appearanceId = $distInfo->appearance_id; //查找$data中是否存在mtb_id $inputElements = self::findElementsWithMtbId($data); foreach ($inputElements as $prefix => $elements) { //找查找对应的模板 $template = Model::where('dist_id', $distId)->where('appearance_id', $appearanceId)->where('template_code',$prefix)->first(); if ($template) { //替换模板内容 $oldContent = self::contentChange($template->content,$template->template_code);//旧模板内容 $newContent = self::contentReplace($oldContent,$elements); //更新模板内容 $template->content = $newContent; $template->updated_at = Carbon::now(); $template->save(); //记录日志 DistAppearanceTemplateLog::insertLog($appearanceId,$distId,$template->file_name,$template->file_path,$template->template_code,$newContent,$oldContent); } } } /* * 替换模板内容 * @param $content 模板内容 * @param $elements Array([mtb_id] => 676a6d11f1a57_1,[outHtml] =>
Again3