chengjie hai 5 meses
pai
achega
978f087cff

+ 2 - 14
src/api/hanzi/hanziController.js

@@ -160,8 +160,7 @@ export async function UpdateHanziRecord(ctx) {
160 160
 //新增或删除汉字完成结果
161 161
 export async function UpdateHanziFinished(ctx) {
162 162
     const param = ctx.request.body;
163
-    if (param.Style == "undefined")
164
-        param.Style = "";
163
+    
165 164
     if (param.IsFinished) {
166 165
         delete param.IsFinished;
167 166
         if (param.UserID) {
@@ -182,8 +181,6 @@ export async function GetHanziFinishedData(ctx) {
182 181
     const param = {
183 182
         UserID: ctx.query.UserID || 0,
184 183
     };
185
-    if (param.UserID=="undefined")
186
-        param.UserID=0;
187 184
 
188 185
     const result = await hanzi.GetHanziFinishedData(param);
189 186
     if (result && result.length > 0)
@@ -692,8 +689,6 @@ export async function GetHanziCustomList(ctx) {
692 689
     const param = {
693 690
         UserID: ctx.query.UserID || 0,
694 691
     };
695
-    if (param.UserID=="undefined")
696
-        param.UserID=0;
697 692
 
698 693
     let result = await hanzi.GetHanziCustomList(param);
699 694
     if (result && result.length > 0) {
@@ -918,8 +913,7 @@ export async function GetHanziRecordData(ctx) {
918 913
         UserID: ctx.query.UserID || 0,
919 914
         Version: ctx.query.Version || "1.0.0",
920 915
     };
921
-    if (param.UserID=="undefined")
922
-        param.UserID=0;
916
+
923 917
 
924 918
     const result = await hanzi.GetHanziRecordData(param);
925 919
 
@@ -1040,8 +1034,6 @@ export async function GetHanziReviewList(ctx) {
1040 1034
     const param = {
1041 1035
         UserID: ctx.query.UserID || 0,
1042 1036
     };
1043
-    if (param.UserID=="undefined")
1044
-        param.UserID=0;
1045 1037
 
1046 1038
     const result = await hanzi.GetHanziReviewList(param);
1047 1039
     if (result && result.length > 0)
@@ -1055,8 +1047,6 @@ export async function GetHanziUserListByIntroducer(ctx) {
1055 1047
     const param = {
1056 1048
         UserID: ctx.query.UserID || 0,
1057 1049
     };
1058
-    if (param.UserID=="undefined")
1059
-        param.UserID=0;
1060 1050
 
1061 1051
     const result = await hanzi.GetNewUserByUserID(param);
1062 1052
     if (result && result.length > 0) {
@@ -1073,8 +1063,6 @@ export async function GetHanziWordListByUnitID(ctx) {
1073 1063
         UnitID: ctx.query.UnitID || 0,
1074 1064
         Type: "all",
1075 1065
     };
1076
-    if (param.UserID == "undefined")
1077
-        param.UserID = 0;
1078 1066
 
1079 1067
     const result = await hanzi.GetHanziWords(param);
1080 1068
     const userCustom = await hanzi.GetUsersUnitCustomList(param);

+ 500 - 113
src/api/mathcalculate/mathController.js

@@ -214,116 +214,503 @@ export async function GetQuestionTypes(ctx) {
214 214
     ctx.body = {"errcode": 10000, result: result};
215 215
 }
216 216
 
217
-// exports.GetQuestionTypesPrint = function* () {
218
-//     var param = {
219
-//         QuestionTypeID: this.query.ID || 1,
220
-//         QuestionTypeCategory:this.query.QuestionTypeCategory || 2,
221
-//         PageNum:this.query.PageNum || 1,
222
-//     }
223
-//     var questionType = yield mathcalculate.GetQuestionTypesInfo(param);
224
-//     questionType = questionType[0];
225
-
226
-
227
-//     var questionNumber = questionType.QuestionNumber2;
228
-//     if (param.QuestionTypeCategory==3)
229
-//         questionNumber = questionType.QuestionNumber3;
230
-
231
-//     questionNumber=questionNumber*param.PageNum;
232
-
233
-//     questionType.QuestionNumber=questionNumber;
234
-//     //console.log("questionType.QuestionNumber:"+questionType.QuestionNumber);
235
-//     var list = getQuestionTypeInfo(questionType);
236
-
237
-//     var questionList = [];
238
-//     //如果要求题目数小于原有题目数,则直接随机获取题目
239
-//     if (list.length > questionNumber) {
240
-
241
-//         do {
242
-//             var rnd = stringClass.Random(0, list.length - 1);
243
-//             if (list[rnd]) {
244
-//                 questionList.push(list[rnd]);
245
-//                 list[rnd] = null;
246
-//             }
247
-//         }
248
-//         while (questionList.length < questionNumber);
249
-//     }
250
-//     //如果要求题目数大于原有题目数,则获取全部原有题目的倍数,再将剩余数随机获取
251
-//     else {
252
-//         var nCount = Math.floor(questionNumber / list.length);
253
-//         for (var n = 0; n < nCount; n++) {
254
-//             for (var i = 0; i < list.length; i++) {
255
-//                 questionList.push(list[i]);
256
-//             }
257
-//         }
258
-
259
-//         while (questionList.length < questionNumber) {
260
-//             var rnd = stringClass.Random(0, list.length - 1);
261
-//             if (list[rnd]) {
262
-//                 questionList.push(list[rnd]);
263
-//                 list[rnd] = null;
264
-//             }
265
-//         }
266
-//     }
267
-
268
-//     questionList = stringClass.RemoveJSONNull(questionList);
269
-
270
-//     questionList.sort(function () {
271
-//         return 0.5 - Math.random()
272
-//     });
273
-
274
-//     var questionListResult = [];
275
-//     for (var i = 0; i < questionList.length; i++) {
276
-//         var item = {};
277
-//         for (var k in questionList[i]) {
278
-//             item[k] = questionList[i][k];
279
-
280
-//             if (item[k]=="−") {
281
-//                 item[k] = "-";
282
-//             }
283
-//         }
284
-//         item.ID = i + 1;
285
-//         var arr = questionType.HiddenColumn.split(",");
286
-//         var hidden = arr[stringClass.Random(0, arr.length - 1)];
287
-//         item.HiddenColumn = hidden;
288
-//         item.Result = item[item.HiddenColumn];
289
-
290
-//         if (param.QuestionTypeCategory==3) {
291
-//             item.Vertical=computeMath(item);
292
-//         }
293
-
294
-//         questionListResult.push(item);
295
-//     }
296
-
297
-//     var categoryArray = [{}, { Num: 1, Name: "一年级", Array: [1, 2] }, { Num: 2, Name: "二年级", Array: [3, 4] }, { Num: 3, Name: "三年级", Array: [5, 6] }, { Num: 4, Name: "四年级及以上", Array: [7] }];
298
-//     var categoryName="";
299
-//     for(var i=1;i<categoryArray.length;i++){
300
-//         for(var j=0;j<categoryArray[i].Array.length;j++){
301
-//             if (categoryArray[i].Array[j]==questionType.Category){
302
-//                 categoryName=categoryArray[i].Name;
303
-//                 break;
304
-//             }
305
-//         }
306
-//     }
307
-
308
-//     var result = {
309
-//         ID: questionType.ID,
310
-//         Category: questionType.Category,
311
-//         CategoryName: categoryName,
312
-//         //错误接口参数
313
-//         Cagegory: questionType.Category,
314
-//         CagegoryName: categoryName,
315
-
316
-//         CreateTime:moment(new Date()).format('YYYY年MM月DD日 HH:mm'),
317
-//         Name: questionType.Name,
318
-//         QuestionTypeCategory:Number(param.QuestionTypeCategory),
319
-//         QuestionTypeLevel: questionType.CategoryName + questionType.CategoryLevel,
320
-//         Difficulty: questionType.Difficulty,
321
-//         PageCount:questionNumber/param.PageNum,
322
-//         QuestionList: questionListResult,
323
-//     }
324
-//     //console.log(result);
325
-//     //var time=buildPrint(result);
326
-
327
-//     this.body = {"errcode": 10000,result:result};
328
-
329
-// }
217
+export async function GetQuestionTypesPrint(ctx) {
218
+    const param = {
219
+        QuestionTypeID: ctx.query.ID || 1,
220
+        QuestionTypeCategory: ctx.query.QuestionTypeCategory || 2,
221
+        PageNum: ctx.query.PageNum || 1,
222
+    };
223
+    const questionTypeArray = await mathcalculate.GetQuestionTypesInfo(param);
224
+    const questionType = questionTypeArray[0];
225
+
226
+    let questionNumber = questionType.QuestionNumber2;
227
+    if (param.QuestionTypeCategory == 3)
228
+        questionNumber = questionType.QuestionNumber3;
229
+
230
+    questionNumber = questionNumber * param.PageNum;
231
+
232
+    questionType.QuestionNumber = questionNumber;
233
+    //console.log("questionType.QuestionNumber:"+questionType.QuestionNumber);
234
+    const list = getQuestionTypeInfo(questionType);
235
+
236
+    const questionList = [];
237
+    //如果要求题目数小于原有题目数,则直接随机获取题目
238
+    if (list.length > questionNumber) {
239
+        do {
240
+            const rnd = stringUtils.Random(0, list.length - 1);
241
+            if (list[rnd]) {
242
+                questionList.push(list[rnd]);
243
+                list[rnd] = null;
244
+            }
245
+        }
246
+        while (questionList.length < questionNumber);
247
+    }
248
+    //如果要求题目数大于原有题目数,则获取全部原有题目的倍数,再将剩余数随机获取
249
+    else {
250
+        const nCount = Math.floor(questionNumber / list.length);
251
+        for (let n = 0; n < nCount; n++) {
252
+            for (let i = 0; i < list.length; i++) {
253
+                questionList.push(list[i]);
254
+            }
255
+        }
256
+
257
+        while (questionList.length < questionNumber) {
258
+            const rnd = stringUtils.Random(0, list.length - 1);
259
+            if (list[rnd]) {
260
+                questionList.push(list[rnd]);
261
+                list[rnd] = null;
262
+            }
263
+        }
264
+    }
265
+
266
+    const cleanedQuestionList = stringUtils.RemoveJSONNull(questionList);
267
+
268
+    cleanedQuestionList.sort(() => 0.5 - Math.random());
269
+
270
+    const questionListResult = [];
271
+    for (let i = 0; i < cleanedQuestionList.length; i++) {
272
+        const item = {};
273
+        for (const k in cleanedQuestionList[i]) {
274
+            item[k] = cleanedQuestionList[i][k];
275
+
276
+            if (item[k] == "−") {
277
+                item[k] = "-";
278
+            }
279
+        }
280
+        item.ID = i + 1;
281
+        const arr = questionType.HiddenColumn.split(",");
282
+        const hidden = arr[stringUtils.Random(0, arr.length - 1)];
283
+        item.HiddenColumn = hidden;
284
+        item.Result = item[item.HiddenColumn];
285
+
286
+        if (param.QuestionTypeCategory == 3) {
287
+            item.Vertical = computeMath(item);
288
+        }
289
+
290
+        questionListResult.push(item);
291
+    }
292
+
293
+    const categoryArray = [{}, { Num: 1, Name: "一年级", Array: [1, 2] }, { Num: 2, Name: "二年级", Array: [3, 4] }, { Num: 3, Name: "三年级", Array: [5, 6] }, { Num: 4, Name: "四年级及以上", Array: [7] }];
294
+    let categoryName = "";
295
+    for (let i = 1; i < categoryArray.length; i++) {
296
+        for (let j = 0; j < categoryArray[i].Array.length; j++) {
297
+            if (categoryArray[i].Array[j] == questionType.Category) {
298
+                categoryName = categoryArray[i].Name;
299
+                break;
300
+            }
301
+        }
302
+    }
303
+
304
+    const result = {
305
+        ID: questionType.ID,
306
+        Category: questionType.Category,
307
+        CategoryName: categoryName,
308
+        //错误接口参数
309
+        Cagegory: questionType.Category,
310
+        CagegoryName: categoryName,
311
+
312
+        CreateTime: moment(new Date()).format('YYYY年MM月DD日 HH:mm'),
313
+        Name: questionType.Name,
314
+        QuestionTypeCategory: Number(param.QuestionTypeCategory),
315
+        QuestionTypeLevel: questionType.CategoryName + questionType.CategoryLevel,
316
+        Difficulty: questionType.Difficulty,
317
+        PageCount: questionNumber / param.PageNum,
318
+        QuestionList: questionListResult,
319
+    };
320
+    //console.log(result);
321
+    //let time=buildPrint(result);
322
+
323
+    ctx.body = { "errcode": 10000, result: result };
324
+}
325
+
326
+function getQuestionTypeInfo(item) {
327
+    const arrQuestion = [];
328
+    let arrA, arrB, arrC, arrD, arrR, arrOperateAB, arrOperateBC, arrOperateCD;
329
+    arrA = getNumberArray(item.A);
330
+    arrOperateAB = getOperate(item.OperateAB);
331
+    arrB = getNumberArray(item.B);
332
+
333
+    if (item.C) {
334
+        arrOperateBC = getOperate(item.OperateBC);
335
+        arrC = getNumberArray(item.C);
336
+    }
337
+    if (item.D) {
338
+        arrOperateCD = getOperate(item.OperateCD);
339
+        arrD = getNumberArray(item.D);
340
+    }
341
+    if (item.R === "[1002001,99980001]")
342
+        arrR = [1002001, 99980001];
343
+    else
344
+        arrR = getNumberArray(item.R);
345
+
346
+    getArray2();
347
+
348
+    for (const info in arrQuestion) {
349
+        if (!arrQuestion[info]) {
350
+            arrQuestion[info] = "";
351
+        }
352
+    }
353
+
354
+    return arrQuestion;
355
+
356
+    function getArray2() {
357
+        for (let i = 0; i < item.QuestionNumber; i++) {
358
+            let a, b, c, d, r, ab, bc, cd;
359
+            ab = arrOperateAB[0];
360
+            if (item.C) {
361
+                bc = arrOperateBC[0];
362
+            }
363
+            let objArray = [];
364
+            if (item.OtherRule && item.OtherRule.substr(0, 7) == "B+C=x00") {
365
+                b = arrB[stringUtils.Random(0, arrB.length - 1)];
366
+                c = 100 - (b - Math.floor(b / 100) * 100);
367
+                a = 0;
368
+                if (item.ID == 108)
369
+                    a = arrA[stringUtils.Random(b + c, arrA.length - 1)];
370
+                else
371
+                    a = arrA[stringUtils.Random(0, arrA.length - 1)];
372
+
373
+                r = computer(a, b, ab);
374
+                r = computer(r, c, bc);
375
+            }
376
+            else if (item.OtherRule && item.OtherRule.substr(0, 7) == "A-B=x00") {
377
+                a = arrA[stringUtils.Random(0, arrA.length - 1)];
378
+                let b1 = a - Math.floor(a / 100) * 100;
379
+                let b2 = 100 * stringUtils.Random(0, Math.floor(a / 100) - 1);
380
+                b = b1 + b2;
381
+                c = arrC[stringUtils.Random(0, arrC.length - 1)];
382
+
383
+                r = computer(a, b, ab);
384
+                r = computer(r, c, bc);
385
+            }
386
+            else if (item.OtherRule && item.OtherRule== "A=B") {
387
+                a = arrA[stringUtils.Random(0, arrA.length - 1)];
388
+                b = a;
389
+                //console.log("a="+a);
390
+                r = computer(a, b, ab);
391
+            }
392
+            else if (item.OtherRule && item.OtherRule== "A=B=C") {
393
+                a = arrA[stringUtils.Random(0, arrA.length - 1)];
394
+                b = a;
395
+                c = a;
396
+                //console.log("a="+a);
397
+                r = computer(a, b, ab);
398
+                r = computer(r, c, bc);
399
+            }
400
+            else {
401
+                let bOK=true;
402
+
403
+                do {
404
+                    r=-1;
405
+                    bOK=false;
406
+                    a = arrA[stringUtils.Random(0, arrA.length - 1)];
407
+                    b = arrB[stringUtils.Random(0, arrB.length - 1)];
408
+                    ab = arrOperateAB[stringUtils.Random(0, arrOperateAB.length - 1)];
409
+
410
+                    //判断规则
411
+                    let bBool = true;
412
+                    if (item.OtherRule) {
413
+                        const aOnes = getOnes(a);
414
+                        const bOnes = getOnes(b);
415
+                        switch (item.OtherRule) {
416
+                            case "aOnes+bOnes<10":
417
+                                bBool = false;
418
+                                if (aOnes + bOnes < 10)
419
+                                    bBool = true;
420
+                                break;
421
+                            case "aOnes-bOnes>=0":
422
+                                bBool = false;
423
+                                if (aOnes - bOnes >= 0)
424
+                                    bBool = true;
425
+                                break;
426
+                            case "aOnes+bOnes>=10":
427
+                                bBool = false;
428
+                                if (aOnes + bOnes >= 10)
429
+                                    bBool = true;
430
+                                break;
431
+                            case "aOnes-bOnes<0":
432
+                                bBool = false;
433
+                                if (aOnes - bOnes < 0)
434
+                                    bBool = true;
435
+                                break;
436
+                            case "A-B=[0,10]":
437
+                                bBool = true;
438
+                                if ((ab === "−" && a - b < 0) || (ab === "+" && a + b > 10))
439
+                                    bBool = false;
440
+                                break;
441
+                            case "A-B<0 or A+B>20":
442
+                                bBool = true;
443
+                                if ((ab === "−" && a - b < 0) || (ab === "+" && a + b > 20))
444
+                                    bBool = false;
445
+                                break;
446
+                            case "A-B<0 or A+B>100":
447
+                                bBool = true;
448
+                                if ((ab === "−" && a - b < 0) || (ab === "+" && a + b > 100))
449
+                                    bBool = false;
450
+                                break;
451
+                            case "A+B=10":
452
+                                bBool = false;
453
+                                if (ab === "+" && a + b === 10)
454
+                                    bBool = true;
455
+                                break;
456
+                            case "A-B=10":
457
+                                bBool = false;
458
+                                if (ab === "−" && a - b === 10)
459
+                                    bBool = true;
460
+                                break;
461
+                            case "remainder":
462
+                                bBool = false;
463
+                                if ((a % b) !== 0) {
464
+                                    bBool = true;
465
+                                }
466
+                                break;
467
+                        }
468
+                    }
469
+
470
+                    //若规则符合,就计算结果
471
+                    if (bBool) {
472
+                        r = computer(a, b, ab);
473
+                        if (item.OtherRule=="remainder"){
474
+                            let quotient = Math.floor(r);
475
+                            let remainder = a % b;
476
+                            r = quotient + "......" + remainder;
477
+                            if (quotient >= arrR[0] && quotient <= arrR[arrR.length - 1])
478
+                                bOK = true;
479
+                            else
480
+                                bOK = false;
481
+                        }
482
+                        else {
483
+
484
+                            if (ab=="÷" && a>=0 && b>=0 && r>=1){
485
+                                if (r>Math.floor(r)){
486
+                                    r=Math.floor(r);
487
+                                    a=r*b;
488
+                                }
489
+                            }
490
+
491
+                            if (item.C) {
492
+                                c = arrC[stringUtils.Random(0, arrC.length - 1)];
493
+                                bc = arrOperateBC[stringUtils.Random(0, arrOperateBC.length - 1)];
494
+                                r = computer(r, c, bc);
495
+                            }
496
+
497
+                            if (item.ID == 111 || item.ID == 153 || item.ID == 154) {
498
+                                r = computer(b, c, bc);
499
+                                r = computer(a, r, ab);
500
+                            }
501
+                            else if (item.ID==195){
502
+                                a=stringUtils.Random(2,9)*1000+stringUtils.Random(2,9)*100+stringUtils.Random(2,9)*10+stringUtils.Random(2,9);
503
+                                b=stringUtils.Random(2,9)*1000+stringUtils.Random(2,9)*100+stringUtils.Random(2,9)*10+stringUtils.Random(2,9);
504
+                                r = computer(a, b, ab);
505
+                            }
506
+
507
+                            if (r >= arrR[0] && r <= arrR[arrR.length - 1]) {
508
+                                bOK = true;
509
+
510
+                                if (item.OtherRule == "A+B=10 or A+C=10 or B+C=10") {
511
+                                    bOK=false;
512
+                                    if (a + b == 10 || a + c == 10 || b + c == 10){
513
+                                        //console.log("过程1:"+a+ab+b+bc+c+"="+r);
514
+                                        bOK = true;
515
+                                    }
516
+                                }
517
+                            }
518
+
519
+                        }
520
+                    }
521
+                    else
522
+                        bOK=false;
523
+
524
+
525
+                    //stringUtils.loopBreaker(360);
526
+
527
+                    
528
+                } while (!bOK);
529
+
530
+            }
531
+            if (!c) c="";
532
+            if (!bc) bc="";
533
+
534
+            //console.log("结果2:"+a+ab+b+bc+c+"="+r);
535
+
536
+            let obj1 = {
537
+                QuestionTypeID: item.ID,
538
+                A: a,
539
+                B: b,
540
+                C: c,
541
+                OperateAB: ab,
542
+                OperateBC: bc,
543
+                R: r,
544
+            };
545
+            objArray.push(obj1);
546
+            let obj2 = {
547
+                QuestionTypeID: item.ID,
548
+                A: a,
549
+                B: c,
550
+                C: b,
551
+                OperateAB: bc,
552
+                OperateBC: ab,
553
+                R: r,
554
+            };
555
+            objArray.push(obj2);
556
+            let obj3 = {
557
+                QuestionTypeID: item.ID,
558
+                A: c,
559
+                B: a,
560
+                C: b,
561
+                OperateAB: ab,
562
+                OperateBC: bc,
563
+                R: r,
564
+            };
565
+            objArray.push(obj3);
566
+            let obj4 = {
567
+                QuestionTypeID: item.ID,
568
+                A: c,
569
+                B: b,
570
+                C: a,
571
+                OperateAB: ab,
572
+                OperateBC: bc,
573
+                R: r,
574
+            };
575
+            objArray.push(obj4);
576
+            let obj5 = {
577
+                QuestionTypeID: item.ID,
578
+                A: b,
579
+                B: a,
580
+                C: c,
581
+                OperateAB: ab,
582
+                OperateBC: bc,
583
+                R: r,
584
+            };
585
+            objArray.push(obj5);
586
+            let obj6 = {
587
+                QuestionTypeID: item.ID,
588
+                A: b,
589
+                B: c,
590
+                C: a,
591
+                OperateAB: ab,
592
+                OperateBC: bc,
593
+                R: r,
594
+            };
595
+            objArray.push(obj6);
596
+
597
+
598
+            if (item.OtherRule && item.OtherRule.indexOf("A↔B↔C") >= 0) {
599
+                const rnd = stringUtils.Random(0, 5);
600
+                arrQuestion.push(objArray[rnd]);
601
+            }
602
+            else if (item.OtherRule && item.OtherRule.indexOf("A↔B") >= 0) {
603
+                let rnd = stringUtils.Random(0, 1);
604
+                if (rnd === 1)
605
+                    rnd = 4;
606
+                arrQuestion.push(objArray[rnd]);
607
+            }
608
+            else if (item.OtherRule && item.OtherRule.indexOf("B↔C") >= 0) {
609
+                const rnd = stringUtils.Random(0, 1);
610
+                arrQuestion.push(objArray[rnd]);
611
+            }
612
+            else {
613
+                arrQuestion.push(objArray[0]);
614
+            }
615
+        }
616
+    }
617
+
618
+
619
+    //得到数的所有取值数组
620
+    function getNumberArray(range) {
621
+        let result = [];
622
+        let arrTemp = range.split(",");
623
+        for (let i = 0; i < arrTemp.length; i++) {
624
+            if (arrTemp[i].indexOf("[") < 0)
625
+                result.push(Number(arrTemp[i]));
626
+            else {
627
+                let a = Number(arrTemp[i].substr(1));
628
+                i++;
629
+                let b = Number(arrTemp[i].substring(0, arrTemp[i].length - 1));
630
+
631
+                let obj=getLenAndPow(a,b);
632
+
633
+                a=Number(a.toFixed(obj.len));
634
+                b=Number(b.toFixed(obj.len));
635
+                //console.log("a:"+a);
636
+                //console.log("b:"+b);
637
+                //console.log("len:"+len);
638
+                //console.log("pow:"+pow);
639
+
640
+                for (let j = a*obj.pow; j <= b*obj.pow; j++) {
641
+                    //console.log("j:"+j);
642
+                    let item=j/obj.pow;
643
+                    //console.log("item:"+item);
644
+                    result.push(item);
645
+                }
646
+            }
647
+            //console.log(result);
648
+        }
649
+        return result;
650
+    }
651
+
652
+    function getLenAndPow(a,b){
653
+        //console.log("a:"+a);
654
+        //console.log("b:"+b);
655
+
656
+        let aLen=getDotLen(a);
657
+        let bLen=getDotLen(b);
658
+        let len=aLen>=bLen?aLen:bLen;
659
+        let pow=Math.pow(10,len);
660
+        return {len:len,pow:pow};
661
+    }
662
+
663
+    //得到小数位数
664
+    function getDotLen(num){
665
+        let len=0;
666
+        //console.log(num);
667
+        if (num && num.toString().indexOf(".")>=0){
668
+            len=num.toString().split(".")[1].length;
669
+        }
670
+        return len
671
+    }
672
+    //得到随机数
673
+    function getNumber(arr) {
674
+        let rnd = common.random(0, arr.length - 1);
675
+        return arr[rnd];
676
+    }
677
+
678
+    //得到个位数
679
+    function getOnes(num) {
680
+        return num % 10;
681
+    }
682
+
683
+    function getOperate(operate) {
684
+        return operate.split(",");
685
+    }
686
+
687
+    function computer(numberA, numberB, operate) {
688
+        let result = 0;
689
+
690
+        let obj=getLenAndPow(numberA,numberB);
691
+
692
+        switch (operate) {
693
+            case "+":
694
+                result = (numberA*obj.pow + numberB*obj.pow)/obj.pow;
695
+                result = Math.round(result*obj.pow)/obj.pow;
696
+                break;
697
+            case "−":
698
+                result = ((numberA*obj.pow) - (numberB*obj.pow))/obj.pow;
699
+                result = Math.round(result*obj.pow)/obj.pow;
700
+                break;
701
+            case '×':
702
+                result = (numberA*obj.pow * numberB*obj.pow)/(obj.pow * obj.pow);
703
+                //console.log("numberA:"+numberA);
704
+                //console.log("numberB:"+numberB);
705
+                //console.log("obj.pow:"+obj.pow);
706
+                //console.log("result:"+result);
707
+                result=Math.round(result*obj.pow)/obj.pow;
708
+                break;
709
+            case '÷':
710
+                result = ((numberA*obj.pow) / (numberB*obj.pow))/1;
711
+                break;
712
+        }
713
+
714
+        return result;
715
+    }
716
+}

+ 453 - 0
src/api/mathcalculate/mathStarController.js

@@ -0,0 +1,453 @@
1
+import moment from 'moment';
2
+import commonModel from '../../model/commonModel.js';
3
+import mathcalculate from '../../model/mathcalculate.js';
4
+import config from '../../config/index.js';
5
+import _ from 'lodash';
6
+import axios from 'axios';
7
+import { Encrypt, Decrypt } from '../../util/crypto/index.js';
8
+import { stringUtils } from '../../util/stringClass.js';
9
+import WXBizDataCrypt from '../../util/WXBizDataCrypt.js';
10
+import { globalCache } from '../../util/GlobalCache.js';
11
+import constantClass from '../../util/constant/index.js';
12
+import fs from 'fs';
13
+import { promises as fsPromises } from 'fs';
14
+import COS from 'cos-nodejs-sdk-v5';
15
+
16
+export async function MathStarLogin(ctx) {
17
+    let param = ctx.request.body;
18
+    if (param.param) {
19
+        const paramStr = Decrypt(param.param, config.urlSecrets.aes_key, config.urlSecrets.aes_iv);
20
+        //console.log("paramStr:"+paramStr);
21
+        param = JSON.parse(paramStr);
22
+    }
23
+    const code = param.Code;
24
+    //console.log("code:"+code);
25
+    const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${config.wx.mathStar_appid}&secret=${config.wx.mathStar_appsecret}&js_code=${code}&grant_type=authorization_code`;
26
+
27
+    let result = await axios.get(url)
28
+        .then(res => {
29
+            const json = res.data;
30
+            //console.log("json:"+json);
31
+            if (json && json.openid) {
32
+                param.OpenID = json.openid;
33
+                param.sessionKey = json.session_key;
34
+                if (json.unionid)
35
+                    param.UnionID = json.unionid;
36
+                return {errcode: 10000};
37
+            }
38
+            else {
39
+                return json;
40
+            }
41
+        })
42
+        .catch(err => {
43
+            return {errcode: 101, errStr: err};
44
+        });
45
+
46
+    if (result.errcode == 10000) {
47
+        delete param.Code;
48
+        if (param.sessionKey && param.iv && param.encryptedData){
49
+            //console.log("param.sessionKey:"+param.sessionKey);
50
+            const pc = new WXBizDataCrypt(config.wx.math_appid, param.sessionKey);
51
+            const dataUnionID = pc.decryptData(param.encryptedData , param.iv);
52
+            //console.log(dataUnionID);
53
+            param.UnionID = dataUnionID.unionId;
54
+        }
55
+
56
+        delete param.sessionKey;
57
+        delete param.iv;
58
+        delete param.encryptedData;
59
+
60
+        //todo
61
+        //param.OpenID="o4UHq4gaNlHfdTWxgl3fTgC1mFsI";
62
+
63
+        let userList = await mathcalculate.GetUsersInfo(param);
64
+        if (userList.length > 0) {
65
+            param.LastLoginTime = new Date();
66
+            const time1 = moment(userList[0].ProductServiceTime).format('YYYY-MM-DD HH:mm:ss');
67
+            const time3 = moment().format('YYYY-MM-DD HH:mm:ss');
68
+            if (time1 < time3)
69
+                param.IsMember = 0;
70
+
71
+            delete param.Introducer;
72
+            delete param.UserSource;
73
+            delete param.SourceID;
74
+            //console.log(param.NickName);
75
+            if (param.NickName == "陌生用户") {
76
+                delete param.NickName;
77
+                delete param.AvatarUrl;
78
+                delete param.Language;
79
+                delete param.Gender;
80
+                delete param.City;
81
+                delete param.Province;
82
+                delete param.Country;
83
+            }
84
+
85
+            await mathcalculate.UpdateUsers(param);
86
+            userList = await mathcalculate.GetUsersInfo(param);
87
+        }
88
+        else {
89
+            param.NickName = "陌生用户";
90
+            param.AvatarUrl = "../images/userface_default.png";
91
+            param.CreateTime = new Date();
92
+            param.LastLoginTime = param.CreateTime;
93
+            param.ProductServiceTime = param.CreateTime;
94
+            const inseredID = await mathcalculate.AddUsers(param);
95
+            userList = await mathcalculate.GetUsersInfo(param);
96
+        }
97
+
98
+        delete userList[0].OpenID;
99
+        delete userList[0].UnionID;
100
+
101
+        //产品支付是否显示
102
+        if (param.ProgramVersion) {
103
+            let param2 = {
104
+                ProgramID: 164,
105
+                Version: param.ProgramVersion,
106
+            };
107
+            let result3 = await commonModel.GetProductVersionList(param2);
108
+            if (result3) {
109
+                if ((param2.Version == result3[0].Version && result3[0].IsShowPay <= 0)
110
+                    || param2.Version > result3[0].Version) {
111
+                    userList[0].IsShow = result3[0].IsShowPay;
112
+                }
113
+                else {
114
+                    userList[0].IsShow = 1;
115
+                }
116
+
117
+                //针对iphone测试用户,永远是无支付状态
118
+                if (userList[0].Brand == 'iPhone' && userList[0].WXLanguage == 'en-US'
119
+                    && userList[0].UserSource == '1001' && userList[0].IsPay == 0) {
120
+                    userList[0].IsShow = 0;
121
+                }
122
+
123
+                //针对微信测试用户,永远是无支付状态
124
+                if ((userList[0].UserSource=='1001' && userList[0].System=="iOS 10.0.1")
125
+                    || (!userList[0].UserSource && (!userList[0].LastUserSource || userList[0].LastUserSource>10000))
126
+                    || userList[0].NickName.indexOf("dgztest")>=0){
127
+                    userList[0].IsShow=-1;
128
+                }
129
+
130
+                if (userList[0].IsMember===1)
131
+                    userList[0].IsShow=1;
132
+            }
133
+        }
134
+
135
+        result = {errcode: 10000, result: userList[0]};
136
+    }
137
+
138
+    ctx.body = result;
139
+}
140
+
141
+//得到所有题库知识点(500版)
142
+// exports.GetQuestionTypes500 = function* () {
143
+//     var categoryArray = [
144
+//         {
145
+//             Num: 1,
146
+//             Name: "一年级",
147
+//             List:[
148
+//                 {
149
+//                     Name: "练习的方法",
150
+//                     List: [
151
+//                         {
152
+//                             CategoryID: 0,
153
+//                             Difficulty: 0,
154
+//                             Title1: "刻意练习",
155
+//                             Title2: "",
156
+//                         },
157
+//                     ]
158
+//                 },
159
+//                 {
160
+//                     Name:"加减运算",
161
+//                     List:[
162
+//                         {
163
+//                             CategoryID:1,
164
+//                             Difficulty:2,
165
+//                             Title1:"开始吧",
166
+//                             Title2:"简单的",
167
+//                         },
168
+//                         {
169
+//                             CategoryID:1,
170
+//                             Difficulty:3,
171
+//                             Title1:"循序渐进",
172
+//                             Title2:"普通的",
173
+//                         },
174
+//                         {
175
+//                             CategoryID:1,
176
+//                             Difficulty:4,
177
+//                             Title1:"攀登高峰",
178
+//                             Title2:"困难的",
179
+//                         },
180
+//                         {
181
+//                             CategoryID:2,
182
+//                             Difficulty:2,
183
+//                             Title1:"承上启下",
184
+//                             Title2:"简单的",
185
+//                         },
186
+//                         {
187
+//                             CategoryID:2,
188
+//                             Difficulty:3,
189
+//                             Title1:"一鼓作气",
190
+//                             Title2:"普通的",
191
+//                         },
192
+//                         {
193
+//                             CategoryID:2,
194
+//                             Difficulty:4,
195
+//                             Title1:"再攀高峰",
196
+//                             Title2:"困难的",
197
+//                         },
198
+//                     ]
199
+//                 }
200
+//             ],
201
+
202
+//         },
203
+//         {
204
+//             Num: 2,
205
+//             Name: "二年级",
206
+//             List:[
207
+//                 {
208
+//                     Name: "预备知识",
209
+//                     List: [
210
+//                         {
211
+//                             CategoryID: 0,
212
+//                             Difficulty: 0,
213
+//                             Title1: "热身练习",
214
+//                             Title2: "开始吧",
215
+//                         },
216
+//                     ]
217
+//                 },
218
+//                 {
219
+//                     Name: "乘除运算",
220
+//                     List: [
221
+//                         {
222
+//                             CategoryID: 4,
223
+//                             Difficulty: 2,
224
+//                             Title1: "温故知新",
225
+//                             Title2: "简单的",
226
+//                         },
227
+//                         {
228
+//                             CategoryID: 4,
229
+//                             Difficulty: 3,
230
+//                             Title1: "锲而不舍",
231
+//                             Title2: "普通的",
232
+//                         },
233
+//                         {
234
+//                             CategoryID: 4,
235
+//                             Difficulty: 4,
236
+//                             Title1: "摘取桂枝",
237
+//                             Title2: "困难的",
238
+//                         },
239
+//                     ]
240
+//                 },
241
+//                 {
242
+//                     Name: "加减运算",
243
+//                     List: [
244
+//                         {
245
+//                             CategoryID: 3,
246
+//                             Difficulty: 2,
247
+//                             Title1: "循序渐进",
248
+//                             Title2: "简单的",
249
+//                         },
250
+//                         {
251
+//                             CategoryID: 3,
252
+//                             Difficulty: 3,
253
+//                             Title1: "奋起直追",
254
+//                             Title2: "普通的",
255
+//                         },
256
+//                         {
257
+//                             CategoryID: 3,
258
+//                             Difficulty: 4,
259
+//                             Title1: "厚积薄发",
260
+//                             Title2: "困难的",
261
+//                         },
262
+//                     ]
263
+//                 }
264
+//             ],
265
+//         },
266
+//         {
267
+//             Num: 3,
268
+//             Name: "三年级",
269
+//             List:[
270
+//                 {
271
+//                     Name: "预备知识",
272
+//                     List: [
273
+//                         {
274
+//                             CategoryID: 0,
275
+//                             Difficulty: 0,
276
+//                             Title1: "热身练习",
277
+//                             Title2: "开始吧",
278
+//                         },
279
+//                     ]
280
+//                 },
281
+//                 {
282
+//                     Name: "乘除运算",
283
+//                     List: [
284
+//                         {
285
+//                             CategoryID: 5,
286
+//                             Difficulty: 2,
287
+//                             Title1: "温故知新",
288
+//                             Title2: "简单的",
289
+//                         },
290
+//                         {
291
+//                             CategoryID: 5,
292
+//                             Difficulty: 3,
293
+//                             Title1: "激流勇进",
294
+//                             Title2: "普通的",
295
+//                         },
296
+//                         {
297
+//                             CategoryID: 5,
298
+//                             Difficulty: 4,
299
+//                             Title1: "攀登高峰",
300
+//                             Title2: "困难的",
301
+//                         },
302
+//                     ]
303
+//                 },
304
+//                 {
305
+//                     Name: "四则运算",
306
+//                     List: [
307
+//                         {
308
+//                             CategoryID: 6,
309
+//                             Difficulty: 2,
310
+//                             Title1: "承上启下",
311
+//                             Title2: "简单的",
312
+//                         },
313
+//                         {
314
+//                             CategoryID: 6,
315
+//                             Difficulty: 3,
316
+//                             Title1: "数学奥秘",
317
+//                             Title2: "普通的",
318
+//                         },
319
+//                         {
320
+//                             CategoryID: 6,
321
+//                             Difficulty: 4,
322
+//                             Title1: "知识桂冠",
323
+//                             Title2: "困难的",
324
+//                         },
325
+//                     ]
326
+//                 }
327
+//             ],
328
+//         },
329
+//         {
330
+//             Num: 4,
331
+//             Name: "四年级及以上",
332
+//             List:[
333
+//                 {
334
+//                     Name: "预备知识",
335
+//                     List: [
336
+//                         {
337
+//                             CategoryID: 0,
338
+//                             Difficulty: 0,
339
+//                             Title1: "热身练习",
340
+//                             Title2: "开始吧",
341
+//                         },
342
+//                     ]
343
+//                 },
344
+//                 {
345
+//                     Name: "小数运算",
346
+//                     List: [
347
+//                         {
348
+//                             CategoryID: 7,
349
+//                             Difficulty: 2,
350
+//                             Title1: "温故知新",
351
+//                             Title2: "简单的",
352
+//                         },
353
+//                         {
354
+//                             CategoryID: 7,
355
+//                             Difficulty: 3,
356
+//                             Title1: "锐意进取",
357
+//                             Title2: "普通的",
358
+//                         },
359
+//                         {
360
+//                             CategoryID: 7,
361
+//                             Difficulty: 4,
362
+//                             Title1: "进击终点",
363
+//                             Title2: "困难的",
364
+//                         },
365
+//                     ]
366
+//                 },
367
+//             ],
368
+//         }
369
+//     ];
370
+
371
+//     var arrPrev=[[],[3,6,15,24,26,29],[3,6,15,66,67,106,175,176],[3,6,15,66,67,106,113,104,155,108]];
372
+
373
+//     var param = {
374
+//     }
375
+//     var list = yield mathcalculate.GetQuestionTypesList(param);
376
+//     var result = categoryArray;
377
+//     var temp;
378
+//     var arr = [];
379
+//     for (var i = 0; i < result.length; i++) {
380
+//         for (var j = 0; j < result[i].List.length; j++) {
381
+//             for (var k = 0; k < result[i].List[j].List.length; k++) {
382
+//                 var item=result[i].List[j].List[k];
383
+//                 item.List=[];
384
+//                 if (i>0 && j==0){
385
+//                     var arrTemp=arrPrev[i];
386
+//                     for(var m=0;m<arrTemp.length;m++){
387
+//                         for(var n=0;n<list.length;n++){
388
+//                             if (arrTemp[m]==list[n].ID){
389
+//                                 item.List.push(list[n]);
390
+//                             }
391
+//                         }
392
+//                     }
393
+//                 }
394
+//                 else{
395
+//                     for(var n=0;n<list.length;n++){
396
+//                         if (item.CategoryID==list[n].CategoryID && item.Difficulty==list[n].Difficulty){
397
+//                             item.List.push(list[n]);
398
+//                         }
399
+//                     }
400
+//                 }
401
+//             }
402
+//         }
403
+//     }
404
+
405
+
406
+
407
+//     for (var i = 0; i < result.length; i++) {
408
+//         var arrLevel=[];
409
+//         var jMin=0;
410
+//         if (i>0)
411
+//             jMin=1;
412
+//         for (var j = jMin; j < result[i].List.length; j++) {
413
+//             for (var k = 0; k < result[i].List[j].List.length; k++) {
414
+//                 for(var n=0;n<result[i].List[j].List[k].List.length;n++) {
415
+//                     var item = result[i].List[j].List[k].List[n];
416
+//                     delete item.CategoryID;
417
+//                     delete item.CategoryName;
418
+//                     delete item.CategoryLevel;
419
+//                     delete item.CategoryDescription;
420
+//                     delete item.CategoryImageUrl;
421
+
422
+//                     arrLevel.push(item.ID);
423
+//                 }
424
+//             }
425
+//         }
426
+//         //console.log(arrLevel);
427
+//         //增加难关ID号
428
+//         var arrLevel2=[],arrTemp=[],tempJ=0;
429
+//         for(var j=0;j<arrLevel.length;j++){
430
+//             arrTemp.push(arrLevel[j]);
431
+//             if (j % 4==3) {
432
+//                 arrLevel2.push(arrTemp);
433
+//                 arrTemp=[];
434
+//                 tempJ=j+1;
435
+//             }
436
+//         }
437
+//         //console.log(tempJ);
438
+//         //console.log(arrLevel.length);
439
+//         for(var j=tempJ+1;j<arrLevel.length;j++){
440
+//             arrTemp.push(arrLevel[j]);
441
+//         }
442
+//         if (arrTemp.length>0)
443
+//             arrLevel2.push(arrTemp);
444
+//         result[i].LevelList=arrLevel2;
445
+//     }
446
+
447
+//     result = JSON.stringify(result);
448
+//     result = Crypto.Encrypt(result, config.urlSecrets.aes_key, config.urlSecrets.aes_iv);
449
+
450
+
451
+//     this.body = {"errcode": 10000, result: result};
452
+
453
+// };

+ 5 - 1
src/api/mathcalculate/routes.js

@@ -1,11 +1,15 @@
1 1
 import Router from 'koa-router';
2 2
 import * as math from './mathController.js';
3
+import * as mathStar from './mathStarController.js';
3 4
 
4 5
 
5 6
 const router = new Router();
6 7
 
7 8
 router.post('/api/MathLogin',math.MathLogin);
8 9
 router.get('/api/GetQuestionTypes',math.GetQuestionTypes);
9
-//router.get('/api/GetQuestionTypesPrint',math.GetQuestionTypesPrint);
10
+router.get('/api/GetQuestionTypesPrint',math.GetQuestionTypesPrint);
11
+
12
+router.post('/api/MathStarLogin',mathStar.MathStarLogin);
13
+//router.get('/api/GetQuestionTypes500',mathStar.GetQuestionTypes500);
10 14
 
11 15
 export default router;

+ 0 - 2
src/api/mps/mpsSchoolController.js

@@ -556,8 +556,6 @@ export async function GetMPSSchoolCollect(ctx) {
556 556
     const param = {
557 557
         UserID: ctx.query.UserID || 0,
558 558
     };
559
-    if (param.UserID=="undefined")
560
-        param.UserID=0;
561 559
     
562 560
     const result = {};
563 561
     result.收藏的高中 = [];

+ 1 - 13
src/api/phonics/phonicsController.js

@@ -159,8 +159,6 @@ export async function GetPhonicsRecordData(ctx) {
159 159
         UserID: ctx.query.UserID || 0,
160 160
         Version: ctx.query.Version || "1.0.0",
161 161
     };
162
-    if (param.UserID === "undefined")
163
-        param.UserID = 0;
164 162
 
165 163
     const result = await phonics.GetPhonicsRecordData(param);
166 164
 
@@ -266,8 +264,6 @@ export async function GetArticleInfo(ctx) {
266 264
         ID: ctx.query.ID || 0,
267 265
         UserID: ctx.query.UserID || 0,
268 266
     };
269
-    if (param.UserID === "undefined")
270
-        param.UserID = 0;
271 267
 
272 268
     const result = await phonics.GetArticles(param);
273 269
     if (result && result.length > 0) {
@@ -284,8 +280,7 @@ export async function GetArticleInfo(ctx) {
284 280
 //新增或删除自然拼读完成结果
285 281
 export async function UpdatePhonicsFinished(ctx) {
286 282
     const param = ctx.request.body;
287
-    if (param.Style === "undefined")
288
-        param.Style = "";
283
+
289 284
     if (param.IsFinished) {
290 285
         delete param.IsFinished;
291 286
         if (param.UserID && param.Title) {
@@ -309,8 +304,6 @@ export async function GetPhonicsFinishedData(ctx) {
309 304
         UserID: ctx.query.UserID || 0,
310 305
         Category: ctx.query.Category || 0,
311 306
     };
312
-    if (param.UserID === "undefined")
313
-        param.UserID = 0;
314 307
 
315 308
     if (param.Category === "basic" || param.Category === "intermediate")
316 309
         param.Category = "all";
@@ -412,8 +405,6 @@ export async function GetPhonicsReviewList(ctx) {
412 405
     const param = {
413 406
         UserID: ctx.query.UserID || 0,
414 407
     };
415
-    if (param.UserID === "undefined")
416
-        param.UserID = 0;
417 408
 
418 409
     const result = await phonics.GetPhonicsReviewList(param);
419 410
     if (result && result.length > 0)
@@ -428,9 +419,6 @@ export async function AddPhonicsTestScore(ctx) {
428 419
         UserID: ctx.query.UserID || 0,
429 420
         Score: ctx.query.Score,
430 421
     };
431
-    if (param.UserID === "undefined")
432
-        param.UserID = 0;
433
-
434 422
     let result = {
435 423
         MaxScore: param.Score,
436 424
         IsRecord: 1,

+ 0 - 9
src/api/pinyin/pinyinController.js

@@ -155,8 +155,6 @@ export async function GetPinyinRecordData(ctx) {
155 155
         UserID: ctx.query.UserID || 0,
156 156
         Version: ctx.query.Version || "1.0.0",
157 157
     };
158
-    if (param.UserID === "undefined")
159
-        param.UserID = 0;
160 158
 
161 159
     const result = await pinyin.GetPinyinRecordData(param);
162 160
 
@@ -241,8 +239,6 @@ export async function GetPinyinRecordData(ctx) {
241 239
 //新增或删除拼音完成结果
242 240
 export async function UpdatePinyinFinished(ctx) {
243 241
     const param = ctx.request.body;
244
-    if (param.Style === "undefined")
245
-        param.Style = "";
246 242
     if (param.IsFinished) {
247 243
         delete param.IsFinished;
248 244
         if (param.UserID) {
@@ -264,8 +260,6 @@ export async function GetPinyinFinishedData(ctx) {
264 260
         UserID: ctx.query.UserID || 0,
265 261
         Category: ctx.query.Category || 0,
266 262
     };
267
-    if (param.UserID === "undefined")
268
-        param.UserID = 0;
269 263
 
270 264
     const result = await pinyin.GetPinyinFinishedData(param);
271 265
     if (result && result.length > 0)
@@ -281,9 +275,6 @@ export async function SetPinyinUserExchange(ctx) {
281 275
         ID: ctx.query.ProductPayInfoID || 0,
282 276
         ExchangeTime: new Date(),
283 277
     };
284
-    if (param.ID === "undefined")
285
-        param.ID = 0;
286
-
287 278
     const ProductPayInfo = await pinyin.GetPinyinUserExchange(param);
288 279
     if (ProductPayInfo && ProductPayInfo.length) {
289 280
         if (ProductPayInfo[0].ExchangeUserID === 0) {

+ 2 - 0
src/app.js

@@ -7,6 +7,7 @@ import { fileURLToPath } from 'url';
7 7
 import config from './config/index.js';
8 8
 import { decryptUrlMiddle } from './util/crypto/index.js';
9 9
 import { stringUtils } from './util/stringClass.js';
10
+import queryParamSanitizer from './middleware/queryParamSanitizer.js';
10 11
 
11 12
 import commonRouter from './api/common/routes.js';
12 13
 import mpsRouter from './api/mps/routes.js';
@@ -22,6 +23,7 @@ const app = new Koa();
22 23
 
23 24
 // 使用中间件
24 25
 app.use(bodyParser());
26
+app.use(queryParamSanitizer());
25 27
 
26 28
 // 静态文件服务
27 29
 app.use(serve(__dirname + '/../public'));

+ 43 - 0
src/middleware/queryParamSanitizer.js

@@ -0,0 +1,43 @@
1
+/**
2
+ * 查询参数清理中间件
3
+ * 处理查询参数中的字符串"undefined",将其转换为适当的默认值
4
+ */
5
+const ParamArr=['UserID', 'SchoolID', 'DistrictID', 'ClickLikeID', 'QuestionTypeID',"Style"];
6
+
7
+export default function queryParamSanitizer() {
8
+    return async (ctx, next) => {
9
+        // 处理查询参数
10
+        if (ctx.query) {
11
+            Object.keys(ctx.query).forEach(key => {
12
+                if (ctx.query[key] === 'undefined') {
13
+                    // 数字类型参数默认设为0
14
+                    if (ParamArr.includes(key)) {
15
+                        ctx.query[key] = 0;
16
+                    } 
17
+                    // 字符串类型参数默认设为空字符串
18
+                    else {
19
+                        ctx.query[key] = '';
20
+                    }
21
+                }
22
+            });
23
+        }
24
+
25
+        // 处理请求体参数(如果是JSON或表单数据)
26
+        if (ctx.request.body && typeof ctx.request.body === 'object') {
27
+            Object.keys(ctx.request.body).forEach(key => {
28
+                if (ctx.request.body[key] === 'undefined') {
29
+                    // 数字类型参数默认设为0
30
+                    if (ParamArr.includes(key)) {
31
+                        ctx.request.body[key] = 0;
32
+                    } 
33
+                    // 字符串类型参数默认设为空字符串
34
+                    else {
35
+                        ctx.request.body[key] = '';
36
+                    }
37
+                }
38
+            });
39
+        }
40
+
41
+        await next();
42
+    };
43
+}

+ 64 - 0
src/model/mathcalculate.js

@@ -93,6 +93,70 @@ class MathCalculation {
93 93
         }
94 94
 
95 95
     }
96
+
97
+    /**
98
+     * 获取构建问题类型列表
99
+     * @param {Object} obj 查询参数
100
+     * @returns {Promise<Array>} 问题类型列表
101
+     */
102
+    static async GetQuestionTypesListByBuild(obj) {
103
+        try {
104
+            //const sql = "select * from QuestionTypes order by ID;";
105
+            const sql = "select * from QuestionTypes where ID>=98 and ID<1000;";
106
+            //const sql = "select * from QuestionTypes where ID>=86;";
107
+            return await query(sql);
108
+        } catch (error) {
109
+            console.error('获取构建问题类型列表失败:', error);
110
+            throw error;
111
+        }
112
+    }
113
+
114
+    /**
115
+     * 获取问题类型信息
116
+     * @param {Object} obj 查询参数
117
+     * @returns {Promise<Array>} 问题类型信息
118
+     */
119
+    static async GetQuestionTypesInfo(obj) {
120
+        try {
121
+            if (!obj.QuestionTypeID)
122
+                obj.QuestionTypeID = 0;
123
+            const sql = "SELECT qc.*,qt.* FROM QuestionTypes qt inner join QuestionCategory qc on qt.Category=qc.CategoryID where qt.ID=" + obj.QuestionTypeID + ";";
124
+            return await query(sql);
125
+        } catch (error) {
126
+            console.error('获取问题类型信息失败:', error);
127
+            throw error;
128
+        }
129
+    }
130
+
131
+    /**
132
+     * 更新问题类型
133
+     * @param {Object} obj 更新参数
134
+     * @returns {Promise<Object>} 更新结果
135
+     */
136
+    static async UpdateQuestionTypes(obj) {
137
+        try {
138
+            const sql = "Update QuestionTypes SET ? where ID=?";
139
+            return await query(sql, [obj, obj.ID]);
140
+        } catch (error) {
141
+            console.error('更新问题类型失败:', error);
142
+            throw error;
143
+        }
144
+    }
145
+
146
+    /**
147
+     * 插入问题
148
+     * @param {Object} obj 问题信息
149
+     * @returns {Promise<Object>} 插入结果
150
+     */
151
+    static async InsertQuestion(obj) {
152
+        try {
153
+            const sql = "insert into QuestionLibrary SET ?";
154
+            return await query(sql, [obj]);
155
+        } catch (error) {
156
+            console.error('插入问题失败:', error);
157
+            throw error;
158
+        }
159
+    }
96 160
 }
97 161
 
98 162
 export default MathCalculation;

+ 508 - 0
src/model/mathstar.js

@@ -0,0 +1,508 @@
1
+import { queryAsync } from '../util/mysql.js';
2
+import moment from 'moment';
3
+
4
+/**
5
+ * MathStar 模型
6
+ */
7
+class MathStar {
8
+    /**
9
+     * 获取用户信息(通过OpenID)
10
+     * @param {Object} obj 查询参数
11
+     * @returns {Promise<Array>} 用户信息
12
+     */
13
+    static async GetUsersInfo(obj) {
14
+        try {
15
+            const sql = "select * from MathStarWXUsers where OpenID=?";
16
+            return await queryAsync(sql, [obj.OpenID]);
17
+        } catch (error) {
18
+            console.error('获取用户信息失败:', error);
19
+            throw error;
20
+        }
21
+    }
22
+
23
+    /**
24
+     * 获取用户信息(通过UserID)
25
+     * @param {Object} obj 查询参数
26
+     * @returns {Promise<Array>} 用户信息
27
+     */
28
+    static async GetUsersInfoByUserID(obj) {
29
+        try {
30
+            const sql = "select * from MathStarWXUsers where UserID=?";
31
+            return await queryAsync(sql, [obj.UserID]);
32
+        } catch (error) {
33
+            console.error('获取用户信息失败:', error);
34
+            throw error;
35
+        }
36
+    }
37
+
38
+    /**
39
+     * 添加用户
40
+     * @param {Object} obj 用户信息
41
+     * @returns {Promise<Object>} 插入结果
42
+     */
43
+    static async AddUsers(obj) {
44
+        try {
45
+            const sql = "INSERT INTO MathStarWXUsers SET ?";
46
+            return await queryAsync(sql, obj);
47
+        } catch (error) {
48
+            console.error('添加用户失败:', error);
49
+            throw error;
50
+        }
51
+    }
52
+
53
+    /**
54
+     * 更新用户信息(通过OpenID)
55
+     * @param {Object} obj 更新参数
56
+     * @returns {Promise<Object>} 更新结果
57
+     */
58
+    static async UpdateUsers(obj) {
59
+        try {
60
+            const sql = "Update MathStarWXUsers SET ? where OpenID=?";
61
+            return await queryAsync(sql, [obj, obj.OpenID]);
62
+        } catch (error) {
63
+            console.error('更新用户信息失败:', error);
64
+            throw error;
65
+        }
66
+    }
67
+
68
+    /**
69
+     * 更新用户信息(通过UserID)
70
+     * @param {Object} obj 更新参数
71
+     * @returns {Promise<Object>} 更新结果
72
+     */
73
+    static async UpdateUsersByUserID(obj) {
74
+        try {
75
+            const sql = "Update MathStarWXUsers SET ? where UserID=?";
76
+            return await queryAsync(sql, [obj, obj.UserID]);
77
+        } catch (error) {
78
+            console.error('更新用户信息失败:', error);
79
+            throw error;
80
+        }
81
+    }
82
+
83
+    /**
84
+     * 获取用户单个知识点的信息
85
+     * @param {Object} obj 查询参数
86
+     * @returns {Promise<Array>} 知识点信息
87
+     */
88
+    static async GetQuestionTypeInfoByUserID500(obj) {
89
+        try {
90
+            let sql;
91
+            if (obj.StarNumber) {
92
+                sql = "SELECT StarNumber,count(*) as count FROM MathStarScores where QuestionTypeID=? and UserID=? and Flag=0 group by StarNumber order by StarNumber;";
93
+                return await queryAsync(sql, [obj.QuestionTypeID, obj.UserID]);
94
+            } else if (obj.DayNumber) {
95
+                sql = "SELECT count(distinct date_format(CreateTime,'%Y-%m-%d')) As DayNumber,count(ScoreID) as PracticeNumber,Min(Duration) as MinDuration,Max(Speed_Level) as MaxSpeedLevel From MathStarScores where QuestionTypeID=? and UserID=? and Duration>0 and Flag=0;";
96
+                return await queryAsync(sql, [obj.QuestionTypeID, obj.UserID]);
97
+            }
98
+        } catch (error) {
99
+            console.error('获取用户知识点信息失败:', error);
100
+            throw error;
101
+        }
102
+    }
103
+
104
+    /**
105
+     * 获取用户问题列表
106
+     * @param {Object} obj 查询参数
107
+     * @returns {Promise<Array>} 问题列表
108
+     */
109
+    static async GetUserQuestionListByUserID2(obj) {
110
+        try {
111
+            if (!obj.UserID) {
112
+                obj.UserID = 0;
113
+            }
114
+            let sql;
115
+            if (obj.History) {
116
+                sql = "SELECT A,B,C,D,R,OperateAB,OperateBC,OperateCD,Result,HiddenColumn,Familiarity,1 as 'FamiliarityUnit' FROM UserQuestion2 where UserID=? and Flag=0 and Familiarity<100 order by Familiarity,CreateTime desc limit 5;";
117
+            } else {
118
+                sql = "SELECT A,B,C,D,R,OperateAB,OperateBC,OperateCD,Result,HiddenColumn,0 as 'Familiarity',5 as 'FamiliarityUnit' FROM UserQuestion2 where UserID=? and ((CreateTime>=CURDATE() and CreateTime=UpdateTime) or (UpdateTime>=CURDATE() and Familiarity=0) or UpdateTime<CURDATE()) order by UpdateTime;";
119
+            }
120
+            return await queryAsync(sql, [obj.UserID]);
121
+        } catch (error) {
122
+            console.error('获取用户问题列表失败:', error);
123
+            throw error;
124
+        }
125
+    }
126
+
127
+    /**
128
+     * 获取用户分数列表
129
+     * @param {Object} obj 查询参数
130
+     * @returns {Promise<Array>} 分数列表
131
+     */
132
+    static async GetScoreListByUserID500(obj) {
133
+        try {
134
+            const sql = "select s.QuestionTypeID,qt.Name,qt.IconName,count(s.ScoreID) as Count,sum(if(s.StarNumber=1,1,0)) as Star1 ,sum(if(s.StarNumber=2,1,0)) as Star2,sum(if(s.StarNumber=3,1,0)) as Star3 from MathStarScores s inner join QuestionTypes qt on s.QuestionTypeID=qt.ID inner join QuestionCategory qc on qt.Category=qc.CategoryID where s.UserID=? and s.Flag=0 and s.QuestionTypeID>0 and qc.Grade=? group by s.QuestionTypeID order by qt.Category,qt.Difficulty,qt.Sort;";
135
+            return await queryAsync(sql, [obj.UserID, obj.Grade]);
136
+        } catch (error) {
137
+            console.error('获取用户分数列表失败:', error);
138
+            throw error;
139
+        }
140
+    }
141
+
142
+    /**
143
+     * 获取用户复习列表
144
+     * @param {Object} obj 查询参数
145
+     * @returns {Promise<Array>} 复习列表
146
+     */
147
+    static async GetReviewListByUserID500(obj) {
148
+        try {
149
+            const sql = "SELECT Category,QuestionTypeID,Max(CreateTime) as 'UpdateTime',Max(Score) as 'Score',Max(StarNumber) as 'StarNumber',Count(*) as 'PracticeNumber' FROM MathStarScores where UserID=? and Flag=0 and Category=7 Group by Category,QuestionTypeID order by Category,QuestionTypeID desc;";
150
+            return await queryAsync(sql, [obj.UserID]);
151
+        } catch (error) {
152
+            console.error('获取用户复习列表失败:', error);
153
+            throw error;
154
+        }
155
+    }
156
+
157
+    /**
158
+     * 获取用户星级数量列表
159
+     * @param {Object} obj 查询参数
160
+     * @returns {Promise<Array>} 星级数量列表
161
+     */
162
+    static async GetUserStarNumberCountList500(obj) {
163
+        try {
164
+            let sql = "select s.QuestionTypeID,count(s.ScoreID) as Count from QuestionTypes q left join MathStarScores s on q.ID=s.QuestionTypeID where s.Flag=0 and s.Category=7 and s.StarNumber>=3 and s.UserID=?";
165
+            const params = [obj.UserID];
166
+            
167
+            if (obj.Category > 0) {
168
+                sql += " and q.Category=?";
169
+                params.push(obj.Category);
170
+            }
171
+            
172
+            sql += " group by s.QuestionTypeID order by q.Category,q.Difficulty,q.Sort,q.ID;";
173
+            return await queryAsync(sql, params);
174
+        } catch (error) {
175
+            console.error('获取用户星级数量列表失败:', error);
176
+            throw error;
177
+        }
178
+    }
179
+
180
+    /**
181
+     * 添加测试分数
182
+     * @param {Object} obj 分数信息
183
+     * @returns {Promise<Object>} 插入结果
184
+     */
185
+    static async AddScore500Test(obj) {
186
+        try {
187
+            const sql = "INSERT INTO MathStarUserTestScore SET ?";
188
+            return await queryAsync(sql, obj);
189
+        } catch (error) {
190
+            console.error('添加测试分数失败:', error);
191
+            throw error;
192
+        }
193
+    }
194
+
195
+    /**
196
+     * 获取用户强化列表
197
+     * @param {Object} obj 查询参数
198
+     * @returns {Promise<Array>} 强化列表
199
+     */
200
+    static async GetUserIntensifyListByUserIDAndQuestionTypeID(obj) {
201
+        try {
202
+            const sql = "SELECT * from MathStarUserQuestionType where Flag=0 and UserID=? and QuestionTypeID=?";
203
+            return await queryAsync(sql, [obj.UserID, obj.QuestionTypeID]);
204
+        } catch (error) {
205
+            console.error('获取用户强化列表失败:', error);
206
+            throw error;
207
+        }
208
+    }
209
+
210
+    /**
211
+     * 添加用户强化
212
+     * @param {Object} obj 强化信息
213
+     * @returns {Promise<Object>} 插入结果
214
+     */
215
+    static async AddUserIntensify(obj) {
216
+        try {
217
+            const sql = "INSERT INTO MathStarUserQuestionType SET ?";
218
+            return await queryAsync(sql, obj);
219
+        } catch (error) {
220
+            console.error('添加用户强化失败:', error);
221
+            throw error;
222
+        }
223
+    }
224
+
225
+    /**
226
+     * 更新用户强化
227
+     * @param {Object} obj 更新参数
228
+     * @returns {Promise<Object>} 更新结果
229
+     */
230
+    static async UpdateUserIntensify(obj) {
231
+        try {
232
+            const sql = "update MathStarUserQuestionType SET ? where UserID=? and QuestionTypeID=?";
233
+            return await queryAsync(sql, [obj, obj.UserID, obj.QuestionTypeID]);
234
+        } catch (error) {
235
+            console.error('更新用户强化失败:', error);
236
+            throw error;
237
+        }
238
+    }
239
+
240
+    /**
241
+     * 获取分数星级数
242
+     * @param {Object} obj 查询参数
243
+     * @returns {Promise<Array>} 星级数
244
+     */
245
+    static async GetScoreStarNumberByUserIDAndQuestionTypeID(obj) {
246
+        try {
247
+            const sql = "select count(ScoreID) as 'Count' from MathStarScores where Flag=0 and StarNumber=3 and CreateTime>? and UserID=? and QuestionTypeID=?";
248
+            return await queryAsync(sql, [obj.UpdateTime, obj.UserID, obj.QuestionTypeID]);
249
+        } catch (error) {
250
+            console.error('获取分数星级数失败:', error);
251
+            throw error;
252
+        }
253
+    }
254
+
255
+    /**
256
+     * 获取用户强化列表
257
+     * @param {Object} obj 查询参数
258
+     * @returns {Promise<Array>} 强化列表
259
+     */
260
+    static async GetUserIntensifyListByUserID(obj) {
261
+        try {
262
+            const sql = "SELECT uqt.*,qt.Name,qt.IconName from MathStarUserQuestionType uqt inner join QuestionTypes qt on uqt.QuestionTypeID=qt.ID where uqt.Flag=0 and uqt.UserID=? order by uqt.UpdateTime desc;";
263
+            return await queryAsync(sql, [obj.UserID]);
264
+        } catch (error) {
265
+            console.error('获取用户强化列表失败:', error);
266
+            throw error;
267
+        }
268
+    }
269
+
270
+    /**
271
+     * 获取本学期信息
272
+     * @param {Object} obj 查询参数
273
+     * @returns {Promise<Array>} 学期信息
274
+     */
275
+    static async GetThisTermByUserID500(obj) {
276
+        try {
277
+            let timeTermStart = "";
278
+            let dayNumber = 0;
279
+            const arrDate = ["2018-09-01", "2019-01-24", "2019-06-30", "2020-01-17", "2020-06-30", "2021-02-01"];
280
+            const stimeToday = moment();
281
+
282
+            for (let i = arrDate.length - 2; i >= 0; i--) {
283
+                const timeEnd = moment(arrDate[i]);
284
+                const dayNumber1 = stimeToday.diff(timeEnd, 'days');
285
+                if (dayNumber1 > 0) {
286
+                    timeTermStart = arrDate[i];
287
+                    dayNumber = moment(arrDate[i + 1]).diff(stimeToday, 'days');
288
+                    break;
289
+                }
290
+            }
291
+
292
+            const sql = "select date_format(Min(CreateTime),'%Y年%m月%d日') as TimeStart,count(distinct date_format(CreateTime,'%Y-%m-%d')) As DayNumber,? as TimeEndDayNumber from MathStarScores where UserID=? and Flag=0 and QuestionTypeID>0 and CreateTime>=?;";
293
+            return await queryAsync(sql, [dayNumber, obj.UserID, timeTermStart]);
294
+        } catch (error) {
295
+            console.error('获取本学期信息失败:', error);
296
+            throw error;
297
+        }
298
+    }
299
+
300
+    /**
301
+     * 获取用户问题列表
302
+     * @param {Object} obj 查询参数
303
+     * @returns {Promise<Array>} 问题列表
304
+     */
305
+    static async GetUserQuestionListByObj(obj) {
306
+        try {
307
+            let sql = "select * from MathStarUserQuestion where UserID=? and Flag=0 and HiddenColumn=? and A=? and OperateAB=? and B=? and R=?";
308
+            const params = [obj.UserID, obj.HiddenColumn, obj.A, obj.OperateAB, obj.B, obj.R];
309
+
310
+            if (obj.OperateBC && obj.C) {
311
+                sql += " and OperateBC=? and C=?";
312
+                params.push(obj.OperateBC, obj.C);
313
+                if (obj.OperateCD && obj.D) {
314
+                    sql += " and OperateCD=? and D=?";
315
+                    params.push(obj.OperateCD, obj.D);
316
+                }
317
+            }
318
+            sql += ";";
319
+            return await queryAsync(sql, params);
320
+        } catch (error) {
321
+            console.error('获取用户问题列表失败:', error);
322
+            throw error;
323
+        }
324
+    }
325
+
326
+    /**
327
+     * 更新用户问题
328
+     * @param {Object} obj 更新参数
329
+     * @returns {Promise<Object>} 更新结果
330
+     */
331
+    static async UpdateUserQuestion(obj) {
332
+        try {
333
+            const sql = "Update MathStarUserQuestion SET ? where UserQuestionID=?";
334
+            return await queryAsync(sql, [obj, obj.UserQuestionID]);
335
+        } catch (error) {
336
+            console.error('更新用户问题失败:', error);
337
+            throw error;
338
+        }
339
+    }
340
+
341
+    /**
342
+     * 添加用户问题
343
+     * @param {Object} obj 问题信息
344
+     * @returns {Promise<Object>} 插入结果
345
+     */
346
+    static async AddUserQuestion(obj) {
347
+        try {
348
+            const sql = "INSERT INTO MathStarUserQuestion SET ?";
349
+            return await queryAsync(sql, obj);
350
+        } catch (error) {
351
+            console.error('添加用户问题失败:', error);
352
+            throw error;
353
+        }
354
+    }
355
+
356
+    /**
357
+     * 获取用户最佳成绩
358
+     * @param {Object} obj 查询参数
359
+     * @returns {Promise<Array>} 最佳成绩
360
+     */
361
+    static async GetScoreBestByUserID(obj) {
362
+        try {
363
+            if (!obj.UserID) {
364
+                obj.UserID = 0;
365
+            }
366
+            const sql = "select UserID,QuestionTypeID,Min(Duration+0) MinDuration,Max(Score+0) MaxScore,count(*) Count,Max(StarNumber) MaxStarNumber,Sum(StarNumber) SumStarNumber,count(GoldCoin) as GoldCoin,max(Point) as 'MaxPoints',max(PointLevel) as 'PointLevel',max(SpeedLevel) as 'SpeedLevel' from MathStarScores where Flag=0 and QuestionTypeID=? and UserID=? and Duration>0;";
367
+            return await queryAsync(sql, [obj.QuestionTypeID, obj.UserID]);
368
+        } catch (error) {
369
+            console.error('获取用户最佳成绩失败:', error);
370
+            throw error;
371
+        }
372
+    }
373
+
374
+    /**
375
+     * 获取用户统计数据
376
+     * @param {Object} obj 查询参数
377
+     * @returns {Promise<Array>} 统计数据
378
+     */
379
+    static async GetScoreStatisticsByUserID(obj) {
380
+        try {
381
+            let sql;
382
+            if (!obj.Time) {
383
+                sql = "SELECT count(distinct date_format(CreateTime,'%Y-%m-%d')) As DayNumber,Max(Score) as 'Score',sum(StarNumber) as 'StarNumber',sum(Duration) as 'Duration',count(*) as 'QuestionType',sum(QuestionNumber) as 'QuestionNumber',sum(Point) as 'Point',sum(GoldCoin) as 'GoldCoin',sum(EnergyBall) as 'EnergyBall' FROM MathStarScores where Duration>0 and UserID=?";
384
+            } else {
385
+                sql = "SELECT sum(StarNumber) as 'StarNumber',count(*) as 'QuestionType',sum(Point) as 'Point',sum(GoldCoin) as 'GoldCoin',sum(EnergyBall) as 'EnergyBall' FROM MathStarScores where UserID=? and Duration>0 and Flag=0 and CreateTime>=CURDATE();";
386
+            }
387
+            return await queryAsync(sql, [obj.UserID]);
388
+        } catch (error) {
389
+            console.error('获取用户统计数据失败:', error);
390
+            throw error;
391
+        }
392
+    }
393
+
394
+    /**
395
+     * 更新分数记录状态
396
+     * @param {Object} obj 更新参数
397
+     * @returns {Promise<Object>} 更新结果
398
+     */
399
+    static async UpdateScoreIsRecord(obj) {
400
+        try {
401
+            const sql = "Update MathStarScores SET IsRecord=0 where UserID=? and QuestionTypeID=?";
402
+            return await queryAsync(sql, [obj.UserID, obj.QuestionTypeID]);
403
+        } catch (error) {
404
+            console.error('更新分数记录状态失败:', error);
405
+            throw error;
406
+        }
407
+    }
408
+
409
+    /**
410
+     * 获取题卡排名成绩列表
411
+     * @param {Object} obj 查询参数
412
+     * @returns {Promise<Array>} 排名成绩列表
413
+     */
414
+    static async GetScoreListByQuestionTypeID(obj) {
415
+        try {
416
+            const sql = "SELECT s.UserID,u.NickName2,s.Duration FROM MathStarScores s inner join MathStarWXUsers u on s.UserID=u.UserID where s.QuestionTypeID=? and s.Score=100 and s.Flag=0 and s.IsRecord=1 order by s.Duration;";
417
+            return await queryAsync(sql, [obj.QuestionTypeID]);
418
+        } catch (error) {
419
+            console.error('获取题卡排名成绩列表失败:', error);
420
+            throw error;
421
+        }
422
+    }
423
+
424
+    /**
425
+     * 添加分数
426
+     * @param {Object} obj 分数信息
427
+     * @returns {Promise<Object>} 插入结果
428
+     */
429
+    static async AddScore(obj) {
430
+        try {
431
+            const sql = "INSERT INTO MathStarScores SET ?";
432
+            return await queryAsync(sql, obj);
433
+        } catch (error) {
434
+            console.error('添加分数失败:', error);
435
+            throw error;
436
+        }
437
+    }
438
+
439
+    /**
440
+     * 获取用户统计数据500
441
+     * @param {Object} obj 查询参数
442
+     * @returns {Promise<Array>} 统计数据
443
+     */
444
+    static async GetScoreStatisticsByUserID500(obj) {
445
+        try {
446
+            let sql;
447
+            if (!obj.WeekDate) {
448
+                sql = "SELECT count(distinct date_format(CreateTime,'%Y-%m-%d')) As DayNumber,count(*) as 'QuestionType',sum(Point) as 'Point',sum(GoldCoin) as 'GoldCoin',sum(EnergyBall) as 'EnergyBall',sum(if(StarNumber=3,1,0)) as StarNumber FROM MathStarScores where Flag=0 and Duration>0 and UserID=?";
449
+                return await queryAsync(sql, [obj.UserID]);
450
+            } else if (obj.TimeType === "week") {
451
+                sql = "SELECT date_format(CreateTime,'%Y-%m-%d') as 'WeekDate',count(*) as 'Count',sum(Point) as 'Point',sum(if(StarNumber=3,1,0)) as Star3,sum(if(StarNumber=2,1,0)) as Star2,sum(if(StarNumber=1,1,0)) as Star1 FROM MathStarScores where Flag=0 and Duration>0 and UserID=? and CreateTime>=? Group by date_format(CreateTime,'%Y-%m-%d');";
452
+                return await queryAsync(sql, [obj.UserID, obj.WeekDate + " 00:00:00"]);
453
+            } else if (obj.TimeType === "7day") {
454
+                sql = "SELECT date_format(CreateTime,'%Y-%m-%d') as 'WeekDate',count(*) as 'Count',sum(Point) as 'Point',sum(if(StarNumber=3,1,0)) as Star3,sum(if(StarNumber=2,1,0)) as Star2,sum(if(StarNumber=1,1,0)) as Star1 FROM MathStarScores where Flag=0 and Duration>0 and UserID=? Group by date_format(CreateTime,'%Y-%m-%d') order by date_format(CreateTime,'%Y-%m-%d') desc limit 7;";
455
+                return await queryAsync(sql, [obj.UserID]);
456
+            }
457
+        } catch (error) {
458
+            console.error('获取用户统计数据500失败:', error);
459
+            throw error;
460
+        }
461
+    }
462
+
463
+    /**
464
+     * 获取用户测试分数列表
465
+     * @param {Object} obj 查询参数
466
+     * @returns {Promise<Array>} 测试分数列表
467
+     */
468
+    static async GetUserTestScoreListByUserID(obj) {
469
+        try {
470
+            const sql = "SELECT GradeLevel,count(UserTestID) as Count,sum(IsPass) as IsPassCount,max(Points) as MaxPoints FROM MathStarUserTestScore where UserID=? and Grade=? and Flag=0 group by GradeLevel order by GradeLevel";
471
+            return await queryAsync(sql, [obj.UserID, obj.Grade]);
472
+        } catch (error) {
473
+            console.error('获取用户测试分数列表失败:', error);
474
+            throw error;
475
+        }
476
+    }
477
+
478
+    /**
479
+     * 获取用户天数
480
+     * @param {Object} obj 查询参数
481
+     * @returns {Promise<Array>} 用户天数信息
482
+     */
483
+    static async GetUserDayNumber(obj) {
484
+        try {
485
+            const sql = "select count(a.CreateTime1) as DayNumber, Max(a.CreateTime1) as 'Max' from (SELECT distinct date_format(CreateTime,'%Y-%m-%d') As CreateTime1 FROM MathStarScores where UserID=? union all SELECT distinct date_format(CreateTime,'%Y-%m-%d') As CreateTime1 FROM MathStarUserTestScore where UserID=?) a order by a.CreateTime1;";
486
+            return await queryAsync(sql, [obj.UserID, obj.UserID]);
487
+        } catch (error) {
488
+            console.error('获取用户天数失败:', error);
489
+            throw error;
490
+        }
491
+    }
492
+
493
+    /**
494
+     * 获取最新练习成绩
495
+     * @returns {Promise<Array>} 练习成绩列表
496
+     */
497
+    static async GetScoresNew500() {
498
+        try {
499
+            const sql = "SELECT s.UserID as '用户ID',u.NickName as '昵称',u.IsPay as '支付',u.ProductServiceTime,s.QuestionTypeName as '题卡名称',s.Point as '得分',u.ProgramVersion as '版本',u.Province as '省',u.Model as '手机',s.CreateTime as '时间' FROM MathStarScores s inner join MathStarWXUsers u on s.UserID=u.UserID where s.flag=0 order by s.CreateTime desc limit 200;";
500
+            return await queryAsync(sql);
501
+        } catch (error) {
502
+            console.error('获取最新练习成绩失败:', error);
503
+            throw error;
504
+        }
505
+    }
506
+}
507
+
508
+export default MathStar;