GradeModel.php 964 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace addons\exam\model;
  3. use app\admin\model\exam\CateModel;
  4. class GradeModel extends \app\admin\model\exam\GradeModel
  5. {
  6. public function user()
  7. {
  8. return $this->belongsTo(UserModel::class, 'user_id', 'id');
  9. }
  10. public function cate()
  11. {
  12. return $this->belongsTo(CateModel::class, 'cate_id', 'id');
  13. }
  14. public function paper()
  15. {
  16. return $this->belongsTo(PaperModel::class, 'paper_id', 'id');
  17. }
  18. /**
  19. * 获取用户某日考试次数
  20. * @param int $paper_id 试卷ID
  21. * @param int $user_id 用户ID
  22. * @param string $date 日期
  23. * @return int|string
  24. */
  25. public static function getUserDateGradeCount($paper_id, $user_id, $date = '')
  26. {
  27. if (!$user_id) {
  28. return 0;
  29. }
  30. $date = $date ?: date('Y-m-d');
  31. return self::where('user_id', $user_id)->where('paper_id', $paper_id)->where('date', $date)->count();
  32. }
  33. }