|
...
|
...
|
@@ -2,7 +2,10 @@ |
|
|
|
|
|
|
|
namespace App\Http\Controllers\Aside;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Models\Template\ATemplate;
|
|
|
|
use App\Models\Template\ATemplateHtml;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 模板
|
|
...
|
...
|
@@ -22,9 +25,22 @@ class TemplateController extends BaseController |
|
|
|
*/
|
|
|
|
public function index(){
|
|
|
|
|
|
|
|
$limit = $this->param['limit']??20;
|
|
|
|
|
|
|
|
|
|
|
|
return view('a');
|
|
|
|
$lists = ATemplate::where(function ($query){
|
|
|
|
|
|
|
|
!empty($this->param['status']) && $query->where('status',$this->param['status']);
|
|
|
|
!empty($this->param['name']) && $query->where('status',$this->param['name']);
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
->select(['id','name','status','is_default','sort','thumb','url','created_at','updated_at'])
|
|
|
|
->orderBy('sort')
|
|
|
|
->paginate($limit);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($lists->toArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -34,7 +50,7 @@ class TemplateController extends BaseController |
|
|
|
* @time 2023/5/4 16:19
|
|
|
|
*/
|
|
|
|
public function edit(){
|
|
|
|
|
|
|
|
$this->save(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -43,12 +59,168 @@ class TemplateController extends BaseController |
|
|
|
* @time 2023/5/5 9:30
|
|
|
|
*/
|
|
|
|
public function insert(){
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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($is_edit=false){
|
|
|
|
|
|
|
|
$verify = [
|
|
|
|
'role' => [
|
|
|
|
'id' => ['required','integer'],
|
|
|
|
'name' => ['required'],
|
|
|
|
'status' => ['required',Rule::in(0,1)],
|
|
|
|
'is_default' => ['required',Rule::in(0,1)],
|
|
|
|
'sort' => ['required','integer'],
|
|
|
|
'thumb' => ['required'],
|
|
|
|
'url' => ['required'],
|
|
|
|
],
|
|
|
|
'message' => [
|
|
|
|
'id.required' => 'id必须',
|
|
|
|
'id.integer' => 'id必须',
|
|
|
|
|
|
|
|
'name.required' => '名称必须',
|
|
|
|
'status.integer' => '状态错误',
|
|
|
|
'status.in' => '状态错误',
|
|
|
|
'is_default.integer' => '是否默认',
|
|
|
|
'is_default.in' => '是否默认',
|
|
|
|
'sort.required' => '排序必须',
|
|
|
|
'sort.integer' => '排序必须',
|
|
|
|
'thumb.required' => '缩略图必须',
|
|
|
|
'url.required' => '预览链接必须',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
if(!$is_edit) unset($verify['role']['id']);
|
|
|
|
|
|
|
|
$data = $this->validate(request() ,$verify['role'],$verify['message']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
$id = ATemplate::_save($data,$data['id']??0);
|
|
|
|
|
|
|
|
if(!$id){
|
|
|
|
return $this->response('保存失败',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success(ATemplate::_find($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除
|
|
|
|
* @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 = ATemplateHtml::where('template_id',$template_id)->get();
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success($lists->toArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function save($name = ''){
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
* @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']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
$id = ATemplateHtml::_save($template_id,$data,$data['id']??0);
|
|
|
|
|
|
|
|
if(!$id){
|
|
|
|
return $this->response('保存失败',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success(ATemplateHtml::_find($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -57,12 +229,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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|