20], [['nick_name','open_id'], 'string', 'max' => 255], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'create_time' => 'Create Time', 'update_time' => 'Update Time', 'open_id' => 'Open ID', 'score' => 'Score', 'nick_name' => 'Nick Name', ]; } /** * Function Description:查询用户成绩排名 * Function Name: getRankList * @param $start_time * * @return array|ActiveRecord[] * * @author 娄梦宁 */ public function getRankList($start_time) { $select=[ 'a.open_id', 'a.nick_name', 'score'=>new Expression('min(a.score)'), 'avatar_url'=>new Expression('(select avatar_url from sg_user where open_id =a.open_id)') ]; $where=['>','create_time',$start_time]; $result=self::find()->from(self::tableName().' a')->select($select) ->where($where)->groupBy('open_id')->orderBy('score,id')->asArray()->all(); return $result; } /** * Function Description:根据open_id获取个人最好的20次成绩 * Function Name: getSelfRankList * @param $open_id * * @return array|ActiveRecord[] * * @author 娄梦宁 */ public function getSelfRankList($open_id) { $select=[ 'nick_name', 'score', 'create_time', ]; $result=self::find()->from(self::tableName())->select($select) ->where(['=','open_id',$open_id])->orderBy('score,id') ->limit(20)->asArray()->all(); return $result; } }