Commit 0423b061 authored by ZhuChunYang's avatar ZhuChunYang

update

parent c0fadf4b
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace backend\models\coin; namespace backend\models\coin;
use backend\models\BaseForm; use backend\models\BaseForm;
use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplicationCategory; use common\models\psources\CoinApplicationCategory;
class CoinApplicationCategoryForm extends BaseForm class CoinApplicationCategoryForm extends BaseForm
...@@ -118,6 +119,10 @@ class CoinApplicationCategoryForm extends BaseForm ...@@ -118,6 +119,10 @@ class CoinApplicationCategoryForm extends BaseForm
{ {
$coin_applicate_category = CoinApplicationCategory::getCategoryById($id); $coin_applicate_category = CoinApplicationCategory::getCategoryById($id);
if($coin_applicate_category){ if($coin_applicate_category){
$hasApp = CoinAppCate::getAppCountByCateId($id);
if($hasApp){
return ['code' => 1,'msg' => '分类下有应用,无法删除'];
}
$coin_applicate_category->delete(); $coin_applicate_category->delete();
return ['code' => 0,'msg' => '应用分类删除成功']; return ['code' => 0,'msg' => '应用分类删除成功'];
}else{ }else{
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
</form> </form>
</div> </div>
</div> </div>
<div class="layui-col-md8"> <div class="layui-col-md9">
<table class="layui-table" id="table1" lay-filter="table1"></table> <table class="layui-table" id="table1" lay-filter="table1"></table>
</div> </div>
...@@ -125,6 +125,10 @@ ...@@ -125,6 +125,10 @@
field: 'name', field: 'name',
title: '名称', title: '名称',
}, },
{
field: 'app_count',
title: '应用',
},
{ {
field: 'icon_url', field: 'icon_url',
......
...@@ -28,4 +28,14 @@ class CoinAppCate extends BaseActiveRecord ...@@ -28,4 +28,14 @@ class CoinAppCate extends BaseActiveRecord
return self::find()->where(['cate_id' => $cate_id])->asArray()->all(); return self::find()->where(['cate_id' => $cate_id])->asArray()->all();
} }
public static function getAppCountByCateId($cate_id)
{
return self::find()->where(['cate_id' => $cate_id])->count();
}
public static function getAppCountByCateIds($cate_ids)
{
$data = self::find()->select('cate_id,count(*) as num')->where(['in','cate_id',$cate_ids])->groupBy('cate_id')->asArray()->all();
return array_column($data,'num','cate_id');
}
} }
\ No newline at end of file
...@@ -55,6 +55,5 @@ class CoinApplication extends BaseActiveRecord ...@@ -55,6 +55,5 @@ class CoinApplication extends BaseActiveRecord
} }
} }
return ['count' => $count, 'data' => $data, 'code' => 0]; return ['count' => $count, 'data' => $data, 'code' => 0];
} }
} }
\ No newline at end of file
...@@ -55,8 +55,11 @@ class CoinApplicationCategory extends BaseActiveRecord ...@@ -55,8 +55,11 @@ class CoinApplicationCategory extends BaseActiveRecord
$data = $data->asArray()->all(); $data = $data->asArray()->all();
$icon_Items = array_column($data,'icon'); $icon_Items = array_column($data,'icon');
$banner_Items = array_column($data,'banner'); $banner_Items = array_column($data,'banner');
$id_Items = array_column($data,'id');
$image_Items = array_merge($icon_Items,$banner_Items); $image_Items = array_merge($icon_Items,$banner_Items);
$icon_Infos = CoinImage::getItemsByIds($image_Items); $icon_Infos = CoinImage::getItemsByIds($image_Items);
//获取分类应用数量
$cate_app_items = CoinAppCate::getAppCountByCateIds($id_Items);
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'];
...@@ -68,6 +71,11 @@ class CoinApplicationCategory extends BaseActiveRecord ...@@ -68,6 +71,11 @@ class CoinApplicationCategory extends BaseActiveRecord
}else{ }else{
$value['banner_image_url'] = ''; $value['banner_image_url'] = '';
} }
if(isset($cate_app_items[$value['id']])){
$value['app_count'] = $cate_app_items[$value['id']];
}else{
$value['app_count'] = 0;
}
} }
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