Officer.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\home\controller;
  3. use app\common\model\OfficerAnswerDetailModel;
  4. use app\common\model\OfficerAnswerModel;
  5. use app\common\model\OfficerReviewModel;
  6. use app\common\model\OfficerReviewSectionModel;
  7. use app\common\model\OfficerReviewTitleModel;
  8. use app\mobile\MobileBaseController;
  9. class Officer extends MobileBaseController
  10. {
  11. public function index()
  12. {
  13. $id = input('id', 1);
  14. $aid = input('aid', 0);
  15. if (empty($id)) {
  16. return '该题库不存在或已删除';
  17. }
  18. $review = OfficerReviewModel::find($id);
  19. if (empty($review)) {
  20. return '该题库不存在或已删除';
  21. }
  22. if ($aid > 0) {
  23. $answer = OfficerAnswerModel::find($aid);
  24. $new_answer = OfficerAnswerModel::create([
  25. 'rid' => $id,
  26. 'name' => $answer['name'],
  27. 'sex' => $answer['sex'],
  28. 'age' => $answer['age'],
  29. 'marry' => $answer['marry'],
  30. 'education' => $answer['education'],
  31. 'major' => $answer['major'],
  32. 'seniority' => $answer['seniority'],
  33. 'leader' => $answer['leader'],
  34. 'industry' => $answer['industry'],
  35. 'company' => $answer['company'],
  36. 'company_text' => $answer['company_text'],
  37. 'job' => $answer['job'],
  38. 'job_text' => $answer['job_text'],
  39. 'current_position' => $answer['current_position'],
  40. ]);
  41. $aid = $new_answer['id'];
  42. }
  43. return view('', [
  44. 'review' => $review,
  45. 'aid' => $aid,
  46. ]);
  47. }
  48. public function answer()
  49. {
  50. $id = input('id', 0);
  51. $aid = input('aid', 0);
  52. if (empty($id)) {
  53. return '该题库不存在或已删除';
  54. }
  55. $section_list = OfficerReviewSectionModel::where('rid', $id)->column('name', 'id');
  56. $list = OfficerReviewTitleModel::where('rid', $id)->order('no', 'asc')->select()->toArray();
  57. if (empty($list)) {
  58. return '该题库不存在或已删除';
  59. }
  60. foreach ($list as &$v) {
  61. $v['section'] = $section_list[$v['rsid']];
  62. unset($v);
  63. }
  64. return view('', [
  65. 'id' => $id,
  66. 'aid' => $aid,
  67. 'list' => json_encode($list),
  68. ]);
  69. }
  70. public function answerPost()
  71. {
  72. $answer = input('answer');
  73. $answer['rid'] = input('rid');
  74. $officer_answer = OfficerAnswerModel::create($answer);
  75. ajax_return(0, '', $officer_answer['id']);
  76. }
  77. public function answerDetailPost()
  78. {
  79. $id = input('id');
  80. $aid = input('aid');
  81. $no = input('no');
  82. $index = input('index');
  83. $option = [];
  84. $review_title = OfficerReviewTitleModel::where('rid', $id)->where('no', $no)->find();
  85. foreach ($review_title['option'] as $v) {
  86. if ($v['score'] == $index) {
  87. $option = $v;
  88. break;
  89. }
  90. }
  91. OfficerAnswerDetailModel::create([
  92. 'aid' => $aid,
  93. 'no' => $no,
  94. 'title' => $review_title['title'],
  95. 'score' => $option['score'],
  96. 'option_title' => $option['title'],
  97. ]);
  98. ajax_return();
  99. }
  100. public function answerFinish()
  101. {
  102. $id = input('id');
  103. $review = OfficerReviewModel::find($id);
  104. $aid = input('aid');
  105. $score = OfficerAnswerDetailModel::where('aid', $aid)->sum('score');
  106. OfficerAnswerModel::update(['score' => $score, 'status' => 2], ['id' => $aid]);
  107. ajax_return(0, '', $review['next_id']);
  108. }
  109. // public function answerPost()
  110. // {
  111. // $id = input('id');
  112. // $answer = input('answer');
  113. // $answer_detail = input('answer_detail');
  114. //
  115. // $officer_answer = OfficerAnswerModel::create($answer);
  116. // $review_title = OfficerReviewTitleModel::where('rid', $id)->column('option,title', 'no');
  117. // $score_sum = 0;
  118. // foreach ($answer_detail as $k => $v) {
  119. // $options = json_decode($review_title[$k]['option'], true);
  120. // $option = $options[$v];
  121. // OfficerAnswerDetailModel::create([
  122. // 'aid' => $officer_answer['id'],
  123. // 'no' => $k,
  124. // 'title' => $review_title[$k]['title'],
  125. // 'score' => $option['score'],
  126. // 'option_title' => $option['title'],
  127. // ]);
  128. // $score_sum += $option['score'];
  129. // }
  130. // OfficerAnswerModel::update(['score' => $score_sum], ['id' => $officer_answer['id']]);
  131. //
  132. // ajax_return();
  133. // }
  134. public function finish()
  135. {
  136. return view();
  137. }
  138. }