Commit 642fa5fc authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/explore' into 'master'

Feature/explore See merge request !193
parents becac46d 155b354d
...@@ -14,23 +14,32 @@ class ExploreController extends BaseController ...@@ -14,23 +14,32 @@ class ExploreController extends BaseController
{ {
$header = Yii::$app->request->headers; $header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null; $platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$data = null;
if (false == $platform_id) { if (false == $platform_id) {
$msg = '参数错误'; $msg = '参数错误';
$code = -1; $code = -1;
$data = null;
goto doEnd; goto doEnd;
} }
$app_category_model = ExploreAppCategory::find()->where(['platform_id' => $platform_id, 'status' => ExploreAppCategory::STATUS_ON])->all(); $app_category_model = ExploreAppCategory::find()->where(['platform_id' => $platform_id, 'status' => ExploreAppCategory::STATUS_ON])->orderBy('sort')->all();
foreach ($app_category_model as &$val) { if (false == $app_category_model) {
$msg = 'success';
$code = 0;
goto doEnd;
}
foreach ($app_category_model as $key => $val) {
unset($val->apps); unset($val->apps);
$val->name = $val->name[$this->lang]; $val->name = $val->name[$this->lang];
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan') $apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
->where(['app_category_id' => (int)$val->id]) ->where(['app_category_id' => (int)$val->id, 'status' => ExploreApp::STATUS_ON])
->orderBy('sort') ->orderBy('sort')
->limit($val->limit) ->limit($val->limit)
->all(); ->all();
if (empty($apps_model)) {
unset($app_category_model[$key]);
continue;
}
foreach ($apps_model as &$app) { foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang]; $app->name = $app->name[$this->lang];
} }
...@@ -39,7 +48,9 @@ class ExploreController extends BaseController ...@@ -39,7 +48,9 @@ class ExploreController extends BaseController
unset($val->limit); unset($val->limit);
unset($val->platform_id); unset($val->platform_id);
} }
$data = $app_category_model; foreach ($app_category_model as $val) {
$data[] = $val;
}
$msg = 'success'; $msg = 'success';
$code = 0; $code = 0;
doEnd : doEnd :
...@@ -60,6 +71,12 @@ class ExploreController extends BaseController ...@@ -60,6 +71,12 @@ class ExploreController extends BaseController
} }
$app_category_model = ExploreAppCategory::find()->where(['id' => (int)$category_id, 'platform_id' => $platform_id])->all(); $app_category_model = ExploreAppCategory::find()->where(['id' => (int)$category_id, 'platform_id' => $platform_id])->all();
if (false == $app_category_model) {
$msg = 'success';
$code = 0;
$data = null;
goto doEnd;
}
foreach ($app_category_model as &$val) { foreach ($app_category_model as &$val) {
foreach ($val->applications as $app) { foreach ($val->applications as $app) {
$app->name = $app->name[$this->lang]; $app->name = $app->name[$this->lang];
...@@ -95,10 +112,17 @@ class ExploreController extends BaseController ...@@ -95,10 +112,17 @@ class ExploreController extends BaseController
$id_arr = explode(',', $ids); $id_arr = explode(',', $ids);
$order = "FIELD(`id`,$ids)"; $order = "FIELD(`id`,$ids)";
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan') $apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
->where(['in', 'id', $id_arr]) ->where(['status' => ExploreApp::STATUS_ON])
->andWhere(['in', 'id', $id_arr])
->orderBy([$order => true]) ->orderBy([$order => true])
->limit(4) ->limit(4)
->all(); ->all();
if (false == $apps_model) {
$msg = 'success';
$code = 0;
$data = null;
goto doEnd;
}
foreach ($apps_model as &$app) { foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang]; $app->name = $app->name[$this->lang];
} }
......
...@@ -59,7 +59,7 @@ class ExploreAppCategory extends BaseActiveRecord ...@@ -59,7 +59,7 @@ class ExploreAppCategory extends BaseActiveRecord
public function getApplications() public function getApplications()
{ {
return $this->hasMany(ExploreApp::className(), ['app_category_id' => 'id'])->select(['id', 'name', 'icon', 'app_url', 'slogan', 'type']); return $this->hasMany(ExploreApp::className(), ['app_category_id' => 'id'])->select(['id', 'name', 'icon', 'app_url', 'slogan', 'type'])->orderBy('sort');
} }
} }
\ 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