TestPaperObtain.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\model\topic;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\wap\model\special\Special;
  15. use app\wap\model\special\SpecialSource;
  16. use app\wap\model\topic\TestPaper;
  17. /**
  18. * 获得试卷 Model
  19. */
  20. class TestPaperObtain extends ModelBasic
  21. {
  22. use ModelTrait;
  23. /**记录用户获取试卷
  24. * @param $order_id
  25. * @param $test_id
  26. * @param $uid
  27. * @param $type
  28. * @param $source
  29. * @return object
  30. */
  31. public static function setUserTestPaper($order_id, $test_id, $uid, $type, $source, $planid)
  32. {
  33. $add_time = time();
  34. if (self::be(['uid' => $uid, 'test_id' => $test_id, 'type' => $type, 'is_del' => 0])) return false;
  35. return self::set(compact('order_id', 'test_id', 'uid', 'type', 'source', 'add_time', 'planid'));
  36. }
  37. /**判断是否获得试卷
  38. * @param $test_id
  39. * @param $uid
  40. * @param $type
  41. * @return bool
  42. * @throws \think\Exception
  43. */
  44. public static function PayTestPaper($test_id, $uid, $type)
  45. {
  46. return self::where(['uid' => $uid, 'test_id' => $test_id, 'type' => $type, 'is_del' => 0])->count() ? true : false;
  47. }
  48. /**购买专题获得试卷
  49. * @param $order_id
  50. * @param $uid
  51. * @param $special_id
  52. * @return bool
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. */
  57. public static function setTestPaper($order_id, $uid, $special_id, $source, $planid = 0)
  58. {
  59. if (!$uid || !$special_id) return false;
  60. $special = Special::PreWhere()->where(['id'=>$special_id])->find();
  61. if ($special['type'] == SPECIAL_COLUMN) {
  62. $special_source = SpecialSource::getSpecialSource($special['id']);
  63. if (!$special_source) return false;
  64. foreach ($special_source as $k => $v) {
  65. $task_special = Special::PreWhere()->where(['id'=>$v['source_id']])->find();
  66. if (!$task_special) continue;
  67. if ($task_special['is_show'] != 1) continue;
  68. $test_ids = Relation::setWhere(2, $task_special['id'])->column('relation_id');
  69. if (count($test_ids) <= 0) continue;
  70. foreach ($test_ids as $ks => $value) {
  71. self::setUserTestPaper($order_id, $value, $uid, 2, $source, $planid);
  72. }
  73. }
  74. }
  75. $test_ids = Relation::setWhere(2, $special_id)->column('relation_id');
  76. if (count($test_ids) <= 0) return false;
  77. foreach ($test_ids as $kf => $value) {
  78. self::setUserTestPaper($order_id, $value, $uid, 2, $source, $planid);
  79. }
  80. }
  81. /**获取用户的试卷
  82. * @param $type
  83. * @param $uid
  84. */
  85. public static function getUserTestPaper($type, $uid, $page, $limit)
  86. {
  87. $list = self::alias('b')->join('TestPaper t', 'b.test_id=t.id')
  88. ->where(['b.type' => $type, 'b.uid' => $uid, 'b.is_del' => 0, 't.is_del' => 0, 't.is_show' => 1, 't.status' => 1])
  89. ->field('t.id,b.uid,b.test_id,b.type,b.source,b.number,b.add_time,t.title,t.image,t.item_number')
  90. ->page((int)$page, (int)$limit)->order('b.add_time DESC')
  91. ->select();
  92. $list = count($list) > 0 ? $list->toArray() : [];
  93. return $list;
  94. }
  95. }