RoomGradeModel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace addons\exam\model;
  3. use app\admin\model\exam\CateModel;
  4. use think\Db;
  5. class RoomGradeModel extends \app\admin\model\exam\RoomGradeModel
  6. {
  7. public function user()
  8. {
  9. return $this->belongsTo(UserModel::class, 'user_id', 'id');
  10. }
  11. public function cate()
  12. {
  13. return $this->belongsTo(CateModel::class, 'cate_id', 'id');
  14. }
  15. public function paper()
  16. {
  17. return $this->belongsTo(PaperModel::class, 'paper_id', 'id');
  18. }
  19. public function room()
  20. {
  21. return $this->belongsTo(RoomModel::class, 'room_id', 'id');
  22. }
  23. public static function getRank($room_id)
  24. {
  25. }
  26. /**
  27. * 获取试卷参与人员
  28. * @param $room_id
  29. * @param $slice
  30. * @return array
  31. */
  32. public static function getJoinUsers($room_id, $slice = 0)
  33. {
  34. $user_ids = Db::name('exam_room_grade')->where('room_id', $room_id)->group('user_id')->column('user_id');
  35. if ($user_ids) {
  36. // 截取数组
  37. $user_ids = $slice ? array_slice($user_ids, $slice) : $user_ids;
  38. return Db::name('user')->whereIn('id', $user_ids)->select();
  39. }
  40. return [];
  41. }
  42. }