|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+import moment from 'moment';
|
|
|
2
|
+import commonModel from '../../model/commonModel.js';
|
|
|
3
|
+import mathcalculate from '../../model/mathcalculate.js';
|
|
|
4
|
+import config from '../../config/index.js';
|
|
|
5
|
+import _ from 'lodash';
|
|
|
6
|
+import axios from 'axios';
|
|
|
7
|
+import { Encrypt, Decrypt } from '../../util/crypto/index.js';
|
|
|
8
|
+import { stringUtils } from '../../util/stringClass.js';
|
|
|
9
|
+import WXBizDataCrypt from '../../util/WXBizDataCrypt.js';
|
|
|
10
|
+import { globalCache } from '../../util/GlobalCache.js';
|
|
|
11
|
+import constantClass from '../../util/constant/index.js';
|
|
|
12
|
+import fs from 'fs';
|
|
|
13
|
+import { promises as fsPromises } from 'fs';
|
|
|
14
|
+import COS from 'cos-nodejs-sdk-v5';
|
|
|
15
|
+
|
|
|
16
|
+export async function MathLogin(ctx) {
|
|
|
17
|
+ let param = ctx.request.body;
|
|
|
18
|
+ if (param.param) {
|
|
|
19
|
+ const paramStr = Decrypt(param.param, config.urlSecrets.aes_key, config.urlSecrets.aes_iv);
|
|
|
20
|
+ //console.log("paramStr:"+paramStr);
|
|
|
21
|
+ param = JSON.parse(paramStr);
|
|
|
22
|
+ }
|
|
|
23
|
+ const code = param.Code;
|
|
|
24
|
+ //console.log("code:"+code);
|
|
|
25
|
+ const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${config.wx.math_appid}&secret=${config.wx.math_appsecret}&js_code=${code}&grant_type=authorization_code`;
|
|
|
26
|
+
|
|
|
27
|
+ let result = await axios.get(url)
|
|
|
28
|
+ .then(res => {
|
|
|
29
|
+ const json = res.data;
|
|
|
30
|
+ //console.log("json:"+json);
|
|
|
31
|
+ if (json && json.openid) {
|
|
|
32
|
+ param.OpenID = json.openid;
|
|
|
33
|
+ param.sessionKey = json.session_key;
|
|
|
34
|
+ if (json.unionid)
|
|
|
35
|
+ param.UnionID = json.unionid;
|
|
|
36
|
+ return {errcode: 10000};
|
|
|
37
|
+ }
|
|
|
38
|
+ else {
|
|
|
39
|
+ return json;
|
|
|
40
|
+ }
|
|
|
41
|
+ })
|
|
|
42
|
+ .catch(err => {
|
|
|
43
|
+ return {errcode: 101, errStr: err};
|
|
|
44
|
+ });
|
|
|
45
|
+
|
|
|
46
|
+ if (result.errcode == 10000) {
|
|
|
47
|
+ delete param.Code;
|
|
|
48
|
+ if (param.sessionKey && param.iv && param.encryptedData){
|
|
|
49
|
+ //console.log("param.sessionKey:"+param.sessionKey);
|
|
|
50
|
+ const pc = new WXBizDataCrypt(config.wx.math_appid, param.sessionKey);
|
|
|
51
|
+ const dataUnionID = pc.decryptData(param.encryptedData , param.iv);
|
|
|
52
|
+ //console.log(dataUnionID);
|
|
|
53
|
+ param.UnionID = dataUnionID.unionId;
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+ delete param.sessionKey;
|
|
|
57
|
+ delete param.iv;
|
|
|
58
|
+ delete param.encryptedData;
|
|
|
59
|
+
|
|
|
60
|
+ //todo
|
|
|
61
|
+ //param.OpenID="o4UHq4gaNlHfdTWxgl3fTgC1mFsI";
|
|
|
62
|
+
|
|
|
63
|
+ let userList = await mathcalculate.GetUsersInfo(param);
|
|
|
64
|
+ if (userList.length > 0) {
|
|
|
65
|
+ param.LastLoginTime = new Date();
|
|
|
66
|
+ const time1 = moment(userList[0].ProductServiceTime).format('YYYY-MM-DD HH:mm:ss');
|
|
|
67
|
+ const time3 = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
68
|
+ if (time1 < time3)
|
|
|
69
|
+ param.IsMember = 0;
|
|
|
70
|
+
|
|
|
71
|
+ delete param.Introducer;
|
|
|
72
|
+ delete param.UserSource;
|
|
|
73
|
+ delete param.SourceID;
|
|
|
74
|
+ //console.log(param.NickName);
|
|
|
75
|
+ if (param.NickName == "陌生用户") {
|
|
|
76
|
+ delete param.NickName;
|
|
|
77
|
+ delete param.AvatarUrl;
|
|
|
78
|
+ delete param.Language;
|
|
|
79
|
+ delete param.Gender;
|
|
|
80
|
+ delete param.City;
|
|
|
81
|
+ delete param.Province;
|
|
|
82
|
+ delete param.Country;
|
|
|
83
|
+ }
|
|
|
84
|
+
|
|
|
85
|
+ await mathcalculate.UpdateUsers(param);
|
|
|
86
|
+ userList = await mathcalculate.GetUsersInfo(param);
|
|
|
87
|
+ }
|
|
|
88
|
+ else {
|
|
|
89
|
+ param.NickName = "陌生用户";
|
|
|
90
|
+ param.AvatarUrl = "../images/userface_default.png";
|
|
|
91
|
+ param.CreateTime = new Date();
|
|
|
92
|
+ param.LastLoginTime = param.CreateTime;
|
|
|
93
|
+ param.ProductServiceTime = param.CreateTime;
|
|
|
94
|
+ const inseredID = await mathcalculate.AddUsers(param);
|
|
|
95
|
+ userList = await mathcalculate.GetUsersInfo(param);
|
|
|
96
|
+ }
|
|
|
97
|
+
|
|
|
98
|
+ delete userList[0].OpenID;
|
|
|
99
|
+ delete userList[0].UnionID;
|
|
|
100
|
+
|
|
|
101
|
+ //产品支付是否显示
|
|
|
102
|
+ if (param.ProgramVersion) {
|
|
|
103
|
+ let param2 = {
|
|
|
104
|
+ ProgramID: 105,
|
|
|
105
|
+ Version: param.ProgramVersion,
|
|
|
106
|
+ };
|
|
|
107
|
+ let result3 = await commonModel.GetProductVersionList(param2);
|
|
|
108
|
+ if (result3) {
|
|
|
109
|
+ if ((param2.Version == result3[0].Version && result3[0].IsShowPay <= 0)
|
|
|
110
|
+ || param2.Version > result3[0].Version) {
|
|
|
111
|
+ userList[0].IsShow = result3[0].IsShowPay;
|
|
|
112
|
+ }
|
|
|
113
|
+ else {
|
|
|
114
|
+ userList[0].IsShow = 1;
|
|
|
115
|
+ }
|
|
|
116
|
+
|
|
|
117
|
+ //针对iphone测试用户,永远是无支付状态
|
|
|
118
|
+ if (userList[0].Brand == 'iPhone' && userList[0].WXLanguage == 'en-US'
|
|
|
119
|
+ && userList[0].UserSource == '1001' && userList[0].IsPay == 0) {
|
|
|
120
|
+ userList[0].IsShow = 0;
|
|
|
121
|
+ }
|
|
|
122
|
+
|
|
|
123
|
+ //针对微信测试用户,永远是无支付状态
|
|
|
124
|
+ if ((userList[0].UserSource=='1001' && userList[0].System=="iOS 10.0.1")
|
|
|
125
|
+ || (!userList[0].UserSource && (!userList[0].LastUserSource || userList[0].LastUserSource>10000))
|
|
|
126
|
+ || userList[0].NickName.indexOf("dgztest")>=0){
|
|
|
127
|
+ userList[0].IsShow=-1;
|
|
|
128
|
+ }
|
|
|
129
|
+
|
|
|
130
|
+ if (userList[0].IsMember===1)
|
|
|
131
|
+ userList[0].IsShow=1;
|
|
|
132
|
+ }
|
|
|
133
|
+ }
|
|
|
134
|
+
|
|
|
135
|
+ result = {errcode: 10000, result: userList[0]};
|
|
|
136
|
+ }
|
|
|
137
|
+
|
|
|
138
|
+ ctx.body = result;
|
|
|
139
|
+}
|
|
|
140
|
+
|
|
|
141
|
+export async function GetQuestionTypes(ctx) {
|
|
|
142
|
+ const param = {
|
|
|
143
|
+ QuestionMode: ctx.query.Mode,
|
|
|
144
|
+ };
|
|
|
145
|
+ const list = await mathcalculate.GetQuestionTypesList(param);
|
|
|
146
|
+ const result = [];
|
|
|
147
|
+ let temp;
|
|
|
148
|
+ let arr = [];
|
|
|
149
|
+
|
|
|
150
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
151
|
+ const item = list[i];
|
|
|
152
|
+ if (temp && temp.Category != item.Category) {
|
|
|
153
|
+ const obj = {
|
|
|
154
|
+ ID: temp.CategoryID,
|
|
|
155
|
+ Name: temp.CategoryName + "·" + temp.CategoryLevel,
|
|
|
156
|
+ Description: temp.CategoryDescription,
|
|
|
157
|
+ ImageUrl: temp.CategoryImageUrl,
|
|
|
158
|
+ QuestionCategoryInfoShow: true,
|
|
|
159
|
+ List: arr,
|
|
|
160
|
+ };
|
|
|
161
|
+ result.push(obj);
|
|
|
162
|
+ arr = [];
|
|
|
163
|
+ }
|
|
|
164
|
+
|
|
|
165
|
+ item.Example = item.Example.split(",");
|
|
|
166
|
+ item.SelectItemClass = "";
|
|
|
167
|
+
|
|
|
168
|
+ arr.push(item);
|
|
|
169
|
+ temp = item;
|
|
|
170
|
+ }
|
|
|
171
|
+
|
|
|
172
|
+ const obj = {
|
|
|
173
|
+ ID: temp.CategoryID,
|
|
|
174
|
+ Name: temp.CategoryName + temp.CategoryLevel,
|
|
|
175
|
+ Description: temp.CategoryDescription,
|
|
|
176
|
+ ImageUrl: temp.CategoryImageUrl,
|
|
|
177
|
+ QuestionCategoryInfoShow: true,
|
|
|
178
|
+ List: arr,
|
|
|
179
|
+ };
|
|
|
180
|
+ result.push(obj);
|
|
|
181
|
+
|
|
|
182
|
+ for (let i = 0; i < result.length; i++) {
|
|
|
183
|
+ for (let j = 0; j < result[i].List.length; j++) {
|
|
|
184
|
+ const item = result[i].List[j];
|
|
|
185
|
+ delete item.CategoryID;
|
|
|
186
|
+ delete item.CategoryName;
|
|
|
187
|
+ delete item.CategoryLevel;
|
|
|
188
|
+ delete item.CategoryDescription;
|
|
|
189
|
+ delete item.CategoryImageUrl;
|
|
|
190
|
+ }
|
|
|
191
|
+ }
|
|
|
192
|
+
|
|
|
193
|
+ for (let i = 0; i < result.length; i++) {
|
|
|
194
|
+ for (let j = 0; j < result[i].List.length; j++) {
|
|
|
195
|
+ const item = result[i].List[j];
|
|
|
196
|
+ switch (item.ID){
|
|
|
197
|
+ case 167:
|
|
|
198
|
+ case 174:
|
|
|
199
|
+ case 166:
|
|
|
200
|
+ case 190:
|
|
|
201
|
+ case 191:
|
|
|
202
|
+ case 192:
|
|
|
203
|
+ case 193:
|
|
|
204
|
+ case 164:
|
|
|
205
|
+ case 165:
|
|
|
206
|
+ case 195:
|
|
|
207
|
+ item.CategoryName = "乘除运算";
|
|
|
208
|
+ item.CategoryLevel = "3级";
|
|
|
209
|
+ break;
|
|
|
210
|
+ }
|
|
|
211
|
+ }
|
|
|
212
|
+ }
|
|
|
213
|
+
|
|
|
214
|
+ ctx.body = {"errcode": 10000, result: result};
|
|
|
215
|
+}
|
|
|
216
|
+
|
|
|
217
|
+// exports.GetQuestionTypesPrint = function* () {
|
|
|
218
|
+// var param = {
|
|
|
219
|
+// QuestionTypeID: this.query.ID || 1,
|
|
|
220
|
+// QuestionTypeCategory:this.query.QuestionTypeCategory || 2,
|
|
|
221
|
+// PageNum:this.query.PageNum || 1,
|
|
|
222
|
+// }
|
|
|
223
|
+// var questionType = yield mathcalculate.GetQuestionTypesInfo(param);
|
|
|
224
|
+// questionType = questionType[0];
|
|
|
225
|
+
|
|
|
226
|
+
|
|
|
227
|
+// var questionNumber = questionType.QuestionNumber2;
|
|
|
228
|
+// if (param.QuestionTypeCategory==3)
|
|
|
229
|
+// questionNumber = questionType.QuestionNumber3;
|
|
|
230
|
+
|
|
|
231
|
+// questionNumber=questionNumber*param.PageNum;
|
|
|
232
|
+
|
|
|
233
|
+// questionType.QuestionNumber=questionNumber;
|
|
|
234
|
+// //console.log("questionType.QuestionNumber:"+questionType.QuestionNumber);
|
|
|
235
|
+// var list = getQuestionTypeInfo(questionType);
|
|
|
236
|
+
|
|
|
237
|
+// var questionList = [];
|
|
|
238
|
+// //如果要求题目数小于原有题目数,则直接随机获取题目
|
|
|
239
|
+// if (list.length > questionNumber) {
|
|
|
240
|
+
|
|
|
241
|
+// do {
|
|
|
242
|
+// var rnd = stringClass.Random(0, list.length - 1);
|
|
|
243
|
+// if (list[rnd]) {
|
|
|
244
|
+// questionList.push(list[rnd]);
|
|
|
245
|
+// list[rnd] = null;
|
|
|
246
|
+// }
|
|
|
247
|
+// }
|
|
|
248
|
+// while (questionList.length < questionNumber);
|
|
|
249
|
+// }
|
|
|
250
|
+// //如果要求题目数大于原有题目数,则获取全部原有题目的倍数,再将剩余数随机获取
|
|
|
251
|
+// else {
|
|
|
252
|
+// var nCount = Math.floor(questionNumber / list.length);
|
|
|
253
|
+// for (var n = 0; n < nCount; n++) {
|
|
|
254
|
+// for (var i = 0; i < list.length; i++) {
|
|
|
255
|
+// questionList.push(list[i]);
|
|
|
256
|
+// }
|
|
|
257
|
+// }
|
|
|
258
|
+
|
|
|
259
|
+// while (questionList.length < questionNumber) {
|
|
|
260
|
+// var rnd = stringClass.Random(0, list.length - 1);
|
|
|
261
|
+// if (list[rnd]) {
|
|
|
262
|
+// questionList.push(list[rnd]);
|
|
|
263
|
+// list[rnd] = null;
|
|
|
264
|
+// }
|
|
|
265
|
+// }
|
|
|
266
|
+// }
|
|
|
267
|
+
|
|
|
268
|
+// questionList = stringClass.RemoveJSONNull(questionList);
|
|
|
269
|
+
|
|
|
270
|
+// questionList.sort(function () {
|
|
|
271
|
+// return 0.5 - Math.random()
|
|
|
272
|
+// });
|
|
|
273
|
+
|
|
|
274
|
+// var questionListResult = [];
|
|
|
275
|
+// for (var i = 0; i < questionList.length; i++) {
|
|
|
276
|
+// var item = {};
|
|
|
277
|
+// for (var k in questionList[i]) {
|
|
|
278
|
+// item[k] = questionList[i][k];
|
|
|
279
|
+
|
|
|
280
|
+// if (item[k]=="−") {
|
|
|
281
|
+// item[k] = "-";
|
|
|
282
|
+// }
|
|
|
283
|
+// }
|
|
|
284
|
+// item.ID = i + 1;
|
|
|
285
|
+// var arr = questionType.HiddenColumn.split(",");
|
|
|
286
|
+// var hidden = arr[stringClass.Random(0, arr.length - 1)];
|
|
|
287
|
+// item.HiddenColumn = hidden;
|
|
|
288
|
+// item.Result = item[item.HiddenColumn];
|
|
|
289
|
+
|
|
|
290
|
+// if (param.QuestionTypeCategory==3) {
|
|
|
291
|
+// item.Vertical=computeMath(item);
|
|
|
292
|
+// }
|
|
|
293
|
+
|
|
|
294
|
+// questionListResult.push(item);
|
|
|
295
|
+// }
|
|
|
296
|
+
|
|
|
297
|
+// var categoryArray = [{}, { Num: 1, Name: "一年级", Array: [1, 2] }, { Num: 2, Name: "二年级", Array: [3, 4] }, { Num: 3, Name: "三年级", Array: [5, 6] }, { Num: 4, Name: "四年级及以上", Array: [7] }];
|
|
|
298
|
+// var categoryName="";
|
|
|
299
|
+// for(var i=1;i<categoryArray.length;i++){
|
|
|
300
|
+// for(var j=0;j<categoryArray[i].Array.length;j++){
|
|
|
301
|
+// if (categoryArray[i].Array[j]==questionType.Category){
|
|
|
302
|
+// categoryName=categoryArray[i].Name;
|
|
|
303
|
+// break;
|
|
|
304
|
+// }
|
|
|
305
|
+// }
|
|
|
306
|
+// }
|
|
|
307
|
+
|
|
|
308
|
+// var result = {
|
|
|
309
|
+// ID: questionType.ID,
|
|
|
310
|
+// Category: questionType.Category,
|
|
|
311
|
+// CategoryName: categoryName,
|
|
|
312
|
+// //错误接口参数
|
|
|
313
|
+// Cagegory: questionType.Category,
|
|
|
314
|
+// CagegoryName: categoryName,
|
|
|
315
|
+
|
|
|
316
|
+// CreateTime:moment(new Date()).format('YYYY年MM月DD日 HH:mm'),
|
|
|
317
|
+// Name: questionType.Name,
|
|
|
318
|
+// QuestionTypeCategory:Number(param.QuestionTypeCategory),
|
|
|
319
|
+// QuestionTypeLevel: questionType.CategoryName + questionType.CategoryLevel,
|
|
|
320
|
+// Difficulty: questionType.Difficulty,
|
|
|
321
|
+// PageCount:questionNumber/param.PageNum,
|
|
|
322
|
+// QuestionList: questionListResult,
|
|
|
323
|
+// }
|
|
|
324
|
+// //console.log(result);
|
|
|
325
|
+// //var time=buildPrint(result);
|
|
|
326
|
+
|
|
|
327
|
+// this.body = {"errcode": 10000,result:result};
|
|
|
328
|
+
|
|
|
329
|
+// }
|