Commit 4970322d authored by ZhuChunYang's avatar ZhuChunYang

update

parent 1342e47d
......@@ -10,6 +10,7 @@ use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplicateRecommend;
use common\models\psources\CoinApplication;
use common\models\psources\CoinApplicationCategory;
use common\models\psources\CoinBanner;
use common\models\psources\CoinImage;
use Yii;
class ApplicationBusiness
......@@ -64,6 +65,7 @@ class ApplicationBusiness
$cate_app_item['apps'] = [];
}
$cate_app_data[] = $cate_app_item;
$cate_app_item = [];
}
return $cate_app_data;
}
......@@ -149,5 +151,90 @@ class ApplicationBusiness
}
public static function getH5CategoryAppList($limit=0)
{
$data = CoinApplicationCategory::getAllList();
$cate_app_data = [];
$icon_Items = array_column($data,'icon');
$icon_Infos = CoinImage::getItemsByIds($icon_Items);
$banner_data = array_column($data,'h5_banner');
$banner_items = [];
foreach($banner_data as $item){
if($item){
$banner_items = array_merge($banner_items,explode(',',$item));
}
}
$banner_infos = CoinBanner::getBannerDataByIds($banner_items);
$cate_app_Infos = self::getH5CateAppInfo($limit);
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['h5_banner']){
$banner_ids = explode(',',$value['h5_banner']);
foreach($banner_ids as $banner_id){
$cate_app_item['h5_banner'][] = $banner_infos[$banner_id];
}
}else{
$cate_app_item['h5_banner'] = [];
}
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;
$cate_app_item = [];
}
return $cate_app_data;
}
/**
* @return mixed
* 获取分类以及应用(H5)
*/
public static function getH5CateAppInfo($limit=0,$condition = [])
{
$app_cate_Model = CoinAppCate::find();
$query = $app_cate_Model->JoinWith(['application'], false)
->select('cate_id,app_id,name,h5_icon,show_width,show_height,introduce_image,official_url,type,native_url,native_login_url,h5_url,android_url,ios_url,app_store_url,redirect_type,open_type,'.CoinAppCate::tableName().'.sort')
->orderBy(CoinAppCate::tableName().'.sort asc');
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$data = $query->asArray()->all();
$icon_Items = array_column($data,'h5_icon');
$introduce_image_Items = array_column($data,'introduce_image');
$icon_Items = array_unique($icon_Items);
$image_Items = array_merge($icon_Items,$introduce_image_Items);
$image_Infos = CoinImage::getItemsByIds($image_Items);
$cate_app_item = [];
foreach($data as &$value){
if($value['h5_icon']){
$value['h5_icon'] = $image_Infos[$value['h5_icon']]['base_url'].$image_Infos[$value['h5_icon']]['file_url'];
}else{
$value['h5_icon'] = '';
}
if($value['introduce_image']){
$value['introduce_image'] = $image_Infos[$value['introduce_image']]['base_url'].$image_Infos[$value['introduce_image']]['file_url'];
}else{
$value['introduce_image'] = '';
}
}
foreach($data as $item){
if($limit && isset($cate_app_item[$item['cate_id']]) && count($cate_app_item[$item['cate_id']])>=$limit){
continue;
}else{
$cate_app_item[$item['cate_id']] []= $item;
}
}
return $cate_app_item;
}
}
\ No newline at end of file
......@@ -51,5 +51,14 @@ class CoinApplicateRank extends BaseActiveRecord
return $data;
}
public static function getH5AppList($type)
{
$applicate_rank_model = self::find();
$data = $applicate_rank_model->JoinWith(['application'], false)
->select('relate_id as app_id,sort,name,h5_icon,introduce_image,show_width,show_height,advertise,native_url,native_login_url,h5_url,android_url,ios_url,app_store_url,redirect_type,open_type,'.CoinApplication::tableName().".type")
->orderBy(self::tableName().'.sort asc')->where([self::tableName().'.type' => $type])->asArray()->all();
return $data;
}
}
\ No newline at end of file
......@@ -48,4 +48,23 @@ class CoinBanner extends BaseActiveRecord
return self::find()->where(['id' => $id])->one();
}
public static function getBannerDataByIds($banner_ids)
{
if ($banner_ids) {
if (is_array($banner_ids)) {
$idItems = $banner_ids;
} else {
$idItems = explode(',', $banner_ids);
}
$data = self::find()->where(['in', 'id', $idItems])->asArray()->all();
$image_id_items = array_column($data, 'image_id');
$image_info = CoinImage::getItemsByIds($image_id_items);
foreach ($data as &$value) {
$value['banner_image_url'] = $image_info[$value['image_id']]['base_url'] . $image_info[$value['image_id']]['file_url'];
unset($value['image_id']);
}
}
return array_column($data,null,'id');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/11/13
* Time: 15:52
*/
namespace h5\controllers;
use common\business\ApplicationBusiness;
use common\models\psources\CoinApplicateRank;
use common\models\psources\CoinImage;
use h5\base\ResponseBuild;
use h5\base\BaseController;
use Yii;
/**
* Class CoinController
* 应用控制器
*
* @package h5\controllers
*/
class ApplicationController extends BaseController
{
public function actionIndex()
{
$response_ = new ResponseBuild();
$recommendData = ApplicationBusiness::getRecommendList();
$data['recommend'] =$recommendData;
$cate_app_data = ApplicationBusiness::getH5CategoryAppList(8);
$data['cate_app_data'] = $cate_app_data;
$response_->build(ResponseBuild::STATUS_SUCCEED, '', $data);
return $response_;
}
public function actionRankList()
{
$response_ = new ResponseBuild();
$request = Yii::$app->request;
$type = $request->post('type',1);
$result['code'] = 0;
$data = CoinApplicateRank::getH5AppList($type);
$icon_Items = array_column($data,'h5_icon');
$introduce_image_Items = array_column($data,'introduce_image');
$image_items = array_merge($icon_Items,$introduce_image_Items);
$image_Infos = CoinImage::getItemsByIds($image_items);
foreach($data as $key => &$value){
if($value['h5_icon']){
$value['h5_icon'] = $image_Infos[$value['h5_icon']]['base_url'].$image_Infos[$value['h5_icon']]['file_url'];
}else{
$value['h5_icon'] = "";
}
if($value['introduce_image']){
$value['introduce_image'] = $image_Infos[$value['introduce_image']]['base_url'].$image_Infos[$value['introduce_image']]['file_url'];
}else{
$value['introduce_image'] = "";
}
$value['app_user_num'] = ApplicationBusiness::getAppUserNum($value['app_id']);
}
$response_->build(ResponseBuild::STATUS_SUCCEED, '', $data);
return $response_;
}
}
\ No newline at end of file
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