作者 jinglong

增加主要服务模块

... ... @@ -36,11 +36,11 @@ class AdminSeriesTypeController extends AdminBaseController
//获取列表数据
public static function getList(){
$parent_res = Db::name('type')
->where(['type'=>0,'pid'=>0])
->where(['pid'=>0])
->select()
->toArray();
$res = Db::name('type')
->where(['type'=>0,'pid'=>['<>',0]])
->where(['pid'=>['<>',0]])
->select()
->toArray();
foreach($parent_res as &$value){
... ... @@ -60,7 +60,7 @@ class AdminSeriesTypeController extends AdminBaseController
//添加页面
public function add(){
$selectCategory = Db::name('type')
->where(['type'=>0,'pid'=>0])
->where(['pid'=>0])
->field('id,name')
->select()
->toArray();
... ... @@ -85,7 +85,7 @@ class AdminSeriesTypeController extends AdminBaseController
$id = $this->request->param('id');
//分类
$selectCategory = Db::name('type')
->where(['type'=>0,'pid'=>0])
->where(['pid'=>0])
->field('id,name')
->select()
->toArray();
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\ServiceModel;
use cmf\controller\AdminBaseController;
use think\Db;
use app\portal\model\PortalPostModel;
class AdminServiceController extends AdminBaseController
{
//主要服务分类
//列表
public function index(){
$list = Db::name('service')
->select()
->toArray();
$this->assign('list',$list);
return $this->fetch();
}
//添加页面
public function add(){
return $this->fetch();
}
//添加提交
public function addPost(){
$data = $this->request->param();
$result = $this->validate($data,'AdminService.edit');
if($result !== true){
$this->error($result);
}
$serviceModel = new ServiceModel();
$res = $serviceModel->create($data);
if($res){
$this->success('添加成功!', url('AdminService/index'));
}else{
$this->error('失败');
}
}
//编辑页面
public function edit(){
$id = $this->request->param('id');
//内容
$post = Db::name('service')
->where(['id'=>$id])
->find();
$contentModel = new PortalPostModel();
$post['detail'] = $contentModel->getPostContentAttr($post['detail']);
$post['detail_en'] = $contentModel->getPostContentAttr($post['detail_en']);
$this->assign('post',$post);
return $this->fetch();
}
//编辑提交
public function editPost(){
$data = $this->request->param();
$result = $this->validate($data,'AdminService.edit');
if($result !== true){
$this->error($result);
}
$serviceModel = new ServiceModel();
$contentModel = new PortalPostModel();
$data['detail'] = $contentModel->setPostContentAttr($data['detail']);
$data['detail_en'] = $contentModel->setPostContentAttr($data['detail_en']);
// 显式指定更新数据操作
$res = $serviceModel->isUpdate(true)->save($data);
if($res){
$this->success('保存成功!', url('AdminService/index'));
}else{
$this->error('失败');
}
}
//删除
public function delete(){
$id = $this->request->param('id');
$serviceModel = new ServiceModel();
$res = $serviceModel->where(['id'=>$id])->delete();
if($res){
$this->success('删除成功!');
}else{
$this->error('失败');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\model;
use think\Model;
class ServiceModel extends Model
{
protected $autoWriteTimestamp = true;
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\validate;
use think\Validate;
class AdminServiceValidate extends Validate
{
protected $rule = [
'name' => 'require|max:80',
'name_en' => 'require|max:80',
'detail' => 'require',
'detail_en' => 'require',
];
protected $message = [
'name.require' => '分类名称不能为空',
'name.max' => '分类名称不能超过80个字符',
'name_en.require' => '分类名称(英文)不能为空',
'name_en.max' => '分类名称(英文)不能超过80个字符',
'detail.require' => '详情不能为空',
'detail_en.require' => '详情(英文)不能为空',
];
protected $scene = [
'edit' => ['name','name_en','detail','detail_en'],
];
}
\ No newline at end of file
... ...
... ... @@ -68,6 +68,27 @@
</div>
</div>
</div>
<div class="col-md-3">
<table class="table table-bordered">
<tr>
<th>分类图片</th>
</tr>
<tr>
<td>
<div style="text-align: center;">
<input type="hidden" name="thumbnail" id="thumbnail">
<a href="javascript:uploadOneImage('图片上传','#thumbnail');">
<img src="__TMPL__/public/assets/images/default-thumbnail.png"
id="thumbnail-preview"
width="135" style="cursor: pointer"/>
</a>
<input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
</div>
</td>
</tr>
</table>
</div>
</div>
</form>
</div>
... ...
... ... @@ -63,6 +63,28 @@
</tr>
</table>
</div>
<div class="col-md-3">
<table class="table table-bordered">
<tr>
<th>分类图片</th>
</tr>
<tr>
<td>
<div style="text-align: center;">
<input type="hidden" name="thumbnail" id="thumbnail" value="{$post.thumbnail|default=''}">
<a href="javascript:uploadOneImage('图片上传','#thumbnail');">
<if condition="empty($post.thumbnail)">
<img src="__TMPL__/public/assets/images/default-thumbnail.png" id="thumbnail-preview" width="135" style="cursor: pointer"/>
<else/>
<img src="{:cmf_get_image_preview_url($post.thumbnail)}" id="thumbnail-preview" width="135" style="cursor: pointer"/>
</if>
</a>
<input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
... ...
... ... @@ -31,6 +31,7 @@
</th>
<th width="80">ID</th>
<th>分类名称</th>
<th>分类图片</th>
<th>创建时间</th>
<th>操作</th>
</tr>
... ... @@ -46,6 +47,15 @@
{$vo.name}
</td>
<td>
<notempty name="vo.thumbnail">
<a href="javascript:parent.imagePreviewDialog('{:cmf_get_image_preview_url($vo.thumbnail)}');">
<i class="fa fa-photo fa-fw"></i>
</a>
<else/>
<i class="fa fa-close fa-fw"></i>
</notempty>
</td>
<td>
{:date('Y-m-d H:i:s',$vo['create_time'])}
</td>
<td>
... ... @@ -65,6 +75,15 @@
{$voo.name}
</td>
<td>
<notempty name="voo.thumbnail">
<a href="javascript:parent.imagePreviewDialog('{:cmf_get_image_preview_url($voo.thumbnail)}');">
<i class="fa fa-photo fa-fw"></i>
</a>
<else/>
<i class="fa fa-close fa-fw"></i>
</notempty>
</td>
<td>
{:date('Y-m-d H:i:s',$voo['create_time'])}
</td>
<td>
... ...
<include file="public@header"/>
<style type="text/css">
.pic-list li {
margin-bottom: 5px;
}
</style>
<script type="text/html" id="photos-item-tpl">
<li id="saved-image{id}">
<input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
<input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
style="width: 200px;" title="图片名称">
<img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
onclick="imagePreviewDialog(this.src);">
<a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
<a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
</li>
</script>
<script type="text/html" id="files-item-tpl">
<li id="saved-file{id}">
<input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
<input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
style="width: 200px;" title="文件名称">
<a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
<a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
<a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
</li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('AdminService/index')}">主要服务列表</a></li>
<li class="active"><a href="#">添加主要服务</a></li>
</ul>
<form action="{:url('AdminService/addPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
<div class="row">
<div class="col-md-9">
<table class="table table-bordered">
<tr>
<th width="150">分类名称<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="name" required placeholder="请输入分类名称"/>
</td>
</tr>
<tr>
<th>分类名称(英文)<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="name_en" required placeholder="请输入分类名称(英文)"/>
</td>
</tr>
<tr>
<th>详情<span class="form-required">*</span></th>
<td>
<script type="text/plain" id="content" name="detail"></script>
</td>
</tr>
<tr>
<th>详情(英文)<span class="form-required">*</span></th>
<td>
<script type="text/plain" id="content_en" name="detail_en"></script>
</td>
</tr>
</table>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
<a class="btn btn-default" href="{:url('AdminService/index')}">{:lang('BACK')}</a>
</div>
</div>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
//编辑器路径定义
var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
$(function () {
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content');
try {
editorcontent.sync();
} catch (err) {
}
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content_en');
try {
editorcontent.sync();
} catch (err) {
}
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
});
</script>
</body>
</html>
... ...
<include file="public@header"/>
<style type="text/css">
.pic-list li {
margin-bottom: 5px;
}
</style>
<script type="text/html" id="photos-item-tpl">
<li id="saved-image{id}">
<input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
<input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
style="width: 200px;" title="图片名称">
<img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
onclick="imagePreviewDialog(this.src);">
<a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
<a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
</li>
</script>
<script type="text/html" id="files-item-tpl">
<li id="saved-file{id}">
<input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
<input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
style="width: 200px;" title="文件名称">
<a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
<a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
<a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
</li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('AdminService/index')}">主要服务列表</a></li>
<li class="active"><a href="#">编辑主要服务</a></li>
</ul>
<form action="{:url('AdminService/editPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
<div class="row">
<div class="col-md-9">
<table class="table table-bordered">
<tr>
<th width="150">分类名称<span class="form-required">*</span></th>
<td>
<input type="hidden" name="id" required value="{$post.id}"/>
<input class="form-control" type="text" name="name" required placeholder="请输入分类名称" value="{$post.name}"/>
</td>
</tr>
<tr>
<th>分类名称(英文)<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="name_en" required placeholder="请输入分类名称(英文)" value="{$post.name_en}"/>
</td>
</tr>
<tr>
<th>详情<span class="form-required">*</span></th>
<td>
<script type="text/plain" id="content" name="detail">{$post.detail}</script>
</td>
</tr>
<tr>
<th>详情(英文)<span class="form-required">*</span></th>
<td>
<script type="text/plain" id="content_en" name="detail_en">{$post.detail_en}</script>
</td>
</tr>
</table>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
<a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
//编辑器路径定义
var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
$(function () {
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content');
try {
editorcontent.sync();
} catch (err) {
}
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content_en');
try {
editorcontent.sync();
} catch (err) {
}
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
});
</script>
</body>
</html>
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="javascript:;">主要服务列表</a></li>
<li><a href="{:url('AdminService/add')}">添加主要服务</a></li>
</ul>
<form class="well form-inline margin-top-20" method="get" action="{:url('AdminService/index')}">
<!--时间:-->
<!--<input type="text" class="form-control js-bootstrap-datetime" name="start_time"-->
<!--value="{$start_time|default=''}"-->
<!--style="width: 140px;" autocomplete="off">- -->
<!--<input type="text" class="form-control js-bootstrap-datetime" name="end_time"-->
<!--value="{$end_time|default=''}"-->
<!--style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;-->
<!--关键字:-->
<!--<input type="text" class="form-control" name="keyword" style="width: 200px;"-->
<!--value="{$keyword|default=''}" placeholder="请输入关键字...">-->
<!--<input type="submit" class="btn btn-primary" value="搜索"/>-->
<!--<a class="btn btn-danger" href="{:url('AdminService/index')}">清空</a>-->
</form>
<form class="js-ajax-form" action="" method="post">
<table class="table table-hover table-bordered table-list">
<thead>
<tr>
<th width="50">
<label>
<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
</label>
</th>
<th width="80">ID</th>
<th>分类名称</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<volist name="list" id="vo">
<tr>
<td>
<input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
value="{$vo.id}" title="ID:{$vo.id}">
</td>
<td>{$vo.id}</td>
<td>
{$vo.name}
</td>
<td>
{:date('Y-m-d H:i:s',$vo['create_time'])}
</td>
<td>
<a class="btn btn-xs btn-primary" href="{:url('AdminService/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
<a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('AdminService/delete',array('id'=>$vo['id']))}">{:lang('DELETE')}</a>
</td>
</tr>
</volist>
</table>
</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
function reloadPage(win) {
win.location.reload();
}
</script>
</body>
</html>
\ No newline at end of file
... ...