Commit edb380fa authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

fix See merge request !184
parents 3d90fffd 638cae70
...@@ -100,7 +100,7 @@ class ServiceController extends BaseController ...@@ -100,7 +100,7 @@ class ServiceController extends BaseController
$type = Yii::$app->request->get('type', 1); $type = Yii::$app->request->get('type', 1);
$coin_recommendItems = $this->coinRecommendList($platform_id, $type); $coin_recommendItems = $this->coinRecommendList($platform_id, $type);
$fields = ['id', 'sid', 'icon', 'name', 'nickname', 'chain', 'platform']; $fields = ['id', 'sid', 'icon', 'name', 'nickname', 'chain', 'platform'];
$rows = Coin::getSelectList(1, 999, $fields, [['in', 'id', $coin_recommendItems]]); $rows = Coin::getSelectList(1, 999, $fields, [['in', 'id', $coin_recommendItems]], $coin_recommendItems);
foreach ($rows['data'] as $key => &$value) { foreach ($rows['data'] as $key => &$value) {
$nickname = json_decode($value['nickname'], true); $nickname = json_decode($value['nickname'], true);
$value['nickname'] = $nickname[$this->lang]; $value['nickname'] = $nickname[$this->lang];
......
...@@ -63,14 +63,23 @@ class Coin extends BaseActiveRecord ...@@ -63,14 +63,23 @@ class Coin extends BaseActiveRecord
* @param array $condition * @param array $condition
* @return array|\yii\db\ActiveRecord[] * @return array|\yii\db\ActiveRecord[]
*/ */
public static function getSelectList($page = 1, $limit = 10, $columns = [], $condition = []) public static function getSelectList($page = 1, $limit = 10, $columns = [], $condition = [], $orderBy = [])
{ {
$ids_str = implode(',', $orderBy);
$order = "FIELD(`id`,$ids_str)";
$query = self::find(); $query = self::find();
foreach ($condition as $item) { foreach ($condition as $item) {
$query = $query->andWhere($item); $query = $query->andWhere($item);
} }
$count = $query->count(); $count = $query->count();
if (false != $orderBy) {
$ids_str = implode(',', $orderBy);
$order = "FIELD(`id`,$ids_str)";
$data = $query->select($columns)->offset(($page - 1) * $limit)->limit($limit)->asArray()->orderBy([$order => true])->all();
} else {
$data = $query->select($columns)->offset(($page - 1) * $limit)->limit($limit)->asArray()->all(); $data = $query->select($columns)->offset(($page - 1) * $limit)->limit($limit)->asArray()->all();
}
return ['count' => $count, 'data' => $data]; return ['count' => $count, 'data' => $data];
} }
......
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