Commit bedbcfb8 authored by ZhuChunYang's avatar ZhuChunYang

update

parent aafde1d8
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/16
* Time: 20:44
*/
namespace backend\controllers;
use backend\models\coin\CoinApplicationCategoryForm;
use common\models\psources\CoinApplicationCategory;
use Yii;
use yii\web\UploadedFile;
class ApplicateRecommendController extends BaseController
{
public function actionAdd()
{
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){
}else{
return ['code' => 1 ,'msg' => '首页推荐失败'];
}
}
}
}
\ No newline at end of file
......@@ -39,8 +39,9 @@ class ApplicationController extends BaseController
$id = Yii::$app->request->get('id');
if($id){
$parent_category = CoinApplicationCategory::getCategoryById($id);
$cate_items = CoinApplicationCategory::getCateItemsArray();
if($parent_category){
return $this->render('list',['parent_category' => $parent_category]);
return $this->render('list',['parent_category' => $parent_category,'cate_items' => $cate_items]);
}else{
$this->error('id参数不合法', Yii::$app->request->getReferrer());
}
......@@ -116,5 +117,16 @@ class ApplicationController extends BaseController
return ['code' => 1, 'msg' => 'failed'];
}
public function actionAddCategory()
{
if(Yii::$app->request->isPost){
Yii::$app->response->format = 'json';
$cate_id = Yii::$app->request->post('cate_id');
$app_id = Yii::$app->request->post('app_id');
$coin_applicateion_form = new CoinApplicationForm();
return $coin_applicateion_form->addCategory($app_id,$cate_id);
}
}
}
\ No newline at end of file
......@@ -169,4 +169,23 @@ class CoinApplicationForm extends BaseForm
}
/**
* @param $id
* 添加所属分类
*/
public function addCategory($id,$category_id)
{
$coin_app_cate = CoinAppCate::getAppCate($category_id,$id);
if($coin_app_cate){
return ['code' => 1,'msg' => '应用已属于该分类,不能再添加'];
}else{
$coin_app_cate = new CoinAppCate();
$coin_app_cate->app_id = $id;
$coin_app_cate->cate_id = $category_id;
$coin_app_cate->save();
return ['code' => 0,'msg' => '应用所属分类添加成功'];
}
}
}
\ No newline at end of file
......@@ -6,6 +6,11 @@
* Time: 14:29
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<h4>所属分类---<?= $parent_category->name ?></h4>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md1">
......@@ -15,10 +20,28 @@
</div>
</div>
<input id="category_id" type="hidden" value="<?= $parent_category->id ?>">
<div class="layui-col-md8">
<div class="layui-col-md10">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<!-- 添加页面 -->
<div class="layui-row" 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 id="app_id" name="app_id" type="hidden" value="">
<div class="layui-form-item">
<label class="layui-form-label">所属分类</label>
<div class="layui-input-block">
<select name="cate_id" id="cate_id">
<?php foreach ($cate_items as $cate_item): ?>
<option value="<?= $cate_item['id'] ?>"><?= $cate_item['name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</form>
</div>
</div>
<script type="text/html" id="iconTpl">
<img src="{{d.icon_url}}" style="max-width: 32px; max-height: 32px;"/>
......@@ -26,9 +49,14 @@
<script type="text/html" id="operationTpl">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add_category">添加所属分类</a>
</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">
var form = layui.form;
form.render();
var table = layui.table;
var category_id = $("#category_id").val();
table.render({
......@@ -94,7 +122,13 @@
},
{
title: '操作',
templet: '#operationTpl'
templet: '#operationTpl',
width: 300
},
{
title: '首页推荐',
field: 'isrecommend',
templet: '#recommendTpl',
},
{
field: 'icon',
......@@ -106,8 +140,6 @@
]],
});
var form = layui.form;
form.render();
table.on('tool(table1)', function(obj) {
var data = obj.data;
var event = obj.event;
......@@ -146,9 +178,46 @@
}
});
});
}else if ('add_category' === event) {
$("#app_id").val(data.id);
var index = layer.open({
title: '添加应用分类',
area: ['500px','400px'],
type: 1,
content: $("#_form"),
btn: ['保存', '取消'],
btn1: function() {
$.post('/admin/application/add-category', $("#form1").serialize(), function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
$("#_form").css('display', 'none');
}
});
},
btn2: function() {
layer.close(index);
$("#_form").css('display', 'none');
},
cancel: function() {
layer.close(index);
$("#_form").css('display', 'none');
}
});
}
});
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:2}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
obj.elem.checked=false;
}
});
}
});
</script>
\ No newline at end of file
......@@ -74,6 +74,7 @@ class CoinApplication extends BaseActiveRecord
}else{
$value['has_ios'] = 0;
}
$value['isrecommend'] = 1;
}
return ['count' => $count, 'data' => $data, 'code' => 0];
}
......
......@@ -88,4 +88,10 @@ class CoinApplicationCategory extends BaseActiveRecord
return self::find()->where(['id' => $id])->one();
}
public static function getCateItemsArray()
{
return self::find()->asArray()->all();
}
}
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