Commit 881be1ed authored by ZhuChunYang's avatar ZhuChunYang

update

parent bedbcfb8
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
namespace backend\controllers; namespace backend\controllers;
use backend\models\coin\CoinApplicationCategoryForm; use common\models\psources\CoinApplicateRecommend;
use common\models\psources\CoinApplication;
use common\models\psources\CoinApplicationCategory; use common\models\psources\CoinApplicationCategory;
use Yii; use Yii;
use yii\web\UploadedFile;
class ApplicateRecommendController extends BaseController class ApplicateRecommendController extends BaseController
...@@ -24,11 +24,65 @@ class ApplicateRecommendController extends BaseController ...@@ -24,11 +24,65 @@ class ApplicateRecommendController extends BaseController
$id = $request->get('id', ''); $id = $request->get('id', '');
$type = $request->get('type',''); $type = $request->get('type','');
if($id && $type){ if($id && $type){
$recommend = CoinApplicateRecommend::getRecommend($id,$type);
if($recommend){
return ['code' => 1,'msg' =>'分类/应用已经添加为首页推荐,不能再添加'];
}
$count = CoinApplicateRecommend::getRecommendCount();
if($count >= 8){
return ['code' => 1,'msg' =>'首页推荐分类/应用数量已经8个,无法再添加'];
}
if($type == 1){ //分类
$applicate_category = CoinApplicationCategory::getCategoryById($id);
$name = $applicate_category->name;
}else{ //应用
$applicate = CoinApplication::getApplicate($id);
$name = $applicate->name;
}
$recommend = new CoinApplicateRecommend();
$recommend->relate_id = $id;
$recommend->type = $type;
$recommend->name = $name;
$recommend->save();
return ['code' => 0,'msg' => '首页推荐添加成功'];
}else{
return ['code' => 1 ,'msg' => '首页推荐添加失败'];
}
}
}
public function actionDelete()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
$type = $request->get('type','');
if($id && $type){
$recommend = CoinApplicateRecommend::getRecommend($id,$type);
if(!$recommend){
return ['code' => 1,'msg' =>'首页推荐不存在,不能删除'];
}
$recommend->delete();
return ['code' => 0,'msg' => '首页推荐删除成功'];
}else{ }else{
return ['code' => 1 ,'msg' => '首页推荐失败']; return ['code' => 1 ,'msg' => '首页推荐删除失败'];
} }
} }
} }
/**
* 应用/分类推荐列表
*/
public function actionIndex()
{
if(Yii::$app->request->isAjax){
Yii::$app->response->format = 'json';
$data = CoinApplicateRecommend::find()->asArray()->all();
return [ 'data' =>$data, 'code' => 0];
}
return $this->render('index');
}
} }
\ No newline at end of file
...@@ -11,7 +11,6 @@ namespace backend\controllers; ...@@ -11,7 +11,6 @@ namespace backend\controllers;
use backend\models\coin\CoinApplicationCategoryForm; use backend\models\coin\CoinApplicationCategoryForm;
use common\models\psources\CoinApplicationCategory; use common\models\psources\CoinApplicationCategory;
use Yii; use Yii;
use yii\web\UploadedFile;
class ApplicationCategoryController extends BaseController class ApplicationCategoryController extends BaseController
......
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/17
* Time: 10:55
*/
?>
<h4>首页推荐列表</h4>
<div class="layui-col-md9">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="typeTpl">
{{# if(d.type==1){ }}
应用分类
{{# } else { }}
应用
{{# } }}
</script>
<script type="text/html" id="operationTpl">
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
var table = layui.table;
table.render({
elem: '#table1',
url: '/admin/applicate-recommend/index',
cols: [[
{
field: 'relate_id',
title: '应用/分类ID'
},
{
field: 'name',
title: '名称',
},
{
field: 'type',
title: '类型',
templet: '#typeTpl'
},
{
field: 'sort',
title: '排序'
},
{
title: '操作',
templet: '#operationTpl'
}
]],
});
var form = layui.form;
form.render();
table.on('tool(table1)', function(obj) {
var event = obj.event;
var data = obj.data;
if (event === 'del') {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/applicate-recommend/delete', {id: data.relate_id,type:data.type}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table1',{
page:{curr:1}
});
}
});
});
}
});
</script>
\ No newline at end of file
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
</form> </form>
</div> </div>
</div> </div>
<div class="layui-col-md9"> <div class="layui-col-md10">
<table class="layui-table" id="table1" lay-filter="table1"></table> <table class="layui-table" id="table1" lay-filter="table1"></table>
</div> </div>
...@@ -108,6 +108,9 @@ ...@@ -108,6 +108,9 @@
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/application/list?id={{d.id}}" >应用列表</a> <a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/application/list?id={{d.id}}" >应用列表</a>
</script> </script>
<script type="text/html" id="recommendTpl">
<input type="checkbox" name="isrecommend" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="recommendDemo" {{ d.isrecommend == 1 ? 'checked' : '' }}>
</script>
<script type="text/javascript"> <script type="text/javascript">
var table = layui.table; var table = layui.table;
...@@ -149,6 +152,11 @@ ...@@ -149,6 +152,11 @@
templet: '#operationTpl' templet: '#operationTpl'
}, },
{ {
title: '首页推荐',
field: 'isrecommend',
templet: '#recommendTpl',
},
{
field: 'icon', field: 'icon',
title: '图标', title: '图标',
hide:true, hide:true,
...@@ -321,6 +329,25 @@ ...@@ -321,6 +329,25 @@
$("#icon1").attr('src', ''); $("#icon1").attr('src', '');
$("#icon2").attr('src', ''); $("#icon2").attr('src', '');
} }
form.on('switch(recommendDemo)', function(obj){
//layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);return;
if(obj.elem.checked){
$.get('/admin/applicate-recommend/add', {id:this.value,type:1}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
}
});
}else{
$.get('/admin/applicate-recommend/delete', {id:this.value,type:1}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
}
});
}
});
</script> </script>
\ No newline at end of file
...@@ -213,7 +213,15 @@ ...@@ -213,7 +213,15 @@
layer.msg(rev.msg); layer.msg(rev.msg);
if (0 == rev.code) { if (0 == rev.code) {
}else{ }else{
obj.elem.checked=false;
}
});
}else{
$.get('/admin/applicate-recommend/delete', {id:this.value,type:2}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
} }
}); });
} }
......
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/17
* Time: 9:36
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
class CoinApplicateRecommend extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_applicate_recommend}}';
}
public static function getRecommend($relate_id,$type)
{
return self::find()->where(['relate_id' => $relate_id,'type'=>$type])->one();
}
public static function getRecommendCount()
{
return self::find()->count();
}
/**
* @param $type
* 1 分类 2 应用
*/
public static function getRecommendItemsByType($type)
{
$data = self::find()->where(['type'=>$type])->asArray()->all();
return array_column($data,null,'relate_id');
}
}
\ No newline at end of file
...@@ -47,6 +47,7 @@ class CoinApplication extends BaseActiveRecord ...@@ -47,6 +47,7 @@ class CoinApplication extends BaseActiveRecord
$data = $data->asArray()->all(); $data = $data->asArray()->all();
$icon_Items = array_column($data,'icon'); $icon_Items = array_column($data,'icon');
$icon_Infos = CoinImage::getItemsByIds($icon_Items); $icon_Infos = CoinImage::getItemsByIds($icon_Items);
$recommendItems = CoinApplicateRecommend::getRecommendItemsByType(2);
foreach($data as $key => &$value){ foreach($data as $key => &$value){
if($value['icon']){ if($value['icon']){
$value['icon_url'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url']; $value['icon_url'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
...@@ -74,7 +75,9 @@ class CoinApplication extends BaseActiveRecord ...@@ -74,7 +75,9 @@ class CoinApplication extends BaseActiveRecord
}else{ }else{
$value['has_ios'] = 0; $value['has_ios'] = 0;
} }
$value['isrecommend'] = 1; if(isset($recommendItems[$value['id']])){
$value['isrecommend'] = 1;
}
} }
return ['count' => $count, 'data' => $data, 'code' => 0]; return ['count' => $count, 'data' => $data, 'code' => 0];
} }
......
...@@ -60,6 +60,7 @@ class CoinApplicationCategory extends BaseActiveRecord ...@@ -60,6 +60,7 @@ class CoinApplicationCategory extends BaseActiveRecord
$icon_Infos = CoinImage::getItemsByIds($image_Items); $icon_Infos = CoinImage::getItemsByIds($image_Items);
//获取分类应用数量 //获取分类应用数量
$cate_app_items = CoinAppCate::getAppCountByCateIds($id_Items); $cate_app_items = CoinAppCate::getAppCountByCateIds($id_Items);
$recommendItems = CoinApplicateRecommend::getRecommendItemsByType(1);
foreach($data as $key => &$value){ foreach($data as $key => &$value){
if($value['icon']){ if($value['icon']){
$value['icon_url'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url']; $value['icon_url'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
...@@ -76,6 +77,9 @@ class CoinApplicationCategory extends BaseActiveRecord ...@@ -76,6 +77,9 @@ class CoinApplicationCategory extends BaseActiveRecord
}else{ }else{
$value['app_count'] = 0; $value['app_count'] = 0;
} }
if(isset($recommendItems[$value['id']])){
$value['isrecommend'] = 1;
}
} }
return ['count' => $count, 'data' => $data, 'code' => 0]; return ['count' => $count, 'data' => $data, 'code' => 0];
} }
......
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