pbl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. // ROUTES FOR OUR API
  2. // =============================================================================
  3. var express = require("express");
  4. var request = require("request");
  5. var bcrypt = require("bcryptjs");
  6. let axios = require("axios");
  7. var router = express.Router(); // get an instance of the express Router
  8. const querystring = require("querystring");
  9. var mysql = require("./mysql");
  10. // const _mysqlLabor = ["123.58.32.151", "sc_app"]; //edu數據庫信息
  11. // const _mysqluser = ["123.58.32.151", "cocorobouser"]; //用户数据库信息
  12. // const _mysqlLabor = ["127.0.0.1", "sc_app"]; //袁一鸣
  13. // const _mysqlLabor = ["10.3.13.84", "sc_app"]; //袁一鸣
  14. const _mysqlLabor = ["172.16.12.5", "sc_app"]; // 提交的使用用这两个edu數據庫信息
  15. // const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
  16. var crypto = require("crypto");
  17. var https = require("https");
  18. let jwt = require("jsonwebtoken");
  19. let multer = require("multer");
  20. const wx = {
  21. appid: "wx1260af162664fd04", // 填写用户自己的appid
  22. secret: "9d399b3aa0a9e8bce68d20e7734b73e0", // 填写用户自己的密钥
  23. // appid: "wxcf19f82bc4ca3229", // lqh
  24. // secret: "148b350f8bbd2daed7c2f75a8b4411aa", // 填写用户自己的密钥
  25. };
  26. //統壹處理區域
  27. router.use(async function (req, res, next) {
  28. await asynnext(req, res, next);
  29. //// make sure we go to the next routes and don't stop here
  30. //res.end("");
  31. });
  32. /**
  33. * @des 參數解釋同上
  34. */
  35. function asynnext(req, res, next) {
  36. //異步處理
  37. return new Promise(async (resolve, reject) => {
  38. next();
  39. //resolve(true);aa
  40. });
  41. }
  42. /*測試*/
  43. router.route("/a").all((req, res, next) => {
  44. res.send({
  45. msg: "成功",
  46. });
  47. return console.log(req.query);
  48. QMysql(req, res, "insert_user");
  49. var json = queryString(req.url);
  50. getmysql(req, res, "a", json["ph"], json["pa"]);
  51. });
  52. router.route("/b").all((req, res, next) => {
  53. var json = queryString(req.url);
  54. getmysql(req, res, "b", json["ph"], json["pa"]);
  55. });
  56. // yym获取微信openID
  57. router.get("/weChatCode", async (req, res) => {
  58. console.log(req.query);
  59. let response = await axios.get(
  60. "https://api.weixin.qq.com/sns/jscode2session",
  61. {
  62. params: {
  63. appid: wx.appid,
  64. secret: wx.secret,
  65. js_code: req.query.codes,
  66. grant_type: "authorization_code",
  67. },
  68. }
  69. );
  70. // console.log(response.data);
  71. res.send(response.data.openid);
  72. // QMysql(req, res, "update_NewStatusById");
  73. });
  74. //yym注册接口
  75. router.post("/login", (req, res) => {
  76. postmysql3(req, res, "insert_user");
  77. });
  78. //yym查询用户(查询是否注册过)
  79. router.post("/selectUser", (req, res) => {
  80. // console.log(req.body);
  81. // let { openid } = req.body;
  82. postmysql3(req, res, "Select_user");
  83. // console.log(res.end);
  84. });
  85. // yym更新头像昵称
  86. router.post("/updateUser", (req, res) => {
  87. // console.log(req.body);
  88. postmysql3(req, res, "update_User");
  89. });
  90. //yym上传活动
  91. router.post("/insertActive", (req, res) => {
  92. // console.log(req.body);
  93. postmysql3(req, res, "insert_activity");
  94. // res.send({
  95. // code: 200,
  96. // msg: "上传成功",
  97. // });
  98. });
  99. //yym 获取活动
  100. router.post("/selectActivity", (req, res) => {
  101. // console.log(req.body);
  102. postmysql3(req, res, "select_activity");
  103. });
  104. //yym 获取用户收藏信息
  105. router.post("/selectColl", (req, res) => {
  106. // console.log(req.body);
  107. postmysql3(req, res, "select_coll");
  108. });
  109. //yym 更新用户收藏信息
  110. router.post("/updateColl", (req, res) => {
  111. // console.log('更新用户收藏信息',req.body);
  112. postmysql3(req, res, "update_coll");
  113. });
  114. //获取用户订阅信息 xlh
  115. router.post("/selectSub", (req, res) => {
  116. postmysql3(req, res, "select_sub");
  117. });
  118. //更新用户订阅信息 xlh
  119. router.post("/updateSub", (req, res) => {
  120. postmysql3(req, res, "update_sub");
  121. });
  122. //yym 获取用户收藏数据(数组查询) 废弃
  123. router.post("/selectCollList", (req, res) => {
  124. // console.log('获取',req.body);
  125. postmysql3(req, res, "select_collList");
  126. });
  127. //yym 获取用户订阅数据(数组查询) 废弃
  128. router.post("/selectSubList", (req, res) => {
  129. // console.log('获取',req.body);
  130. postmysql3(req, res, "select_subList");
  131. });
  132. //yym 获取用户信息
  133. router.post("/selectUserInfo", (req, res) => {
  134. // console.log('获取',req.body);
  135. postmysql3(req, res, "select_UserInfo");
  136. });
  137. //yym 更新用户信息
  138. router.post("/updateUserInfo", (req, res) => {
  139. // console.log("获取用户信息", req.body);
  140. postmysql3(req, res, "update_userInfo");
  141. });
  142. //yym 用户报名收藏等操作 0收藏 1订阅 2报名
  143. router.post("/insertOperator", (req, res) => {
  144. // console.log('获取',req.body);
  145. postmysql3(req, res, "insert_operator");
  146. });
  147. //yym 查询用户全部报名收藏 0收藏 1订阅 2报名
  148. router.post("/selectOperator", (req, res) => {
  149. // console.log('获取',req.body);
  150. postmysql3(req, res, "select_operator");
  151. });
  152. //yym 查询用户 单个 报名收藏
  153. router.post("/selectOneOperator", (req, res) => {
  154. // console.log('获取',req.body);
  155. postmysql3(req, res, "select_oneOperator");
  156. });
  157. //yym 删除用户收藏或订阅
  158. router.post("/deleteOperator", (req, res) => {
  159. // console.log('获取',req.body);
  160. postmysql3(req, res, "delete_Operator");
  161. });
  162. //yym 我的发布页面获取要修改的活动数据
  163. router.post("/selectAmendAct", (req, res) => {
  164. // console.log('获取',req.body);
  165. postmysql3(req, res, "select_amendAct");
  166. });
  167. //yym 获取活动详情页面是否收藏订阅报名
  168. router.post("/selectSignup", (req, res) => {
  169. // console.log('获取',req.body);
  170. postmysql3(req, res, "select_signup");
  171. });
  172. //yym 报名活动
  173. router.post("/insertSignup", (req, res) => {
  174. // console.log('获取',req.body);
  175. postmysql3(req, res, "insert_Signup");
  176. });
  177. //yym 做最后判断防止同一时间进入报名页面都报名成功
  178. router.post("/selectIntercept", (req, res) => {
  179. // console.log('获取',req.body);
  180. postmysql3(req, res, "select_intercept");
  181. });
  182. //yym 获取活动报名人
  183. router.post("/selectApplyUser", (req, res) => {
  184. // console.log('获取',req.body);
  185. postmysql3(req, res, "select_applyUser");
  186. });
  187. //yym 添加活动通知
  188. router.post("/insertMessage", (req, res) => {
  189. // console.log('获取',req.body);
  190. postmysql3(req, res, "insert_message");
  191. });
  192. //yym 信息列表查询信息
  193. router.post("/selectMessage", (req, res) => {
  194. // console.log('获取',req.body);
  195. postmysql3(req, res, "select_message");
  196. });
  197. //yym 查询所有未读信息
  198. router.post("/selectAllMessage", (req, res) => {
  199. // console.log('获取',req.body);
  200. postmysql3(req, res, "select_allMessage");
  201. });
  202. //yym 信息页面分组查询未读信息
  203. router.post("/selectGroupMessage", (req, res) => {
  204. // console.log('获取',req.body);
  205. postmysql3(req, res, "select_groupMessage");
  206. });
  207. //yym 更新未读信息
  208. router.post("/updateIsRead", (req, res) => {
  209. // console.log("获取", req.body);
  210. postmysql3(req, res, "update_isRead");
  211. });
  212. //yym 我的页面,我的收藏活动列表
  213. router.post("/selectCollAcList", (req, res) => {
  214. // console.log("获取", req.body);
  215. postmysql3(req, res, "select_collAcList");
  216. });
  217. //yym 我的页面,我的收藏课程列表
  218. router.post("/selectCollClassList", (req, res) => {
  219. // console.log("获取", req.body);
  220. postmysql3(req, res, "select_collClassList");
  221. });
  222. //yym 获取资源库
  223. router.post("/selectResource", (req, res) => {
  224. // console.log("获取", req.body);
  225. postmysql3(req, res, "select_resource");
  226. });
  227. //yym 获取精品慕课
  228. router.post("/selectJTeach", (req, res) => {
  229. // console.log("获取", req.body);
  230. postmysql3(req, res, "select_jTeach");
  231. });
  232. //yym 获取课程
  233. router.post("/selectOperatorTech", (req, res) => {
  234. // console.log("获取", req.body);
  235. postmysql3(req, res, "select_operatorTech");
  236. });
  237. //yym 获取我的消息,未读红点所填数据
  238. router.post("/selectUnreadMsg", (req, res) => {
  239. // console.log("获取", req.body);
  240. postmysql3(req, res, "select_unreadMsg");
  241. });
  242. //yym 单个点击信息变已读
  243. router.post("/updateOneIsRead", (req, res) => {
  244. // console.log("获取", req.body);
  245. postmysql3(req, res, "update_oneIsRead");
  246. });
  247. //yym 我的活动-获取已报名数据
  248. router.post("/selectRegistered", (req, res) => {
  249. // console.log("获取", req.body);
  250. postmysql3(req, res, "selectRegistered");
  251. });
  252. // yym 活动搜索框
  253. router.get("/selectActSearch", (req, res) => {
  254. // console.log("获取", req.body);
  255. var json = req.query;
  256. getmysql(
  257. req,
  258. res,
  259. "selectActSearch",
  260. json["openid"],
  261. json["txt"],
  262. json["ty"]
  263. );
  264. });
  265. // yym 搜索所有学校
  266. router.get("/selectColleges", (req, res) => {
  267. // console.log("获取", req.body);
  268. var json = req.query;
  269. getmysql(req, res, "selectColleges");
  270. });
  271. // 搜索对应学校的专业
  272. router.get("/selectMajors", (req, res) => {
  273. // console.log("获取", req.body);
  274. var json = req.query;
  275. getmysql(req, res, "selectMajors", json["mid"]);
  276. });
  277. // 模糊搜索学校
  278. router.get("/selectLikeColleges", (req, res) => {
  279. // console.log("获取", req.body);
  280. var json = req.query;
  281. getmysql(req, res, "selectLikeColleges", json["txt"]);
  282. });
  283. // 模糊搜索专业
  284. router.get("/selectLikeMajors", (req, res) => {
  285. // console.log("获取", req.body);
  286. var json = req.query;
  287. getmysql(req, res, "selectLikeMajors", json["mid"], json["txt"]);
  288. });
  289. // yym 课程搜索框
  290. router.get("/selectSearchdata", (req, res) => {
  291. var json = req.query;
  292. getmysql(
  293. req,
  294. res,
  295. "selectSearchdata",
  296. json["openid"],
  297. json["txt"],
  298. json["ty"]
  299. );
  300. });
  301. // yym 根据学号/工号自动获取信息
  302. router.get("/selectStudentNumber", (req, res) => {
  303. var json = req.query;
  304. getmysql(req, res, "selectStudentNumber", json["txt"]);
  305. });
  306. //yym 取消报名
  307. router.post("/deleteApply", (req, res) => {
  308. // console.log("获取", req.body);
  309. postmysql3(req, res, "deleteApply");
  310. });
  311. //yym 发布资源库数据
  312. router.post("/insertResource", (req, res) => {
  313. // console.log("获取", req.body);
  314. postmysql3(req, res, "insertResource");
  315. });
  316. //yym 更新用户查看课程views
  317. router.post("/updateUserViews", (req, res) => {
  318. postmysql3(req, res, "updateUserViews");
  319. });
  320. //yym 查询用户活跃排行
  321. router.get("/selectUserActivity", (req, res) => {
  322. var json = req.query;
  323. getmysql(req, res, "selectUserActivity", json["oid"]);
  324. });
  325. //yym 获取广告
  326. router.get("/selectAdvertisement", (req, res) => {
  327. var json = req.query;
  328. getmysql(req, res, "selectAdvertisement", json["typ"]);
  329. });
  330. //yym 发布反馈与帮助
  331. router.post("/insertFeedback", (req, res) => {
  332. // console.log("获取", req.body);
  333. postmysql3(req, res, "insertFeedback");
  334. });
  335. //yym 获取反馈信息
  336. router.get("/selectFeedback", (req, res) => {
  337. var json = req.query;
  338. getmysql(req, res, "selectFeedback", json["pa"], 10);
  339. });
  340. //yym 获取所有课程
  341. router.get("/selectAllAct", (req, res) => {
  342. var json = req.query;
  343. getmysql(req, res, "selectAllAct", json["typ"], json["inp"], json["fin"]);
  344. });
  345. //yym 更新活动信息
  346. router.post("/updateActInfo", (req, res) => {
  347. postmysql3(req, res, "updateActInfo");
  348. });
  349. //yym 更新反馈状态
  350. router.post("/updateFeedback", (req, res) => {
  351. // console.log("获取", req.body);
  352. postmysql3(req, res, "updateFeedback");
  353. });
  354. //yym 订阅页面获取活动报名人数据
  355. router.get("/selectEnrollUser", (req, res) => {
  356. var json = req.query;
  357. getmysql(
  358. req,
  359. res,
  360. "selectEnrollUser",
  361. json["oid"],
  362. json["aid"],
  363. json["type"],
  364. json["page"],
  365. 30
  366. );
  367. });
  368. //yym 获取所有注册用户
  369. router.get("/selectAllUser", (req, res) => {
  370. var json = req.query;
  371. getmysql(req, res, "selectAllUser");
  372. });
  373. //lqh获取活动acid
  374. router.post("/selectActivityID", (req, res) => {
  375. postmysql3(req, res, "select_activityID");
  376. });
  377. //查询当前用户发布的活动 xlh
  378. router.post("/selectMyPublish", (req, res) => {
  379. postmysql3(req, res, "select_mypublish");
  380. });
  381. //删除当前用户发布的活动 xlh
  382. router.post("/deleteMyPublish", (req, res) => {
  383. postmysql3(req, res, "delete_mypublish");
  384. });
  385. //查询当前的活动是否是当前的用户发布的 xlh
  386. router.post("/selectPublisher", (req, res) => {
  387. postmysql3(req, res, "select_activity_publisher");
  388. });
  389. //报名申请加入 zwb
  390. router.post("/insertActivityEnroll", (req, res) => {
  391. // console.log(req.body);
  392. postmysql3(req, res, "insert_activity_enroll");
  393. // res.send({
  394. // msg: "上传成功",
  395. // });
  396. });
  397. // 查询我的活动 zwb
  398. router.post("/selectActivityEnroll", (req, res) => {
  399. postmysql3(req, res, "select_activity_enroll");
  400. });
  401. //查询用户是否报名 zwb
  402. router.post("/selectActivityEnrollid", (req, res) => {
  403. postmysql3(req, res, "select_activity_enroll_ID");
  404. });
  405. //查询全部活动
  406. router.route("/selectAct").all((req, res, next) => {
  407. // var json = queryString(req.url);
  408. getmysql(req, res, "selectAct");
  409. });
  410. queryString = function (url) {
  411. var a = url.split("?");
  412. var json = querystring.parse(a[1]);
  413. return json;
  414. };
  415. //post存儲過程處理
  416. postmysql = function (req, res, functionname) {
  417. //mode的處理
  418. if (req.body[0]) {
  419. p = Object.values(req.body[0]);
  420. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  421. //執行存儲過程
  422. mysql.usselect(p, function (ret) {
  423. res.end(JSON.stringify(ret));
  424. });
  425. }
  426. };
  427. //post存儲過程處理
  428. postmysql2 = function (req, res, functionname) {
  429. //mode的處理
  430. if (req.body) {
  431. p = Object.values(req.body)[0].split(",");
  432. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  433. //執行存儲過程
  434. mysql.usselect(p, function (ret) {
  435. res.end(JSON.stringify(ret));
  436. });
  437. }
  438. };
  439. //post存儲過程處理
  440. postmysql3 = function (req, res, functionname) {
  441. //mode的處理
  442. if (req.body) {
  443. p = Object.values(req.body);
  444. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  445. //執行存儲過程
  446. mysql.usselect(p, function (ret) {
  447. res.end(JSON.stringify(ret));
  448. });
  449. }
  450. };
  451. //get獲取數據庫信息
  452. getmysql = function (req, res, functionname, ...p) {
  453. p = p || [];
  454. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  455. //執行存儲過程
  456. mysql.usselect(p, function (ret) {
  457. res.end(JSON.stringify(ret));
  458. }); //
  459. };
  460. //post存储过程处理
  461. userpostmysql = function (req, res, functionname) {
  462. //mode的处理
  463. if (req.body.mode) {
  464. p = req.body.mode.split(",");
  465. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  466. //执行存储过程
  467. mysql.usselect(p, function (ret) {
  468. res.end(JSON.stringify(ret));
  469. });
  470. }
  471. };
  472. //get获取数据库信息
  473. usergetmysql = function (req, res, functionname, ...p) {
  474. p = p || [];
  475. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  476. //执行存储过程
  477. mysql.usselect(p, function (ret) {
  478. res.end(JSON.stringify(ret));
  479. }); //
  480. };
  481. module.exports = router;