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

129 рядки
3.4 KiB

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