Commit 86cf011b authored by ZhuChunYang's avatar ZhuChunYang

添加热门搜索

parent 286be60e
......@@ -101,5 +101,68 @@ class ApplicateRankController extends BaseController
}
}
public function actionAddSearch()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request->post();
$serach_name = $request['name'];
if($serach_name){
Yii::$app->redis_app->zadd('application_hot_search',1,$serach_name);
return ['code' => 0, 'msg' => '添加成功'];
}else{
return ['code' => 1, 'msg' => '添加失败'];
}
}
}
public function actionSearchIndex()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$redis = Yii::$app->redis_app;
$data = $redis->zrange('application_hot_search',0,-1);
$search_data = [];
foreach($data as $value){
$item['name'] = $value;
$item['sort'] = $redis->zscore('application_hot_search',$value);
$search_data[] = $item;
}
return ['data' => $search_data, 'code' => 0];
}
}
public function actionSearchDelete()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$name = $request->get('name', '');
if ($name) {
Yii::$app->redis_app->zrem('application_hot_search',$name);
return ['code' => 0, 'msg' => '热门搜索删除成功'];
} else {
return ['code' => 1, 'msg' => '热门搜索删除失败'];
}
}
}
public function actionSetSearchSort()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$name = $request->get('name', '');
$sort = $request->get('sort', 1);
if ($name) {
Yii::$app->redis_app->zadd('application_hot_search',$sort,$name);
return ['code' => 0, 'msg' => '排序设置成功'];
} else {
return ['code' => 1, 'msg' => '排序设置失败'];
}
}
}
}
\ No newline at end of file
......@@ -15,21 +15,26 @@ IndexAsset::register($this);
<ul class="layui-tab-title">
<li class="layui-this">热度榜</li>
<li>新品榜</li>
<li>热门搜索</li>
</ul>
<div class="layui-tab-content">
<div class="layui-tab-item layui-show">
<button class="layui-btn layui-btn-default" id="add1">添加热度应用</button>
<table class="layui-table" id="table1" lay-filter="table1"></table>
<table class="layui-table" id="table1" lay-filter="table"></table>
</div>
<div class="layui-tab-item">
<button class="layui-btn layui-btn-default" id="add2">添加新品应用</button>
<table class="layui-table" id="table2" lay-filter="table2"></table>
<table class="layui-table" id="table2" lay-filter="table"></table>
</div>
<div class="layui-tab-item">
<button class="layui-btn layui-btn-default" id="add3">添加热门搜索</button>
<table class="layui-table" id="table3" lay-filter="table"></table>
</div>
</div>
</div>
</div>
<!-- 添加页面 -->
<!-- 添加应用页面 -->
<div class="layui-row add" style="display: none;padding: 5px;">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form form_add" action="javascript:void(0)" method="post" lay-filter="form1">
......@@ -54,6 +59,31 @@ IndexAsset::register($this);
</div>
</div>
<!-- 添加热门搜索页面 -->
<div class="layui-row add_search" style="display: none;padding: 5px;">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form form_add" action="javascript:void(0)" method="post" lay-filter="form1">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<div class="layui-form-item">
<label class="layui-form-label">名称</label>
<div class="layui-input-block">
<input type="text" name="name" required lay-verify="required" placeholder="" autocomplete="off"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn btn_add_submit" lay-submit lay-filter="formSearch">立即提交</button>
</div>
</div>
</form>
</div>
</div>
<script type="text/html" id="operTpl">
<a class="btn_delete" lay-event="delete"><i class="layui-icon" style="color: #4b67ff">&#xe640;</i></a>
</script>
<script type="text/html" id="operSearchTpl">
<a class="btn_delete" lay-event="delete_search"><i class="layui-icon" style="color: #4b67ff">&#xe640;</i></a>
</script>
\ No newline at end of file
var table1 = layui.table;
var table2 = layui.table;
var table3 = layui.table;
var form = layui.form;
var layer_add;
......@@ -25,6 +26,16 @@ table2.render({
{title: '操作', templet: '#operTpl'},
]]
});
table3.render({
elem: '#table3',
url: '/admin/applicate-rank/search-index',
cols: [[
{field: 'name', title: '热门搜索名称'},
{field: 'sort', title: '排序',edit: 'text'},
{title: '操作', templet: '#operSearchTpl'},
]]
});
form.render();
layui.table.on('tool(table)', function (obj) {
......@@ -43,6 +54,19 @@ layui.table.on('tool(table)', function (obj) {
}
});
});
}else if(event == 'delete_search'){
var ldelete = layer.confirm('确定要删除?', {
icon: 3,
title: '删除'
}, function (index) {
$.get('/admin/applicate-rank/search-delete', {name: data.name}, function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
obj.del();
layer.close(ldelete);
}
});
});
}
});
//添加图层
......@@ -77,6 +101,21 @@ $("#add2").click(function () {
}
});
});
$("#add3").click(function () {
layer_add = layer.open({
type: 1,
title: '版本信息',
content: $('.add_search'), //这里content是一个普通的String
scrollbar: false,
area: ['700px','200px'],
cancel: function (index, layero) {
$('.add_search').attr('style', 'display:none;padding: 5px;');
$('input[name="name"]').val('');
form.render();
},
});
});
form.on('submit(formDemo)', function (data) {
$.post('/admin/applicate-rank/add', data.field, function (rev) {
layer.msg(rev.msg);
......@@ -88,41 +127,54 @@ form.on('submit(formDemo)', function (data) {
return false;
});
form.on('submit(formSearch)', function (data) {
$.post('/admin/applicate-rank/add-search', data.field, function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(layer_add);
$('.add_search').attr('style', 'display:none;padding: 5px;');
$('input[name="name"]').val('');
table3.reload('table3', {});
form.render();
}
});
return false;
});
function after_close_add(reflush = true) {
if (reflush) {
table1.reload('table1', {});
table2.reload('table2', {});
}
$('.add').attr('style', 'display:none');
$('.add').attr('style', 'display:none;padding: 5px;');
$('input[name="id"]').val('');
$('select[name="applicate_id"]').val(0);
form.render();
}
//监听单元格编辑
layui.table.on('edit(table1)', function(obj){
layui.table.on('edit(table)', function(obj){
var value = obj.value; //得到修改后的值
var data = obj.data; //得到所在行所有键值
$.get('/admin/applicate-rank/set-sort', {id:data.id,type:data.type,sort:value}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
table1.reload('table1',{});
if(data.type){
var params = {id:data.id,type:data.type,sort:value};
var url = '/admin/applicate-rank/set-sort';
}else{
var params = {name:data.name,sort:value};
var url = '/admin/applicate-rank/set-search-sort';
}
});
});
//监听单元格编辑
layui.table.on('edit(table2)', function(obj){
var value = obj.value; //得到修改后的值
var data = obj.data; //得到所在行所有键值
$.get('/admin/applicate-rank/set-sort', {id:data.id,type:data.type,sort:value}, function(rev) {
$.get(url, params, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
table2.reload('table2',{});
if(data.type){
layui.table.reload('table'+ data.type,{});
}else{
layui.table.reload('table3',{});
}
}else{
}
});
});
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