diff --git a/test_mini/app.js b/test_mini/app.js index d0a0567..1ca2a22 100644 --- a/test_mini/app.js +++ b/test_mini/app.js @@ -20,6 +20,7 @@ App({ if(res.code==200){ this.globalData.token = res.data.token this.globalData.userinfo = res.data.userinfo + console.log(res.data.userinfo) if(res.data.userinfo.username == null){ //匿名用户 wx.reLaunch({ @@ -55,8 +56,8 @@ App({ userinfo: null, // 服务器传回的消费者信息 host: 'https://apitest.ctcshe.com', mediahost: 'https://apitest.ctcshe.com', - // host: 'http://127.0.0.1:8000', - // mediahost: 'http://127.0.0.1:8000', + //host: 'http://127.0.0.1:8000', + //mediahost: 'http://127.0.0.1:8000', token : '', } }) \ No newline at end of file diff --git a/test_mini/pages/main/main.js b/test_mini/pages/main/main.js index c2cd933..29b755b 100644 --- a/test_mini/pages/main/main.js +++ b/test_mini/pages/main/main.js @@ -20,8 +20,7 @@ Page({ { title: "如有疑问,请致电课程顾问师老师:18355135390" },] }, imgH: function (e) { - let winWid = wx.getSystemInfoSync().windowWidth; - console.log(e) //获取当前屏幕的宽度 + let winWid = wx.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度 let imgh = e.detail.height;                //图片高度 let imgw = e.detail.width; let swiperH = winWid * imgh / imgw + "px"; @@ -116,15 +115,32 @@ Page({ } }, goMoni: function () { + var that = this const workscope = getApp().globalData.userinfo.workscope if (workscope) { - this.genPaper(workscope) - } else { - wx.showToast({ - title: '未开通权限\r\n请致电18355135390', - icon: 'none', - duration: 2000 - }) + that.genPaper(workscope) + } + else { + const remain_count = getApp().globalData.userinfo.remain_count + let confirmText, showCancel + if(remain_count>0){ + wx.showModal({ + title: '未开通权限!', + content: '您有' + remain_count + '次体验次数.', + confirmText: '体验一下', + success(res) { + if (res.confirm) { + that.genPaper2() + } + } + }) + }else{ + wx.showModal({ + title: '未开通权限!', + content: '体验次数已用完', + showCancel: false, + }) + } } }, goYati: function () { @@ -150,7 +166,7 @@ Page({ title: '正在生成试卷', mask:true }) - api.request('/examtest/workscope/' + workId + '/monitest', 'GET').then(res => { + api.request('/examtest/workscope/' + workId + '/monitest/', 'GET').then(res => { wx.hideLoading() try { wx.setStorageSync('examtest', res.data) @@ -161,4 +177,21 @@ Page({ }) }, + genPaper2: function () { + wx.showLoading({ + title: '正在生成试卷', + mask: true + }) + api.request('/examtest/workscope/monitest2/', 'GET').then(res => { + wx.hideLoading() + try { + wx.setStorageSync('examtest', res.data) + getApp().globalData.userinfo.remain_count = res.data.remain_count + } catch (e) { } + wx.navigateTo({ + url: '/pages/moni/note', + }) + }) + + }, }) \ No newline at end of file diff --git a/test_server/crm/migrations/0013_consumer_remain_count.py b/test_server/crm/migrations/0013_consumer_remain_count.py new file mode 100644 index 0000000..a460b5c --- /dev/null +++ b/test_server/crm/migrations/0013_consumer_remain_count.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.4 on 2020-04-21 08:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('crm', '0012_auto_20200402_2313'), + ] + + operations = [ + migrations.AddField( + model_name='consumer', + name='remain_count', + field=models.IntegerField(default=1, verbose_name='可考次数'), + ), + ] diff --git a/test_server/crm/models.py b/test_server/crm/models.py index 270a896..4bb67fc 100644 --- a/test_server/crm/models.py +++ b/test_server/crm/models.py @@ -32,6 +32,7 @@ class Consumer(SoftCommonModel): subjects = models.ManyToManyField(Questioncat, verbose_name='付费学科', through='PaySubject') workscope = models.ForeignKey(WorkScope, verbose_name='工作类别', on_delete=models.SET_NULL, null=True, blank=True) collects = models.ManyToManyField(Question, verbose_name='收藏试题') + remain_count = models.IntegerField('可考次数', default=1) class Meta: diff --git a/test_server/examtest/views.py b/test_server/examtest/views.py index 9063e52..6062afa 100644 --- a/test_server/examtest/views.py +++ b/test_server/examtest/views.py @@ -102,6 +102,50 @@ class WorkScopeViewSet(ModelViewSet): i['total_score'] = ret['panduan_score'] ret['questions'] = questions return Response(ret) + + @action(methods=['get'], detail=False,url_path='monitest2', url_name='gen_monitest2', perms_map=[{'get':'gen_monitest'}]) + def monitest2(self, request, pk=None): + ''' + 生成体验版自助模拟考试 + ''' + ret = {} + rule = TestRule.objects.first() + ret['name'] = '自助模考' + datetime.now().strftime('%Y%m%d%H%M') + ret['type'] = '自助模考' # 自助模拟考试 + ret['limit'] = rule.limit + ret['total_score'] = rule.total_score + ret['pass_score'] = rule.pass_score + ret['danxuan_count'] = rule.danxuan_count + ret['danxuan_score'] = rule.danxuan_score + ret['duoxuan_count'] = rule.duoxuan_count + ret['duoxuan_score'] = rule.duoxuan_score + ret['panduan_count'] = rule.panduan_count + ret['panduan_score'] = rule.panduan_score + question_queryset = Question.objects.none() + queryset = Question.objects.filter(is_delete=0) + if ret['danxuan_count']: + danxuan = queryset.filter(type='单选').order_by('?')[:ret['danxuan_count']] + question_queryset = question_queryset | danxuan + if ret['duoxuan_count']: + duoxuan = queryset.filter(type='多选').order_by('?')[:ret['duoxuan_count']] + question_queryset = question_queryset | duoxuan + if ret['panduan_count']: + panduan = queryset.filter(type='判断').order_by('?')[:ret['panduan_count']] + question_queryset = question_queryset | panduan + questions = QuestionSerializer(instance=question_queryset.order_by('type'),many=True).data + for i in questions: + if i['type'] == '单选': + i['total_score'] = ret['danxuan_score'] + elif i['type'] == '多选': + i['total_score'] = ret['duoxuan_score'] + else: + i['total_score'] = ret['panduan_score'] + ret['questions'] = questions + user = request.user + user.remain_count = user.remain_count -1 + request.user.save() + ret['remain_count'] = user.remain_count + return Response(ret) class BannerViewSet(ModelViewSet): diff --git a/test_server/question/views.py b/test_server/question/views.py index 642b10d..9bc9fd9 100644 --- a/test_server/question/views.py +++ b/test_server/question/views.py @@ -226,7 +226,7 @@ class QuestionViewSet(ModelViewSet): class ExerciseView(APIView): def post(self, request): questioncat = request.data['questioncat'] - queryset = Question.objects.filter(is_delete=0,questioncat=questioncat).order_by('type') + queryset = Question.objects.filter(is_delete=0,questioncat=questioncat).order_by('type','name') if 'ydtms' in request.data and request.data['ydtms']: queryset = queryset.exclude(id__in = request.data['ydtms']) count = queryset.count()