ExamEmpResult.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class ExamEmpResult extends Model
  5. {
  6. //relaitonship
  7. public function paper()
  8. {
  9. return $this->belongsTo('ExamPaper', 'paper_id')->bind([
  10. 'name', 'starttime', 'endtime', 'duringtime', 'total_score', 'base_score','checkway'
  11. ]);
  12. }
  13. public function employee()
  14. {
  15. return $this->belongsTo(Employee::class, 'employee_id')->bind(['emp_name' => 'name']);
  16. }
  17. public function employees()
  18. {
  19. return $this->belongsTo(Employee::class, 'aprove_employee_id')->bind(['p_name' => 'name']);
  20. }
  21. //funcitons
  22. public static function autoPaperAnswerCheck($emp_answer = '', $keywordsstr = '', $fullscore = 0)
  23. {
  24. $keywordsarr = array_filter(explode('|', $keywordsstr));
  25. $keynum = count($keywordsarr);
  26. $eachkeyscore = 0;
  27. if (!empty($fullscore) && !empty($keynum)) {
  28. $eachkeyscore = $fullscore / $keynum;
  29. }
  30. $gotkeys = [];
  31. foreach ($keywordsarr as $keyw) {
  32. $posnum = strpos($emp_answer, $keyw);
  33. if ($posnum === false) continue;
  34. $gotkeys[] = $keyw;
  35. $markentity = '<span class="keyw" style="color:red;">' . $keyw . '</span>';
  36. $emp_answer = str_replace($keyw, $markentity, $emp_answer);
  37. }
  38. $got_key_num = count(array_unique($gotkeys));
  39. $got_score = floor($got_key_num * $eachkeyscore);
  40. $data = [
  41. 'got_score' => $got_score,
  42. 'emp_answer' => $emp_answer,
  43. 'gotkeys' => $gotkeys
  44. ];
  45. return $data;
  46. }
  47. public function paperid()
  48. {
  49. return $this->belongsTo(ExamPaper::class, 'paper_id')->bind(['total_score' => 'total_score']);
  50. }
  51. public function emp()
  52. {
  53. return $this->belongsTo(Employee::class, 'employee_id');
  54. }
  55. public function paperInfo()
  56. {
  57. return $this->belongsTo('ExamPaper', 'paper_id'); //
  58. }
  59. public function paperShowRealName()
  60. {
  61. return $this->belongsTo(ExamPaper::class, 'paper_id')->bind(['show_real_name']);
  62. }
  63. }