|
...
|
...
|
@@ -2,7 +2,13 @@ |
|
|
|
|
|
|
|
namespace App\Http\Controllers\Aside;
|
|
|
|
|
|
|
|
use App\Models\Template\AHeadFoot;
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Logic\Aside\Template\TemplateLogic;
|
|
|
|
use App\Http\Requests\Aside\Template\TemplateRequest;
|
|
|
|
use App\Http\Requests\Scene;
|
|
|
|
use App\Models\Template\ATemplate;
|
|
|
|
use App\Models\Template\ATemplateHtml;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 模板
|
|
...
|
...
|
@@ -22,21 +28,8 @@ class TemplateController extends BaseController |
|
|
|
*/
|
|
|
|
public function index(){
|
|
|
|
|
|
|
|
$data = AHeadFoot::all();
|
|
|
|
$lists = [];
|
|
|
|
// 以名字为单位区分
|
|
|
|
foreach ($data as $datum){
|
|
|
|
if(empty($lists[$datum['name']])) $lists[$datum['name']] = [];
|
|
|
|
$lists[$datum['name']]['name'] = $datum['name'];
|
|
|
|
$lists[$datum['name']]['default'] = $datum['is_default'];
|
|
|
|
$lists[$datum['name']]['sort'] = $datum['sort'];
|
|
|
|
$lists[$datum['name']]['status'] = $datum['status'];
|
|
|
|
$lists[$datum['name']]['created_at'] = $datum['created_at'];
|
|
|
|
// $lists[$datum['name']]['tags'] = $datum['tags'];
|
|
|
|
$lists[$datum['name']][$datum['type']==AHeadFoot::TYPE_HEADER?'header':'footer'] = $datum['html'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success($lists);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -47,7 +40,7 @@ class TemplateController extends BaseController |
|
|
|
* @time 2023/5/4 16:19
|
|
|
|
*/
|
|
|
|
public function edit(){
|
|
|
|
|
|
|
|
$this->save(Scene::$UPDATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -56,12 +49,134 @@ class TemplateController extends BaseController |
|
|
|
* @time 2023/5/5 9:30
|
|
|
|
*/
|
|
|
|
public function insert(){
|
|
|
|
$this->save(Scene::$CREATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 save($scene){
|
|
|
|
|
|
|
|
|
|
|
|
$data = $this->verify(TemplateRequest::class,$scene);
|
|
|
|
|
|
|
|
|
|
|
|
TemplateLogic::instance()->save($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 ATemplate)->list($this->map,$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(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']);
|
|
|
|
|
|
|
|
|
|
|
|
private function save($name = ''){
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
$id = ATemplateHtml::_save($template_id,$data,$data['id']??0);
|
|
|
|
|
|
|
|
if(!$id){
|
|
|
|
return $this->response('保存失败',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success(ATemplateHtml::_find($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -70,12 +185,28 @@ class TemplateController extends BaseController |
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/4 17:10
|
|
|
|
*/
|
|
|
|
public function delete(){
|
|
|
|
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->success(ATemplateHtml::$typeMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|