问答新增/编辑

This commit is contained in:
gongfuxiang 2019-03-31 01:22:56 +08:00
parent 8e5b4d76f1
commit e9f54dc779
8 changed files with 173 additions and 17 deletions

View File

@ -92,6 +92,67 @@ class Answer extends Common
return $this->fetch();
}
/**
* [SaveInfo 添加/编辑页面]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-14T21:37:02+0800
*/
public function SaveInfo()
{
// 参数
$params = input();
// 数据
$data = [];
if(!empty($params['id']))
{
// 获取列表
$data_params = array(
'm' => 0,
'n' => 1,
'where' => ['id'=>intval($params['id'])],
'field' => '*',
);
$ret = AnswerService::AnswerList($data_params);
$data = empty($ret['data'][0]) ? [] : $ret['data'][0];
}
$this->assign('data', $data);
// 状态
$this->assign('common_is_show_list', lang('common_is_show_list'));
// 是否
$this->assign('common_is_text_list', lang('common_is_text_list'));
// 参数
unset($params['id']);
$this->assign('params', $params);
return $this->fetch();
}
/**
* [Save 保存]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-25T22:36:12+0800
*/
public function Save()
{
// 是否ajax请求
if(!IS_AJAX)
{
return $this->error('非法访问');
}
// 开始处理
$params = input();
return AnswerService::AnswerSave($params);
}
/**
* 问答删除
* @author Devil

View File

@ -39,6 +39,12 @@
</form>
<!-- form end -->
<!-- operation start -->
<div class="am-g m-t-15">
<a href="{{:MyUrl('admin/answer/saveinfo')}}" class="am-btn am-btn-secondary am-radius am-btn-xs am-icon-plus"> 新增</a>
</div>
<!-- operation end -->
<!-- list start -->
<table class="am-table am-table-striped am-table-hover am-text-middle m-t-10">
<thead>
@ -93,7 +99,7 @@
<td>{{$v.title}}</td>
<td class="am-hide-sm-only reply-content">{{$v.content}}</td>
<td class="am-hide-sm-only reply-content">
{{if $v['is_reply'] eq 1}}
{{if !empty($v['reply'])}}
{{$v.reply}}
{{else /}}
<span class="cr-ddd">未回复</span>
@ -161,7 +167,7 @@
<dt>回复内容</dt>
<dd>
{{if $v['is_reply'] eq 1}}
{{if !empty($v['reply'])}}
{{$v.reply}}
{{else /}}
<span class="cr-ddd">未回复</span>
@ -182,8 +188,11 @@
</div>
</td>
<td class="view-operation">
<a href="{{:MyUrl('admin/answer/saveinfo', array_merge($params, ['id'=>$v['id']]))}}">
<button class="am-btn am-btn-secondary am-btn-xs am-radius am-icon-edit"> 编辑</button>
</a>
{{if $v['is_reply'] eq 0}}
<button class="am-btn am-btn-secondary am-btn-xs am-radius submit-reply am-icon-gavel" data-am-modal="{target: '#my-popup-reply'}" data-json='{{:json_encode($v)}}'> 回复</button>
<button class="am-btn am-btn-success am-btn-xs am-radius submit-reply am-icon-gavel" data-am-modal="{target: '#my-popup-reply'}" data-json='{{:json_encode($v)}}'> 回复</button>
{{/if}}
<button class="am-btn am-btn-danger am-btn-xs am-radius am-icon-trash-o submit-delete" data-url="{{:MyUrl('admin/answer/delete')}}" data-id="{{$v.id}}"> 删除</button>
</td>

View File

@ -0,0 +1,66 @@
{{include file="public/header" /}}
<!-- right content start -->
<div class="content-right">
<div class="content">
<!-- form start -->
<form class="am-form form-validation view-save" action="{{:MyUrl('admin/answer/save')}}" method="POST" request-type="ajax-url" request-value="{{:MyUrl('admin/answer/index', $params)}}" enctype="multipart/form-data">
<legend>
<span class="fs-16">
{{if empty($data['id'])}}
问答添加
{{else /}}
问答编辑
{{/if}}
</span>
<a href="{{:MyUrl('admin/answer/index', $params)}}" class="fr fs-14 m-t-5 am-icon-mail-reply"> 返回</a>
</legend>
<div class="am-form-group">
<label>联系人</label>
<input type="text" name="name" placeholder="联系人" maxlength="30" data-validation-message="联系人格式最多 30 个字符" class="am-radius" value="{{if !empty($data['name'])}}{{$data.name}}{{/if}}" />
</div>
<div class="am-form-group">
<label>电话</label>
<input type="text" name="tel" placeholder="电话" data-validation-message="请填写电话" class="am-radius" value="{{if !empty($data['tel'])}}{{$data.tel}}{{/if}}" />
</div>
<div class="am-form-group">
<label>标题</label>
<input type="text" name="title" placeholder="标题" maxlength="60" data-validation-message="标题格式最多 60 个字符" class="am-radius" value="{{if !empty($data['title'])}}{{$data.title}}{{/if}}" />
</div>
<div class="am-form-group">
<label>访问次数</label>
<input type="number" name="access_count" placeholder="访问次数" data-validation-message="请填写有效的访问次数" class="am-radius" value="{{if !empty($data['access_count'])}}{{$data.access_count}}{{else /}}0{{/if}}" />
</div>
<div class="am-form-group">
<label>内容<span class="am-form-group-label-tips-must">必填</span></label>
<textarea class="am-radius am-validate" name="content" rows="5" minlength="5" maxlength="230" placeholder="5~230个字符之间" data-validation-message="内容格式 5~230 个字符之间" required>{{if !empty($data['content'])}}{{$data.content}}{{/if}}</textarea>
</div>
<div class="am-form-group">
<label>回复内容</label>
<textarea class="am-radius am-validate" name="reply" rows="5" maxlength="230" placeholder="最多 230 个字符" data-validation-message="内容格式最多 230 个字符">{{if !empty($data['reply'])}}{{$data.reply}}{{/if}}</textarea>
</div>
<div class="am-form-group">
<label class="block">是否已回复</label>
<input name="is_reply" value="1" type="checkbox" data-off-text="否" data-on-text="是" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if isset($data['is_reply']) and $data['is_reply'] eq 1}}checked="true"{{/if}} />
</div>
<div class="am-form-group">
<label class="block">是否显示</label>
<input name="is_show" value="1" type="checkbox" data-off-text="否" data-on-text="是" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if isset($data['is_show']) and $data['is_show'] eq 1}}checked="true"{{/if}} />
</div>
<div class="am-form-group am-form-group-refreshing">
<input type="hidden" name="id" {{if !empty($data['id'])}} value="{{$data.id}}"{{/if}} />
<input type="hidden" name="user_id" {{if !empty($data['user_id'])}} value="{{$data.user_id}}"{{/if}} />
<button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm w100" data-am-loading="{loadingText:'处理中...'}">保存</button>
</div>
</form>
<!-- form end -->
</div>
</div>
<!-- right content end -->
<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->

View File

@ -94,7 +94,7 @@ class Answer extends Common
$params = $this->data_post;
$params['user'] = $this->user;
return AnswerService::Add($params);
return AnswerService::AnswerSave($params);
}
}
?>

View File

@ -218,7 +218,7 @@ class Index extends Controller
{
$params = input('post.');
$params['user'] = UserService::LoginUserInfo();
return AnswerService::Add($params);
return AnswerService::AnswerSave($params);
}
}
?>

View File

@ -36,7 +36,7 @@ class Index extends Controller
{
$params = input('post.');
$params['user'] = UserService::LoginUserInfo();
return AnswerService::Add($params);
return AnswerService::AnswerSave($params);
}
/**

View File

@ -162,7 +162,7 @@ class AnswerService
}
/**
* 用户留言添加
* 用户留言保存
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
@ -170,7 +170,7 @@ class AnswerService
* @desc description
* @param [array] $params [输入参数]
*/
public static function Add($params = [])
public static function AnswerSave($params = [])
{
// 参数校验
$p = [
@ -207,18 +207,38 @@ class AnswerService
// 开始操作
$data = [
'user_id' => isset($params['user']['id']) ? intval($params['user']['id']) : 0,
'user_id' => isset($params['user']['id']) ? intval($params['user']['id']) : (isset($params['user_id']) ? intval($params['user_id']) : 0),
'name' => isset($params['name']) ? $params['name'] : '',
'tel' => isset($params['tel']) ? $params['tel'] : '',
'title' => isset($params['title']) ? $params['title'] : '',
'content' => $params['content'],
'reply' => isset($params['reply']) ? $params['reply'] : '',
'access_count' => isset($params['access_count']) ? intval($params['access_count']) : 0,
'is_reply' => isset($params['is_reply']) ? intval($params['is_reply']) : 0,
'is_show' => isset($params['is_show']) ? intval($params['is_show']) : 0,
'add_time' => time(),
];
if(Db::name('Answer')->insertGetId($data) > 0)
// 回复时间
$data['reply_time'] = (isset($data['is_reply']) && $data['is_reply'] == 1) ? time() : 0;
// 不存在添加,则更新
if(empty($params['id']))
{
return DataReturn('提交成功', 0);
$data['add_time'] = time();
if(Db::name('Answer')->insertGetId($data) > 0)
{
return DataReturn('提交成功', 0);
}
return DataReturn('提交失败', -100);
} else {
$data['upd_time'] = time();
if(Db::name('Answer')->where(['id'=>intval($params['id'])])->update($data))
{
return DataReturn('编辑成功', 0);
}
return DataReturn('编辑失败', -100);
}
return DataReturn('提交失败', -100);
}
/**

File diff suppressed because one or more lines are too long