20], [['open_id', 'nick_name'], '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: getHighByOpenId * @param $open_id * * @return array|null|ActiveRecord * * @author 娄梦宁 */ public function getHighByOpenId($open_id) { $result=self::find()->select('max(score) as score')->from(self::tableName()) ->where(['=','open_id',$open_id])->asArray()->one(); return $result; } /** * 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('max(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 desc,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 desc,id') ->limit(50)->asArray()->all(); return $result; } }