Topic.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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\wap\controller;
  12. use service\GroupDataService;
  13. use service\SystemConfigService;
  14. use think\Cache;
  15. use think\Request;
  16. use think\Url;
  17. use service\JsonService;
  18. use service\UtilService;
  19. use app\wap\model\topic\TestPaperCategory;
  20. use app\wap\model\topic\TestPaper;
  21. use app\wap\model\topic\TestPaperQuestions;
  22. use app\wap\model\special\Special as SpecialModel;
  23. use app\wap\model\topic\Questions;
  24. use app\wap\model\topic\ExaminationRecord;
  25. use app\wap\model\topic\ExaminationTestRecord;
  26. use app\wap\model\topic\ExaminationWrongBank;
  27. use app\wap\model\topic\TestPaperObtain;
  28. use app\wap\model\topic\CertificateRecord;
  29. use app\wap\model\topic\CertificateRelated;
  30. use app\wap\model\topic\Relation;
  31. use app\wap\model\merchant\Merchant as MerchantModel;
  32. /**题库控制器
  33. * Class Topic
  34. * @package app\wap\controller
  35. */
  36. class Topic extends AuthController
  37. {
  38. /**
  39. * 白名单
  40. * */
  41. public static function WhiteList()
  42. {
  43. return [
  44. 'question_category',
  45. 'testPaperCate',
  46. 'practiceList',
  47. 'problem_index',
  48. 'specialTestPaper',
  49. 'testPaperDetails',
  50. 'situationRecord',
  51. 'userAnswer',
  52. 'takeTheTestAgain',
  53. 'continueAnswer'
  54. ];
  55. }
  56. /**练习详情
  57. * @return mixed
  58. */
  59. public function problem_index($id = 0)
  60. {
  61. if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  62. $title = TestPaper::PreExercisesWhere()->where('id', $id)->value('title');
  63. $this->assign(['uid' => $this->uid, 'titles' => $title, 'id' => $id]);
  64. return $this->fetch();
  65. }
  66. /**练习答题
  67. * @return mixed
  68. */
  69. public function problem_detail($test_id)
  70. {
  71. if (!$test_id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  72. $title = TestPaper::PreExercisesWhere()->where('id', $test_id)->value('title');
  73. $isPay = (!$this->uid || $this->uid == 0) ? false : TestPaperObtain::PayTestPaper($test_id, $this->uid, 1);
  74. if (!$isPay) $this->failed('您暂未获得练习试题', Url::build('topic/problem_index', ['id' => $test_id]));
  75. $this->assign(['uid' => $this->uid, 'titles' => $title]);
  76. return $this->fetch();
  77. }
  78. /**练习答题卡
  79. * @return mixed
  80. */
  81. public function problem_sheet()
  82. {
  83. return $this->fetch();
  84. }
  85. /**考试答题
  86. * @return mixed
  87. */
  88. public function question_detail($test_id)
  89. {
  90. if (!$test_id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  91. $test = TestPaper::PreExercisesWhere()->where('id', $test_id)->field('title,txamination_time')->find();
  92. $isPay = (!$this->uid || $this->uid == 0) ? false : TestPaperObtain::PayTestPaper($test_id, $this->uid, 2);
  93. if (!$isPay) $this->failed('您还未购买考试试卷', Url::build('special/question_index', ['id' => $test_id]));
  94. $this->assign(['uid' => $this->uid, 'titles' => $test['title'], 'txamination_time' => $test['txamination_time']]);
  95. return $this->fetch();
  96. }
  97. /**考试答题卡
  98. * @return mixed
  99. */
  100. public function question_sheet()
  101. {
  102. return $this->fetch();
  103. }
  104. /**考试评测
  105. * @return mixed
  106. */
  107. public function question_user()
  108. {
  109. return $this->fetch();
  110. }
  111. /**我的错题
  112. * @return mixed
  113. */
  114. public function question_wrong()
  115. {
  116. return $this->fetch();
  117. }
  118. /**
  119. * 练习、考试 列表
  120. */
  121. public function question_category($type = 1)
  122. {
  123. $this->assign([
  124. 'homeLogo' => SystemConfigService::get('home_logo'),
  125. 'type' => $type
  126. ]);
  127. return $this->fetch();
  128. }
  129. /**
  130. * 我的证书
  131. */
  132. public function certificate_list()
  133. {
  134. return $this->fetch();
  135. }
  136. /**
  137. * 荣誉证书
  138. */
  139. public function certificate_detail()
  140. {
  141. return $this->fetch();
  142. }
  143. /**
  144. * 考试结果
  145. */
  146. public function question_result()
  147. {
  148. return $this->fetch();
  149. }
  150. /**
  151. * 练习结果
  152. */
  153. public function problem_result()
  154. {
  155. return $this->fetch();
  156. }
  157. /**
  158. * 错题详情
  159. */
  160. public function question_detail_wrong()
  161. {
  162. return $this->fetch();
  163. }
  164. /**
  165. * 试卷分类
  166. * @param int $type 1=练习 2=考试
  167. */
  168. public function testPaperCate($type = 1)
  169. {
  170. $cateogry = TestPaperCategory::with('children')->where(['is_show' => 1, 'is_del' => 0, 'type' => $type])->order('sort desc,id desc')->where('pid', 0)->select();
  171. return JsonService::successful($cateogry->toArray());
  172. }
  173. /**
  174. * 试卷列表
  175. */
  176. public function practiceList($type = 1)
  177. {
  178. list($page, $limit, $pid, $tid, $search) = UtilService::PostMore([
  179. ['page', 1],
  180. ['limit', 10],
  181. ['pid', 0],
  182. ['tid', 0],
  183. ['search', ''],
  184. ], $this->request, true);
  185. return JsonService::successful(TestPaper::getTestPaperExercisesList($type, $page, $limit, $pid, $tid, $search));
  186. }
  187. /**试卷详情
  188. * @param int $id
  189. */
  190. public function testPaperDetails($id = 0)
  191. {
  192. if (!$id) return JsonService::fail('缺少参数,无法访问');
  193. $testPaper = TestPaper::PreExercisesWhere()->where('id', $id)->find();
  194. if (!$testPaper) return JsonService::fail('试卷不存在');
  195. $isPay = 0;
  196. $surplus = -1; //剩余考试次数 -1 无限次 0 无法答题
  197. if ($this->uid) {
  198. if ($testPaper['type'] == 1) {
  199. $isPay = 1;
  200. if (!TestPaperObtain::PayTestPaper($id, $this->uid, 1)) {
  201. TestPaperObtain::setUserTestPaper('', $id, $this->uid, 1, 2);
  202. }
  203. } else if ($testPaper['type'] == 2) {
  204. if (in_array($testPaper['money'], [0, 0.00]) || in_array($testPaper['pay_type'], [PAY_NO_MONEY])) {
  205. $res = true;
  206. if (!TestPaperObtain::PayTestPaper($id, $this->uid, 2)) {
  207. $res = TestPaperObtain::setUserTestPaper('', $id, $this->uid, 2, 2);
  208. }
  209. if ($res) $isPay = 1;
  210. } else {
  211. $business = isset($this->userInfo['business']) ? $this->userInfo['business'] : 0;
  212. $isPay = TestPaperObtain::PayTestPaper($id, $this->uid, 2);
  213. if (!$isPay && $business) {
  214. $mer_id = MerchantModel::getMerId($this->uid);
  215. $res = false;
  216. if ($mer_id == $testPaper['mer_id']) {
  217. $res = TestPaperObtain::setUserTestPaper('', $id, $this->uid, 2, 2);
  218. }
  219. if ($res) $isPay = 1;
  220. }
  221. }
  222. $surplus = $testPaper['frequency'] == 0 ? -1 : $testPaper['frequency'];
  223. if ($isPay && $testPaper['frequency'] > 0) {
  224. $number = TestPaperObtain::where(['uid' => $this->uid, 'test_id' => $id, 'type' => 2, 'is_del' => 0])->value('number');
  225. $surplus = bcsub($testPaper['frequency'], $number, 0);
  226. }
  227. }
  228. }
  229. $testPaper['surplus'] = $surplus;
  230. $testPaper['isPay'] = $isPay;
  231. return JsonService::successful($testPaper);
  232. }
  233. /**检查试卷答题情况
  234. * @param $id
  235. * @throws \think\Exception
  236. * @throws \think\db\exception\DataNotFoundException
  237. * @throws \think\db\exception\ModelNotFoundException
  238. * @throws \think\exception\DbException
  239. */
  240. public function situationRecord($id)
  241. {
  242. if (!$id) return JsonService::fail('缺少参数,无法访问');
  243. $testPaper = TestPaper::PreExercisesWhere()->where('id', $id)->find();
  244. if (!$testPaper) return JsonService::fail('试卷不存在');
  245. $record = 0;
  246. if (!$this->uid) return JsonService::successful('ok', $record);
  247. $count = ExaminationRecord::where(['test_id' => $testPaper['id'], 'type' => $testPaper['type'], 'uid' => $this->uid])->count();
  248. if ($count) {
  249. $userRecord = ExaminationRecord::where(['test_id' => $testPaper['id'], 'type' => $testPaper['type'], 'uid' => $this->uid, 'is_submit' => 0])->order('id desc')->find();
  250. if ($userRecord) {
  251. $record = 2;//继续答题
  252. if ($testPaper['type'] == 2) {
  253. if (bcsub($userRecord['end_time'], time(), 0) <= 0) {
  254. $data = [
  255. 'examination_id' => $userRecord['id'],
  256. 'type' => $testPaper['type'],
  257. 'duration' => $testPaper['txamination_time'],
  258. 'score' => 0
  259. ];
  260. $res = ExaminationRecord::submitExaminationRecord($data, $this->uid);
  261. if (!$res) {
  262. ExaminationRecord::clearLastExamResults($id, $testPaper['type'], $this->uid);
  263. }
  264. $record = 1;
  265. }
  266. }
  267. } else {
  268. $record = 1;//再次答题
  269. }
  270. } else {
  271. $record = 0; //没有答过题
  272. }
  273. return JsonService::successful('ok', $record);
  274. }
  275. /**用户开始答题
  276. * @param int $id
  277. */
  278. public function userAnswer($test_id = 0, $type = 1)
  279. {
  280. if (!$test_id) return JsonService::fail('缺少参数,无法访问');
  281. $testPaper = TestPaper::PreExercisesWhere()->where('id', $test_id)->find();
  282. if (!$testPaper) return JsonService::fail('试卷不存在');
  283. $uid = $this->uid;
  284. if ($type == 2 && $uid && $testPaper['type'] == 2) {
  285. $number = TestPaperObtain::where(['uid' => $uid, 'test_id' => $test_id, 'type' => 2, 'is_del' => 0])->value('number');
  286. if ($number >= $testPaper['frequency'] && $testPaper['frequency'] > 0) return JsonService::fail('您的考试次数已用完');
  287. }
  288. $examination_id = ExaminationRecord::addExaminationRecord($test_id, $type, $uid, $testPaper['txamination_time']);
  289. if ($examination_id) {
  290. return JsonService::successful('ok', $examination_id);
  291. } else {
  292. return JsonService::fail('开始答题失败');
  293. }
  294. }
  295. /**再考一次
  296. * @param int $test_id
  297. * @param int $type
  298. * @throws \think\db\exception\DataNotFoundException
  299. * @throws \think\db\exception\ModelNotFoundException
  300. * @throws \think\exception\DbException
  301. */
  302. public function takeTheTestAgain($test_id = 0, $type = 1)
  303. {
  304. if (!$test_id) return JsonService::fail('缺少参数,无法访问');
  305. $testPaper = TestPaper::PreExercisesWhere()->where('id', $test_id)->find();
  306. if (!$testPaper) return JsonService::fail('试卷不存在');
  307. $uid = $this->uid;
  308. if ($type == 2 && $uid && $testPaper['type'] == 2) {
  309. $number = TestPaperObtain::where(['uid' => $uid, 'test_id' => $test_id, 'type' => 2, 'is_del' => 0])->value('number');
  310. if ($number >= $testPaper['frequency'] && $testPaper['frequency'] > 0) return JsonService::fail('您的考试次数已用完');
  311. }
  312. $examination_id = ExaminationRecord::addExaminationRecord($test_id, $type, $uid, $testPaper['txamination_time']);
  313. if ($examination_id) {
  314. $res = ExaminationRecord::clearLastExamResults($test_id, $type, $uid);
  315. if (!$res) {
  316. return JsonService::fail('再次答题失败');
  317. } else {
  318. return JsonService::successful('ok', $examination_id);
  319. }
  320. } else {
  321. return JsonService::fail('再次答题失败');
  322. }
  323. }
  324. /**继续答题
  325. * @param int $test_id
  326. * @param int $type
  327. * @throws \think\db\exception\DataNotFoundException
  328. * @throws \think\db\exception\ModelNotFoundException
  329. * @throws \think\exception\DbException
  330. */
  331. public function continueAnswer($test_id = 0, $type = 1)
  332. {
  333. if (!$test_id) return JsonService::fail('缺少参数,无法访问');
  334. $testPaper = TestPaper::PreExercisesWhere()->where('id', $test_id)->find();
  335. if (!$testPaper) return JsonService::fail('试卷不存在');
  336. $record = ExaminationRecord::where(['test_id' => $test_id, 'type' => $type, 'uid' => $this->uid, 'is_submit' => 0])->order('id desc')->find();
  337. if ($record) {
  338. return JsonService::successful('ok', $record['id']);
  339. } else {
  340. return JsonService::fail('继续答题失败');
  341. }
  342. }
  343. /**获取试卷中的试题
  344. * @param $test_id 试卷ID
  345. * @param $type
  346. * @param $record_id 继续答题传入
  347. * @param is_correct 0=未答 1=答错 2=正确
  348. */
  349. public function testPaperQuestions($test_id, $type, $record_id = 0)
  350. {
  351. if (!$test_id) return JsonService::fail('缺少参数,无法访问');
  352. $testPaper = TestPaper::PreExercisesWhere()->where('id', $test_id)->find();
  353. if (!$testPaper) return JsonService::fail('试卷不存在');
  354. $arr = ['1' => $testPaper['single_sort'], '2' => $testPaper['many_sort'], '3' => $testPaper['judge_sort']];
  355. arsort($arr);
  356. $question = [];
  357. foreach ($arr as $key => $item) {
  358. $single = TestPaperQuestions::getQuestionslist($test_id, $type, $key);
  359. $question = array_merge($question, $single);
  360. }
  361. if (count($question) <= 0) return JsonService::fail('试卷中试题为空');
  362. if ($record_id) {
  363. $record = ExaminationRecord::where(['id' => $record_id, 'test_id' => $test_id, 'type' => $type, 'uid' => $this->uid])->order('id desc')->find();
  364. } else {
  365. $record = false;
  366. }
  367. foreach ($question as $key => &$value) {
  368. if ($record) {
  369. $value['userAnswer'] = ExaminationTestRecord::checkWhetherAnswerQuestions($record['id'], $type, $this->uid, $value['questions_id']);
  370. } else {
  371. $value['userAnswer'] = [];
  372. }
  373. $value['option'] = json_decode($value['option']);
  374. $value['special'] = Relation::getRelationSpecial(3, $value['questions_id']);
  375. }
  376. return JsonService::successful($question);
  377. }
  378. /**答题卡
  379. * @param $test_id 试卷ID
  380. * @param $type
  381. * @param int $record_id 答题记录ID
  382. */
  383. public function answerSheet($test_id, $type, $record_id = 0)
  384. {
  385. if (!$test_id || !$record_id) return JsonService::fail('缺少参数,无法访问');
  386. $testPaper = TestPaper::PreExercisesWhere()->where('id', $test_id)->find();
  387. if (!$testPaper) return JsonService::fail('试卷不存在');
  388. $arr = ['1' => $testPaper['single_sort'], '2' => $testPaper['many_sort'], '3' => $testPaper['judge_sort']];
  389. arsort($arr);
  390. $testPaperQuestion = [];
  391. foreach ($arr as $key => $item) {
  392. $single = TestPaperQuestions::getQuestionslist($test_id, $type, $key);
  393. $testPaperQuestion = array_merge($testPaperQuestion, $single);
  394. }
  395. $record = ExaminationRecord::where(['id' => $record_id, 'test_id' => $test_id, 'type' => $type, 'uid' => $this->uid])->order('id desc')->find();
  396. if (!$record) return JsonService::fail('考试记录不存在');
  397. foreach ($testPaperQuestion as $key => &$value) {
  398. $value['userAnswer'] = ExaminationTestRecord::checkWhetherAnswerQuestions($record['id'], $type, $this->uid, $value['questions_id']);
  399. }
  400. return JsonService::successful($testPaperQuestion);
  401. }
  402. /**考试结果
  403. * @param $test_id
  404. * @param $type
  405. */
  406. public function examinationResults($test_id, $type)
  407. {
  408. if (!$test_id) return JsonService::fail('缺少参数,无法访问');
  409. $testPaper = TestPaper::PreExercisesWhere()->where('id', $test_id)->find();
  410. if (!$testPaper) return JsonService::fail('试卷不存在');
  411. $arr = ['1' => $testPaper['single_sort'], '2' => $testPaper['many_sort'], '3' => $testPaper['judge_sort']];
  412. arsort($arr);
  413. $testPaperQuestion = [];
  414. foreach ($arr as $key => $item) {
  415. $single = TestPaperQuestions::getQuestionslist($test_id, $type, $key);
  416. $testPaperQuestion = array_merge($testPaperQuestion, $single);
  417. }
  418. $record = ExaminationRecord::where(['test_id' => $test_id, 'type' => $type, 'uid' => $this->uid, 'is_submit' => 1])->order('id desc')->find();
  419. if (!$record) return JsonService::fail('考试记录不存在');
  420. foreach ($testPaperQuestion as $key => &$value) {
  421. $value['userAnswer'] = ExaminationTestRecord::checkWhetherAnswerQuestions($record['id'], $type, $this->uid, $value['questions_id']);
  422. }
  423. $record['title'] = $testPaper['title'];
  424. $record['is_score'] = $testPaper['is_score'];
  425. $record['test_paper_question'] = $testPaperQuestion;
  426. $record['not_questions'] = bcsub($testPaper['item_number'], bcadd($record['yes_questions'], $record['wrong_question'], 0), 0);
  427. return JsonService::successful($record);
  428. }
  429. /**保存试题答题结果
  430. * @param int $id
  431. */
  432. public function submitQuestions()
  433. {
  434. $data = UtilService::PostMore([
  435. ['e_id', 0],
  436. ['type', 1],
  437. ['questions_id', 0],
  438. ['user_answer', ''],
  439. ['answer', ''],
  440. ['is_correct', 0],
  441. ['score', 0]
  442. ], $this->request);
  443. if ($data['e_id'] <= 0) return JsonService::fail('参数错误');
  444. $res = ExaminationTestRecord::addExaminationTestRecord($data, $this->uid);
  445. if ($res) return JsonService::successful('提交成功');
  446. else return JsonService::fail('提交失败');
  447. }
  448. /**
  449. * 提交试卷
  450. */
  451. public function submitTestPaper()
  452. {
  453. $data = UtilService::PostMore([
  454. ['examination_id', 0],
  455. ['type', 1],
  456. ['duration', ''],
  457. ['score', '']
  458. ], $this->request);
  459. $res = ExaminationRecord::submitExaminationRecord($data, $this->uid);
  460. if ($res) return JsonService::successful('提交成功');
  461. else return JsonService::fail(ExaminationRecord::getErrorInfo('提交失败'));
  462. }
  463. /**检测是否提交
  464. * @return void
  465. * @throws \think\db\exception\DataNotFoundException
  466. * @throws \think\db\exception\ModelNotFoundException
  467. * @throws \think\exception\DbException
  468. */
  469. public function is_submit()
  470. {
  471. $data = UtilService::PostMore([
  472. ['examination_id', 0],
  473. ['type', 1],
  474. ], $this->request);
  475. $record = ExaminationRecord::where(['id' => $data['examination_id'], 'type' => $data['type'], 'uid' => $this->uid])->find();
  476. if(!$record) return JsonService::fail('记录不存在');
  477. return JsonService::successful($record['is_submit']);
  478. }
  479. /**专题下关联的练习、考试 post提交
  480. * @param $special_id
  481. */
  482. public function specialTestPaper()
  483. {
  484. list($special_id, $type) = UtilService::PostMore([
  485. ['special_id', 0],
  486. ['type', 1],
  487. ], $this->request, true);
  488. if (!$special_id) return JsonService::fail('缺少参数,无法访问');
  489. $data = [];
  490. switch ($type) {
  491. case 1:
  492. $relationship = 1;
  493. break;
  494. case 2:
  495. $relationship = 2;
  496. break;
  497. }
  498. $test_ids = Relation::setWhere($relationship, $special_id)->column('relation_id');
  499. if (count($test_ids)) {
  500. $data = TestPaper::PreExercisesWhere()->where('type', $type)->where('id', 'in', $test_ids)->order('sort desc,id desc')->select();
  501. $data = count($data) > 0 ? $data->toArray() : [];
  502. foreach ($data as $key => &$value) {
  503. if ($type == 1) {
  504. $record = ExaminationRecord::where(['test_id' => $value['id'], 'uid' => $this->uid, 'type' => 1])->order('id desc')->find();
  505. if (!$record) $value['done'] = 0;
  506. else $value['done'] = ExaminationTestRecord::where(['e_id' => $record['id'], 'uid' => $this->uid, 'type' => 1])->count();
  507. } else if ($type == 2) {
  508. $value['is_pay'] = (!$this->uid || $this->uid == 0) ? false : TestPaperObtain::PayTestPaper($value['id'], $this->uid, 2);
  509. }
  510. }
  511. }
  512. return JsonService::successful($data);
  513. }
  514. /**
  515. * 我的错题库列表
  516. */
  517. public function userWrongBank()
  518. {
  519. list($page, $limit, $is_master) = UtilService::PostMore([
  520. ['page', 1],
  521. ['limit', 10],
  522. ['is_master', ''],
  523. ], $this->request, true);
  524. $list = ExaminationWrongBank::userWrongBankList($this->uid, $page, $limit, $is_master);
  525. return JsonService::successful($list);
  526. }
  527. /**
  528. * 我的错题库id列表
  529. */
  530. public function userWrongBankIdArr()
  531. {
  532. list($id, $is_master, $order) = UtilService::PostMore([
  533. ['id', 0],
  534. ['is_master', ''],
  535. ['order', 1],
  536. ], $this->request, true);
  537. $list = ExaminationWrongBank::getUserWrongBankIDList($this->uid, $is_master, $id, $order);
  538. return JsonService::successful($list);
  539. }
  540. /**删除错题
  541. * @param $id
  542. */
  543. public function delWrongBank($id)
  544. {
  545. if (!$id) return JsonService::fail('缺少参数');
  546. $res = ExaminationWrongBank::delUserWrongBank($id);
  547. return JsonService::successful($res);
  548. }
  549. /**获取错题库的试题 未使用
  550. * @throws \think\db\exception\DataNotFoundException
  551. * @throws \think\db\exception\ModelNotFoundException
  552. * @throws \think\exception\DbException
  553. */
  554. public function lookTopicWrongBank()
  555. {
  556. list($is_master) = UtilService::PostMore([
  557. ['is_master', 0],
  558. ], $this->request, true);
  559. $list = ExaminationWrongBank::getUserWrongBankListAll($this->uid, $is_master);
  560. return JsonService::successful($list);
  561. }
  562. /**获取单个错题
  563. * @param $id
  564. * @throws \think\db\exception\DataNotFoundException
  565. * @throws \think\db\exception\ModelNotFoundException
  566. * @throws \think\exception\DbException
  567. */
  568. public function oneWrongBank($id)
  569. {
  570. if (!$id) return JsonService::fail('缺少参数,无法访问');
  571. $wrong = ExaminationWrongBank::getUserWrongBankListOne($this->uid, $id);
  572. $wrong['special'] = Relation::getRelationSpecial(3, $wrong['questions_id']);
  573. return JsonService::successful($wrong);
  574. }
  575. /**
  576. * 错题库未掌握试题提交
  577. */
  578. public function submitWrongBank()
  579. {
  580. $data = UtilService::PostMore([
  581. ['wrong_id', 0],
  582. ['questions_id', 0],
  583. ['is_master', 0]
  584. ], $this->request);
  585. if ((int)$data['wrong_id'] <= 0 || (int)$data['questions_id'] <= 0) return JsonService::fail('参数错误');
  586. $res = ExaminationWrongBank::userSubmitWrongBank($data, $this->uid);
  587. if ($res) return JsonService::successful('ok');
  588. else return JsonService::fail('err');
  589. }
  590. /**
  591. * 考试检测是否达到领取标准
  592. * $test_id 试卷ID
  593. */
  594. public function inspect($test_id = 0)
  595. {
  596. $res = CertificateRelated::getCertificateRelated($test_id, 0, 2, $this->uid);
  597. if ($res) {
  598. return JsonService::successful('ok');
  599. } else {
  600. return JsonService::fail('err');
  601. }
  602. }
  603. /**用户领取证书
  604. * $test_id 试卷ID
  605. */
  606. public function getTheCertificate($test_id)
  607. {
  608. $res = CertificateRecord::getUserTheCertificate($test_id, 2, $this->uid);
  609. if ($res) {
  610. return JsonService::successful($res);
  611. } else {
  612. return JsonService::fail('领取失败');
  613. }
  614. }
  615. /**
  616. * 我的试卷
  617. * @param int $type 1=练习 2=考试
  618. */
  619. public function myTestPaper()
  620. {
  621. list($page, $limit, $type) = UtilService::PostMore([
  622. ['page', 1],
  623. ['limit', 10],
  624. ['type', 1]
  625. ], $this->request, true);
  626. $list = TestPaperObtain::getUserTestPaper($type, $this->uid, $page, $limit);
  627. return JsonService::successful($list);
  628. }
  629. /**
  630. * 我的证书
  631. */
  632. public function getUserCertificate()
  633. {
  634. list($page, $limit) = UtilService::PostMore([
  635. ['page', 1],
  636. ['limit', 10]
  637. ], $this->request, true);
  638. $list = CertificateRecord::getUserCertificate($this->uid, $page, $limit);
  639. return JsonService::successful($list);
  640. }
  641. /**查看证书
  642. * @param $id
  643. * @param $obtain
  644. * @throws \think\db\exception\DataNotFoundException
  645. * @throws \think\db\exception\ModelNotFoundException
  646. * @throws \think\exception\DbException
  647. */
  648. public function viewCertificate($id, $obtain)
  649. {
  650. $data = CertificateRecord::getCertificate($id, $obtain, $this->uid);
  651. if ($data) {
  652. return JsonService::successful($data);
  653. } else {
  654. return JsonService::fail('关联证书已被移除');
  655. }
  656. }
  657. }