Commit ee7ec9fb authored by 章建武's avatar 章建武

dep

parent 37c2c4f5
<?php
/**
* 精品项目控制器
*/
namespace app\admin\controller;
use app\common\model\Attachment;
use think\Request;
use think\Db;
use app\common\model\IndexBanner;
use app\common\validate\IndexBannerValidate;
class BoutiqueController extends Controller
{
//列表
public function index(Request $request, IndexBanner $model)
{
$param = $request->param();
$model = $model->scope('where', $param);
$data = $model->where(['type'=>[5,6,7],'delete_time'=>0])->paginate($this->admin['per_page'], false, ['query' => $request->get()]);
foreach ($data as &$v){
$v['language_type'] = $v['language_type'] === 1 ? '英语' : '中文';
$v['type'] = $this->getCat($v['type']);
$v['created_at'] = date('Y-m-d H:i:s',$v['created_at']);
}
//关键词,排序等赋值
$this->assign($request->get());
$this->assign([
'data' => $data,
'page' => $data->render(),
'total' => $data->total(),
]);
return $this->fetch();
}
//添加
public function add(Request $request, IndexBanner $model)
{
if ($request->isPost()) {
$param = $request->param();
//处理图片
$attachment_avatar = new Attachment;
$pic = $attachment_avatar->uploadMulti('path');
$data = [];
foreach ($pic as $k => $v){
$data[] = [
'path' => $v,
'language_type' => $param['language_type'],
'title' => $param['title'],
'content' => $param['content'],
'created_at' => time(),
'type' => $param['type'],
'url' => 'http://'.$_SERVER['SERVER_NAME'],
'img_title' => $param['img_title'][$k],
];
}
$result = $model->insertAll($data);
$url = URL_BACK;
if (isset($param['_create']) && $param['_create'] == 1) {
$url = URL_RELOAD;
}
return $result ? success('添加成功', $url) : error();
}
$this->assign([
'language_type' => $model->language_type,
'type' => $model->type,
'pic' => 'http://'.$_SERVER['SERVER_NAME'].'/empty.jpg'
]);
return $this->fetch('add');
}
//修改
public function edit($id, Request $request, IndexBanner $model, IndexBannerValidate $validate)
{
$data = $model::get($id);
if ($request->isPost()) {
$param = $request->param();
$validate_result = $validate->scene('edit')->check($param);
if (!$validate_result) {
return error($validate->getError());
}
//处理头像上传
if (!empty($_FILES['path']['name'])) {
$attachment_avatar = new Attachment;
$file_avatar = $attachment_avatar->upload('path');
if ($file_avatar) {
$param['path'] = $file_avatar->url;
}
}
$result = $data->save($param);
return $result ? success() : error();
}
$this->assign([
'data' => $data,
'type' => $model->type,
'language_type' => $model->language_type,
'pic' => 'http://'.$_SERVER['SERVER_NAME'].'/empty.jpg'
]);
return $this->fetch('edit');
}
//删除
public function del($id, IndexBanner $model)
{
if (count($model->noDeletionId) > 0) {
if (is_array($id)) {
if (array_intersect($model->noDeletionId, $id)) {
return error('ID为' . implode(',', $model->noDeletionId) . '的数据无法删除');
}
} else if (in_array($id, $model->noDeletionId)) {
return error('ID为' . $id . '的数据无法删除');
}
}
if ($model->softDelete) {
$result = $model->whereIn('id', $id)->update(['delete_time'=>time()]);
} else {
$result = $model->whereIn('id', $id)->update(['delete_time'=>time()]);
}
return $result ? success('操作成功', URL_RELOAD) : error();
}
protected function getCat($type){
if($type == 5){
return '空间景观';
}elseif($type == 6){
return '活动运营';
}elseif($type == 7){
return '艺术街区';
}
}
}
{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
<style>
.form-pic span input
{
position: absolute;
left: 0;
bottom: 0;
width: 100px;
height: 100px;
opacity: 0;
cursor: pointer;
}
.form-pic span {
position: relative;
margin-left: 10px;
display: inline-block;
width: 100px;
height: 100px;
}
.form-pic img {
width: 100px;
height: 100px;
}
</style>
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<!-- 表单头部 -->
<div class="box-header with-border">
<div class="btn-group">
<a class="btn flat btn-sm btn-default BackButton">
<i class="fa fa-arrow-left"></i>
返回
</a>
</div>
</div>
<!-- 表单 -->
<form id="dataForm" class="form-horizontal dataForm" action="" method="post"
enctype="multipart/form-data">
<!-- 表单字段区域 -->
<div class="box-body">
<div class="form-group">
<label for="language_type" class="col-sm-2 control-label">选择语言</label>
<div class="col-sm-10 col-md-4">
<select name="language_type" id="language_type" class="form-control select2">
{foreach name='language_type' item='item' }
<option value="{$key}" {if isset($data) && $data.language_type==$key}selected{/if}>
{$item}
</option>
{/foreach}
</select>
</div>
</div>
<script>
$('#language_type').select2();
</script>
<div class="form-group">
<label for="type" class="col-sm-2 control-label">图片分类</label>
<div class="col-sm-10 col-md-4">
<select name="type" id="type" class="form-control select2">
{foreach name='type' item='item'}
<option value="{$key}" {if isset($data) &&
$data.type==$key}selected{/if}>
{$item}
</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label for="mobile" class="col-sm-2 control-label">标题</label>
<div class="col-sm-10 col-md-4">
<input id="mobile" name="title" value="{$data.manager_position|default=''}" placeholder="请输入标题"
type="text" maxlength="50" class="form-control field-mobile">
</div>
</div>
<div class="form-group">
<label for="nickname" class="col-sm-2 control-label">文章</label>
<div class="col-sm-10 col-md-4">
<input id="nickname" name="content" placeholder="请输入内容" type="text" class="form-control field-text">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">图片</label>
<a class="btn btn-sm btn-info add_people" style="margin-left: 15px;">添加图片</a>
<div class="row repair_people" style="display:none;margin: 15px;">
</div>
</div>
</div>
<!-- 表单底部 -->
<div class="box-footer">
{:token()}
<div class="col-sm-2">
</div>
<div class="col-sm-10 col-md-4">
{if !isset($data)}
<div class="btn-group pull-right">
<label class="createContinue">
<input type="checkbox" value="1" id="_create" name="_create"
title="继续添加数据">继续添加</label>
</div>
{/if}
<div class="btn-group">
<button type="submit" class="btn flat btn-info dataFormSubmit">
保存
</button>
</div>
<div class="btn-group">
<button type="reset" class="btn flat btn-default dataFormReset">
重置
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<!--预览图片-->
<script type="text/javascript">
$(document).on('change','.form-pic .inp',function(event){
event.stopPropagation();
if ($(this).get(0).files[0]) {
var src=window.URL.createObjectURL($(this).get(0).files[0]);
var dom = $(this).get(0);
var fileSize = dom.files[0].size;
if(fileSize>5120000){
alert('上传的图片不能超过5M');
$(this).val('');
$(this).prev().attr('src','');
return false;
}
if(src!=null){
$(this).prev().attr('src',src);
}
} else {
$(this).prev().attr('src',$(this).prev().data('ori'));
}
});
</script>
<!--施工团队-->
<script>
var j=-1;
$('body').delegate('.p_del','click',function(){
j--;
var num = $(this).data('id');
var str_confirm = confirm('你确定删除当前的内容?');
if(str_confirm){
$('.team_'+num).remove();
}
});
$(function(){
$('body').delegate('.add_people','click',function(){
j++;
$(".repair_people").css('display','block');
var str =
'<div class="row team_'+j+'" style="padding-left:15px;">'+
'<div class="form-group">'+
'<label class="col-sm-2 control-label" >图片标题</label>'+
'<input class="" name="img_title[]" maxlength="20" required="required" style="width:300px;margin-left:12px;"value="" type="text"/>'+
'<span class="btn btn-sm btn-danger p_del" data-id="'+j+'" style="margin-left: 10px;">删除</span>'+
'</div>'+
'<div class="form-group" style="padding-left:10px;">'+
'<div class="form-group">'+
'<label class="col-sm-2 control-label">图片</label>'+
'<div class="form-group form-pic">'+
'<span>'+
'<img class="hall_pic" data-ori="" src="{$pic}">'+
'<input class="inp" type="file" name="path[]">'+
'</span>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
$('.repair_people').prepend(str);
})
});
</script>
<script>
/** 表单验证 **/
$('#dataForm').validate({
rules: {
'user_level_id': {
required: true,
},
},
messages: {
'user_level_id': {
required: "用户等级不能为空",
},
}
});
</script>
{/block}
\ No newline at end of file
{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
<style>
.form-pic span input
{
position: absolute;
left: 0;
bottom: 0;
width: 100px;
height: 100px;
opacity: 0;
cursor: pointer;
}
.form-pic span {
position: relative;
margin-left: 10px;
display: inline-block;
width: 100px;
height: 100px;
}
.form-pic img {
width: 100px;
height: 100px;
}
</style>
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<!-- 表单头部 -->
<div class="box-header with-border">
<div class="btn-group">
<a class="btn flat btn-sm btn-default BackButton">
<i class="fa fa-arrow-left"></i>
返回
</a>
</div>
</div>
<!-- 表单 -->
<form id="dataForm" class="form-horizontal dataForm" action="" method="post"
enctype="multipart/form-data">
<!-- 表单字段区域 -->
<div class="box-body">
<div class="form-group">
<label for="language_type" class="col-sm-2 control-label">选择语言</label>
<div class="col-sm-10 col-md-4">
<select name="language_type" id="language_type" class="form-control select2">
{foreach name='language_type' item='item' }
<option value="{$key}" {if isset($data) && $data.language_type==$key}selected{/if}>
{$item}
</option>
{/foreach}
</select>
</div>
</div>
<script>
$('#language_type').select2();
</script>
<div class="form-group">
<label for="type" class="col-sm-2 control-label">图片分类</label>
<div class="col-sm-10 col-md-4">
<select name="type" id="type" class="form-control select2">
{foreach name='type' item='item'}
<option value="{$key}" {if isset($data) &&
$data.type==$key}selected{/if}>
{$item}
</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label for="mobile" class="col-sm-2 control-label">标题</label>
<div class="col-sm-10 col-md-4">
<input id="mobile" name="title" value="{$data.title|default=''}" placeholder="请输入标题"
type="text" maxlength="50" class="form-control field-mobile">
</div>
</div>
<div class="form-group">
<label for="nickname" class="col-sm-2 control-label">文章</label>
<div class="col-sm-10 col-md-4">
<input id="nickname" name="content" placeholder="请输入内容" value="{$data.content}" type="text" class="form-control field-text">
</div>
</div>
<div class="form-group">
<!--<label class="col-sm-2 control-label">图片</label>-->
<!--<a class="btn btn-sm btn-info add_people" style="margin-left: 15px;">添加图片</a>-->
<div class="row repair_people" style="margin: 15px;">
<div class="row team_'+j+'" style="padding-left:15px;">
<div class="form-group">
<label class="col-sm-2 control-label" >图片标题</label>
<input class="" name="img_title" maxlength="10" value="{$data.img_title}" required="required" style="width:525px;margin-left:12px;"value="" type="text"/>
</div>
<div class="form-group" style="padding-left:10px;">
<div class="form-group">
<label class="col-sm-2 control-label">图片</label>
<div class="form-group form-pic">
<span>
<img class="hall_pic" data-ori="" src="{$data.path}">
<input class="inp" type="file" name="path">
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 表单底部 -->
<div class="box-footer">
{:token()}
<div class="col-sm-2">
</div>
<div class="col-sm-10 col-md-4">
{if !isset($data)}
<div class="btn-group pull-right">
<label class="createContinue">
<input type="checkbox" value="1" id="_create" name="_create"
title="继续添加数据">继续添加</label>
</div>
{/if}
<div class="btn-group">
<button type="submit" class="btn flat btn-info dataFormSubmit">
保存
</button>
</div>
<div class="btn-group">
<button type="reset" class="btn flat btn-default dataFormReset">
重置
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<!--预览图片-->
<script type="text/javascript">
$(document).on('change','.form-pic .inp',function(event){
event.stopPropagation();
if ($(this).get(0).files[0]) {
var src=window.URL.createObjectURL($(this).get(0).files[0]);
var dom = $(this).get(0);
var fileSize = dom.files[0].size;
if(fileSize>5120000){
alert('上传的图片不能超过5M');
$(this).val('');
$(this).prev().attr('src','');
return false;
}
if(src!=null){
$(this).prev().attr('src',src);
}
} else {
$(this).prev().attr('src',$(this).prev().data('ori'));
}
});
</script>
<!--施工团队-->
<script>
var j=-1;
$('body').delegate('.p_del','click',function(){
j--;
var num = $(this).data('id');
var str_confirm = confirm('你确定删除当前的内容?');
if(str_confirm){
$('.team_'+num).remove();
}
});
$(function(){
$('body').delegate('.add_people','click',function(){
j++;
$(".repair_people").css('display','block');
var str =
'<div class="row team_'+j+'" style="padding-left:15px;">'+
'<div class="form-group">'+
'<label class="col-sm-2 control-label" >图片标题</label>'+
'<input class="" name="img_title[]" maxlength="10" required="required" style="width:300px;margin-left:12px;"value="" type="text"/>'+
'<span class="btn btn-sm btn-danger p_del" data-id="'+j+'" style="margin-left: 10px;">删除</span>'+
'</div>'+
'<div class="form-group" style="padding-left:10px;">'+
'<div class="form-group">'+
'<label class="col-sm-2 control-label">图片</label>'+
'<div class="form-group form-pic">'+
'<span>'+
'<img class="hall_pic" data-ori="" src="{$pic}">'+
'<input class="inp" type="file" name="path[]">'+
'</span>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
$('.repair_people').prepend(str);
})
});
</script>
<script>
/** 表单验证 **/
$('#dataForm').validate({
rules: {
'user_level_id': {
required: true,
},
},
messages: {
'user_level_id': {
required: "用户等级不能为空",
},
}
});
</script>
{/block}
\ No newline at end of file
{extend name="public/base" /}
{block name='content'}
{include file='public/content_header' /}
<!--数据列表页面-->
<section class="content">
<!--顶部搜索筛选-->
<div class="row">
<div class="col-md-12">
<div class="box">
<div class="box-body">
<form class="form-inline searchForm" id="searchForm" action="{:url('index')}" method="GET">
<div class="form-group">
<input value="{$_keywords ? $_keywords : '' ;}"
name="_keywords" id="_keywords" class="form-control input-sm"
placeholder="图片标题">
</div>
<div class="form-group">
<select name="_by" id="_by" class="form-control input-sm index-order">
<option value="">排序方式</option>
<option value="desc" {if isset($_by) && $_by=='desc'}selected{/if}>倒序</option>
<option value="asc" {if isset($_by) && $_by=='asc'}selected{/if}>正序</option>
</select>
</div>
<script>
$('#_order').select2();
$('#_by').select2();
</script>
<div class="form-group">
<button class="btn btn-sm btn-primary" type="submit"><i class="fa fa-search"></i> 查询
</button>
</div>
<!--<div class="form-group">-->
<!--<button onclick="exportData()" class="btn btn-sm btn-warning exportData" type="button"><i-->
<!--class="fa fa-search"></i> 导出-->
<!--</button>-->
<!--</div>-->
<div class="form-group">
<button onclick="clearSearchForm()" class="btn btn-sm btn-default" type="button"><i
class="fa fa-eraser"></i> 清空查询
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="box">
<!--数据列表顶部-->
<div class="box-header">
<div>
<a title="添加" data-toggle="tooltip" class="btn btn-primary btn-sm add" href="{:url('add')}">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-danger btn-sm AjaxButton" data-toggle="tooltip" title="删除选中数据"
data-confirm-title="删除确认" data-confirm-content="您确定要删除选中的数据吗?" data-id="checked"
data-url="{:url('del')}">
<i class="fa fa-trash"></i> 删除
</a>
<!--<a class="btn btn-success btn-sm AjaxButton" data-toggle="tooltip" title="启用选中数据"-->
<!--data-confirm-title="启用确认" data-confirm-content="您确定要启用选中的数据吗?" data-id="checked"-->
<!--data-url="{:url('enable')}">-->
<!--<i class="fa fa-circle"></i> 启用-->
<!--</a>-->
<!--<a class="btn btn-warning btn-sm AjaxButton" data-toggle="tooltip" title="禁用选中数据"-->
<!--data-confirm-title="禁用确认" data-confirm-content="您确定要禁用选中的数据吗?" data-id="checked"-->
<!--data-url="{:url('disable')}">-->
<!--<i class="fa fa-circle"></i> 禁用-->
<!--</a>-->
<a class="btn btn-success btn-sm ReloadButton" data-toggle="tooltip" title="刷新">
<i class="fa fa-refresh"></i> 刷新
</a>
</div>
</div>
<div class="box-body table-responsive">
<table class="table table-hover table-bordered datatable" width="100%">
<thead>
<tr>
<th>
<input id="dataCheckAll" type="checkbox" onclick="checkAll(this)" class="checkbox"
placeholder="全选/取消">
</th>
<th>ID</th>
<th>图片</th>
<th>图片标题</th>
<th>分类</th>
<th>语言</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{foreach name="data" id="item"}
<tr>
<td>
<input type="checkbox" onclick="checkThis(this)" name="data-checkbox"
data-id="{$item.id}" class="checkbox data-list-check" value="{$item.id}"
placeholder="选择/取消">
</td>
<td>{$item.id}</td>
<td><img style="max-width: 60px" src="{$item.path}"></td>
<td>{$item.img_title}</td>
<td>{$item.type}</td>
<td>{$item.language_type}</td>
<td>{$item.created_at}</td>
<td class="td-do">
<a href="{:url('edit',['id'=>$item.id])}"
class="btn btn-primary btn-xs" title="修改" data-toggle="tooltip">
<i class="fa fa-pencil"></i>
</a>
<a class="btn btn-danger btn-xs AjaxButton" data-toggle="tooltip" title="删除"
data-id="{$item.id}" data-confirm-title="删除确认"
data-confirm-content='您确定要删除ID为 <span class="text-red">{$item.id}</span> 的数据吗'
data-url="{:url('del')}">
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
<!-- 数据列表底部 -->
<div class="box-footer">
{$page|raw}
<label class="control-label pull-right" style="margin-right: 10px; font-weight: 100;">
<small>共{$total}条记录</small>&nbsp;
<small>每页显示</small>
&nbsp;
<select class="input-sm" onchange="changePerPage(this)">
<option value="10" {if $admin.per_page==10}selected{/if}>10</option>
<option value="20" {if $admin.per_page==20}selected{/if}>20</option>
<option value="30" {if $admin.per_page==30}selected{/if}>30</option>
<option value="50" {if $admin.per_page==50}selected{/if}>50</option>
<option value="100" {if $admin.per_page==100}selected{/if}>100</option>
</select>
&nbsp;
<small>条记录</small>
</label>
</div>
</div>
</div>
</div>
</section>
{/block}
<?php
/**
* 图片模型
*/
namespace app\common\model;
class IndexBanner extends Model
{
protected $name = 'index_banner';
//可搜索字段
protected $searchField = ['img_title'];
public $language_type = [
0 => '中文',
1 => '英语'
];
public $type = [
5 => '空间景观',
6 => '活动运营',
7 => '艺术街区',
];
}
<?php
/**
* 精品项目验证器
*/
namespace app\common\validate;
class IndexBannerValidate extends Validate
{
protected $rule = [
'title|标题' => 'require',
'content|职位' => 'require',
'img_title|图片标题' => 'require',
];
protected $message = [
'title.require' => '标题不能为空',
'content.require' => '文章不能为空',
'img_title.require' => '图片标题不能为空',
];
protected $scene = [
'add' => ['path', 'language_type', 'title','content',],
'edit' => ['path', 'language_type', 'title','content',],
];
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment