Commit 39b895f7 authored by ZhuChunYang's avatar ZhuChunYang

新增api首页接口

parent 7d297e16
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/17
* Time: 19:53
*/
namespace api\controllers;
use api\base\BaseController;
use common\business\ApplicationBusiness;
use common\models\psources\CoinAppCate;
class ApplicationController extends BaseController
{
/**
* 首页接口
*/
public function actionIndex()
{
$result['code'] = 0;
$recommendData = ApplicationBusiness::getRecommendList();
$result['recommend'] =$recommendData;
$cate_app_data = ApplicationBusiness::getCategoryAppList();
$result['cate_app_data'] = $cate_app_data;
return $result;
}
/**
* 分类/应用接口
*/
public function actionCateAppInfo()
{
$result['code'] = 0;
$result['data'] = ApplicationBusiness::getCategoryAppList();
return $result;
}
/**
* 获取应用详情
*/
public function actionAppInfo()
{
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/17
* Time: 19:56
*/
namespace common\business;
use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplicateRecommend;
use common\models\psources\CoinApplicationCategory;
use common\models\psources\CoinImage;
class ApplicationBusiness
{
/**
* @return array|\yii\db\ActiveRecord[]
* 获取首页推荐
*/
public static function getRecommendList()
{
$data = CoinApplicateRecommend::getRecommendList();
return $data;
}
public static function getCategoryAppList()
{
$data = CoinApplicationCategory::getAllList();
$cate_app_data = [];
$icon_Items = array_column($data,'icon');
$banner_Items = array_column($data,'banner');
$image_Items = array_merge($icon_Items,$banner_Items);
$icon_Infos = CoinImage::getItemsByIds($image_Items);
$cate_app_Infos = self::getCateAppInfo();
foreach($data as $value){
$cate_app_item['id'] = $value['id'];
$cate_app_item['name'] = $value['name'];
if($value['icon']){
$cate_app_item['icon_url'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
}else{
$cate_app_item['icon_url'] = '';
}
if($value['banner']){
$cate_app_item['banner_image_url'] = $icon_Infos[$value['banner']]['base_url'].$icon_Infos[$value['banner']]['file_url'];
}else{
$cate_app_item['banner_image_url'] = '';
}
$cate_app_item['banner_url'] = $value['banner_url'];
if(isset($cate_app_Infos[$value['id']])){ //分类下面有应用
$cate_app_item['apps'] = $cate_app_Infos[$value['id']];
}else{
$cate_app_item['apps'] = [];
}
$cate_app_data[] = $cate_app_item;
}
return $cate_app_data;
}
/**
* @return mixed
* 获取分类以及应用
*/
public static function getCateAppInfo()
{
$app_cate_Model = CoinAppCate::find();
$data = $app_cate_Model->JoinWith(['application'], false)
->select('cate_id,app_id,name,icon,sort,redirect_type')
->orderBy('sort asc')->asArray()->all();
$icon_Items = array_column($data,'icon');
$icon_Items = array_unique($icon_Items);
$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'] = '';
}
}
foreach($data as $item){
$cate_app_item[$item['cate_id']] []= $item;
}
return $cate_app_item;
}
}
\ No newline at end of file
...@@ -23,6 +23,13 @@ class CoinAppCate extends BaseActiveRecord ...@@ -23,6 +23,13 @@ class CoinAppCate extends BaseActiveRecord
return '{{%coin_app_cate}}'; return '{{%coin_app_cate}}';
} }
public function getApplication()
{
return $this->hasOne(CoinApplication::class, ['id' => 'app_id']);
}
public static function getAppIdByCateId($cate_id) public static function getAppIdByCateId($cate_id)
{ {
return self::find()->where(['cate_id' => $cate_id])->asArray()->all(); return self::find()->where(['cate_id' => $cate_id])->asArray()->all();
...@@ -50,4 +57,5 @@ class CoinAppCate extends BaseActiveRecord ...@@ -50,4 +57,5 @@ class CoinAppCate extends BaseActiveRecord
} }
} }
\ No newline at end of file
...@@ -60,6 +60,12 @@ class CoinApplicateRecommend extends BaseActiveRecord ...@@ -60,6 +60,12 @@ class CoinApplicateRecommend extends BaseActiveRecord
} }
} }
public static function getRecommendList()
{
return self::find()->select('relate_id as app_cate_id,name,type')->asArray()->orderBy('sort asc')->all();
}
} }
\ No newline at end of file
...@@ -91,4 +91,5 @@ class CoinApplication extends BaseActiveRecord ...@@ -91,4 +91,5 @@ class CoinApplication extends BaseActiveRecord
{ {
return self::find()->where(['id' => $id])->one(); return self::find()->where(['id' => $id])->one();
} }
} }
\ No newline at end of file
...@@ -97,5 +97,11 @@ class CoinApplicationCategory extends BaseActiveRecord ...@@ -97,5 +97,11 @@ class CoinApplicationCategory extends BaseActiveRecord
return self::find()->asArray()->all(); return self::find()->asArray()->all();
} }
public static function getAllList()
{
return self::find()->orderBy('sort asc')->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