QuestionController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Created by north.Deng's MAC
  4. * User: north.Deng
  5. * Date: 2018/5/4
  6. * Time: 下午12:34
  7. * description :
  8. */
  9. class QuestionController extends JBaseController
  10. {
  11. public function actionList()
  12. {
  13. /*$tmp = Question::get(new MongoId('5aebea7d9f51603e1b8b46a6'));
  14. for ($i=0;$i<20;$i++) {
  15. $q = new Question();
  16. $q->title = $tmp->title;
  17. $q->question = $tmp->question;
  18. $q->save();
  19. }*/
  20. $pageParams = CommonFn::getPageParams();
  21. $cursor = Question::model()->findAll();
  22. $rows = CommonFn::getRowsFromCursor($cursor);
  23. $parsedRows = Question::model()->parse($rows);
  24. $total = $cursor->count();
  25. if ($total > 5) {
  26. $offset = rand(0,$total-5);
  27. $limit = 5;
  28. $pageParams['offset'] = $offset;
  29. $pageParams['limit'] = $limit;
  30. $criteria = new EMongoCriteria($pageParams);
  31. $cursor = Question::model()->findAll($criteria);
  32. $rows = CommonFn::getRowsFromCursor($cursor);
  33. $parsedRows = Question::model()->parse($rows);
  34. $total = $cursor->count();
  35. }
  36. echo CommonFn::composeDatagridData($parsedRows, $total);
  37. }
  38. public function actionResult()
  39. {
  40. $user_id = Yii::app()->request->getParam('id','');
  41. $score = Yii::app()->request->getParam('score','');
  42. $jgemp = JGEmploye::get(new MongoId($user_id));
  43. if (!empty($jgemp)) {
  44. $jgemp->score = (int)$jgemp->score + (int)$score;
  45. $jgemp->score_time = date('Y-m-d H:i:s');
  46. if ($jgemp->degree >= 1) {
  47. $jgemp->degree -= 1;
  48. } else {
  49. CommonFn::requestAjax(true, '今日次数已用完', array());exit;
  50. }
  51. $jgemp->save();
  52. }
  53. CommonFn::requestAjax(true, '答题完毕', array());
  54. }
  55. }