作者 邓超

自定义

... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside;
use App\Models\Template\ATemplate;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplateData;
/**
... ... @@ -93,6 +94,25 @@ class TemplateController extends BaseController
}
/**
* 自定义块
* @author:dc
* @time 2023/5/10 14:55
*/
public function customChunk(){
$html = $this->param['html']??[];
if(!is_array($html)){
return $this->response('参数异常','B_CUSTOM_CHUNK_PARAMS');
}
$data = BTemplateData::_insert();
}
... ...
... ... @@ -59,7 +59,7 @@ class BCustom extends Base
$model->description = $data['description'];
$model->url = $data['url'];
$model->status = $data['status'];
// $model->html = $data['html'];
$model->html = $data['html']??'';
$model->save();
... ...
... ... @@ -73,28 +73,28 @@ class BSetting extends \App\Models\Base{
$data->save();
// 是否有模板
if(!BTemplate::_isExist($project_id,$template_id)){
// 没有模板
$aData = ATemplate::_find($template_id);
// 保存到自己的数据中
BTemplate::_insert($project_id,$aData);
$aDataHtml = ATemplateHtml::_all($template_id);
DB::beginTransaction();
foreach ($aDataHtml as $item){
try {
// 插入子数据
BTemplateHtml::_insert($project_id,$item);
}catch (\Throwable $e){
DB::rollBack();
return $data->id;
break;
}
}
DB::commit();
}
// if(!BTemplate::_isExist($project_id,$template_id)){
// // 没有模板
// $aData = ATemplate::_find($template_id);
// // 保存到自己的数据中
// BTemplate::_insert($project_id,$aData);
//
// $aDataHtml = ATemplateHtml::_all($template_id);
// DB::beginTransaction();
// foreach ($aDataHtml as $item){
// try {
// // 插入子数据
// BTemplateHtml::_insert($project_id,$item);
// }catch (\Throwable $e){
// DB::rollBack();
//
// return $data->id;
// break;
// }
//
// }
// DB::commit();
// }
return $data->id;
... ...
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @author:dc
* @time 2023/5/10 14:31
* Class BTemplateData
* @package App\Models\Template
*/
class BTemplateData extends \App\Models\Base{
protected $table = 'gl_web_template_data';
protected $hidden = ['project_id'];
/**
* 插入
* @param $project_id
* @param $data
* @return mixed
* @author:dc
* @time 2023/5/10 10:23
*/
public static function _insert($project_id,$data)
{
$model = new static();
$model->project_id = $project_id;
$model->template_id = $data['template_id'];
$model->name = $data['name'];
$model->type = $data['type'];
$model->is_edit = $data['is_edit'];
$model->css = $data['css'];
$model->script = $data['script'];
$model->html = $data['html'];
$model->data_ext = $data['data_ext'];
$model->save();
return $model->id;
}
}
... ...