PaperService.class.php
139 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
<?php
/**
* 试卷表
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-19 17:43:16
*/
namespace Common\Service;
use Common\Common\AttachOperation;
use Common\Common\Cache;
use Common\Common\Msg;
use Common\Common\TaskCenter;
use Common\Common\User;
use Common\Model\AnswerDetailExtendModel;
use Common\Model\AnswerModel;
use Common\Model\AttrModel;
use Common\Model\BankModel;
use Common\Model\CategoryModel;
use Common\Model\PaperModel;
use Common\Model\PaperTempModel;
use Common\Model\RandomSnapshotModel;
use Common\Model\RightModel;
use Common\Model\SnapshotModel;
use Common\Model\TagModel;
use Common\Model\TopicAttrModel;
use Common\Model\TopicModel;
use VcySDK\Cron;
use VcySDK\Logger;
use VcySDK\Service;
use Common\Common\StudyMap;
class PaperService extends AbstractService
{
// 闯关通过
const MY_BREAK_PASS = 1;
// 闯关不通过
const MY_BREAK_NO_PASS = 2;
// 闯关未交卷状态
const NOT_ASSIGNMENT = 0;
// 闯关已交卷状态
const ASSIGNMENT = 1;
/** @var RandomSnapshotModel */
protected $_d_random;
/** @var CategoryModel */
protected $_d_cate;
/** @var AnswerModel */
protected $_d_answer;
/** @var RightModel */
protected $_d_right;
/** @var BankModel */
protected $_d_bank;
/** @var TagModel */
protected $_d_tag;
/** @var AttrModel */
protected $_d_attr;
/** @var SnapshotModel */
protected $_d_snapshot;
/** @var PaperTempModel */
protected $_d_temp;
/** @var TopicModel */
protected $_d_topic;
/** @var TopicAttrModel */
protected $_d_topic_attr;
protected $_d_answer_detail_extend;
// 构造方法
public function __construct()
{
$this->_d = new PaperModel();
$this->_d_cate = new CategoryModel();
$this->_d_answer = new AnswerModel();
$this->_d_right = new RightModel();
$this->_d_bank = new BankModel();
$this->_d_tag = new TagModel();
$this->_d_attr = new AttrModel();
$this->_d_snapshot = new SnapshotModel();
$this->_d_temp = new PaperTempModel();
$this->_d_topic = new TopicModel();
$this->_d_topic_attr = new TopicAttrModel();
$this->_d_random = new RandomSnapshotModel();
$this->_d_answer_detail_extend = new AnswerDetailExtendModel();
parent::__construct();
}
/**
* 获取试卷基本信息(详情用)
*
* @author:daijun
*
* @param int $ep_id 试卷ID
*
* @return array|bool
*/
public function get_paper_detail_admin($ep_id = 0)
{
// 获取试卷信息(此处需加上不是初始化状态的数据)
$data = $this->_d->get_by_conds(['ep_id' => $ep_id, 'exam_status>?' => self::PAPER_INIT]);
// 判断试卷是否存在
if (empty($data)) {
E('_EMPTY_PAPER_DATA');
}
// 默认关闭积分策略
$is_open_integral = self::CLOSE_INTEGRAL;
// 如果启用的自定义或者默认积分策略
if ($data['integral_action_type'] != self::INTEGRAL_ACTION_TYPE_NO) {
// 开启策略
$is_open_integral = self::OPEN_INTEGRAL;
}
// 默认关闭学分策略
$is_open_credit = self::CLOSE_INTEGRAL;
// 如果启用的自定义或者默认学分策略
if ($data['credit_action_type'] != self::CREDIT_ACTION_TYPE_FALSE) {
// 开启策略
$is_open_credit = self::OPEN_INTEGRAL;
}
// 获取试卷分类名称
$cate_data = $this->_d_cate->get($data['ec_id']);
$result = [
'ep_id' => intval($ep_id),
'ep_name' => $data['ep_name'],
'exam_type' => intval($data['exam_type']),
'paper_type' => intval($data['paper_type']),
'ep_type' => intval($data['ep_type']),
'is_all' => intval($data['is_all']),
'begin_time' => $data['begin_time'],
'end_time' => $data['end_time'],
'paper_time' => intval($data['paper_time']),
'is_notify' => intval($data['is_notify']),
'notify_begin' => intval($data['notify_begin']),
'notify_end' => intval($data['notify_end']),
'is_recommend' => intval($data['is_recommend']),
'answer_resolve' => intval($data['answer_resolve']),
'total_score' => intval($data['total_score']),
'pass_score' => intval($data['pass_score']),
'intro' => $data['intro'],
'reason' => $data['reason'], // 终止原因
'reason_time' => $data['reason_time'], // 终止时间
'marking_type' => intval($data['marking_type']),// 阅卷类型
'is_open_integral' => $is_open_integral, // 是否开启积分策略
'integral_action_type' => intval($data['integral_action_type']), // 积分策略
'integral_strategyid' => strval($data['integral_strategyid']), // 积分策略ID
'is_open_credit' => $is_open_credit, // 是否开启积分策略
'credit_action_type' => intval($data['credit_action_type']), // 积分策略
'credit_strategyid' => strval($data['credit_strategyid']), // 积分策略ID
'is_pushmsg' => intval($data['is_pushmsg']), // 是否发送及时消息
'ep_status' => $this->paper_status($data['exam_status'], $data['begin_time'], $data['end_time']), // 获取试卷当前状态
'ec_id' => intval($data['ec_id']),
'ec_name' => $cate_data['ec_name'],
'import_num' => 0, // 导入人员数量
'is_upset_topic' => intval($data['is_upset_topic']), // 是否打乱题目 (1:是 2: 否)
'is_upset_option' => intval($data['is_upset_option']), // 是否打乱选项 (1:是 2: 否)
'is_see_after_submit' => intval($data['is_see_after_submit']), // 交卷后可见性设置:(0:全部不可见 1:得分可见,2:对错可见,3:解析可见)
'is_see_after_over' => intval($data['is_see_after_over']), // 考试结束后可见性设置:(0:全部不可见 1:得分可见,2:对错可见,3:解析可见)
'is_open_anonymous_marking' => intval($data['is_open_anonymous_marking']), // 是否开启匿名阅卷:(1:开启 2:不开启)
'is_open_makeup' => intval($data['is_open_makeup']), // 是否开启补考功能:(1:开启 2:不开启)
'makeup_num' => intval($data['makeup_num']), // 补考次数限制
'makeup_start_time' => intval($data['makeup_start_time']), // 补考开始时间
'makeup_end_time' => intval($data['makeup_end_time']), // 补考结束时间
];
// 获取封面图片
$result['is_cover_open'] = intval($data['is_cover_open']);
if (self::IS_COVER_PIC_OPEN == $data['is_cover_open']) {
// 如果开启,则获取路径
$result['cover_url'] = $this->format_cover($data['cover_id']);
} else {
$result['cover_url'] = '';
}
// 获取阅卷信息
list($show_marking, $marking_list) = $this->get_marking($ep_id);
$result['show_marking'] = $show_marking;// 是否显示阅卷
$result['marking_list'] = $marking_list; // 阅卷人员列表
return $result;
}
/**
* 【后台】根据试卷ID获取试卷信息
*
* @author 何岳龙
*
* @param int $ep_id 试卷ID
*
* @return array
*/
private function get_marking($ep_id = 0)
{
// 初始化是否显示阅卷
$show_marking = self::NOT_SHOW_MARKING;
// 初始化阅卷人员列表
$marking_list = [];
// 获取试卷信息(此处需加上不是初始化状态的数据)
$data = $this->_d->get_by_conds(['ep_id' => $ep_id]);
// 如果是模拟试卷
if ($data['paper_type'] == self::SIMULATION_PAPER_TYPE) {
return [$show_marking, $marking_list];
}
// 自主抽题或者固定抽题
if (self::TOPIC_CUSTOMER == $data['ep_type'] || self::TOPIC_RULE == $data['ep_type']) {
// 语音问答题总数
$voice_total = $this->_d_snapshot->count_by_conds(['ep_id' => $ep_id, 'et_type' => self::TOPIC_TYPE_VOICE]);
// 问答题总数
$question_total = $this->_d_snapshot->count_by_conds([
'ep_id' => $ep_id,
'et_type' => self::TOPIC_TYPE_QUESTION
]);
// 获取题目总数
$total = intval($voice_total) + intval($question_total);
}
// 随机抽题
if (self::TOPIC_RANDOM == $data['ep_type']) {
// 解析rule权限
$rule = unserialize($data['rule']);
// 计算题目总数
$total = intval($rule['question_count']) + intval($rule['voice_count']);
}
// 如果存在问答题以及语音问答题
if (!empty($total)) {
$show_marking = self::SHOW_MARKING;
// 获取阅读人员权限
$right_uids = $this->_d_right->list_by_conds(['er_type' => self::RIGHT_MARKING, 'epc_id' => $ep_id],
null, [], 'uid');
// 如果有阅读权限
if ($right_uids) {
// 获取有权限的阅读人UID
$uids = array_unique(array_column($right_uids, 'uid'));
// 初始化用户类
$userServ = &User::instance();
// 排序
sort($uids);
// 获取用户类型表
$users = $userServ->listAll(['memUids' => $uids]);
// 遍历用户
foreach ($users as $user) {
// 组装数据
$marking_list[] = [
'memID' => $user['memUid'],
'memUsername' => $user['memUsername'],
'memFace' => $user['memFace'],
];
}
}
}
return [$show_marking, $marking_list];
}
/**
* 获取试卷基本信息(编辑用)
*
* @author:daijun
*
* @param int $ep_id 试卷ID
*
* @return array|bool
*/
public function get_paper_base_detail($ep_id = 0)
{
// 获取试卷信息
$data = $this->_d->get($ep_id);
// 判断试卷是否存在
if (empty($data)) {
E('_EMPTY_PAPER_DATA');
}
// 默认关闭积分策略
$is_open_integral = self::CLOSE_INTEGRAL;
// 如果启用的自定义或者默认积分策略
if ($data['integral_action_type'] != self::INTEGRAL_ACTION_TYPE_NO) {
// 开启策略
$is_open_integral = self::OPEN_INTEGRAL;
}
// 默认关闭学分策略
$is_open_credit = self::CLOSE_INTEGRAL;
// 如果启用的自定义或者默认学分策略
if ($data['credit_action_type'] != self::CREDIT_ACTION_TYPE_FALSE) {
// 开启策略
$is_open_credit = self::OPEN_INTEGRAL;
}
// 获取阅卷信息
list($show_marking, $marking_list) = $this->get_marking($ep_id);
// 格式化返回数据
$result = [
'ep_id' => intval($data['ep_id']),
'exam_type' => intval($data['exam_type']),
'ep_type' => intval($data['ep_type']),
'ep_name' => $data['ep_name'],
'is_all' => intval($data['is_all']),
'begin_time' => $data['begin_time'],
'end_time' => $data['end_time'],
'paper_time' => intval($data['paper_time']),
'is_notify' => intval($data['is_notify']),
'notify_begin' => intval($data['notify_begin']),
'notify_end' => intval($data['notify_end']),
'is_recommend' => intval($data['is_recommend']),
'is_pushmsg' => intval($data['is_pushmsg']),
'answer_resolve' => intval($data['answer_resolve']),
'total_score' => intval($data['total_score']),
'pass_score' => intval($data['pass_score']),
'exam_status' => intval($data['exam_status']),
'intro' => $data['intro'],
'marking_type' => intval($data['marking_type']), // 阅卷类型
'show_marking' => $show_marking, // 是否显示阅卷
'marking_list' => $marking_list, // 阅卷人员列表
'paper_type' => intval($data['paper_type']), // 试卷类型
'is_open_integral' => $is_open_integral, // 是否启用积分策略
'integral_action_type' => intval($data['integral_action_type']), // 积分策略类型
'integral_strategyid' => $data['integral_strategyid'], // 积分策略ID
'is_open_credit' => $is_open_credit, // 是否启用学分策略
'credit_action_type' => intval($data['credit_action_type']), // 学分策略类型
'credit_strategyid' => $data['credit_strategyid'], // 学分策略ID
'is_cover_open' => intval($data['is_cover_open']), // 是否开启封面图片上传 (1:开启2:关闭)
'import_num' => 0, // 导入人员数量
'is_upset_topic' => intval($data['is_upset_topic']), // 是否打乱题目 (1:是 2: 否)
'is_upset_option' => intval($data['is_upset_option']), // 是否打乱选项 (1:是 2: 否)
'is_see_after_submit' => intval($data['is_see_after_submit']), // 交卷后可见性设置:(0:全部不可见 1:得分可见,2:对错可见,3:解析可见)
'is_see_after_over' => intval($data['is_see_after_over']), // 考试结束后可见性设置:(0:全部不可见 1:得分可见,2:对错可见,3:解析可见)
'is_open_anonymous_marking' => intval($data['is_open_anonymous_marking']), // 是否开启匿名阅卷:(1:开启 2:不开启)
'is_open_makeup' => intval($data['is_open_makeup']), // 是否开启补考功能:(1:开启 2:不开启)
'makeup_num' => intval($data['makeup_num']), // 补考次数限制
'makeup_start_time' => intval($data['makeup_start_time']), // 补考开始时间
'makeup_end_time' => intval($data['makeup_end_time']), // 补考结束时间
];
if (self::IS_COVER_PIC_OPEN == $data['is_cover_open']) {
// 如果开启,则格式化图片路径
$result['cover_id'] = $data['cover_id'];
$result['cover_url'] = $this->format_cover($data['cover_id']);
} else {
$result['cover_id'] = '';
$result['cover_url'] = '';
}
return $result;
}
/**
* 查询总数
*
* @param $data array 查询条件
*
* @return int|mixed
*/
public function count_by_paper($data)
{
return $this->_d->count_by_paper($data);
}
/**
* 查询列表
*
* @author: 蔡建华
*
* @param array $data 查询条件
* @param null $page_option 分页参数
* @param array $order_option 排序参数
* @param string $fields 查询的字段
*
* @return array|bool
*/
public function list_by_paper($data, $page_option = null, $order_option = [], $fields = '*')
{
return $this->_d->list_by_paper($data, $page_option, $order_option, $fields);
}
/**
* 获取手机端试卷列表
*
* @param array $conds 查询条件
* @param null $page_option 分页
* @param array $order_option 排序
* @param string $fields 字段
*
* @return array|bool 试卷列表
*/
public function paper_api_list($conds = [], $page_option = null, $order_option = [], $fields = '*')
{
return $this->_d->paper_api_list($conds, $page_option, $order_option, $fields);
}
/**
* 格式化试题列表返回数据
* @author: 蔡建华
*
* @param array $list 待格式化数据
* @param int $join_type 参与类型
* @param string $uid 用户ID
*
* @return array 格式化后数据
*/
public function paper_format($list = [], $join_type = 0, $uid = '')
{
// 待格式化数据不为空
if ($list) {
$ep_ids = array_column($list, 'ep_id');
// 查询补考次数
$answer_list = $this->_d_answer->list_by_conds(['ep_id' => $ep_ids, 'uid' => $uid, 'is_makeup' => self::IS_MAKEUP], null, ['ep_id' => 'DESC'], 'ea_id,ep_id');
// 转换成以ep_id为主键的二维数组
$new_data = array_count_values(array_column($answer_list, 'ep_id'));
foreach ($list as $key => $val) {
// 默认不显示补考标签
$makeup_tag = 0;
$ep_status = $this->paper_status($val['exam_status'], $val['begin_time'], $val['end_time']);
$now_time = MILLI_TIME;
// 如果是常规考试 && 是测评试卷 && 开启补考 && 当前时间大于补考开始时间 && 当前时间小于补考结束时间
if (self::NOMAL_TYPE == $val['exam_type'] && self::EVALUATION_PAPER_TYPE == $val['paper_type'] && self::OPEN_MAKEUP == $val['is_open_makeup'] && $now_time < $val['makeup_end_time'] && $now_time > $val['makeup_start_time']) {
if ($val['my_is_pass'] != self::MY_PASS && intval($new_data[$val['ep_id']]) == 0 && in_array($ep_status, [self::STATUS_STOP, self::STATUS_END])) {
// 考试已结束或者已终止 && 未参加考试
$makeup_tag = 1; // 显示补考标签
} elseif ($val['my_is_pass'] != self::MY_PASS && $val['ea_id'] > 0 && intval($new_data[$val['ep_id']]) < $val['makeup_num']) {
// 尚有补考次数
$makeup_tag = 1; // 显示补考标签
}
// 查询待批阅的答卷记录 和未交卷的 答卷记录
$answer_list_marking = $this->_d_answer->list_by_conds(['ep_id' => $val['ep_id'], 'uid' => $uid, 'answer_status<?' => self::READ_OVER], [0, 1], ['ea_id' => 'ASC']);
if (!empty($answer_list_marking)) {
// 存在待批阅或者待交卷的答卷信息
$val['answer_status'] = $answer_list_marking[0]['answer_status'];
$val['ea_id'] = $answer_list_marking[0]['ea_id'];
$makeup_tag = 0;
}
}
// 重新赋值
$list[$key] = [
'ep_id' => intval($val['ep_id']),
'join_type' => $join_type,
'paper_type' => intval($val['paper_type']),
'ep_name' => $val['ep_name'],
'total_score' => $val['total_score'],
'ep_status' => $ep_status,
'my_score' => $join_type ? $val['my_score'] : '0',
'my_is_pass' => $join_type ? intval($val['my_is_pass']) : 0,
'answer_status' => $join_type ? intval($val['answer_status']) : 0,
'end_time' => $val['end_time'],
'join_count' => intval($val['join_count']),
'makeup_tag' => $makeup_tag,
'ea_id' => intval($val['ea_id']),
];
}
}
return $list;
}
/**
* 根据权限查询
* @param array $conds
* +++ right array 权限数据
* +++ ec_id int 试卷分类
* @param string $fields 查询参数
*
* @return array
*/
public function list_by_right($conds = [], $fields = '*')
{
$right_ep_list = $this->_d->get_ep_ids_by_right($conds['right']);
// 根据权限查询出来的试卷ID集合
$ep_ids = array_column($right_ep_list, 'epc_id');
$paper_list = [];
if ($ep_ids) {
$conds_new = [
'ep_id' => $ep_ids,
'exam_type' => self::NOMAL_TYPE, // 试卷类型:常规试卷
'exam_status' => [self::PAPER_PUBLISH, self::PAPER_STOP], // 状态为已发布或者已终止
];
if ($conds['ec_id']) {
// 如果试卷分类不为空
$conds_new['ec_id'] = $conds['ec_id'];
}
$paper_list = $this->_d->list_by_conds($conds_new, null, [], $fields);
}
return $paper_list;
}
/**
* 新增试卷规则
*
* @author:daijun
*
* @param array $param 传入参数
*
* @return mixed
*/
public function rule_add($param = [])
{
// 验证数据
$data = $this->check_rule_add($param);
// 属性序列化(序列化)
$tag_data = !empty($param['tag_data']) ? serialize($param['tag_data']) : '';
$data['tag_data'] = $tag_data;
// 发布人ID
$data['admin_id'] = '';
// 发布人
$data['launch_man'] = '';
// 选中题目列表(序列化)
$data['check_topic_data'] = '';
// 考试说明
$data['intro'] = '';
// 终止理由
$data['reason'] = '';
// 终止人员ID
$data['reason_user_id'] = '';
// 终止人员名称
$data['reason_user'] = '';
// 试卷状态
$data['exam_status'] = self::PAPER_INIT;
// 新数据
$data['is_old'] = self::NEW_DATA_STATE;
if (!empty($param['rule'])) {
// 随机选题 此处需要计算总分
$rule = $param['rule'];
// 将题目数为0的题目分数置为0
$rule = $this->set_rule($rule);
// 计算总分
$data['total_score'] = intval($rule['single_count']) * intval($rule['single_score'])
+ intval($rule['multiple_count']) * intval($rule['multiple_score'])
+ intval($rule['judgment_count']) * intval($rule['judgment_score'])
+ intval($rule['question_count']) * intval($rule['question_score'])
+ intval($rule['voice_count']) * intval($rule['voice_score']);
}
try {
// 开始事务
$this->start_trans();
// 保存基本信息
$ep_id = $this->_d->insert($data);
$temp_list = [];
// 按照抽取规则和抽取条件进行抽取符合条件的题目
$topic_list = $this->get_temp_list_by_epid($ep_id);
if (!$topic_list || !is_array($topic_list) || empty($topic_list)) {
// 若没有抽到题目回滚
$this->rollback();
E('_ERR_TOPIC_NOT_GET_LIST_DATA');
}
// 非随机抽取
if ($data['ep_type'] != self::TOPIC_RANDOM) {
// 初始化编号
$i = self::ORDER_NUM;
foreach ($topic_list as $v) {
$topic_data['ep_id'] = $ep_id;
$topic_data['et_id'] = $v['et_id'];
$topic_data['score'] = $v['score'];
$topic_data['order_num'] = $i;
$temp_list[] = $topic_data;
$i++;
}
if (!empty($temp_list)) {
// 存入备选题目列表
$this->_d_temp->insert_all($temp_list);
}
} elseif (self::TOPIC_RANDOM == $data['ep_type']) {
// 题库题目数验证
$this->check_topic_data($topic_list, $data);
// / 初始化编号
$k = self::ORDER_NUM;
foreach ($topic_list as $v) {
// 根据规则设置分数
$score_rule = unserialize($data['rule']);
$score = $this->get_score_by_type($v['et_type'], $score_rule);
$topic_data['ep_id'] = $ep_id;
$topic_data['et_id'] = $v['et_id'];
$topic_data['eb_id'] = $v['eb_id'];
$topic_data['et_type'] = $v['et_type'];
$topic_data['score'] = $score;
$topic_data['title'] = $v['title'];
$topic_data['title_pic'] = $v['title_pic'];
$topic_data['options'] = $v['options'];
$topic_data['answer'] = $v['answer'];
$topic_data['answer_resolve'] = $v['answer_resolve'];
$topic_data['answer_coverage'] = $v['answer_coverage'];
$topic_data['match_type'] = $v['match_type'];
$topic_data['answer_keyword'] = $v['answer_keyword'];
$topic_data['order_num'] = $k;
$temp_list[] = $topic_data;
$k++;
}
if (!empty($temp_list)) {
// 存入随机题库列表
$this->_d_random->insert_all($temp_list);
}
}
// 如果没有抽到对应的题
if (empty($temp_list)) {
$this->rollback();
E('_ERR_TOPIC_NOT_DATA');
}
// 提交事务
$this->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$this->_set_error($e->getMessage(), $e->getCode());
$this->rollback();
return false;
} catch (\Exception $e) {
\Think\Log::record($e);
$this->_set_error($e->getMessage(), $e->getCode());
// 事务回滚
$this->rollback();
return false;
}
return $ep_id;
}
/**
* 添加试题规则参数验证
*
* @author:daijun
*
* @param array $param
*
* @return array|bool
*/
public function check_rule_add($param = [])
{
$data = [];
// 验证试卷名称不能为空
if (empty($param['ep_name'])) {
E('_EMPTY_PAPER_NAME');
}
// 验证试卷名称长度
if (get_str_len($param['ep_name']) > 64) {
E('_ERR_PAPER_NAME_LENGTH');
}
$data['ep_name'] = $param['ep_name'];
// 验证试卷分类
if (empty($param['ec_id'])) {
E('_EMPTY_CATE_ID');
}
$data['ec_id'] = $param['ec_id'];
// 验证考试类型
if (empty($param['exam_type'])) {
E('_EMPTY_EXAM_TYPE');
}
$data['exam_type'] = $param['exam_type'];
// 验证试卷类型
if (!isset($param['paper_type'])) {
E('_EMPTY_PAPER_TYPE');
}
$data['paper_type'] = $param['paper_type'];
// 验证出题类型
if (empty($param['ep_type'])) {
E('_EMPTY_CHOICE_TYPE');
}
$data['ep_type'] = $param['ep_type'];
// 验证所选题库列表
if (empty($param['bank_list']) || !is_array($param['bank_list'])) {
E('_EMPTY_BANK_LIST');
}
// 如果选择的题库多于50,则抛错
if (count($param['bank_list']) > 50) {
E('_ERR_BANK_LIST_MAX');
}
// 获取题库列表
$eb_ids = array_column($param['bank_list'], 'eb_id');
if (empty($eb_ids)) {
E('_EMPTY_BANK_LIST');
}
sort($eb_ids);
$data['bank_data'] = implode(',', $eb_ids);
// 验证筛选类型
if (!empty($param['search_type'])) {
$data['search_type'] = $param['search_type'];
}
// 如果是规则抽题 和 随机选题
if (self::TOPIC_RULE == $param['ep_type'] || self::TOPIC_RANDOM == $param['ep_type']) {
// 固定规则抽题和随机生成试卷规则调整,验证是否开启高级抽取规则
if (!in_array($param['advanced_choose'], [self::ADVANCED_CHOOSE_OPEN, self::ADVANCED_CHOOSE_CLOSE])) {
// 高级抽取规则类型不正确
E('_ERR_ADVANCED_CHOOSE');
}
$data['advanced_choose'] = $param['advanced_choose'];
// 验证出题规则是否设置
if (empty($param['rule'])) {
E('_EMPTY_BANK_RULE');
}
$rule = $param['rule'];
// 根据规则前端传的计算总题数
$total_topic = intval($rule['single_count']) + intval($rule['multiple_count']) + intval($rule['judgment_count']) + intval($rule['question_count']) + intval($rule['voice_count']);
if ($total_topic == 0) {
// 题目总数为0,则抛错
E('_ERR_TOTAL_TOPIC');
}
// 判断如果题目数不为空,则对应分数也不能为空,否则抛错
if (is_int($rule['single_count']) && !$rule['single_count']) {
// 单选题
E('_ERR_SINGLE_TOPIC_SCORE');
}
if (is_int($rule['multiple_count']) && !$rule['multiple_count']) {
// 多选题
E('_ERR_MULTIPLE_TOPIC_SCORE');
}
if (is_int($rule['judgment_count']) && !$rule['judgment_count']) {
// 判断题
E('_ERR_JUDGMENT_TOPIC_SCORE');
}
if (is_int($rule['question_count']) && !$rule['question_count']) {
// 问答题
E('_ERR_QUESTION_TOPIC_SCORE');
}
if (is_int($rule['voice_count']) && !$rule['voice_count']) {
// 语音题
E('_ERR_VOICE_TOPIC_SCORE');
}
// 序列化抽题规则
$data['rule'] = serialize($rule);
// 开启高级抽取规则的,允许设置题库规则
if (self::ADVANCED_CHOOSE_OPEN == $param['advanced_choose']) {
// 验证所选题库设置的题目数
if (empty($param['bank_topic_data'])) {
// 试卷所选题库题目设置不能为空
E('_EMPTY_BANK_TOPIC_DATA');
}
// 循环去除多余的字段
foreach ($param['bank_topic_data'] as &$v) {
unset($v['$$hashKey']);
}
// 序列化题库题目设置
$data['bank_topic_data'] = serialize($param['bank_topic_data']);
} else {
if (!empty($param['bank_topic_data'])) {
// 没有开启高级抽取规则时 设置题库抽取规则为空
E("_EMPTY_BANK_TOPIC_DATABASE");
}
$data['bank_topic_data'] = '';
}
} else {
if ($data['rule'] && $data['bank_topic_data']) {
E("_EMPTY_BANK_CHOOLSE_TOPIC_DATA");
}
// 自主抽题
$data['rule'] = '';
$data['bank_topic_data'] = '';
$data['advanced_choose'] = self::ADVANCED_CHOOSE_CLOSE;
}
return $data;
}
/**
* 将选择题目数为0的题目分数置0
*
* @param array $rule 题目规则
*
* @return array
*/
public function set_rule($rule = [])
{
if ($rule['single_count'] == 0) {
$rule['single_score'] = 0;
}
if ($rule['multiple_count'] == 0) {
$rule['multiple_score'] = 0;
}
if ($rule['judgment_count'] == 0) {
$rule['judgment_score'] = 0;
}
if ($rule['question_count'] == 0) {
$rule['question_score'] = 0;
}
if ($rule['voice_count'] == 0) {
$rule['voice_score'] = 0;
}
return $rule;
}
/**
* 按照试卷设置的规则抽题
*
* @author:daijun
*
* @param int $ep_id 试卷ID
* @param int $type (0:后台抽题,1:前台抽题)
*
* @return array
*/
public function get_temp_list_by_epid($ep_id = 0, $type = 0)
{
$paper = $this->_d->get($ep_id);
if (empty($paper)) {
E('_EMPTY_PAPER_DATA');
}
// 标签属性数据
$attr_ids = [];
if (!empty($paper['tag_data'])) {
// 反序标签属性
$tag_data = unserialize($paper['tag_data']);
foreach ($tag_data as $v) {
$attr_ids_arr = [];
// 判断是不是数组
if (is_array($v['attr_data'])) {
$attr_ids_arr = array_column($v['attr_data'], 'attr_id');
}
if (!empty($attr_ids_arr) && is_array($attr_ids_arr)) {
$attr_ids = array_merge($attr_ids, $attr_ids_arr);
}
}
}
// 固定抽取和随机抽取有抽取规则(其中包括每种类型题目数量和分数)
$rule_data = [];
if (!empty($paper['rule'])) {
$rule_data = unserialize($paper['rule']);
}
// 开启高级抽取是有每个题库每个类型的题目数和分数
$bank_topic_data = [];
if (!empty($paper['bank_topic_data'])) {
$bank_topic_data = unserialize($paper['bank_topic_data']);
}
// 获取题库的ID集合
$bank_ids = explode(',', $paper['bank_data']);
$temp_list = [];
// 自主选题 || 随机抽题
if ((self::TOPIC_CUSTOMER == $paper['ep_type'] || self::TOPIC_RANDOM == $paper['ep_type']) && $type == 0) {
// 后台手动自主抽取和随机抽取时调用,查询出所有符合条件的题目
$temp_list = $this->choice_topic($bank_ids, $attr_ids, $paper);
} elseif ((self::TOPIC_RULE == $paper['ep_type'] && $type == 0) || (self::TOPIC_RANDOM == $paper['ep_type'] && $type == 1)) {
// 固定抽取和前端随机抽取时调用
$temp_list = $this->rule_topic($bank_ids, $attr_ids, $paper, $bank_topic_data, $rule_data);
}
return $temp_list;
}
/**
* 通过标签属性和题库进行自主自主选题
*
* @author daijun
*
* @param array $bank_ids 题库ID集合
* @param array $attr_ids 属性ID集合
* @param array $paper 试卷信息
*
* @return array|bool
*/
public function choice_topic($bank_ids = [], $attr_ids = [], $paper = [])
{
// 属性ID去除重复
$attr_ids = array_unique($attr_ids);
$topic_list = [];
if (empty($attr_ids)) {
// 没有选择属性,则查询所选题库的所有试题
$topic_list = $this->_d_topic->list_by_conds(['eb_id' => $bank_ids]);
} else {
// 获取满足其中之一条件的所有数据标签属性关系列表数据
$topic_attr_all_list = $this->_d_topic_attr->list_by_conds(['eb_id' => $bank_ids, 'attr_id' => $attr_ids],
null, ['eb_id' => 'ASC']);
// 如果设置了属性:满足任意一个
if (self::SEARCH_ATTR_TYPE_NOT_ALL == $paper['search_type']) {
// 获取题目ID,并去除重复
$topic_ids = array_unique(array_column($topic_attr_all_list, 'et_id'));
} else {
// 满足所有属性的抽题
// 初始化题库下的题目IDS数组
$eb_list = [];
// 根据题目ID重新组合属性,以题目ID为键值,合并标签属性ID
foreach ($topic_attr_all_list as $item) {
$eb_list[$item['et_id']][] = $item['attr_id'];
}
// 组装符合条件的题目id集合
$topic_ids = [];
foreach ($eb_list as $key => $v) {
// 属性ID去除重复
$v = array_unique($v);
if (array_intersect($attr_ids, $v) == $attr_ids) {
$topic_ids[] = $key;
}
}
}
// 没有获取任何符合条件的题目
if (empty($topic_ids)) {
E('_ERR_TOPIC_NOT_IDS_DATA');
}
// 判断题目总数
$topic_total = count($topic_ids);
// 设置题目每次抽取50条件记录
$count = self::TOPIC_MAX_COUNT;
// 题目ID集合分组
$topic_ids_arr = [];
if ($topic_total > $count) {
// 如果题目总数超过50,则需要进行分页查询,否则用in查询会死掉
$countpage = ceil($topic_total / $count); // 计算总页面数
// 对题目ID集合进行分页组装
for ($i = 0; $i < $countpage; $i++) {
$topic_ids_arr[] = array_slice($topic_ids, $i * $count, $count);
}
} else {
sort($topic_ids);
$topic_ids_arr[] = $topic_ids;
}
// 循环查询题目列表
foreach ($topic_ids_arr as $v) {
// 查询题目列表
$topic_arr = $this->_d_topic->list_by_conds(['et_id' => $v]);
// 合并结果数组
$topic_list = array_merge($topic_arr, $topic_list);
}
}
if (empty($topic_list)) {
E('_ERR_TOPIC_NOT_GET_LIST_DATA');
}
return $topic_list;
}
/**
* 按规则抽题
*
* @author daijun
*
* @param array $bank_ids 题库ID集合
* @param array $attr_ids 属性ID集合
* @param array $paper 试卷信息
* @param array $bank_topic_data 题库题目数量设置
* @param array $rule_data 题目得分规则设置
*
* @return array
*/
public function rule_topic($bank_ids = [], $attr_ids = [], $paper = [], $bank_topic_data = [], $rule_data = [])
{
$topic_all_list = [];
if (empty($attr_ids)) {
// 没有选择标签,则查询所选题库的所有试题
$topic_list = $this->_d_topic->list_by_conds(['eb_id' => $bank_ids]);
// 根据题目ID去除重复数据
$topic_list_ids = array_combine_by_key($topic_list, 'et_id');
} else {
$attr_ids = array_unique($attr_ids);
// 满足任意一个标签的抽题
$topic_attr_all_list = $this->_d_topic_attr->list_by_conds(['attr_id' => $attr_ids, 'eb_id' => $bank_ids],
null, ['eb_id' => 'ASC']);
if (self::SEARCH_ATTR_TYPE_NOT_ALL == $paper['search_type']) {
// 获取对应所有题目IDS
$et_ids = array_column($topic_attr_all_list, 'et_id');
// 查询题目详情
$topic_et_id_list = $this->_d_topic->list_by_conds(['et_id' => $et_ids]);
$topic_et_id_list = array_combine_by_key($topic_et_id_list, 'et_id');
// 新增题目类型
foreach ($topic_attr_all_list as $key => &$topic_v) {
$topic_v['et_type'] = $topic_et_id_list[$topic_v['et_id']]['et_type'];
}
// 满足任意一个标签的抽题
$topic_list_ids = $topic_attr_all_list;
} else {
// 满足所有标签的抽题
// 初始化题库下的题目IDS数组
$eb_list = [];
// 根据题目ID重新组合属性,以题目ID为键值,合并标签属性ID
foreach ($topic_attr_all_list as $item) {
$eb_list[$item['et_id']][] = $item['attr_id'];
}
$topic_ids = [];
// 组装符合条件的数据id集合
foreach ($eb_list as $key => $v) {
$v = array_unique($v);
if (array_intersect($attr_ids, $v) == $attr_ids) {
$topic_ids[] = $key;
}
}
if (!empty($topic_ids)) {
// 查询符合条件的试题列表
$topic_list_ids = $this->_d_topic->list_by_conds(['et_id' => $topic_ids]);
} else {
$topic_list_ids = [];
}
}
}
if (self::ADVANCED_CHOOSE_OPEN == $paper['advanced_choose']) {
// 开启高级抽题规则
$bank_topic_attr = [];
foreach ($topic_list_ids as $item_v) {
$bank_topic_attr[$item_v['eb_id']][] = $item_v['et_id'];
}
// 遍历题库ID
foreach ($bank_ids as $k => $v) {
// 检查是否需要在该题库抽题
$is_bank_topic = true; // 默认需要从该题库需要抽题
// 此处查询该题库是否设置了题目
foreach ($bank_topic_data as $val) {
if ($val['eb_id'] == $v) {
// 计算当前题库设置测抽题数量
$t_count = $val['single_count'] + $val['multiple_count'] + $val['judgment_count'] + $val['question_count'] + $val['voice_count'];
// 不需要抽取题目的题库
if (!$t_count) {
$is_bank_topic = false;
}
break;
}
}
// 如果规则设置不从该题库抽题,则continue
if (!$is_bank_topic) {
continue;
}
// 对该题库下的题目ID集合去重
$et_ids = array_unique($bank_topic_attr[$v]);
if (empty($et_ids)) {
E('_ERR_DELETE_RULE_TOPIC');
}
// 查询该题库下的符合条件的题目列表
$topic_list = $this->_d_topic->list_by_conds(['et_id' => $et_ids]);
// 将题目列表按照题目类型分组返回
$topic_data = $this->format_by_et_type($topic_list, $bank_topic_data, $rule_data, $v);
if (!empty($topic_data) && is_array($topic_data)) {
// 合并组装数组
$topic_all_list = array_merge($topic_all_list, $topic_data);
}
}
} else {
// 没有开高级抽题
$topic_all_list = $this->format_simple_by_et_type($topic_list_ids, $rule_data);
}
if (empty($topic_all_list)) {
E('_ERR_TOPIC_NOT_GET_LIST_DATA');
}
// 对抽取的题目进行打乱
$topics = array_combine_by_key($topic_all_list, 'et_id');
$tp_ids = array_column($topic_all_list, 'et_id');
// 打乱ID
shuffle($tp_ids);
// 循环组装试题信息
$result_list = [];
foreach ($tp_ids as $k => $v) {
$data = $topics[$v];
$data['order_num'] = $k + 1;
$result_list[] = $data;
}
return $result_list;
}
/**
* 将题库题目列表按照题目类型分组返回
*
* @author daijun
*
* @param array $topic_list 题目列表
* @param array $bank_topic_data 题库题目数量设置
* @param array $rule_data 抽题规则
* @param Int $eb_id 题库ID
* @param bool $is_type_data true 默认 false 不处理分数
*
* @return array
*/
public function format_by_et_type(
$topic_list = [],
$bank_topic_data = [],
$rule_data = [],
$eb_id = 0,
$is_type_data = true
)
{
$single_attr = []; //单选题
$multiple_attr = []; //多选题
$judgment_attr = []; //判断题
$question_attr = []; //问答题
$voice_attr = []; //语音题
// 所属题库ID
$bank_id = $eb_id;
// 循环题目,按照类型组成新数组
foreach ($topic_list as $_v) {
// 试题类型:单选题
if (self::TOPIC_TYPE_SINGLE == $_v['et_type']) {
$single_attr[] = $_v;
continue;
}
// 试题类型:判断题
if (self::TOPIC_TYPE_JUDGMENT == $_v['et_type']) {
$judgment_attr[] = $_v;
continue;
}
// 试题类型:问答题
if (self::TOPIC_TYPE_QUESTION == $_v['et_type']) {
$question_attr[] = $_v;
continue;
}
// 试题类型:多选题
if (self::TOPIC_TYPE_MULTIPLE == $_v['et_type']) {
$multiple_attr[] = $_v;
continue;
}
// 试题类型:语音题
if (self::TOPIC_TYPE_VOICE == $_v['et_type']) {
$voice_attr[] = $_v;
continue;
}
}
// 取出该题库的出题规则
$bank_topic = [];
foreach ($bank_topic_data as $v) {
if ($v['eb_id'] == $bank_id) {
$bank_topic = $v;
}
}
// *************************抽题开始*************************
$single_list = []; //单选题
$multiple_list = []; //多选题
$judgment_list = []; //判断题
$question_list = []; //问答题
$voice_list = []; //语音题
if (intval($bank_topic['single_count']) > 0) {
// 存在单选题
if (intval($bank_topic['single_count']) > count($single_attr)) {
// 错误日志
Logger::write('============单选题抽题失败日志记录begin===============');
Logger::write('题库ID:' . $eb_id);
Logger::write('抽题规则设置数量:');
Logger::write(var_export($bank_topic['single_count'], true));
Logger::write('实际抽出数量:');
Logger::write(var_export(count($single_attr), true));
Logger::write('============单选题抽题失败日志记录end===============');
E('_ERR_SINGLE_CHOICE_PAPER');
}
$single_list = $this->get_rand_arr($single_attr, intval($bank_topic['single_count']));
// 重新算分
if ($is_type_data == true) {
foreach ($single_list as &$v) {
$v['score'] = $rule_data['single_score'];
}
}
}
if (intval($bank_topic['multiple_count']) > 0) {
// 存在多选题题
if (intval($bank_topic['multiple_count']) > count($multiple_attr)) {
// 错误日志
Logger::write('============多选题抽题失败日志记录begin===============');
Logger::write('题库ID:' . $eb_id);
Logger::write('抽题规则设置数量:');
Logger::write(var_export($bank_topic['multiple_count'], true));
Logger::write('实际抽出数量:');
Logger::write(var_export(count($multiple_attr), true));
Logger::write('============多选题抽题失败日志记录end===============');
E('_ERR_MULTIPLE_CHOICE_PAPER');
}
$multiple_list = $this->get_rand_arr($multiple_attr, intval($bank_topic['multiple_count']));
if ($is_type_data == true) {
foreach ($multiple_list as &$v) {
$v['score'] = $rule_data['multiple_score'];
}
}
}
if (intval($bank_topic['judgment_count']) > 0) {
// 存在判断题
if (intval($bank_topic['judgment_count']) > count($judgment_attr)) {
// 错误日志
Logger::write('============判断题抽题失败日志记录begin===============');
Logger::write('题库ID:' . $eb_id);
Logger::write('抽题规则设置数量:');
Logger::write(var_export($bank_topic['judgment_count'], true));
Logger::write('实际抽出数量:');
Logger::write(var_export(count($judgment_attr), true));
Logger::write('============判断题抽题失败日志记录end===============');
E('_ERR_JUDGMENT_CHOICE_PAPER');
}
$judgment_list = $this->get_rand_arr($judgment_attr, intval($bank_topic['judgment_count']));
if ($is_type_data == true) {
foreach ($judgment_list as &$v) {
$v['score'] = $rule_data['judgment_score'];
}
}
}
if (intval($bank_topic['question_count']) > 0) {
// 存在问答题
if (intval($bank_topic['question_count']) > count($question_attr)) {
// 错误日志
Logger::write('============问答题抽题失败日志记录begin===============');
Logger::write('题库ID:' . $eb_id);
Logger::write('抽题规则设置数量:');
Logger::write(var_export($bank_topic['question_count'], true));
Logger::write('实际抽出数量:');
Logger::write(var_export(count($question_attr), true));
Logger::write('============问答题抽题失败日志记录end===============');
E('_ERR_QUESTION_CHOICE_PAPER');
}
$question_list = $this->get_rand_arr($question_attr, intval($bank_topic['question_count']));
if ($is_type_data == true) {
foreach ($question_list as &$v) {
$v['score'] = $rule_data['question_score'];
}
}
}
if (intval($bank_topic['voice_count']) > 0) {
// 存在语音题
if (intval($bank_topic['voice_count']) > count($voice_attr)) {
// 错误日志
Logger::write('============语音题抽题失败日志记录begin===============');
Logger::write('题库ID:' . $eb_id);
Logger::write('抽题规则设置数量:');
Logger::write(var_export($bank_topic['voice_count'], true));
Logger::write('实际抽出数量:');
Logger::write(var_export(count($voice_attr), true));
Logger::write('============语音题抽题失败日志记录end===============');
E('_ERR_VOICE_CHOICE_PAPER');
}
$voice_list = $this->get_rand_arr($voice_attr, intval($bank_topic['voice_count']));
if ($is_type_data == true) {
foreach ($voice_list as &$v) {
$v['score'] = $rule_data['voice_score'];
}
}
}
return array_merge($single_list, $judgment_list, $multiple_list, $question_list, $voice_list);
}
/**
* 数组随机返回列表
*
* @author daijun
*
* @param array $topic 原始列表
* @param int $num 随机数量
*
* @return array
*/
public function get_rand_arr($topic = [], $num = 0)
{
if (count($topic) == $num) {
return $topic;
} else {
$topic_list = [];
if ($num == 1) {
$index = rand(0, count($topic) - 1);
$topic_list[] = $topic[$index];
} else {
$index_num = array_rand($topic, $num);
foreach ($index_num as $v) {
$topic_list[] = $topic[$v];
}
}
}
return $topic_list;
}
/**
* 将未开启高级抽取题目列表按照题目类型分组返回
*
* @param array $topic_list 题目列表
* @param array $rule_data 抽题规则
* @param bool $is_type_data true 默认 false 不处理分数
*
* @return array
*/
public function format_simple_by_et_type($topic_list = [], $rule_data = [], $is_type_data = true)
{
$single_attr = []; // 单选题
$multiple_attr = []; // 多选题
$judgment_attr = []; // 判断题
$question_attr = []; // 问答题
$voice_attr = []; // 语音题
// 循环题目,按照类型组成新数组
foreach ($topic_list as $_v) {
// 试题类型:单选题
if (self::TOPIC_TYPE_SINGLE == $_v['et_type']) {
$single_attr[] = $_v;
continue;
}
// 试题类型:判断题
if (self::TOPIC_TYPE_JUDGMENT == $_v['et_type']) {
$judgment_attr[] = $_v;
continue;
}
// 试题类型:问答题
if (self::TOPIC_TYPE_QUESTION == $_v['et_type']) {
$question_attr[] = $_v;
continue;
}
// 试题类型:多选题
if (self::TOPIC_TYPE_MULTIPLE == $_v['et_type']) {
$multiple_attr[] = $_v;
continue;
}
// 试题类型:语音题
if (self::TOPIC_TYPE_VOICE == $_v['et_type']) {
$voice_attr[] = $_v;
continue;
}
}
// *************************抽题开始*************************
$single_list = []; //单选题
$multiple_list = []; //多选题
$judgment_list = []; //判断题
$question_list = []; //问答题
$voice_list = []; //语音题
if (intval($rule_data['single_count']) > 0) {
// 存在单选题
if (intval($rule_data['single_count']) > count($single_attr)) {
// 错误日志
Logger::write('============没有题库单选题抽题失败日志记录begin===============');
Logger::write('没有题库抽题规则设置数量:');
Logger::write(var_export($rule_data['single_count'], true));
Logger::write('没有题库实际抽出数量:');
Logger::write(var_export(count($single_attr), true));
Logger::write('============没有题库单选题抽题失败日志记录end===============');
E('_ERR_SINGLE_CHOICE_PAPER');
}
$single_list = $this->get_rand_arr($single_attr, intval($rule_data['single_count']));
if ($is_type_data == true) {
foreach ($single_list as &$v) {
$v['score'] = $rule_data['single_score'];
}
}
}
if (intval($rule_data['multiple_count']) > 0) {
// 存在多选题题
if (intval($rule_data['multiple_count']) > count($multiple_attr)) {
// 错误日志
Logger::write('============没有题库多选题抽题失败日志记录begin===============');
Logger::write('没有题库抽题规则设置数量:');
Logger::write(var_export($rule_data['multiple_count'], true));
Logger::write('没有题库实际抽出数量:');
Logger::write(var_export(count($multiple_attr), true));
Logger::write('============没有题库多选题抽题失败日志记录end===============');
E('_ERR_MULTIPLE_CHOICE_PAPER');
}
$multiple_list = $this->get_rand_arr($multiple_attr, intval($rule_data['multiple_count']));
if ($is_type_data == true) {
foreach ($multiple_list as &$v) {
$v['score'] = $rule_data['multiple_score'];
}
}
}
if (intval($rule_data['judgment_count']) > 0) {
// 存在判断题
if (intval($rule_data['judgment_count']) > count($judgment_attr)) {
// 错误日志
Logger::write('============没有题库判断题抽题失败日志记录begin===============');
Logger::write('没有题库抽题规则设置数量:');
Logger::write(var_export($rule_data['judgment_count'], true));
Logger::write('没有题库实际抽出数量:');
Logger::write(var_export(count($judgment_attr), true));
Logger::write('============没有题库判断题抽题失败日志记录end===============');
E('_ERR_JUDGMENT_CHOICE_PAPER');
}
$judgment_list = $this->get_rand_arr($judgment_attr, intval($rule_data['judgment_count']));
if ($is_type_data == true) {
foreach ($judgment_list as &$v) {
$v['score'] = $rule_data['judgment_score'];
}
}
}
if (intval($rule_data['question_count']) > 0) {
// 存在问答题
if (intval($rule_data['question_count']) > count($question_attr)) {
// 错误日志
Logger::write('============没有题库问答题抽题失败日志记录begin===============');
Logger::write('没有题库抽题规则设置数量:');
Logger::write(var_export($rule_data['question_count'], true));
Logger::write('没有题库实际抽出数量:');
Logger::write(var_export(count($question_attr), true));
Logger::write('============没有题库问答题抽题失败日志记录end===============');
E('_ERR_QUESTION_CHOICE_PAPER');
}
$question_list = $this->get_rand_arr($question_attr, intval($rule_data['question_count']));
if ($is_type_data == true) {
foreach ($question_list as &$v) {
$v['score'] = $rule_data['question_score'];
}
}
}
if (intval($rule_data['voice_count']) > 0) {
// 存在语音题
if (intval($rule_data['voice_count']) > count($voice_attr)) {
// 错误日志
Logger::write('============没有题库语音题抽题失败日志记录begin===============');
Logger::write('没有题库抽题规则设置数量:');
Logger::write(var_export($rule_data['voice_count'], true));
Logger::write('没有题库实际抽出数量:');
Logger::write(var_export(count($voice_attr), true));
Logger::write('============没有题库语音题抽题失败日志记录end===============');
E('_ERR_VOICE_CHOICE_PAPER');
}
$voice_list = $this->get_rand_arr($voice_attr, intval($rule_data['voice_count']));
if ($is_type_data == true) {
foreach ($voice_list as &$v) {
$v['score'] = $rule_data['voice_score'];
}
}
}
return array_merge($single_list, $judgment_list, $multiple_list, $question_list, $voice_list);
}
/**
* 根据U规则验证题目数量
*
* @author:daijun
*
* @param $topic_list array 题目列表
* @param $params array 试卷表单参数
*/
protected function check_topic_data($topic_list = [], $params = [])
{
if ($params['rule']) {
$score_rule = unserialize($params['rule']);
}
if ($params['bank_topic_data']) {
$bank_topic_data = unserialize($params['bank_topic_data']);
}
$single_attr = []; //单选题
$multiple_attr = []; //多选题
$judgment_attr = []; //判断题
$question_attr = []; //问答题
$voice_attr = []; //语音题
// 循环题目,按照类型组成新数组
foreach ($topic_list as $_v) {
// 试题类型:单选题
if (self::TOPIC_TYPE_SINGLE == $_v['et_type']) {
if (self::ADVANCED_CHOOSE_OPEN == $params['advanced_choose']) {
// 开启高级抽题规则 按照题库组合
$single_attr[$_v['eb_id']][] = $_v;
} else {
$single_attr[] = $_v;
}
continue;
}
// 试题类型:判断题
if (self::TOPIC_TYPE_JUDGMENT == $_v['et_type']) {
if (self::ADVANCED_CHOOSE_OPEN == $params['advanced_choose']) {
// 开启高级抽题规则 按照题库组合
$judgment_attr[$_v['eb_id']][] = $_v;
} else {
$judgment_attr[] = $_v;
}
continue;
}
// 试题类型:问答题
if (self::TOPIC_TYPE_QUESTION == $_v['et_type']) {
if (self::ADVANCED_CHOOSE_OPEN == $params['advanced_choose']) {
// 开启高级抽题规则 按照题库组合
$question_attr[$_v['eb_id']][] = $_v;
} else {
$question_attr[] = $_v;
}
continue;
}
// 试题类型:多选题
if (self::TOPIC_TYPE_MULTIPLE == $_v['et_type']) {
if (self::ADVANCED_CHOOSE_OPEN == $params['advanced_choose']) {
// 开启高级抽题规则 按照题库组合
$multiple_attr[$_v['eb_id']][] = $_v;
} else {
$multiple_attr[] = $_v;
}
continue;
}
// 试题类型:语音题
if (self::TOPIC_TYPE_VOICE == $_v['et_type']) {
if (self::ADVANCED_CHOOSE_OPEN == $params['advanced_choose']) {
// 开启高级抽题规则 按照题库组合
$voice_attr[$_v['eb_id']][] = $_v;
} else {
$voice_attr[] = $_v;
}
continue;
}
}
if (self::ADVANCED_CHOOSE_OPEN == $params['advanced_choose']) {
foreach ($bank_topic_data as $val) {
// 单选
if (intval($val['single_count']) > count($single_attr[$val['eb_id']])) {
E('_ERR_SINGLE_CHOICE_PAPER');
}
// 多选
if (intval($val['multiple_count']) > count($multiple_attr[$val['eb_id']])) {
E('_ERR_MULTIPLE_CHOICE_PAPER');
}
// 判断
if (intval($val['judgment_count']) > count($judgment_attr[$val['eb_id']])) {
E('_ERR_JUDGMENT_CHOICE_PAPER');
}
// 问题
if (intval($val['question_count']) > count($question_attr[$val['eb_id']])) {
E('_ERR_QUESTION_CHOICE_PAPER');
}
// 语音
if (intval($val['voice_count']) > count($voice_attr[$val['eb_id']])) {
E('_ERR_VOICE_CHOICE_PAPER');
}
}
} else {
// 单选
if (intval($score_rule['single_count']) > count($single_attr)) {
E('_ERR_SINGLE_CHOICE_PAPER');
}
// 多选
if (intval($score_rule['multiple_count']) > count($multiple_attr)) {
E('_ERR_MULTIPLE_CHOICE_PAPER');
}
// 判断
if (intval($score_rule['judgment_count']) > count($judgment_attr)) {
E('_ERR_JUDGMENT_CHOICE_PAPER');
}
// 问题
if (intval($score_rule['question_count']) > count($question_attr)) {
E('_ERR_QUESTION_CHOICE_PAPER');
}
// 语音
if (intval($score_rule['voice_count']) > count($voice_attr)) {
E('_ERR_VOICE_CHOICE_PAPER');
}
}
}
/**
* 编辑试卷规则
*
* @author:daijun
*
* @param array $param 传入参数
*
* @return bool
*/
public function rule_save($param = [])
{
// 验证ID
if (empty($param['ep_id'])) {
E('_EMPTY_EP_ID');
}
$ep_id = $param['ep_id'];
// 验证其他数据
if (!$data = $this->check_rule_add($param)) {
E('_EMPTY_SAVE_DATA');
}
// 此处组装其他必填的字段信息
$data['tag_data'] = !empty($param['tag_data']) ? serialize($param['tag_data']) : '';
// 此处查询试卷原始数据
$paper = $this->_d->get($ep_id);
// 如果试卷规则和题库抽题规则无变化,则无需重新抽题
if ($paper['rule'] == $data['rule']
&& $paper['bank_topic_data'] == $data['bank_topic_data']
&& $paper['search_type'] == $data['search_type']
&& $data['tag_data'] == $paper['tag_data']
&& $data['advanced_choose'] == $paper['advanced_choose']
&& $data['ep_type'] == $paper['ep_type'] && $data['bank_data'] == $paper['bank_data']
) {
// 不重新抽题
$is_choice = self::NOT_CHOICE;
} else {
// 重新抽题
$is_choice = self::AGAIN_CHOICE;
}
if (!empty($param['rule'])) {
// 随机选题 此处需要计算总分
$rule = $param['rule'];
// 将题目数为0的题目分数置为0
$rule = $this->set_rule($rule);
$data['total_score'] = intval($rule['single_count']) * intval($rule['single_score'])
+ intval($rule['multiple_count']) * intval($rule['multiple_score'])
+ intval($rule['judgment_count']) * intval($rule['judgment_score'])
+ intval($rule['question_count']) * intval($rule['question_score'])
+ intval($rule['voice_count']) * intval($rule['voice_score']);
}
$data['is_old'] = self::NEW_DATA_STATE; // 新数据
try {
// 开始事务
$this->start_trans();
// 更新试卷表
$this->_d->update($ep_id, $data);
// 如果重新抽题
if (self::AGAIN_CHOICE == $is_choice) {
// 抽题存入
$temp_list = [];
// 如果试卷出题规则不是随机,则按配置抽题
$topic_list = $this->get_temp_list_by_epid($ep_id);
if (!$topic_list || !is_array($topic_list) || empty($topic_list)) {
// 若没有抽到题目回滚
$this->rollback();
E('_ERR_TOPIC_NOT_GET_LIST_DATA');
}
if ($data['ep_type'] != self::TOPIC_RANDOM) {
// 删除备选题目列表
$this->_d_temp->delete_by_conds(['ep_id' => $ep_id]);
// 删除已选题目列表
$this->_d_snapshot->delete_by_conds(['ep_id' => $ep_id]);
// 非随机抽取
// 初始化编号
$i = self::ORDER_NUM;
// 循环组装入库数据
foreach ($topic_list as $v) {
$temp_list[] = [
'ep_id' => $ep_id,
'et_id' => $v['et_id'],
'score' => $v['score'],
'order_num' => $i
];
$i++;
}
if (!empty($temp_list)) {
// 存入备选题目列表
$this->_d_temp->insert_all($temp_list);
}
} elseif (self::TOPIC_RANDOM == $data['ep_type']) {
//按照题库设置进行匹配
$this->check_topic_data($topic_list, $data);
// 删除已选题目列表
$this->_d_random->delete_by_conds(['ep_id' => $ep_id]);
// 取出符合规则的所有试题
$rule_data = unserialize($data['rule']);
// 初始化编号
$k = self::ORDER_NUM;
foreach ($topic_list as $v) {
// 根据规则设置分数
$score = $this->get_score_by_type($v['et_type'], $rule_data);
$topic_data = [];
$topic_data['ep_id'] = $ep_id;
$topic_data['eb_id'] = $v['eb_id'];
$topic_data['et_type'] = $v['et_type'];
$topic_data['et_id'] = $v['et_id'];
$topic_data['title'] = $v['title'];
$topic_data['title_pic'] = $v['title_pic'];
$topic_data['options'] = $v['options'];
$topic_data['score'] = $score;
$topic_data['answer'] = $v['answer'];
$topic_data['answer_resolve'] = $v['answer_resolve'];
$topic_data['answer_coverage'] = $v['answer_coverage'];
$topic_data['match_type'] = $v['match_type'];
$topic_data['answer_keyword'] = $v['answer_keyword'];
$topic_data['order_num'] = $k;
$temp_list[] = $topic_data;
$k++;
}
if (!empty($temp_list)) {
$this->_d_random->insert_all($temp_list);
}
}
}
// 如果没有抽到对应的题
if (empty($temp_list) && self::AGAIN_CHOICE == $is_choice) {
$this->rollback();
E('_ERR_TOPIC_NOT_DATA');
}
// 提交事务
$this->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$this->_set_error($e->getMessage(), $e->getCode());
$this->rollback();
return false;
} catch
(\Exception $e) {
\Think\Log::record($e);
$this->_set_error($e->getMessage(), $e->getCode());
// 事务回滚
$this->rollback();
return false;
}
return $ep_id;
}
/**
* 编辑试卷基本信息(基本试卷)
*
* @author:daijun
*
* @param array $param 传入参数
*
* @return bool
*/
public function base_save($param = [])
{
$ep_id = $param['ep_id'];
// 获取试卷信息
$paper = $this->_d->get($ep_id);
if ($paper['exam_type'] > 1) {
// 如果是任务,线下培训,则走新的验证和更新
$this->base_save_new($param, $paper);
return true;
}
// 被学习路径关联的课程不可删除
$mapUsedIds = StudyMap::checkAppDataUsed((array)$ep_id);
if (!empty($mapUsedIds)) {
E('_ERR_MAP_USED_CANNOT_DELETE');
}
// 验证属性
if (!$data = $this->check_base_save($param)) {
E('_EMPTY_SAVE_DATA');
}
$right = $data['right'];
unset($data['right']);
$uids_old = [];
// 试卷题目列表初始化
$topic_list = [];
// 此处获取所有应参与人员的ID集合
$right_serv = new RightService();
$right_res = $right_serv->format_db_data($right);
// 获取数据更新后的权限用户列表
$right_res['is_all'] = $data['is_all'];
$uids_now = $right_serv->list_uids_by_right($right_res);
// 参与人数
$data['unjoin_count'] = count($uids_now);
// 如果是发布动作
if ($data['exam_status'] == self::PAPER_PUBLISH) {
// 试卷题目查询条件
$conditions_topic['ep_id'] = $ep_id;
// 查询组装总题目数量
if ($paper['ep_type'] != self::TOPIC_RANDOM) {
// 如果不是随机出题,此处查询该试卷的试题总数
$data['topic_count'] = $this->_d_snapshot->count_by_conds($conditions_topic);
// 获取试卷题目列表
$topic_list = $this->_d_snapshot->list_by_conds($conditions_topic);
} else {
// 如果是随机出题
$rule = unserialize($paper['rule']);
$data['topic_count'] = intval($rule['single_count'])
+ intval($rule['multiple_count'])
+ intval($rule['judgment_count'])
+ intval($rule['question_count'])
+ intval($rule['voice_count']);
// 获取试卷题目列表
$topic_list = $this->_d_random->list_by_conds($conditions_topic);
}
// 如果是已发布的试卷进行编辑再次发布,此处需查询之前的权限数据,推送消息会用到
if ($paper['exam_status'] == self::PAPER_PUBLISH) {
// 权限查询条件
$conds = [
'epc_id' => $ep_id,
'er_type' => AnswerService::RIGHT_PAPER
];
// 获取未参与考试人员列表及人数
$answer_serv = new AnswerService();
$unjoin_data = $answer_serv->get_unjoin_data($conds, $ep_id, $paper['is_all']);
// 获取数据更新前的权限用户列表
$uids_old = $unjoin_data['unjoin_list'];
}
// 发布时间
$data['publish_time'] = MILLI_TIME;
}
// 初始化阅卷人权限
$right_marking = [];
if (isset($param['marking_list']) && !empty($param['marking_list'])) {
// 重组阅卷人列表
foreach ($param['marking_list'] as $v) {
// 如果阅卷人存在
if ($v['memID']) {
$right_marking[] = [
'epc_id' => $ep_id,
'er_type' => self::RIGHT_MARKING,
'uid' => $v['memID'],
'cd_id' => '',
'tag_id' => '',
'job_id' => '',
'role_id' => ''
];
}
}
}
// 查询分类详情
$cate_data = $this->_d_cate->get($paper['ec_id']);
// 将分类的状态赋值给试卷状态
$data['cate_status'] = $cate_data['ec_status'];
// 阅卷类型
$data['marking_type'] = $param['marking_type'];
// 获取最后更新时间
$data['last_time'] = MILLI_TIME;
// 如果阅卷人不为空 并且是发布状态
if (!empty($right_marking) && self::PAPER_PUBLISH == $data['exam_status']) {
// 阅卷人发送消息
$this->marking_send($param);
}
// 获取答卷扩展信息
$extend_list = $this->_d_answer_detail_extend->list_by_conds(['ep_id' => $ep_id]);
$extend_list = array_combine_by_key($extend_list, 'et_id');
try {
// 开始事务
$this->start_trans();
// 更新试卷表
$this->_d->update($ep_id, $data);
// 删除之前的权限
$this->_d_right->delete_by_conds(['epc_id' => $ep_id, 'er_type' => self::RIGHT_PAPER]);
// 删除之前的阅卷人权限
$this->_d_right->delete_by_conds(['epc_id' => $ep_id, 'er_type' => self::RIGHT_MARKING]);
// 如果有权限数据
if (!empty($right)) {
// 新增权限数据
$this->_d_right->insert_all($right);
}
// 如果有阅卷人
if (!empty($right_marking)) {
// 新增阅卷
$this->_d_right->insert_all($right_marking);
}
// 分表oa_exam_answer_detail_extend待增数据初始化
$detail_extend_data = [];
if (!empty($topic_list)) {
foreach ($topic_list as $topic) {
$extend_info = $extend_list[$topic['et_id']];
if (empty($extend_info)) {
// 组装题目详情数据
$et_detail = [
'et_type' => $topic['et_type'], // 题目类型(1:单选题 2:判断题 3:问答题 4:多选题,5:语音题)
'title' => $topic['title'], // 题目名称
'title_pic' => $topic['title_pic'], // 题目图片(逗号分割
'answer' => $topic['answer'], // 正确答案(多选用逗号分隔)
'answer_resolve' => $topic['answer_resolve'], // 答案解析
'answer_coverage' => $topic['answer_coverage'], // 答案覆盖率(问答题)
'match_type' => $topic['match_type'], // 是否匹配关键字(0:否 1:是)
'answer_keyword' => unserialize($topic['answer_keyword']) // 答案关键字(序列化:关键字,百分比)
];
// 组装分表数据
$detail_extend_data[] = [
'ep_id' => $ep_id, // 试卷id
'et_id' => $topic['et_id'], // 题目id
'et_option' => $topic['options'], // 题目选项序列化
'et_detail' => serialize($et_detail) // 题目详情序列化
];
}
}
}
if (!empty($detail_extend_data)) {
// 待插入数组去重
$detail_extend_data = $this->remove_duplicate($detail_extend_data);
// 同步往分表新增数据
$this->_d_answer_detail_extend->insert_all($detail_extend_data);
}
// 提交事务
$this->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$this->_set_error($e->getMessage(), $e->getCode());
$this->rollback();
E('_ERR_DATA_SAVE_FAIL');
} catch (\Exception $e) {
\Think\Log::record($e);
$this->_set_error($e->getMessage(), $e->getCode());
// 事务回滚
$this->rollback();
E('_ERR_DATA_SAVE_FAIL');
}
// 附件处理开始
$attach_serv = new AttachOperation();
if (!empty($data['cover_id'])) {
// 将图片设置为已使用
$attach_serv->insert_attach(
APP_DIR,
'paper',
$ep_id,
['attach_ids' => [$data['cover_id']]]
);
}
// 1.推送消息 2.设置定时任务
if (self::PAPER_PUBLISH == $data['exam_status']) {
$ep_id = $param['ep_id'];
// 是否推荐到首页feed流
if ($data['is_recommend']) {
// 判断feed流权限发送
if (self::AUTH_ALL == $data['is_all']) {
$feed_right = [];
} else {
$feed_right = $this->format_feed_data($right);
}
$url = rpcUrl('/Public/Rpc/Recommender/ArticleUpdate');
$data_send = [
'app' => APP_DIR,
'dataCategoryId' => '',
'dataId' => $ep_id,
'title' => $paper['ep_name'],
'summary' => $data['intro'],
'dataType' => $paper['paper_type'] == self::SIMULATION_PAPER_TYPE ? '模拟' : '',
'endTime' => $param['end_time'],
'attachId' => $data['cover_id'],
'pic' => $this->format_cover($data['cover_id'], false),
'url' => 'Exam/Frontend/Index/Msg?ep_id=' . $ep_id,
'right' => $feed_right
];
\Com\Rpc::phprpc($url)->invoke('Index', $data_send);
} else {
// 删除首页feed流
$url = rpcUrl('/Public/Rpc/Recommender/ArticleDelete');
$data_send = [
'app' => APP_DIR,
'dataCategoryId' => '',
'dataId' => $ep_id
];
\Com\Rpc::phprpc($url)->invoke('Index', $data_send);
}
// 如果发送消息通知
if ($data['is_pushmsg']) {
$params['name'] = $paper['ep_name'];
$params['description'] = $data['intro'];
$params['img_id'] = $data['cover_id'];
$params['is_cover_open'] = $data['is_cover_open'];
$params['id'] = $ep_id;
$params['begin_time'] = $data['begin_time'];
$params['end_time'] = $data['end_time'];
if ($paper['exam_status'] == self::PAPER_PUBLISH) {
// 如果之前就是已发布的状态,此处取差集
$uids = array_diff($uids_now, $uids_old);
} else {
// 从草稿发布
$uids = $uids_now;
}
// 如果存在需要发送消息的人员
if (!empty($uids)) {
sort($uids);
// 用户UIDS集合赋值
$params['uids'] = $uids;
// 发送及时消息
$this->new_send_msg($params);
}
}
// 定时任务
$this->cron_add($ep_id);
}
return true;
}
/**
* 编辑试卷基本信息(任务类,线下培训)
*
* @author:daijun
*
* @param array $param 传入参数
* @param array $paper 试卷信息
*
* @return bool
*/
public function base_save_new($param = [], $paper = [])
{
$used_ids = [];
if (!empty($used_ids)) {
E('_ERR_EXAM_USED_EDIT');
}
// 验证属性
if (!$data = $this->check_base_save_new($param)) {
E('_EMPTY_SAVE_DATA');
}
// 如果是发布动作
if ($data['exam_status'] == self::PAPER_PUBLISH) {
// 试卷题目查询条件
$conditions_topic['ep_id'] = $paper['ep_id'];
// 查询组装总题目数量
if ($paper['ep_type'] != self::TOPIC_RANDOM) {
// 如果不是随机出题,此处查询该试卷的试题总数
$data['topic_count'] = $this->_d_snapshot->count_by_conds($conditions_topic);
// 获取试卷题目列表
$topic_list = $this->_d_snapshot->list_by_conds($conditions_topic);
} else {
// 如果是随机出题
$rule = unserialize($paper['rule']);
$data['topic_count'] = intval($rule['single_count'])
+ intval($rule['multiple_count'])
+ intval($rule['judgment_count'])
+ intval($rule['question_count'])
+ intval($rule['voice_count']);
// 获取试卷题目列表
$topic_list = $this->_d_random->list_by_conds($conditions_topic);
}
// 发布时间
$data['publish_time'] = MILLI_TIME;
}
// 初始化阅卷人权限
$right_marking = [];
// 重组阅卷人列表
foreach ($param['marking_list'] as $v) {
// 如果阅卷人存在
if ($v['memID']) {
$right_marking[] = [
'epc_id' => $param['ep_id'],
'er_type' => self::RIGHT_MARKING,
'uid' => $v['memID'],
'cd_id' => '',
'tag_id' => '',
'job_id' => '',
'role_id' => ''
];
}
}
// 查询分类详情
$cate_data = $this->_d_cate->get($paper['ec_id']);
// 将分类的状态赋值给试卷状态
$data['cate_status'] = $cate_data['ec_status'];
// 阅卷类型
$data['marking_type'] = $param['marking_type'];
// 获取最后更新时间
$data['last_time'] = MILLI_TIME;
$data['begin_time'] = 0;
$data['end_time'] = 0;
$data['integral_action_type'] = 2; // 不启用积分策略
// 获取答卷扩展信息
$extend_list = $this->_d_answer_detail_extend->list_by_conds(['ep_id' => $paper['ep_id']]);
$extend_list = array_combine_by_key($extend_list, 'et_id');
// 是否启用封面图片
$data['is_cover_open'] = $param['is_cover_open'];
// 如果上传图片
if (!empty($param['cover_id'])) {
$data['cover_id'] = $param['cover_id'];
}
// 阅卷人发送消息
// $this->marking_send($param);
try {
// 开始事务
$this->start_trans();
// 更新试卷表
$this->_d->update($param['ep_id'], $data);
// 删除之前的阅卷人权限
$this->_d_right->delete_by_conds(['epc_id' => $param['ep_id'], 'er_type' => self::RIGHT_MARKING]);
// 如果有阅卷人
if (!empty($right_marking)) {
// 新增阅卷
$this->_d_right->insert_all($right_marking);
}
// 分表oa_exam_answer_detail_extend待增数据初始化
$detail_extend_data = [];
if (!empty($topic_list)) {
foreach ($topic_list as $topic) {
$extend_info = $extend_list[$topic['et_id']];
if (empty($extend_info)) {
// 组装题目详情数据
$et_detail = [
'et_type' => $topic['et_type'], // 题目类型(1:单选题 2:判断题 3:问答题 4:多选题,5:语音题)
'title' => $topic['title'], // 题目名称
'title_pic' => $topic['title_pic'], // 题目图片(逗号分割
'answer' => $topic['answer'], // 正确答案(多选用逗号分隔)
'answer_resolve' => $topic['answer_resolve'], // 答案解析
'answer_coverage' => $topic['answer_coverage'], // 答案覆盖率(问答题)
'match_type' => $topic['match_type'], // 是否匹配关键字(0:否 1:是)
'answer_keyword' => unserialize($topic['answer_keyword']) // 答案关键字(序列化:关键字,百分比)
];
// 组装分表数据
$detail_extend_data[] = [
'ep_id' => $paper['ep_id'], // 试卷id
'et_id' => $topic['et_id'], // 题目id
'et_option' => $topic['options'], // 题目选项序列化
'et_detail' => serialize($et_detail) // 题目详情序列化
];
}
}
}
if (!empty($detail_extend_data)) {
// 待插入数组去重
$detail_extend_data = $this->remove_duplicate($detail_extend_data);
// 同步往分表新增数据
$this->_d_answer_detail_extend->insert_all($detail_extend_data);
}
// 提交事务
$this->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$this->_set_error($e->getMessage(), $e->getCode());
$this->rollback();
E('_ERR_DATA_SAVE_FAIL');
} catch (\Exception $e) {
\Think\Log::record($e);
$this->_set_error($e->getMessage(), $e->getCode());
// 事务回滚
$this->rollback();
E('_ERR_DATA_SAVE_FAIL');
}
// 1.定时任务
if (self::PAPER_PUBLISH == $data['exam_status']) {
$ep_id = $param['ep_id'];
// 定时任务
$this->cron_add_new($ep_id);
}
// 附件处理开始
$attach_aerv = new AttachOperation();
if (!empty($data['cover_id'])) {
// 将图片设置为已使用
$attach_aerv->make_active([$data['cover_id']]);
}
return true;
}
/**
* 添加试卷基本信息参数验证
*
* @author:daijun
*
* @param array $param
*
* @return array|bool
*/
public function check_base_save_new($param = [])
{
$data = [];
// 验证试卷ID
if (empty($param['ep_id'])) {
E('_EMPTY_EP_ID');
}
// 验证考试时长
if (empty($param['paper_time'])) {
E('_EMPTY_PAPER_TIME');
}
// 验证及格分数
if (empty($param['pass_score'])) {
E('_EMPTY_PASS_SCORE');
}
// 验证考试说明
if (empty($param['intro'])) {
E('_EMPTY_INTRO');
}
// 验证试卷状态
if (empty($param['exam_status'])) {
E('_EMPTY_EXAM_STATUS');
}
// 如果不在指定类型中
if (!in_array($param['marking_type'], [self::MANUAL_MARKING_TYPE, self::AUTO_MARKING_TYPE])) {
E('_ERR_MARKING_TYPE');
}
// 赋值
if (!empty($param['cover_id'])) {
$data['cover_id'] = $param['cover_id'];
}
$data['is_all'] = self::AUTH_ALL;
$data['paper_time'] = $param['paper_time'];
// 显示答案
$data['answer_resolve'] = 1;
$data['pass_score'] = intval($param['pass_score']);
$data['intro'] = $param['intro'];
// 获取是否有权限选择阅卷类型
list($show_marking, $marking_list) = $this->get_marking($param['ep_id']);
// 如果没有权限选择阅卷类型
if (!$show_marking) {
// 如果选择手动阅卷
if (self::MANUAL_MARKING_TYPE == $param['marking_type']) {
E('_ERR_NOT_MARKING_TYPE');
}
}
// 如果是手动阅卷
if (self::MANUAL_MARKING_TYPE == $param['marking_type']) {
// 如果阅读人员列表不是数组
if (!is_array($param['marking_list'])) {
E('_ERR_MARKING_LIST');
}
// 阅卷人IDS
$mem_uids = array_unique(array_column($param['marking_list'], 'memID'));
// 如果阅卷人不存在
if (empty($mem_uids)) {
E('_ERR_MARKING_UID');
}
}
$data['exam_status'] = intval($param['exam_status']);
return $data;
}
/**
* 发布试卷定时任务添加(添加任务,线下培训)
*
* @param array
* ep_id => 试卷id
*
* @return bool
*/
public function cron_add_new($ep_id)
{
// 实例化定时任务类
$cron_serv = new Cron(Service::instance());
// 获取试卷基本信息
$data = $this->_d->get($ep_id);
// 需要定时通知的试卷id
$res_params = ['ep_id' => $ep_id];
// json参数
$json_params = json_encode($res_params);
// 初始化定时任务入库id
$corn_create_exam = $data['corn_create_exam'] ? $data['corn_create_exam'] : '';
// 如果抽题我随机抽题
if ($data['ep_type'] == self::TOPIC_RANDOM && empty($data['corn_create_exam'])) {
// 生成考卷定时任务
$create_exam = [
'crRemark' => 'corn_create_exam',
'crType' => 2,
'crParams' => $json_params,
'crMethod' => 'POST',
'crReqUrl' => oaUrl('Frontend/Callback/CreateExam'), // 回调地址
'crTimes' => 0,
'crCron' => '0 0/5 * * * ?',
'crMonitorExecution' => 0,
'crDescription' => '自动创建考卷'
];
$res_create_exam = $cron_serv->add($create_exam); // crId
$corn_create_exam = $res_create_exam['crId'];
}
$this->_d->update($ep_id, ['corn_create_exam' => $corn_create_exam]);
return true;
}
/**
* 添加试卷基本信息参数验证
*
* @author:daijun
*
* @param array $param
*
* @return array|bool
*/
public function check_base_save($param = [])
{
$data = [];
// 验证试卷ID
if (empty($param['ep_id'])) {
E('_EMPTY_EP_ID');
}
// 验证权限设置
if (!in_array($param['is_all'], [self::AUTH_ALL, self::NO_AUTH_ALL])) {
// 权限类型必须为0和1
E('_ERR_RIGHT_TYPE');
}
// 验证开始时间不能为空
if (empty($param['begin_time'])) {
E('_EMPTY_BEGIN_TIME');
}
// 验证开始时间不能早于当前时间
if ($param['begin_time'] <= MILLI_TIME) {
E('_ERR_BEGIN_TIME');
}
// 验证结束时间不能为空
if (empty($param['end_time'])) {
E('_EMPTY_END_TIME');
}
// 验证结束时间不能早于开始时间
if ($param['end_time'] <= $param['begin_time']) {
E('_ERR_END_TIME');
}
// 验证考试时长
if (($param['begin_time'] + to_milli_time($param['paper_time'] * 60)) > $param['end_time']) {
E('_ERR_PAPER_TIME');
}
// 验证考试时长
if (empty($param['paper_time'])) {
E('_EMPTY_PAPER_TIME');
}
// 验证发送提醒
if (!isset($param['is_pushmsg'])) {
E('_EMPTY_PUSH_MSG');
}
// 验证设置考试通知
if (!isset($param['is_notify'])) {
E('_EMPTY_IS_NOTIFY');
}
// 是否开启封面图片上传验证
if (!in_array($param['is_cover_open'], [self::IS_COVER_PIC_OPEN, self::IS_COVER_PIC_CLOSE])) {
E('_ERR_PIC_TYPE');
}
// 如果开启了考试通知,则时间设置不能为空
if ($param['is_notify']) {
if (empty($param['notify_begin'])) {
E('_ERR_BEGIN_NOTIFY_TIME');
}
if (empty($param['notify_end'])) {
E('_ERR_END_NOTIFY_TIME');
}
}
// 开始前通知时间
if (!empty($param['notify_begin'])) {
// 考试提醒时间验证
if (($param['begin_time'] - intval(to_milli_time($param['notify_begin']) * 60)) <= MILLI_TIME) {
E('_ERR_BEGIN_NOTIFY_TIME');
}
}
// 结束前通知时间
if (!empty($param['notify_end'])) {
// 考试提醒时间验证
if (($param['end_time'] - intval(to_milli_time($param['notify_end']) * 60)) <= MILLI_TIME) {
E('_ERR_END_NOTIFY_TIME');
}
}
// 验证开启推荐
if (!isset($param['is_recommend'])) {
E('_EMPTY_IS_RECOMMEND');
}
// 验证及格分数
if (empty($param['pass_score'])) {
E('_EMPTY_PASS_SCORE');
}
// 验证考试说明
if (empty($param['intro'])) {
E('_EMPTY_INTRO');
}
// 验证试卷状态
if (empty($param['exam_status'])) {
E('_EMPTY_EXAM_STATUS');
}
// 如果不在指定类型中
if (!in_array($param['marking_type'], [self::MANUAL_MARKING_TYPE, self::AUTO_MARKING_TYPE])) {
E('_ERR_MARKING_TYPE');
}
// 验证可见性设置(交卷后)
$data['is_see_after_submit'] = intval($param['is_see_after_submit']);
// 验证可见性设置(结束后)
$data['is_see_after_over'] = intval($param['is_see_after_over']);
if (self::OPEN_MAKEUP == $param['is_open_makeup']) {
// 如果开启了补考,则补考次数和补考时间不能为空
if (empty($param['makeup_num']) || empty($param['makeup_start_time']) || empty($param['makeup_end_time'])) {
E('_EMPTY_MAKEUP_DATA');
}
if ($param['makeup_start_time'] <= $param['begin_time']) {
// 如果补考开始时间大于等于考试开始时间,则抛错
E('_ERR_MAKEUP_START_TIME');
}
if ($param['makeup_start_time'] >= $param['makeup_end_time']) {
// 如果补考开始时间大于等于补考结束时间,则抛错
E('_ERR_MAKEUP_END_TIME');
}
if ($param['makeup_start_time'] + to_milli_time($param['paper_time'] * 60) > $param['makeup_end_time']) {
// 如果开始补考时间加上考试时长大于补考结束时间,则抛错
E('_ERR_MAKEUP_END_TIME_FOR_PAPER_TIME');
}
}
// 是否开启补考
$data['is_open_makeup'] = empty($param['is_open_makeup']) ? self::CLOSE_MAKEUP : $param['is_open_makeup'];
// 补考开始时间
$data['makeup_start_time'] = empty($param['makeup_start_time']) ? 0 : $param['makeup_start_time'];
// 补考结束时间
$data['makeup_end_time'] = empty($param['makeup_end_time']) ? 0 : $param['makeup_end_time'];
// 补考次数
$data['makeup_num'] = intval($param['makeup_num']);
// 初始化封面ID
$data['cover_id'] = '';
// 如果显示封面
if (self::IS_COVER_PIC_OPEN == $param['is_cover_open']) {
$data['cover_id'] = $param['cover_id'];
}
$data['is_cover_open'] = $param['is_cover_open'];
$data['is_all'] = $param['is_all'];
$data['begin_time'] = $param['begin_time'];
$data['end_time'] = $param['end_time'];
$data['paper_time'] = $param['paper_time'];
$data['is_pushmsg'] = intval($param['is_pushmsg']);
$data['is_notify'] = intval($param['is_notify']);
$data['notify_begin'] = intval($param['notify_begin']);
$data['notify_end'] = intval($param['notify_end']);
$data['is_recommend'] = intval($param['is_recommend']);
// 显示答案
$data['answer_resolve'] = 1;
$data['pass_score'] = intval($param['pass_score']);
$data['intro'] = $param['intro'];
$data['is_upset_topic'] = empty($param['is_upset_topic']) ? self::UPSET_TOPIC_NO : $param['is_upset_topic']; // 是否打乱题目
$data['is_upset_option'] = empty($param['is_upset_option']) ? self::UPSET_OPTION_NO : $param['is_upset_option'];// 是否打乱选项
// 获取是否有权限选择阅卷类型
list($show_marking, $marking_list) = $this->get_marking($param['ep_id']);
// 如果没有权限选择阅卷类型 && 选择手动阅卷
if (!$show_marking && self::MANUAL_MARKING_TYPE == $param['marking_type']) {
E('_ERR_NOT_MARKING_TYPE');
}
// 如果是手动阅卷
if (self::MANUAL_MARKING_TYPE == $param['marking_type']) {
// 如果阅读人员列表不是数组
if (!is_array($param['marking_list'])) {
E('_ERR_MARKING_LIST');
}
// 阅卷人IDS
$mem_uids = array_unique(array_column($param['marking_list'], 'memID'));
// 如果阅卷人不存在
if (empty($mem_uids)) {
E('_ERR_MARKING_UID');
}
}
// 是否开启匿名阅卷
$data['is_open_anonymous_marking'] = empty($param['is_open_anonymous_marking']) ? self::CLOSE_ANONYMOUS_MARKING : $param['is_open_anonymous_marking'];
$data['exam_status'] = intval($param['exam_status']);
// 如果不是全公司,组装right数据
$right = [];
if ($data['is_all'] == self::AUTH_NOT_ALL) {
// 用户集合
if (!empty($param['right']['user_list'])) {
$users = array_column($param['right']['user_list'], 'memID');
$users_list = array_combine_by_key($param['right']['user_list'], 'memID');
foreach ($users as $v) {
$right[] = [
'epc_id' => $param['ep_id'],
'er_type' => self::RIGHT_PAPER,
'source_type' => empty($users_list[$v]['source_type']) ? 1 : $users_list[$v]['source_type'], // 权限来源
'uid' => $v,
'cd_id' => '',
'tag_id' => '',
'job_id' => '',
'role_id' => ''
];
}
}
// 部门集合
if (!empty($param['right']['dp_list'])) {
$dps = array_column($param['right']['dp_list'], 'dpID');
foreach ($dps as $v) {
$right[] = [
'epc_id' => $param['ep_id'],
'er_type' => self::RIGHT_PAPER,
'source_type' => 1, // 权限来源为选择
'uid' => '',
'cd_id' => $v,
'tag_id' => '',
'job_id' => '',
'role_id' => ''
];
}
}
// 岗位集合
if (!empty($param['right']['job_list'])) {
$jobs = array_column($param['right']['job_list'], 'jobID');
foreach ($jobs as $v) {
$right[] = [
'epc_id' => $param['ep_id'],
'er_type' => self::RIGHT_PAPER,
'source_type' => 1, // 权限来源为选择
'uid' => '',
'cd_id' => '',
'tag_id' => '',
'job_id' => $v,
'role_id' => ''
];
}
}
// 角色集合
if (!empty($param['right']['role_list'])) {
$roles = array_column($param['right']['role_list'], 'roleID');
foreach ($roles as $v) {
$right[] = [
'epc_id' => $param['ep_id'],
'er_type' => self::RIGHT_PAPER,
'source_type' => 1, // 权限来源为选择
'uid' => '',
'cd_id' => '',
'tag_id' => '',
'job_id' => '',
'role_id' => $v
];
}
}
// 标签集合
if (!empty($param['right']['tag_list'])) {
$tags = array_column($param['right']['tag_list'], 'tagID');
foreach ($tags as $v) {
$right[] = [
'epc_id' => $param['ep_id'],
'er_type' => self::RIGHT_PAPER,
'source_type' => 1, // 权限来源为选择
'uid' => '',
'cd_id' => '',
'tag_id' => $v,
'job_id' => '',
'role_id' => ''
];
}
}
// 权限不能都为空
if (empty($right)) {
E('_EMPTY_RIGHT');
}
}
$data['right'] = $right;
// 如果是否开启策略不符合规范
if (!in_array($param['is_open_integral'], [self::CLOSE_INTEGRAL, self::OPEN_INTEGRAL])) {
E('ERR_IS_OPEN_INTEGRAL');
}
// 默认积分策略ID为空
$data['integral_strategyid'] = '';
// 默认学分策略ID为空
$data['credit_strategyid'] = '';
// 初始化积分策略类型为不使用策略
$data['integral_action_type'] = self::INTEGRAL_ACTION_TYPE_NO;
// 初始化学分策略类型为不使用策略
$data['credit_action_type'] = self::CREDIT_ACTION_TYPE_FALSE;
// 如果开启积分策略
if (self::OPEN_INTEGRAL == $param['is_open_integral']) {
// 如果积分策略为空
if (empty($param['integral_action_type'])) {
E('_EMPTY_INTEGRAL_ACTION');
}
// 如果策略类型不是自定义或者默认
if (!in_array($param['integral_action_type'],
[self::INTEGRAL_ACTION_TYPE_DEFAULT, self::INTEGRAL_ACTION_TYPE_MY])) {
E('ERR_OPEN_INTEGRAL_ACTION_TYPE');
}
$data['integral_action_type'] = $param['integral_action_type'];
// 如果开启的是自定义的策略,则策略ID不能为空
if (self::INTEGRAL_ACTION_TYPE_MY == $param['integral_action_type'] && empty($param['integral_strategyid'])) {
E('_EMPTY_INTEGRAL_ACTIONID');
}
$data['integral_strategyid'] = strval($param['integral_strategyid']);
}
// 如果开启学分策略
if (self::OPEN_INTEGRAL == $param['is_open_credit']) {
// 如果学分策略为空
if (empty($param['credit_action_type'])) {
E('_EMPTY_CREDIT_ACTION');
}
// 如果策略类型不是默认或者自定义
if (!in_array($param['credit_action_type'],
[self::CREDIT_ACTION_TYPE_DEFAULT, self::CREDIT_ACTION_TYPE_CUSTOMIZE])) {
E('ERR_OPEN_CREDIT_ACTION_TYPE');
}
$data['credit_action_type'] = $param['credit_action_type'];
// 如果开启的是自定义的策略,则策略ID不能为空
if (self::CREDIT_ACTION_TYPE_CUSTOMIZE == $param['credit_action_type'] && empty($param['credit_strategyid'])) {
E('_EMPTY_CREDIT_ACTIONID');
}
$data['credit_strategyid'] = strval($param['credit_strategyid']);
}
return $data;
}
/**
*【后台】给阅卷人发送消息
*
* @author 何岳龙
*
* @param array $param POST 数组
*
* @return bool
*/
public function marking_send($param = [])
{
// 初始化原始
$old_marking_user = [];
// 如果是手动阅卷
if (self::MANUAL_MARKING_TYPE == $param['marking_type']) {
// 获取最新阅读人UIDS集合
$new_marking_user = array_unique(array_filter(array_column($param['marking_list'], 'memID')));
// 获取原始阅卷人权限
$right_list = $this->_d_right->list_by_conds([
'epc_id' => $param['ep_id'],
'er_type' => self::RIGHT_MARKING
]);
// 如果有原始数据
if (!empty($right_list)) {
// 获取原始阅卷人用户UIDS集合
$old_marking_user = array_unique(array_filter(array_column($right_list, 'uid')));
}
// 取查集获取发消息用户
$msg_uids = array_diff($new_marking_user, $old_marking_user);
// 获取试卷信息
$paper = $this->_d->get($param['ep_id']);
// 如果有待发消息用户
if (!empty($msg_uids)) {
$msg = [
'uids' => $msg_uids,
'name' => $paper['ep_name'],
'img_id' => $param['cover_id'],
'is_cover_open' => $param['is_cover_open'],
'begin_time' => $param['begin_time'],
'end_time' => $param['end_time'],
'id' => $param['ep_id']
];
// 给阅卷人发送消息
$this->send_msg($msg, self::MARKING_MSG);
}
}
return true;
}
/**
* 格式化feed流权限数据
*
* @author 蔡建华
*
* @param array $right 权限数组
*
* @return array
*/
protected function format_feed_data($right)
{
$feed_right = [];
// 格式化权限字段
if (!empty($right)) {
$users = array_filter(array_column($right, 'uid'));
$departments = array_filter(array_column($right, 'cd_id'));
$jobs = array_filter(array_column($right, 'job_id'));
$roles = array_filter(array_column($right, 'role_id'));
$tags = array_filter(array_column($right, 'tag_id'));
sort($users);
sort($departments);
sort($jobs);
sort($roles);
sort($tags);
$feed_right['users'] = !empty($users) ? $users : '';
$feed_right['departments'] = !empty($departments) ? $departments : '';
$feed_right['jobs'] = !empty($jobs) ? $jobs : '';
$feed_right['roles'] = !empty($roles) ? $roles : '';
$feed_right['tags'] = !empty($tags) ? $tags : '';
}
return $feed_right;
}
/**
* 考试通知发送
*
* @param array $params POST 参数
*
* @return bool
*/
public function new_send_msg($params = [])
{
// 分割成多个元素分组
$uid_groups = array_chunk($params['uids'], Msg::USER_MAX_COUNT);
// 分批发送
foreach ($uid_groups as $uid_group) {
$params['uids'] = $uid_group;
$this->send_msg($params, self::ANSWER_COMING_MSG);
}
return true;
}
/**
* 发布试卷定时任务添加
*
* @param array
* ep_id => 试卷id
*
* @return bool
*/
public function cron_add($ep_id)
{
// 实例化定时任务类
$cron_serv = new Cron(Service::instance());
// 获取试卷基本信息
$data = $this->_d->get($ep_id);
// 存在定时发布
if (!empty($data['begin_corn'])) {
$cron_serv->delete($data['begin_corn']);
}
// 存在定时提醒
if (!empty($data['end_cron'])) {
$cron_serv->delete($data['end_cron']);
}
// 需要定时通知的试卷id
$res_params = ['ep_id' => $ep_id];
// json参数
$json_params = json_encode($res_params);
// 初始化定时任务入库id
$begin_corn = '';
$end_cron = '';
$corn_create_exam = $data['corn_create_exam'] ? $data['corn_create_exam'] : '';
$cron_statistics = $data['cron_statistics'] ? $data['cron_statistics'] : '';
$cron_rank_id = $data['cron_rank_id'] ? $data['cron_rank_id'] : '';
// 如果开始前提醒时间不为空
if (!empty($data['notify_begin'])) {
// 获取截止提醒时间
$remind_time = $data['begin_time'] - to_milli_time($data['notify_begin'] * 60);
// 考试开始前提醒
$conds_remind = [
'crRemark' => 'exam_notify_begin',
'crType' => 2,
'crParams' => $json_params,
'crMethod' => 'POST',
'crReqUrl' => oaUrl('Frontend/Callback/RemindBegin'), // 回调地址
'crTimes' => 1,
'crCron' => rgmdate((String)$remind_time, 's i G j n ? Y'),
'crMonitorExecution' => 0,
'crDescription' => '考试开始提醒'
];
// 创建定时任务
$res_remind = $cron_serv->add($conds_remind); // crId
$begin_corn = $res_remind['crId'];
}
// 如果结束前提醒时间不为空
if (!empty($data['notify_end'])) {
// 获取截止提醒时间
$remind_time = $data['end_time'] - to_milli_time($data['notify_end'] * 60);
//考试结束前提醒
$conds_remind = [
'crRemark' => 'exam_notify_end',
'crType' => 2,
'crParams' => $json_params,
'crMethod' => 'POST',
'crReqUrl' => oaUrl('Frontend/Callback/RemindEnd'), // 回调地址
'crTimes' => 1,
'crCron' => rgmdate((String)$remind_time, 's i G j n ? Y'),
'crMonitorExecution' => 0,
'crDescription' => '考试结束提醒'
];
// 创建定时任务
$res_remind = $cron_serv->add($conds_remind); // crId
$end_cron = $res_remind['crId'];
}
// 如果抽题我随机抽题
if (self::TOPIC_RANDOM == $data['ep_type'] && empty($data['corn_create_exam'])) {
// 生成考卷定时任务
$create_exam = [
'crRemark' => 'corn_create_exam',
'crType' => 2,
'crParams' => $json_params,
'crMethod' => 'POST',
'crReqUrl' => oaUrl('Frontend/Callback/CreateExam'), // 回调地址
'crTimes' => 0,
'crCron' => '0 0/5 * * * ?',
'crMonitorExecution' => 0,
'crDescription' => '自动创建考卷'
];
$res_create_exam = $cron_serv->add($create_exam); // crId
$corn_create_exam = $res_create_exam['crId'];
}
$this->_d->update($ep_id,
[
'begin_corn' => $begin_corn,
'end_cron' => $end_cron,
'corn_create_exam' => $corn_create_exam,
]);
return true;
}
/**
* 格式化获取试卷规则数据
*
* @author daijun
*
* @param array $data 试卷信息
* @param array $bank_topic_total 各题库含有的各题型的总数
* @param array $topic_count_list 普通抽题数列表
*
* @return array
*/
public function format_rule_data($data = [], $bank_topic_total = [], $topic_count_list = [])
{
$result = [
'ep_name' => $data['ep_name'],
'ec_id' => intval($data['ec_id']),
'exam_type' => intval($data['exam_type']),
'paper_type' => intval($data['paper_type']),
'ep_type' => intval($data['ep_type']),
'search_type' => intval($data['search_type']),
'advanced_choose' => intval($data['advanced_choose'])
];
// 获取题库ID集合(一维数组)
$eb_ids = explode(',', $data['bank_data']);
// 查询题库列表
$bank_data = $this->_d_bank->list_by_conds(['eb_id' => $eb_ids], null, [],
'eb_id,eb_name,single_count,multiple_count,judgment_count,question_count,voice_count');
// 格式化组装数据
$bank_list = [];
foreach ($bank_data as $v) {
$bank_list[] = [
'eb_id' => intval($v['eb_id']),
'eb_name' => $v['eb_name'],
'single_count' => intval($v['single_count']),
'multiple_count' => intval($v['multiple_count']),
'judgment_count' => intval($v['judgment_count']),
'question_count' => intval($v['question_count']),
'voice_count' => intval($v['voice_count'])
];
}
$result['topic_count_list'] = $topic_count_list;
$result['bank_list'] = $bank_list;
$bank_topic = array_combine_by_key($bank_topic_total, 'eb_id');
// 格式化题库出题数量数据
if (!empty($data['bank_topic_data'])) {
$bank_topic_data = unserialize($data['bank_topic_data']);
$b_topic_data = [];
foreach ($bank_topic_data as $k => $v) {
$b_topic_data[] = [
'eb_id' => intval($v['eb_id']),
'eb_name' => $v['eb_name'],
'single_count' => intval($v['single_count']),
'multiple_count' => intval($v['multiple_count']),
'judgment_count' => intval($v['judgment_count']),
'question_count' => intval($v['question_count']),
'voice_count' => intval($v['voice_count']),
'single_count_max' => $bank_topic[$v['eb_id']]['single_count'],
'multiple_count_max' => $bank_topic[$v['eb_id']]['multiple_count'],
'judgment_count_max' => $bank_topic[$v['eb_id']]['judgment_count'],
'question_count_max' => $bank_topic[$v['eb_id']]['question_count'],
'voice_count_max' => $bank_topic[$v['eb_id']]['voice_count']
];
}
$result['bank_topic_data'] = $b_topic_data;
} else {
$result['bank_topic_data'] = [];
}
// 格式化出题规则数据
if (!empty($data['rule'])) {
$rule = unserialize($data['rule']);
foreach ($rule as $k => $v) {
$rule[$k] = intval($v);
}
$result['rule'] = $rule;
} else {
$result['rule'] = [];
}
// 格式化标签数据
if (!empty($data['tag_data'])) {
$tag_data = unserialize($data['tag_data']);
// 标签ID集合
$tag_ids = array_column($tag_data, 'etag_id');
// 查询标签列表
$tag_list = $this->_d_tag->list_by_conds(['etag_id' => $tag_ids]);
$tag_list = array_combine_by_key($tag_list, 'etag_id');
// 属性ID集合
$attr_ids = [];
foreach ($tag_data as $v) {
$attr_ids_arr = [];
if (is_array($v['attr_data'])) {
$attr_ids_arr = array_column($v['attr_data'], 'attr_id');
}
if (!empty($attr_ids_arr) && is_array($attr_ids_arr)) {
$attr_ids = array_merge($attr_ids, $attr_ids_arr);
}
}
// 查询属性列表
$attr_list = $this->_d_attr->list_by_conds(['attr_id' => $attr_ids]);
$attr_list = array_combine_by_key($attr_list, 'attr_id');
// 循环格式化组装标签属性
$tag_format_data = [];
foreach ($tag_data as $k => $v) {
$tag_format_data[$k]['etag_id'] = intval($v['etag_id']);
$tag_format_data[$k]['etag_name'] = $tag_list[$v['etag_id']]['tag_name'];
// 循环格式化属性
$attr = [];
foreach ($v['attr_data'] as $_k => $_v) {
$attr[$_k]['attr_id'] = intval($_v['attr_id']);
$attr[$_k]['attr_name'] = $attr_list[$_v['attr_id']]['attr_name'];
}
$tag_format_data[$k]['attr_data'] = $attr;
}
$result['tag_data'] = $tag_format_data;
} else {
$result['tag_data'] = [];
}
return $result;
}
/**
* 格式化试卷信息
*
* @author: 蔡建华
*
* @param array $data 试卷信息
* @param string $uid 用户uid
*
* @return array
*/
public function format_paper_detail($data = [], $uid = '')
{
// 组装格式化数据
$detail = [
'paper_type' => intval($data['paper_type']),
'exam_type' => intval($data['exam_type']),
'ep_name' => $data['ep_name'],
'total_score' => $data['total_score'],
'pass_score' => $data['pass_score'],
'topic_count' => intval($data['topic_count']),
'paper_time' => $data['paper_time'],
'begin_time' => $data['begin_time'],
'end_time' => $data['end_time'],
'join_count' => intval($data['join_count']),
'intro' => $data['intro'],
'marking_type' => intval($data['marking_type'])
];
if (self::IS_COVER_PIC_OPEN == $data['is_cover_open']) {
// 开启封面图片
$detail['cover_url'] = $this->format_cover($data['cover_id']);
} else {
$detail['cover_url'] = '';
}
// 默认未参加
$detail['is_join_test'] = 0;
$makeup_tag = 0; // 补考状态(0:不可补考,1:可补考)
// 常规考试
if (self::NOMAL_TYPE == $data['exam_type']) {
$detail['ep_status'] = $this->paper_status($data['exam_status'], $data['begin_time'], $data['end_time']);
$now_time = MILLI_TIME;
if (self::EVALUATION_PAPER_TYPE == $data['paper_type'] && self::OPEN_MAKEUP == $data['is_open_makeup'] && in_array($detail['ep_status'], [self::STATUS_END, self::STATUS_STOP, self::STATUS_ING]) && $now_time < $data['makeup_end_time'] && $now_time > $data['makeup_start_time']) {
// 如果是测评试卷 && 开启补考 && 是进行中,已结束或者已终止的 && 在补考时间段内
// 查询该用户参加补考的次数
$num = $this->_d_answer->count_by_conds(['ep_id' => $data['ep_id'], 'uid' => $uid, 'my_time>?' => 0, 'is_makeup' => self::IS_MAKEUP]);
if ($data['makeup_num'] > $num && in_array($detail['ep_status'], [self::STATUS_END, self::STATUS_STOP])) {
// 如果补考次数小于设定的次数,则可补考
$makeup_tag = 1;
}
}
// 查询该用户正常参与的次数
$num = $this->_d_answer->count_by_conds(['ep_id' => $data['ep_id'], 'uid' => $uid, 'my_time>?' => 0, 'is_makeup' => self::IS_MAKEUP_FALSE]);
if ($num == 0 && $detail['ep_status'] == self::STATUS_ING) {
// 如果是进行中,并且没有交卷记录,则不可补考
$makeup_tag = 0;
}
if ($num) {
// 已经参加过测评
$detail['is_join_test'] = 1;
}
// 查询该用户补考参与的次数
$num = $this->_d_answer->count_by_conds(['ep_id' => $data['ep_id'], 'uid' => $uid, 'my_time>?' => 0, 'is_makeup' => self::IS_MAKEUP]);
// 计算剩余补考次数
$makeup_num = $data['makeup_num'] - $num;
if ($makeup_num < 0) {
$makeup_num = 0;
}
} else { // 任务类或线下培训:进行中
$detail['ep_status'] = self::STATUS_ING;
}
$detail['makeup_tag'] = $makeup_tag;
$detail['is_open_makeup'] = $data['is_open_makeup']; // 是否开启补考功能:(1:开启 2:不开启)
$detail['makeup_num'] = $makeup_num; // 剩余补考次数
$detail['makeup_start_time'] = $data['makeup_start_time']; // 补考开始时间
$detail['makeup_end_time'] = $data['makeup_end_time']; // 补考结束时间
return $detail;
}
/**
* 重新抽题
*
* @author:daijun
*
* @param int $ep_id
*
* @return bool
*/
public function extract_topic($ep_id = 0)
{
// 如果试卷出题规则不是随机,则按配置抽题
if (!$topic_list = $this->get_temp_list_by_epid($ep_id)) {
E('_ERR_CHOICE_PAPER');
}
try {
// 开始事务
$this->start_trans();
// 删除快照表(即已选择的试题)
$this->_d_snapshot->delete_by_conds(['ep_id' => $ep_id]);
// 删除试卷备选题目信息
$this->_d_temp->delete_by_conds(['ep_id' => $ep_id]);
$temp_list = [];
foreach ($topic_list as $k => $v) {
$temp_list[] = [
'ep_id' => $ep_id,
'et_id' => $v['et_id'],
'score' => $v['score'],
'order_num' => $k,
];
}
if (!empty($temp_list)) {
// 存入备选题目列表
$this->_d_temp->insert_all($temp_list);
}
// 提交事务
$this->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$this->_set_error($e->getMessage(), $e->getCode());
$this->rollback();
return false;
} catch (\Exception $e) {
\Think\Log::record($e);
$this->_set_error($e->getMessage(), $e->getCode());
// 事务回滚
$this->rollback();
return false;
}
return true;
}
/**
* 查询考试统计列表
*
* @author: 英才
*
* @param array $params 查询条件数组
* @param null $page_option 分页
* @param array $order_option 排序数组
* @param String $fields 查询字段
*
* @return array|bool
*/
public function list_search_where($params, $page_option = null, $order_option = [], $fields = '*')
{
try {
return $this->_d->list_search_where($params, $page_option, $order_option, $fields);
} catch (\Exception $e) {
E($e->getCode() . ':' . $e->getMessage());
return false;
}
}
/**
* 统计考试统计列表总数
*
* @author: 英才
*
* @param array $params 查询条件数组
*
* @return array|bool
*/
public function count_search_where($params)
{
try {
return $this->_d->count_search_where($params);
} catch (\Exception $e) {
E($e->getCode() . ":" . $e->getMessage());
return false;
}
}
/**
* 推送停止考试消息与交卷
*
* @author daijun
*
* @param array $data 试卷信息
*/
public function stop_paper($data = [])
{
$right_serv = new RightService();
// 去权限表查询权限信息
$right = $this->_d_right->list_by_conds(['er_type' => 0, 'epc_id' => $data['ep_id']]);
// 格式化权限信息
$right_res = $right_serv->format_db_data($right);
// 获取数据更新后的权限用户列表
$right_res['is_all'] = $data['is_all'];
$params['name'] = $data['ep_name'];
$params['description'] = $data['intro'];
$params['img_id'] = $data['cover_id'];
$params['is_cover_open'] = $data['is_cover_open'];
$params['msg'] = $data['reason'];
$params['id'] = $data['ep_id'];
$params['uids'] = $right_serv->list_uids_by_right($right_res);
// 如果填写了发送的文字则推送考试停止消息
if (!empty($data['reason'])) {
$right_serv->send_msg($params, self::ANSWER_AHEAD_END);
}
// 临时避免定时任务查询或删除失败抛出错误
try {
// 删除定时任务
$this->cron_delete($data);
} catch (\Think\Exception $e) {
\Think\Log::record($e);
}
}
/**
* 删除试卷定时任务
*
* @param $data array 试卷信息
*
* @return bool
*/
public function cron_delete($data = [])
{
// 实例化定时任务类
$cron_serv = new Cron(Service::instance());
// 临时避免定时任务查询或删除失败抛出错误
try {
// 存在定时发布
if (!empty($data['begin_corn'])) {
$cron_serv->delete($data['begin_corn']);
}
// 存在定时提醒
if (!empty($data['end_cron'])) {
$cron_serv->delete($data['end_cron']);
}
// 存在试卷定时任务
if (!empty($data['corn_exam'])) {
$cron_serv->delete($data['corn_exam']);
}
// 存在自动创建考卷的cornid
if (!empty($data['corn_create_exam'])) {
$cron_serv->delete($data['corn_create_exam']);
}
// 存在考试统计cornid
if (!empty($data['cron_statistics'])) {
$cron_serv->delete($data['cron_statistics']);
}
// 存在考试分批推送消息cornid
if (!empty($data['cron_send_msg'])) {
$cron_serv->delete($data['cron_send_msg']);
}
// 存在考试排名列表接口定时更新cornid
if (!empty($data['cron_rank_id'])) {
$cron_serv->delete($data['cron_rank_id']);
}
} catch (\Think\Exception $e) {
\Think\Log::record($e);
return true;
}
return true;
}
/**
* 根据条件更新试卷且不修改最后更新时间
*
* @author 鲜彤
*
* @param $conds array 条件
* @param $data array 数据
*
* @return mixed
*/
public function update_by_paper($conds = [], $data = [])
{
return $this->_d->update_by_paper($conds, $data);
}
/**
* 随机抽取按规则抽题
*
* @author caijainhua
*
* @param array $bank_ids 题库ID集合
* @param array $paper 试卷ID
* @param array $bank_topic_data 题库题目数量设置
* @param array $rule_data 题目得分规则设置
*
* @return array
*/
public function random_rule_topic($bank_ids = [], $paper = [], $bank_topic_data = [], $rule_data = [])
{
$ep_id = $paper['ep_id'];
$topic_all_list = [];
$topic_list_ids = $this->_d_random->list_by_conds(['ep_id' => $ep_id]);
// 开启高级抽取规则值
if (self::ADVANCED_CHOOSE_OPEN == $paper['advanced_choose']) {
// 题库题目属性数组
$bank_topic_attr = [];
foreach ($topic_list_ids as $v) {
$bank_topic_attr[$v['eb_id']][] = $v;
}
// 循环题库
foreach ($bank_ids as $k => $v) {
// 检查是否需要在该题库抽题
$is_bank_topic = 1; // 默认需要从该题库需要抽题
// 此处查询该题库是否设置了题目
foreach ($bank_topic_data as $val) {
if ($val['eb_id'] == $v) {
// 计算当前题库设置测抽题数量
$t_count = $val['single_count'] + $val['multiple_count'] + $val['judgment_count'] + $val['question_count'] + $val['voice_count'];
if (0 == $t_count) {
$is_bank_topic = 0;
}
break;
}
}
// 如果规则设置不从该题库抽题,则continue
if (!$is_bank_topic) {
continue;
}
// 查询该题库下的符合条件的题目列表
$topic_list = $bank_topic_attr[$v];
if (empty($topic_list)) {
E('_ERR_DELETE_RULE_TOPIC');
}
// 将题目列表按照题目类型分组返回
if (!$topic_data = $this->format_by_et_type($topic_list, $bank_topic_data, $rule_data, $v, false)) {
return false;
}
if (!empty($topic_data) && is_array($topic_data)) {
// 合并组装数组
$topic_all_list = array_merge($topic_all_list, $topic_data);
}
}
if (empty($topic_all_list)) {
E('_ERR_CHOICE_PAPER');
}
} else {
// 没有开启高级随机抽题,按照规则总数抽题
$topic_all_list = $this->format_simple_by_et_type(
$topic_list_ids,
$rule_data,
false
);
}
// 对抽取的题目进行打乱
$topics = array_combine_by_key($topic_all_list, 'et_id');
$tp_ids = array_column($topic_all_list, 'et_id');
// 打乱ID
shuffle($tp_ids);
// 循环组装试题信息
$result_list = [];
foreach ($tp_ids as $k => $v) {
$data = $topics[$v];
$data['order_num'] = $k + 1;
$result_list[] = $data;
}
return $result_list;
}
/**
*【后台】将试卷信息写入缓存中
* @author 何岳龙
*
* @param array $param 试卷详情信息
* @param int $exam_status 试卷发布状态
*
* @return bool
*/
public function exam_set_cache($param = [], $exam_status = 0)
{
// 组装前台跳转数据
$cache_data = [
'ep_id' => $param['ep_id'],
'exam_status' => $exam_status,
'begin_time' => $param['begin_time'],
'end_time' => $param['end_time'],
'uids' => $param['uids'], // 应推送新消息人员ID
'cron_id' => $param['cron_id'], // 应推送新消息任务ID
'join_uids' => $param['join_uids'], // 有权参与人员ID集合
];
// 写入缓存
$cache = &Cache::instance();
$cache->set('Common.Exam_' . $param['ep_id'], $cache_data, 7200);
return true;
}
/**
* 闯关交卷
*
* @param array $params 闯关参数
* @param int $uid 用户ID
*
* @return mixed
*/
public function submit_break_papers($params = [], $uid = 0)
{
// 判断课程ID
if (!intval($params['article_id'])) {
E('_EMPTY_BREAK_CID');
}
// 判断用户UID
if (!$uid) {
E('_EMPTY_UID');
}
// 闯关答题列表
$qa_list = $params['qa_list'];
if (empty($qa_list)) {
E('_EMPTY_ANSWER_LIST');
}
$result_list = [];
// 从题库获取闯关试题列表
$et_ids = array_column($qa_list, 'et_id');
$topic_list = $this->_d_topic->list_by_pks($et_ids);
$error_total = 0;
$right_total = 0;
// 闯关实例列表为空时,默认为闯关通过(为了兼容闯关过程中,管理员在后台题库中把闯关题目给删除掉)
if (empty($topic_list)) {
$error_total = 0;
$right_total = count($et_ids);
} else {
// 格式化成以题目ID为键的二维数组
$topic_list = array_combine_by_key($topic_list, 'et_id');
// 循环处理答题列表
foreach ($qa_list as $key => $val) {
$topic_detail = $topic_list[$val['et_id']];
// 获取答案字符串
$answer = $this->get_break_answer($val, $topic_detail);
$answer_detail = $topic_detail;
$answer_detail['my_answer'] = $answer;
// 判断是否正确
$score_res = $this->get_topic_score($answer_detail);
if (self::MY_PASS == $score_res['is_pass']) {
// 答对题目数统计
$right_total++;
} else {
// 答错题目数统计
$error_total++;
}
$result_list[] = [
'et_index' => $key,
'et_id' => $val['et_id'],
'is_pass' => $score_res['is_pass']
];
}
}
$is_pass = $error_total > 0 ? self::MY_BREAK_NO_PASS : self::MY_BREAK_PASS;
unset($params['qa_list']);
$data_params = @urldecode($params['params']);
// 闯关参数拼接
$data = [];
if ($data_params) {
parse_str($data_params, $data);
}
// prc参数拼装
$rpc_params = [
'uid' => $uid,
'article_id' => $params['article_id'],
'is_pass' => $error_total > 0 ? 1 : 2, // 测评是否通过(1=未通过;2=已通过)
'no_total' => intval($error_total),
'yes_total' => intval($right_total),
'article_chapter_id' => intval($params['article_chapter_id']),
'source_id' => intval($params['source_id']),
'customtask_id' => intval($params['customtask_id']),
'plan_id' => intval($params['plan_id']),
'ed_id' => intval($params['ed_id']),
'map_id' => (int)$params['map_id'],
'path_id' => (int)$params['path_id'],
];
$rpc_params = array_merge($rpc_params, $data);
$rpc_url = rpcUrl('/Course/Rpc/Exam/Update');
$rpc_care = \Com\Rpc::phprpc($rpc_url)->invoke('Index', $rpc_params);
if (!empty($rpc_care)) {
foreach ($rpc_care as $key => $value) {
$rpc_care[$key]['content'] = '积分';
}
}
// 闯关通过后,调用常规任务埋点
if ($is_pass == self::MY_BREAK_PASS) {
$taskCenterServ = &TaskCenter::instance();
$taskCenterServ->triggerCustomtask([
'uid' => $uid,
'customtask_id' => $params['customtask_id'],
'app_data_id' => $params['article_id'],
'action_key' => 'course_study',
'description' => '完成课程',
'app' => 'course',
]);
}
return [
'is_pass' => $is_pass,
'care' => $rpc_care,
'answer_list' => $result_list
];
}
/**
* 获取答案字符串
*
* @param array $val 答案数据
* @param array $et_detail 题目详情
*
* @return array|string 答案字符串
*/
public function get_break_answer($val = [], $et_detail = [])
{
$str_answer = '';
// 多选题
if (self::TOPIC_TYPE_MULTIPLE == $et_detail['et_type']) {
if (isset($val['my_answer']) && !empty($val['my_answer'])) {
// 分割答案选项
$my_answer = explode(',', $val['my_answer']);
// 答案选项重新排序
sort($my_answer);
// 答案选项拼接为字符串
$str_answer = implode(',', $my_answer);
}
} elseif (self::TOPIC_TYPE_QUESTION == $et_detail['et_type']
|| self::TOPIC_TYPE_SINGLE == $et_detail['et_type']
|| self::TOPIC_TYPE_JUDGMENT == $et_detail['et_type']
) { // 问答、单选、判断题
$str_answer = strval($val['my_answer']);
}
return $str_answer;
}
/**
* 题目分数正确
*
* @author: 蔡建华
*
* @param array $data 题目信息
*
* @return array 返回 分数和答案是否正确
*/
protected function get_topic_score($data = [])
{
$my_answer = trim($data['my_answer']);
if (empty($my_answer)) {
$my_score = 0;
$is_pass = self::NO_MY_PASS;
} else {
$et_type = $data['et_type'];
if (self::TOPIC_TYPE_SINGLE == $et_type || self::TOPIC_TYPE_MULTIPLE == $et_type || self::TOPIC_TYPE_JUDGMENT == $et_type) {
// 如果是单选或者多选题 或者判断题
if ($my_answer == $data['answer']) {
$my_score = $data['score'];
$is_pass = self::MY_PASS;
} else {
$my_score = $data['score'];
$is_pass = self::NO_MY_PASS;
}
} else {
$answer_serv = new AnswerService();
// 如果是问答题
if (self::KEYWORD_OPEN == $data['match_type']) {
$answer_keyword = unserialize($data['answer_keyword']);
// 匹配关键字方式
$my_score = $answer_serv->_key_question_score($answer_keyword, $my_answer,
$data['score']);
// 得满分算回答正确,否则为回答错误
if ($my_score == $data['score']) {
$is_pass = self::MY_PASS;
} else {
$is_pass = self::NO_MY_PASS;
}
} else {
// 覆盖率方式
$is_pass = $answer_serv->_coverage_question_score($data['answer'],
$data['answer_coverage'],
$my_answer);
$my_score = $is_pass === true ? $data['score'] : 0;
// 得满分算回答正确,否则为回答错误
if ($my_score == $data['score']) {
$is_pass = self::MY_PASS;
} else {
$is_pass = self::NO_MY_PASS;
}
}
}
}
return [
'is_pass' => $is_pass,
'my_score' => $my_score
];
}
}