|
- <?php
- /**
- * 数据库表类 sg_play_log
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm LoginController.php
- * Create By 2018/03/28 16:56 $
- */
-
- namespace common\models;
-
- use yii\db\ActiveRecord;
- use yii\db\Exception;
- use yii\db\Expression;
-
- /**
- * 数据库表类 sg_play_log.
- * @property integer $id
- * @property string $create_time
- * @property string $update_time
- * @property integer $union_id
- * @property double $score
- * @property string $nick_name
- */
- class SgPlayLog extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'sg_play_log';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['update_time'], 'safe'],
- [['score'], 'number'],
- [['create_time'], 'string', 'max' => 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;
- }
- }
|