Commit 30559b18 authored by ZhuChunYang's avatar ZhuChunYang

应用搜索功能添加

parent 5be45e39
...@@ -11,6 +11,8 @@ namespace api\controllers; ...@@ -11,6 +11,8 @@ namespace api\controllers;
use api\base\BaseController; use api\base\BaseController;
use common\business\ApplicationBusiness; use common\business\ApplicationBusiness;
use common\models\psources\CoinApplicateRank; use common\models\psources\CoinApplicateRank;
use common\models\psources\CoinApplication;
use common\models\psources\CoinImage;
use Yii; use Yii;
...@@ -85,10 +87,57 @@ class ApplicationController extends BaseController ...@@ -85,10 +87,57 @@ class ApplicationController extends BaseController
{ {
$request = Yii::$app->request; $request = Yii::$app->request;
$type = $request->post('type',1); $type = $request->post('type',1);
if($id){ $result['code'] = 0;
return CoinApplicateRank::appList($type); $data = CoinApplicateRank::getAppList($type);
}else{ $icon_Items = array_column($data,'icon');
return ['code' => 1,'data' => [],'msg' => 'id不能为空']; $icon_Infos = CoinImage::getItemsByIds($icon_Items);
foreach($data as $key => &$value){
if($value['icon']){
$value['icon'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
}else{
$value['icon'] = "";
}
} }
$result['data'] = $data;
return $result;
} }
/**
* 应用搜索
*/
public function actionAppSearch()
{
$request = Yii::$app->request;
$name = $request->get('name','');
if($name){
$appItems = CoinApplication::getAppItemsByName($name);
if($appItems){
$appIds = array_column($appItems,'id');
$icon_Items = array_column($appItems,'icon');
$icon_Infos = CoinImage::getItemsByIds($icon_Items);
foreach($appItems as &$value){
if($value['icon']){
$value['icon'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
}else{
$value['icon'] = '';
}
}
$cateItems = ApplicationBusiness::getCateInfoByAppIds($appIds);
foreach($cateItems as $item){
$cate_id = $item['cate_id'];
$app_id = $item['app_id'];
$cate_app_items[$cate_id]['cate_id'] = $cate_id;
$cate_app_items[$cate_id]['name'] = $item['name'];
$cate_app_items[$cate_id]['app'][] = $appItems[$app_id];
}
foreach ($cate_app_items as $item){
$categoryItems[] = $item;
}
return ['code' => 0,'data' => $categoryItems];
}
}
return ['code' => 0,'data' => []];
}
} }
\ No newline at end of file
...@@ -134,5 +134,16 @@ class ApplicationBusiness ...@@ -134,5 +134,16 @@ class ApplicationBusiness
return $app_user_num; return $app_user_num;
} }
public static function getCateInfoByAppIds($appIds)
{
$app_cate_Model = CoinAppCate::find();
$data = $app_cate_Model->JoinWith(['category'], false)
->select('cate_id,app_id,name')
->where(['in','app_id',$appIds])
->orderBy(CoinApplicationCategory::tableName().'.sort asc')->asArray()->all();
return $data;
}
} }
\ No newline at end of file
...@@ -28,6 +28,10 @@ class CoinAppCate extends BaseActiveRecord ...@@ -28,6 +28,10 @@ class CoinAppCate extends BaseActiveRecord
return $this->hasOne(CoinApplication::class, ['id' => 'app_id']); return $this->hasOne(CoinApplication::class, ['id' => 'app_id']);
} }
public function getCategory()
{
return $this->hasOne(CoinApplicationCategory::class, ['id' => 'cate_id']);
}
public static function getAppIdByCateId($cate_id) public static function getAppIdByCateId($cate_id)
......
...@@ -46,7 +46,7 @@ class CoinApplicateRank extends BaseActiveRecord ...@@ -46,7 +46,7 @@ class CoinApplicateRank extends BaseActiveRecord
{ {
$applicate_rank_model = self::find(); $applicate_rank_model = self::find();
$data = $applicate_rank_model->JoinWith(['application'], false) $data = $applicate_rank_model->JoinWith(['application'], false)
->select('relate_id as id,sort,name,icon'.self::tableName().".type") ->select('relate_id as id,sort,name,icon,advertise,'.self::tableName().".type")
->orderBy(self::tableName().'.sort asc')->where([self::tableName().'.type' => $type])->asArray()->all(); ->orderBy(self::tableName().'.sort asc')->where([self::tableName().'.type' => $type])->asArray()->all();
return $data; return $data;
} }
......
...@@ -149,5 +149,11 @@ class CoinApplication extends BaseActiveRecord ...@@ -149,5 +149,11 @@ class CoinApplication extends BaseActiveRecord
return self::find()->select('id,name')->asArray()->all(); return self::find()->select('id,name')->asArray()->all();
} }
public static function getAppItemsByName($name)
{
return array_column(self::find()->select('id,name,icon')->where(['like','name',$name])->asArray()->all(),null,'id');
}
} }
\ 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