Commit c7f5bb74 authored by ZhuChunYang's avatar ZhuChunYang

首页推荐添加icon

parent 5026da06
......@@ -11,6 +11,7 @@ namespace backend\controllers;
use common\models\psources\CoinApplicateRecommend;
use common\models\psources\CoinApplication;
use common\models\psources\CoinApplicationCategory;
use common\models\psources\CoinImage;
use Yii;
......@@ -35,17 +36,14 @@ class ApplicateRecommendController extends BaseController
if($type == 1){ //分类
$applicate_category = CoinApplicationCategory::getCategoryById($id);
$name = $applicate_category->name;
$icon = $applicate_category->icon;
}else{ //应用
$applicate = CoinApplication::getApplicate($id);
$name = $applicate->name;
$icon = $applicate->icon;
}
$recommend = new CoinApplicateRecommend();
$recommend->relate_id = $id;
$recommend->type = $type;
$recommend->name = $name;
$recommend->icon = $icon;
$recommend->save();
return ['code' => 0,'msg' => '首页推荐添加成功'];
}else{
......@@ -82,6 +80,15 @@ class ApplicateRecommendController extends BaseController
if(Yii::$app->request->isAjax){
Yii::$app->response->format = 'json';
$data = CoinApplicateRecommend::find()->orderBy('sort asc')->asArray()->all();
$icon_Items = array_column($data,'icon');
$icon_Infos = CoinImage::getItemsByIds($icon_Items);
foreach ($data as &$value){
if($value['icon']){
$value['icon_url'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
}else{
$value['icon_url'] = '';
}
}
return [ 'data' =>$data, 'code' => 0];
}
return $this->render('index');
......@@ -109,5 +116,26 @@ class ApplicateRecommendController extends BaseController
}
}
public function actionSetIcon()
{
if(Yii::$app->request->isPost){
Yii::$app->response->format = 'json';
$id = Yii::$app->request->post('id',0);
$icon = Yii::$app->request->post('icon',0);
if($id && $icon){
$recommend = CoinApplicateRecommend::getRecommendById($id);
if($recommend){
$recommend->icon = $icon;
$recommend->save();
return ['code' => 0, 'msg' => '图片添加成功'];
}else{
return ['code' => 1, 'msg' => '首页推荐不存在'];
}
}else{
return ['code' => 1,'msg'=> '图片添加失败'];
}
}
}
}
\ No newline at end of file
......@@ -102,7 +102,7 @@ class CoinApplicationCategoryForm extends BaseForm
if($coin_applicate_category){
$coin_applicate_category->setAttributes($this->attributes,false);
$coin_applicate_category->save();
CoinApplicateRecommend::updateNameAndIcon($this->id,1,$this->name,$this->icon);
CoinApplicateRecommend::updateName($this->id,1,$this->name);
return ['code' => 0,'msg' => '应用分类修改成功!'];
}else{
return ['code' => 1,'msg' => '应用分类不存在'];
......
......@@ -132,7 +132,7 @@ class CoinApplicationForm extends BaseForm
if($coin_applicate){
$coin_applicate->setAttributes($this->attributes,false);
$coin_applicate->save();
CoinApplicateRecommend::updateNameAndIcon($this->id,2,$this->name,$this->icon); //更新首页推荐name
CoinApplicateRecommend::updateName($this->id,2,$this->name); //更新首页推荐name
return ['code' => 0,'msg' => '应用修改成功!'];
}else{
return ['code' => 1,'msg' => '应用不存在'];
......
......@@ -12,7 +12,29 @@
<div class="layui-col-md9">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<div class="layui-row add" style="display: none;padding: 5px;" id="_form">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form" action="javascript:void(0)" id="form1" method="post" lay-filter="form1">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input type="hidden" name="id" value="">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图标</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px"
id="icon1">
</div>
<input type="hidden" name="icon" value="">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload1" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
</form>
</div>
</div>
<script type="text/html" id="typeTpl">
{{# if(d.type==1){ }}
应用分类
......@@ -20,7 +42,11 @@
应用
{{# } }}
</script>
<script type="text/html" id="iconTpl">
<img src="{{d.icon_url}}" style="max-width: 32px; max-height: 32px;"/>
</script>
<script type="text/html" id="operationTpl">
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑图片</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
......@@ -28,8 +54,6 @@
table.render({
elem: '#table1',
url: '/admin/applicate-recommend/index',
skin: 'row',
size: 'sm',
cols: [[
{
field: 'relate_id',
......@@ -49,7 +73,11 @@
title: '排序',
edit: 'text'
},
{
field: 'icon_url',
title: '图标',
templet: '#iconTpl'
},
{
title: '操作',
templet: '#operationTpl'
......@@ -72,6 +100,39 @@
}
});
});
}else if(event === 'edit'){
var index = layer.open({
title: '编辑图片',
area: '800px',
type: 1,
content: $("#_form"),
btn: ['保存', '取消'],
success: function() {
form.val("form1", {
id: data.id,
icon: data.icon,
});
$("#icon1").attr('src', data.icon_url);
},
btn1: function() {
$.post('/admin/applicate-recommend/set-icon', $("#form1").serialize(), function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
$("#_form").css('display', 'none');
table.reload('table1');
}
});
},
btn2: function() {
layer.close(index);
$("#_form").css('display', 'none');
},
cancel: function() {
layer.close(index);
$("#_form").css('display', 'none');
}
});
}
});
//监听单元格编辑
......@@ -87,6 +148,22 @@
}
});
});
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf},
done: function (res) {
if(res.code == 0){
$("input[name='icon']").val(res.data.image_id);
$("#icon1").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
</script>
\ No newline at end of file
......@@ -43,12 +43,11 @@ class CoinApplicateRecommend extends BaseActiveRecord
return array_column($data,null,'relate_id');
}
public static function updateNameAndIcon($id,$type,$name,$icon)
public static function updateName($id,$type,$name)
{
$recommend = self::find()->where(['relate_id' => $id,'type' => $type])->one();
if($recommend){
$recommend->name=$name;
$recommend->icon=$icon;
$recommend->save();
}
}
......@@ -66,6 +65,11 @@ class CoinApplicateRecommend extends BaseActiveRecord
return self::find()->select('relate_id as app_cate_id,name,type,icon')->asArray()->orderBy('sort asc')->all();
}
public static function getRecommendById($id)
{
return self::find()->where(['id' => $id])->one();
}
......
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