TestPaperScoreGrade.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\merchant\model\questions;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use service\UtilService as Util;
  15. use app\merchant\model\questions\TestPaper as TestPaperModel;
  16. /**
  17. * 试卷分数等级划分 Model
  18. * Class TestPaperScoreGrade
  19. * @package app\admin\model\questions
  20. */
  21. class TestPaperScoreGrade extends ModelBasic
  22. {
  23. use ModelTrait;
  24. /**添加/修改试卷分数等级
  25. * @param array $data
  26. */
  27. public static function testPaperScoreGradeAdd($id = 0, $data = [])
  28. {
  29. if (!$id || count($data) <= 0) return false;
  30. self::where('test_id', $id)->delete();
  31. foreach ($data as $k => $time) {
  32. $time['test_id'] = $id;
  33. self::set($time);
  34. }
  35. return true;
  36. }
  37. /**
  38. * 试卷分数等级列表
  39. */
  40. public static function testPaperScoreGradeList($id = 0)
  41. {
  42. return self::where(['test_id' => $id])->order('id asc')->select();
  43. }
  44. /**获得分数对应的等级
  45. * @param $score
  46. */
  47. public static function getTestPaperScoreGrade($test_id, $score)
  48. {
  49. $grade = self::where(['test_id' => $test_id])->order('id asc')->select();
  50. $grade = count($grade) > 0 ? $grade->toArray() : [];
  51. if (!count($grade)) return '无';
  52. foreach ($grade as $key => $value) {
  53. $arr = explode('~', $value['grade_standard']);
  54. if ($score >= $arr[0] && $score <= $arr[1]) {
  55. return $value['grade_name'];
  56. }
  57. }
  58. return '无';
  59. }
  60. }