作者 sgj
1 个管道 的构建 通过 耗费 1 秒

修改级别bug

... ... @@ -8,6 +8,7 @@
namespace api\index\controller;
use api\index\model\ActivityModel;
use api\index\model\ActivityNewsModel;
use api\index\model\ActivityType;
use api\index\model\ActivityTypeModel;
use api\index\model\JoinModel;
... ... @@ -52,11 +53,10 @@ class IndexController extends RestBaseController
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
* @return begin:最近开始的活动@
* @return news:活动新闻@
* @begin id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
*
*
*
* @return volunteer_page:志愿者下一页
* @return activity_page:活动下一页
*/
... ... @@ -71,10 +71,12 @@ class IndexController extends RestBaseController
$volunteer = $volunteerModel->selectData($volunteer_page,$volunteer_pageNum,array('status'=>2));
//活动
$activityModel = new ActivityModel();
$activity = $activityModel->selectData($activity_page,$activity_pageNum);
$beginAtOnce = $activityModel->beginAtOnce($activity_page,$activity_pageNum);
$activity = $activityModel->selectData($activity_page,$activity_pageNum);
// $beginAtOnce = $activityModel->beginAtOnce($activity_page,$activity_pageNum);
//即将开始的活动
$activityNewsModel = new ActivityNewsModel();
$news = $activityNewsModel->selectData($activity_page,$activity_pageNum);
//幻灯片
$slideItemModel = new SlideItemModel();
... ... @@ -82,7 +84,7 @@ class IndexController extends RestBaseController
$data['slide'] = $slide;
$data['volunteer'] = $volunteer;
$data['activity'] = $activity;
$data['begin'] = $beginAtOnce;
$data['news'] = $news;
$data['volunteer_page'] = $volunteer_page+1;
$data['activity_page'] = $activity_page+1;
$this->success('获取成功!',$data);
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 13:47
*/
namespace api\index\model;
use think\Model;
class ActivityNewsModel extends Model
{
/**
* thumbnail 自动转化
* @param $value
* @return array
*/
public function getThumbnailAttr($value)
{
return cmf_get_image_url($value);
}
/**
* time 自动转化
* @param $value
* @return array
*/
public function getTimeAttr($value)
{
return date('Y-m-d',$value);
}
/**
* content 自动转化
* @param $value
* @return array
*/
public function getContentAttr($value)
{
return cmf_replace_content_file_url(htmlspecialchars_decode($value));
}
public function selectData($page,$pageNum){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['is_up'] = ['eq',1];
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->limit(($page * $pageNum),$pageNum)
->order($order)
->select()
->toArray();
return $data;
}
public function selectCityData($city_id){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
if (!empty($city_id)){
$where['a.position_id'] = $city_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
return $data;
}
public function selectTypeData($type_id){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
if (!empty($type_id)){
$where['a.activity_type'] = $type_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
/**
* 即将开始的活动
* @param $page
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function beginAtOnce($page,$pageNum){
$now=time();
$map['a.create_time']=['<',$now];
$map['a.delete_time'] = ['eq',0];
if ($page<=0){
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit('2')
->select()->toArray();
}else{
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit(($page * $pageNum),$pageNum)
->select()->toArray();
}
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -52,6 +52,40 @@ class ActivityController extends AdminBaseController
$this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
return $this->fetch();
}
public function news(){
$where=[];
$param = $this->request->param();
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
if (!empty($startTime) && !empty($endTime)) {
$where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
} else {
if (!empty($startTime)) {
$where['create_time'] = ['>= time', $startTime];
}
if (!empty($endTime)) {
$where['create_time'] = ['<= time', $endTime];
}
}
$keyword = empty($param['keyword']) ? '' : $param['keyword'];
if (!empty($keyword)) {
$where['activity_name|abstract'] = ['like', "%$keyword%"];
}
$data=Db::name('activity_news')
->where('delete_time',0)
->where($where)
->order('create_time desc')
->paginate(10);
$data->appends($param);
$this->assign([
'data'=>$data,
'page'=>$data->render(),
]);
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
$this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
return $this->fetch();
}
//编辑
public function edit(){
$id=$this->request->param('id', 0, 'intval');
... ... @@ -107,6 +141,60 @@ class ActivityController extends AdminBaseController
return $this->fetch();
}
}
public function editNews(){
$id=$this->request->param('id', 0, 'intval');
if($this->request->isPost()){
$param=$this->request->param();
$param['time'] = strtotime($param['time']);
$param['update_time'] = time();
$validate = new Validate([
'activity_name' => 'require',
'abstract'=>'require',
'content'=>'require',
'time' => 'require',
'thumbnail'=>'require',
]);
$validate->message([
'activity_name'=>'标题不能为空!',
'abstract'=>'摘要不能为空!',
'content' => '内容不能为空!',
'time' => '时间不能为空!',
'thumbnail'=>'请上传缩略图!',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
if(empty($param['is_up'])){
$param['is_up']=0;
}
Db::name('activity_news')
->where('id',$id)
->update($param);
$this->success('更新成功!');
}else{
$data=Db::name('activity_news')
->where('id',$id)
->find();
$activity_type=\db('activity_type')->select()->toArray();
foreach ($activity_type as $k=>$v){
$activity[$v['id']]['type_name']=$v['type_name'];
$activity[$v['id']]['id']=$v['id'];
}
$provincedb=db('position_province')->select()->toArray();
foreach ($provincedb as $k=>$v){
$province[$v['id']]['name']=$v['province_name'];
$province[$v['id']]['id']=$v['id'];
}
//dump($province);
$this->assign([
'data'=>$data,
'type'=>$activity,
'area'=>$province,
]);
return $this->fetch();
}
}
//添加
public function add(){
if($this->request->isPost()){
... ... @@ -156,6 +244,55 @@ class ActivityController extends AdminBaseController
return $this->fetch();
}
}
public function addNews(){
if($this->request->isPost()){
$param=$this->request->param();
$param['create_time']=time();
$param['update_time']=time();
$param['time']=strtotime($param['time']);
$validate = new Validate([
'activity_name' => 'require',
'abstract'=>'require',
'content'=>'require',
'time' => 'require',
'thumbnail'=>'require',
]);
$validate->message([
'activity_name'=>'标题不能为空!',
'abstract'=>'摘要不能为空!',
'content' => '内容不能为空!',
'time' => '时间不能为空!',
'thumbnail'=>'请上传缩略图!',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
if(empty($param['is_up'])){
$param['is_up']=0;
}
Db::name('activity_news')
->insert($param);
$this->success('添加成功!');
}else{
$activity_type=\db('activity_type')->select()->toArray();
foreach ($activity_type as $k=>$v){
$activity[$v['id']]['type_name']=$v['type_name'];
$activity[$v['id']]['id']=$v['id'];
}
$provincedb=db('position_province')->select()->toArray();
foreach ($provincedb as $k=>$v){
$province[$v['id']]['name']=$v['province_name'];
$province[$v['id']]['id']=$v['id'];
}
$this->assign([
'type'=>$activity,
'area'=>$province,
]);
return $this->fetch();
}
}
//删除
public function delete(){
$param = $this->request->param();
... ... @@ -185,6 +322,34 @@ class ActivityController extends AdminBaseController
}
}
}
public function deleteNews(){
$param = $this->request->param();
if (isset($param['id'])) {
$id = $this->request->param('id', 0, 'intval');
$resultPortal = Db::name('activity')
->where(['id' => $id])
->update(['delete_time' => time()]);
if($resultPortal){
$this->success("删除成功!", '');
}else{
$this->error("删除失败!", '');
}
}
if (isset($param['ids'])) {
$ids = $this->request->param('ids/a');
$result = Db::name('activity')
->where(['id' => ['in', $ids]])
->update(['delete_time' => time()]);
if ($result) {
$this->success("删除成功!", '');
}else{
$this->error("删除失败!", '');
}
}
}
//排序
public function sort(){
$ids=$this->request->param('sort/a');
... ...
<include file="public@header"/>
</head>
<body>
<!--<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>-->
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('activity/news')}">新闻列表</a></li>
<li class="active"><a href="{:url('activity/addNews')}">添加新闻</a></li>
</ul>
<form action="{:url('activity/addNews')}" 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="100">标题(限20字)<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="activity_name"
id="title" value="" placeholder="请输入标题"/>
</td>
</tr>
<tr>
<th width="100">摘要(限255字)<span class="form-required">*</span></th>
<td>
<textarea class="form-control" name="abstract"
id="abstract" placeholder="请输入摘要"></textarea>
</td>
</tr>
<tr>
<th width="100">内容<span class="form-required">*</span></th>
<td>
<script type="text/plain" id="content" name="content"></script>
</td>
</tr>
<!--<tr>-->
<!--<th>相册</th>-->
<!--<td>-->
<!--<ul id="photos" class="pic-list list-unstyled form-inline">-->
<!--</ul>-->
<!--<a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"-->
<!--class="btn btn-sm btn-default">选择图片</a>-->
<!--</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="javascript:history.back(-1);">{:lang('BACK')}</a>
</div>
</div>
</div>
<div class="col-md-3">
<table class="table table-bordered">
<tr>
<th>缩略图<span class="form-required">(335px*220px)</span></th>
</tr>
<tr>
<td>
<div style="text-align: center;">
<input type="hidden" name="thumbnail" id="thumbnail"
value="{$data.thumbnail|default=''}">
<a href="javascript:uploadOneImage('image upload','#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>
<tr>
<th><b>发布时间</b></th>
</tr>
<tr>
<td>
<input class="form-control js-bootstrap-date" type="text" name="time"
value="{:date('Y-m-d',time())}">
</td>
</tr>
<tr>
<th>状态</th>
</tr>
<tr>
<td>
<div class="checkbox">
<label><input type="checkbox" name="is_up" value="1" checked>发布</label>
</div>
</td>
</tr>
<tr>
<th>活动类型</th>
</tr>
<tr>
<td>
<select class="form-control" name="activity_type" id="more-template-select">
<foreach name="type" item="vo">
<option value="{$vo.id}">{$vo.type_name}</option>
</foreach>
</select>
</td>
</tr>
<tr>
<th>活动区域</th>
</tr>
<tr>
<td>
<select class="form-control" name="position_id" id="more-template-select">
<foreach name="area" item="vo">
<option value="{$vo.id}">{$vo.name}</option>
</foreach>
</select>
</td>
</tr>
</table>
</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) {
}
$('.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>
<!--<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>-->
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('activity/news')}">新闻列表</a></li>
<li>
<a href="{:url('activity/addNews')}">添加新闻</a>
</li>
<li class="active"><a href="#">编辑新闻</a></li>
</ul>
<form action="{:url('activity/editNews')}" 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="100">标题(限20字)<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="activity_name"
id="title" value="{$data.activity_name}" placeholder="请输入标题"/>
<input type="hidden" name="id" value="{$data.id}">
</td>
</tr>
<tr>
<th width="100">摘要(限255字)<span class="form-required">*</span></th>
<td>
<textarea class="form-control" name="abstract"
id="abstract" placeholder="请输入摘要">{$data.abstract}</textarea>
</td>
</tr>
<tr>
<th width="100">内容<span class="form-required">*</span></th>
<td>
<script type="text/plain" id="content" name="content">{:cmf_replace_content_file_url(htmlspecialchars_decode($data.content))}</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('SAVE')}</button>
<a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
</div>
</div>
</div>
<div class="col-md-3">
<table class="table table-bordered">
<tr>
<th>缩略图<span class="form-required">(335px*220px)</span></th>
</tr>
<tr>
<td>
<div style="text-align: center;">
<input type="hidden" name="thumbnail" id="thumbnail"
value="{$data.thumbnail|default=''}">
<a href="javascript:uploadOneImage('image upload','#thumbnail');">
<if condition="empty($data['thumbnail'])">
<img src="__TMPL__/public/assets/images/default-thumbnail.png"
id="thumbnail-preview"
width="135" style="cursor: pointer"/>
<else/>
<img src="{:cmf_get_image_url($data.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>
<tr>
<th><b>发布时间</b></th>
</tr>
<tr>
<td>
<input class="form-control js-bootstrap-date" type="text" name="time"
value="{:date('Y-m-d',$data.time)}">
</td>
</tr>
<tr>
<th>状态</th>
</tr>
<tr>
<td>
<div class="checkbox">
<label><input type="checkbox" name="is_up" value="1" <eq name="$data.is_up" value="1">checked</eq> >发布</label>
</div>
</td>
</tr>
<tr>
<th>活动类型</th>
</tr>
<tr>
<td>
<select class="form-control" name="activity_type" id="more-template-select">
<option value="{$data['activity_type']|default=''}">
{$type[$data['activity_type']]['type_name']|default=''}</option>
<foreach name="type" item="vo">
<option value="{$vo.id}">{$vo.type_name}</option>
</foreach>
</select>
</td>
</tr>
<tr>
<th>活动区域</th>
</tr>
<tr>
<td>
<select class="form-control" name="position_id" id="more-template-select">
<option value="{$data['position_id']|default=''}">
{$area[$data['position_id']]['name']|default=''}</option>
<foreach name="area" item="vo">
<option value="{$vo.id}">{$vo.name}</option>
</foreach>
</select>
</td>
</tr>
</table>
</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) {
}
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
$('.btn-cancel-thumbnail1').click(function () {
$('#thumbnail-preview1').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail1').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="{:url('activity/news')}">新闻列表</a></li>
<li><a href="{:url('activity/addNews')}">添加新闻</a></li>
</ul>
<!-- <form class="well form-inline margin-top-20" method="post" action="{:url('activity/index')}">
关键字:
<input type="text" class="form-control" name="keyword" style="width: 150px;" value="{$keyword|default=''}" placeholder="请输入关键字">
<input type="submit" class="btn btn-primary" value="搜索" />
<a class="btn btn-danger" href="{:url('activity/index')}">清空</a>
</form>-->
<form class="js-ajax-form" action="" method="post">
<table class="table table-hover table-bordered">
<div class="table-actions">
<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
data-action="{:url('activity/publish',array('yes'=>1))}" data-subcheck="true">发布
</button>
<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
data-action="{:url('activity/publish',array('no'=>1))}" data-subcheck="true">取消发布
</button>
<button class="btn btn-danger btn-sm js-ajax-submit"
data-action="{:url('activity/delete')}" data-subcheck="true" data-msg="你确定删除吗?">
{:lang('DELETE')}
</button>
</div>
<thead>
<tr>
<th width="15">
<label>
<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
</label>
</th>
<th width="20">ID</th>
<th width="50">标题</th>
<th width="20">缩略图</th>
<th width="20">摘要</th>
<th width="30">创建时间</th>
<th width="30">更新时间</th>
<th width="30">发布时间</th>
<th width="30">状态</th>
<th width="100">操作</th>
</tr>
</thead>
<tbody>
<foreach name="data" item="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.activity_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>
</notempty>
</td>
<td>{$vo.abstract}</td>
<!--<td>{:cmf_replace_content_file_url(htmlspecialchars_decode($vo.content))}</td>-->
<td>{:date('Y-m-d H:i:s',$vo['create_time'])}</td>
<td>{:date('Y-m-d H:i:s',$vo['update_time'])}</td>
<td>{:date('Y-m-d',$vo['time'])}</td>
<td>
<notempty name="vo.is_up">
<a data-toggle="tooltip" title="已发布"><i class="fa fa-check"></i></a>
<else/>
<a data-toggle="tooltip" title="未发布"><i class="fa fa-close"></i></a>
</notempty>
</td>
<td>
<a href='{:url("activity/editNews",array("id"=>$vo["id"]))}'>{:lang('EDIT')}</a>|
<a class="js-ajax-delete" href="{:url('activity/deleteNews',array('id'=>$vo['id']))}">{:lang('DELETE')}</a>
<!--<a href="{:url('activity/join',array('id'=>$vo['id']))}">查看参加人员</a>-->
</td>
</tr>
</foreach>
</tbody>
</table>
<div class="pagination">{$page}</div>
</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
... ...