Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

114 рядки
3.0 KiB

  1. <?php
  2. /**
  3. * 数据库表类 sg_play_log
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2018/03/28 16:56 $
  14. */
  15. namespace common\models;
  16. use yii\db\ActiveRecord;
  17. use yii\db\Exception;
  18. use yii\db\Expression;
  19. /**
  20. * 数据库表类 sg_play_log.
  21. * @property integer $id
  22. * @property string $create_time
  23. * @property string $update_time
  24. * @property integer $union_id
  25. * @property double $score
  26. * @property string $nick_name
  27. */
  28. class SgPlayLog extends ActiveRecord
  29. {
  30. /**
  31. * @inheritdoc
  32. */
  33. public static function tableName()
  34. {
  35. return 'sg_play_log';
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['update_time'], 'safe'],
  44. [['score'], 'number'],
  45. [['create_time'], 'string', 'max' => 20],
  46. [['nick_name','open_id'], 'string', 'max' => 255],
  47. ];
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'create_time' => 'Create Time',
  57. 'update_time' => 'Update Time',
  58. 'open_id' => 'Open ID',
  59. 'score' => 'Score',
  60. 'nick_name' => 'Nick Name',
  61. ];
  62. }
  63. /**
  64. * Function Description:查询用户成绩排名
  65. * Function Name: getRankList
  66. * @param $start_time
  67. *
  68. * @return array|ActiveRecord[]
  69. *
  70. * @author 娄梦宁
  71. */
  72. public function getRankList($start_time)
  73. {
  74. $select=[
  75. 'a.open_id',
  76. 'a.nick_name',
  77. 'score'=>new Expression('min(a.score)'),
  78. 'avatar_url'=>new Expression('(select avatar_url from sg_user where open_id =a.open_id)')
  79. ];
  80. $where=['>','create_time',$start_time];
  81. $result=self::find()->from(self::tableName().' a')->select($select)
  82. ->where($where)->groupBy('open_id')->orderBy('score,id')->asArray()->all();
  83. return $result;
  84. }
  85. /**
  86. * Function Description:根据open_id获取个人最好的20次成绩
  87. * Function Name: getSelfRankList
  88. * @param $open_id
  89. *
  90. * @return array|ActiveRecord[]
  91. *
  92. * @author 娄梦宁
  93. */
  94. public function getSelfRankList($open_id)
  95. {
  96. $select=[
  97. 'nick_name',
  98. 'score',
  99. 'create_time',
  100. ];
  101. $result=self::find()->from(self::tableName())->select($select)
  102. ->where(['=','open_id',$open_id])->orderBy('score,id')
  103. ->limit(20)->asArray()->all();
  104. return $result;
  105. }
  106. }