|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Aside;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Logic\Aside\Template\TemplateChunkLogic;
|
|
|
|
use App\Http\Logic\Aside\Template\TemplateLogic;
|
|
|
|
use App\Http\Requests\Aside\Template\TemplateChunkRequest;
|
|
|
|
use App\Http\Requests\Aside\Template\TemplateRequest;
|
|
|
|
use App\Models\Template\ATemplate;
|
|
|
|
use App\Models\Template\ATemplateChunk;
|
|
|
|
use App\Models\Template\ATemplateHtml;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 模板
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/4 17:10
|
|
|
|
* Class TemplateController
|
|
|
|
* @package App\Http\Controllers\Aside
|
|
|
|
*/
|
|
|
|
class TemplateController extends BaseController
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 列表
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/4 17:10
|
|
|
|
*/
|
|
|
|
public function index(){
|
|
|
|
|
|
|
|
$lists = (new ATemplate)->lists(
|
|
|
|
$this->map,
|
|
|
|
$this->page,
|
|
|
|
$this->row,
|
|
|
|
$this->order,
|
|
|
|
['id','name','status','is_default','sort','thumb','url','created_at','updated_at']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->response('success',Code::SUCCESS,$lists);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param false $is_edit
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/11 10:13
|
|
|
|
*/
|
|
|
|
public function save(TemplateRequest $request){
|
|
|
|
|
|
|
|
$res = TemplateLogic::instance()->save($request->validated());
|
|
|
|
|
|
|
|
$data = TemplateLogic::instance()->getInfo($res['id']);
|
|
|
|
|
|
|
|
return $this->response('',Code::SUCCESS,$data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/4 17:10
|
|
|
|
*/
|
|
|
|
public function delete($id){
|
|
|
|
|
|
|
|
if(ATemplate::destroy($id)){
|
|
|
|
return $this->response('删除成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->response('删除失败',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 列表
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/4 17:10
|
|
|
|
*/
|
|
|
|
public function html_index($template_id){
|
|
|
|
|
|
|
|
$lists = (new ATemplateHtml)->list(
|
|
|
|
['template_id'=>$template_id],
|
|
|
|
$this->order
|
|
|
|
// , ['id','name','status','is_default','sort','thumb','url','created_at','updated_at']
|
|
|
|
);
|
|
|
|
$this->response('success',Code::SUCCESS,$lists);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/4 16:19
|
|
|
|
*/
|
|
|
|
public function html_edit($template_id){
|
|
|
|
$this->html_save($template_id,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 新增
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/5 9:30
|
|
|
|
*/
|
|
|
|
public function html_insert($template_id){
|
|
|
|
$this->html_save($template_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param false $is_edit
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/11 10:13
|
|
|
|
*/
|
|
|
|
private function html_save($template_id,$is_edit=false){
|
|
|
|
|
|
|
|
$verify = [
|
|
|
|
'role' => [
|
|
|
|
'id' => ['required','integer'],
|
|
|
|
// 'template_id' => ['required','integer'],
|
|
|
|
'name' => ['required'],
|
|
|
|
'type' => ['required',Rule::in(array_keys(ATemplateHtml::$typeMap))],
|
|
|
|
'css' => [],
|
|
|
|
'script' => [],
|
|
|
|
'html' => ['required'],
|
|
|
|
],
|
|
|
|
'message' => [
|
|
|
|
'id.required' => 'id必须',
|
|
|
|
'id.integer' => 'id必须',
|
|
|
|
|
|
|
|
// 'template_id.required' => '模板选择错误',
|
|
|
|
// 'template_id.integer' => '模板选择错误',
|
|
|
|
|
|
|
|
'name.required' => '名称必须',
|
|
|
|
|
|
|
|
'type.required' => '页面类型选择错误',
|
|
|
|
'type.in' => '页面类型选择错误',
|
|
|
|
|
|
|
|
|
|
|
|
'html.required' => 'html 代码必须',
|
|
|
|
|
|
|
|
]
|
|
|
|
];
|
|
|
|
if(!$is_edit) unset($verify['role']['id']);
|
|
|
|
|
|
|
|
$data = $this->validate(request() ,$verify['role'],$verify['message']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
$id = ATemplateHtml::_save($template_id,$data,$data['id']??0);
|
|
|
|
|
|
|
|
if(!$id){
|
|
|
|
return $this->response('保存失败',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->response('保存成功',Code::SUCCESS,ATemplateHtml::_find($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/4 17:10
|
|
|
|
*/
|
|
|
|
public function html_delete($template_id, $id){
|
|
|
|
|
|
|
|
if(ATemplateHtml::where('template_id',$template_id)->where('id',$id)->delete()){
|
|
|
|
return $this->response('删除成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->response('删除失败',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面类型
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/11 10:29
|
|
|
|
*/
|
|
|
|
public function html_type(){
|
|
|
|
return $this->response('',Code::SUCCESS,ATemplateHtml::$typeMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义界面,块
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/29 10:27
|
|
|
|
*/
|
|
|
|
public function chunk_lists(){
|
|
|
|
$lists = TemplateChunkLogic::instance()->getList()->toArray();
|
|
|
|
return $this->response('',Code::SUCCESS,$lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义界面,块 保存
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/29 10:37
|
|
|
|
*/
|
|
|
|
public function chunk_save(TemplateChunkRequest $request){
|
|
|
|
$data = TemplateChunkLogic::instance()->save($request->validated());
|
|
|
|
return $this->success(TemplateChunkLogic::instance()->getInfo($data['id']));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义界面,块 删除
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/29 10:38
|
|
|
|
*/
|
|
|
|
public function chunk_delete($chunk_id){
|
|
|
|
|
|
|
|
TemplateChunkLogic::instance()->delete($chunk_id);
|
|
|
|
|
|
|
|
return $this->response('删除成功');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |