pbl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. // return console.log(req.body);
  77. // let { openid } = req.body;
  78. postmysql3(req, res, "insert_user");
  79. // let token = jwt.sign({
  80. // openid,
  81. // },
  82. // "secret", {
  83. // expiresIn: "10s",
  84. // }
  85. // );
  86. // res.send({
  87. // code: 200,
  88. // msg: "登录成功",
  89. // token,
  90. // });
  91. });
  92. //yym查询用户(查询是否注册过)
  93. router.post("/selectUser", (req, res) => {
  94. // console.log(req.body);
  95. // let { openid } = req.body;
  96. postmysql3(req, res, "Select_user");
  97. // console.log(res.end);
  98. });
  99. // yym更新头像昵称
  100. router.post("/updateUser", (req, res) => {
  101. // console.log(req.body);
  102. postmysql3(req, res, "update_User");
  103. });
  104. //yym上传活动
  105. router.post("/insertActive", (req, res) => {
  106. // console.log(req.body);
  107. postmysql3(req, res, "insert_activity");
  108. // res.send({
  109. // code: 200,
  110. // msg: "上传成功",
  111. // });
  112. });
  113. //yym 获取活动
  114. router.post("/selectActivity", (req, res) => {
  115. // console.log(req.body);
  116. postmysql3(req, res, "select_activity");
  117. });
  118. //yym 获取用户收藏信息
  119. router.post("/selectColl", (req, res) => {
  120. // console.log(req.body);
  121. postmysql3(req, res, "select_coll");
  122. });
  123. //yym 更新用户收藏信息
  124. router.post("/updateColl", (req, res) => {
  125. // console.log('更新用户收藏信息',req.body);
  126. postmysql3(req, res, "update_coll");
  127. });
  128. //获取用户订阅信息 xlh
  129. router.post("/selectSub", (req, res) => {
  130. postmysql3(req, res, "select_sub");
  131. });
  132. //更新用户订阅信息 xlh
  133. router.post("/updateSub", (req, res) => {
  134. postmysql3(req, res, "update_sub");
  135. });
  136. //yym 获取用户收藏数据(数组查询) 废弃
  137. router.post("/selectCollList", (req, res) => {
  138. // console.log('获取',req.body);
  139. postmysql3(req, res, "select_collList");
  140. });
  141. //yym 获取用户订阅数据(数组查询) 废弃
  142. router.post("/selectSubList", (req, res) => {
  143. // console.log('获取',req.body);
  144. postmysql3(req, res, "select_subList");
  145. });
  146. //yym 获取用户信息
  147. router.post("/selectUserInfo", (req, res) => {
  148. // console.log('获取',req.body);
  149. postmysql3(req, res, "select_UserInfo");
  150. });
  151. //yym 更新用户信息
  152. router.post("/updateUserInfo", (req, res) => {
  153. // console.log("获取用户信息", req.body);
  154. postmysql3(req, res, "update_userInfo");
  155. });
  156. //yym 用户报名收藏等操作 0收藏 1订阅 2报名
  157. router.post("/insertOperator", (req, res) => {
  158. // console.log('获取',req.body);
  159. postmysql3(req, res, "insert_operator");
  160. });
  161. //yym 查询用户全部报名收藏 0收藏 1订阅 2报名
  162. router.post("/selectOperator", (req, res) => {
  163. // console.log('获取',req.body);
  164. postmysql3(req, res, "select_operator");
  165. });
  166. //yym 查询用户 单个 报名收藏
  167. router.post("/selectOneOperator", (req, res) => {
  168. // console.log('获取',req.body);
  169. postmysql3(req, res, "select_oneOperator");
  170. });
  171. //yym 删除用户收藏或订阅
  172. router.post("/deleteOperator", (req, res) => {
  173. // console.log('获取',req.body);
  174. postmysql3(req, res, "delete_Operator");
  175. });
  176. //yym 我的发布页面获取要修改的活动数据
  177. router.post("/selectAmendAct", (req, res) => {
  178. // console.log('获取',req.body);
  179. postmysql3(req, res, "select_amendAct");
  180. });
  181. //yym 获取活动详情页面是否收藏订阅报名
  182. router.post("/selectSignup", (req, res) => {
  183. // console.log('获取',req.body);
  184. postmysql3(req, res, "select_signup");
  185. });
  186. //yym 报名活动
  187. router.post("/insertSignup", (req, res) => {
  188. // console.log('获取',req.body);
  189. postmysql3(req, res, "insert_Signup");
  190. });
  191. //yym 做最后判断防止同一时间进入报名页面都报名成功
  192. router.post("/selectIntercept", (req, res) => {
  193. // console.log('获取',req.body);
  194. postmysql3(req, res, "select_intercept");
  195. });
  196. //yym 获取活动报名人
  197. router.post("/selectApplyUser", (req, res) => {
  198. // console.log('获取',req.body);
  199. postmysql3(req, res, "select_applyUser");
  200. });
  201. //yym 添加活动通知
  202. router.post("/insertMessage", (req, res) => {
  203. // console.log('获取',req.body);
  204. postmysql3(req, res, "insert_message");
  205. });
  206. //yym 信息列表查询信息
  207. router.post("/selectMessage", (req, res) => {
  208. // console.log('获取',req.body);
  209. postmysql3(req, res, "select_message");
  210. });
  211. //yym 查询所有未读信息
  212. router.post("/selectAllMessage", (req, res) => {
  213. // console.log('获取',req.body);
  214. postmysql3(req, res, "select_allMessage");
  215. });
  216. //yym 信息页面分组查询未读信息
  217. router.post("/selectGroupMessage", (req, res) => {
  218. // console.log('获取',req.body);
  219. postmysql3(req, res, "select_groupMessage");
  220. });
  221. //yym 更新未读信息
  222. router.post("/updateIsRead", (req, res) => {
  223. // console.log("获取", req.body);
  224. postmysql3(req, res, "update_isRead");
  225. });
  226. //yym 我的页面,我的收藏活动列表
  227. router.post("/selectCollAcList", (req, res) => {
  228. // console.log("获取", req.body);
  229. postmysql3(req, res, "select_collAcList");
  230. });
  231. //yym 我的页面,我的收藏课程列表
  232. router.post("/selectCollClassList", (req, res) => {
  233. // console.log("获取", req.body);
  234. postmysql3(req, res, "select_collClassList");
  235. });
  236. //yym 获取资源库
  237. router.post("/selectResource", (req, res) => {
  238. // console.log("获取", req.body);
  239. postmysql3(req, res, "select_resource");
  240. });
  241. //yym 获取精品慕课
  242. router.post("/selectJTeach", (req, res) => {
  243. // console.log("获取", req.body);
  244. postmysql3(req, res, "select_jTeach");
  245. });
  246. //yym 获取课程
  247. router.post("/selectOperatorTech", (req, res) => {
  248. // console.log("获取", req.body);
  249. postmysql3(req, res, "select_operatorTech");
  250. });
  251. //yym 获取我的消息,未读红点所填数据
  252. router.post("/selectUnreadMsg", (req, res) => {
  253. // console.log("获取", req.body);
  254. postmysql3(req, res, "select_unreadMsg");
  255. });
  256. //yym 单个点击信息变已读
  257. router.post("/updateOneIsRead", (req, res) => {
  258. // console.log("获取", req.body);
  259. postmysql3(req, res, "update_oneIsRead");
  260. });
  261. //yym 我的活动-获取已报名数据
  262. router.post("/selectRegistered", (req, res) => {
  263. // console.log("获取", req.body);
  264. postmysql3(req, res, "selectRegistered");
  265. });
  266. // yym 活动搜索框
  267. router.get("/selectActSearch", (req, res) => {
  268. // console.log("获取", req.body);
  269. var json = req.query
  270. getmysql(req, res, "selectActSearch",json['openid'],json['txt'],json['ty']);
  271. });
  272. // yym 课程搜索框
  273. router.get("/selectSearchdata", (req, res) => {
  274. // console.log("获取", req.query);
  275. // let json = querystring(req.url)
  276. var json = req.query
  277. // console.log(json['openid']);
  278. // getmysql(req, res, "selectSearchdata",json['openid'],json['txt'],json['ty'],json['page'],json['lim'],);
  279. getmysql(req, res, "selectSearchdata",json['openid'],json['txt'],json['ty']);
  280. });
  281. //lqh获取活动acid
  282. // router.post("/selectActivityID", (req, res) => {
  283. // postmysql3(req, res, "select_activityID");
  284. // });
  285. //查询当前用户发布的活动 xlh
  286. router.post("/selectMyPublish", (req, res) => {
  287. postmysql3(req, res, "select_mypublish");
  288. });
  289. //更改当前用户发布的活动 xlh
  290. router.post("/updateMyPublish", (req, res) => {
  291. postmysql3(req, res, "update_mypublish");
  292. });
  293. //删除当前用户发布的活动 xlh
  294. router.post("/deleteMyPublish", (req, res) => {
  295. postmysql3(req, res, "delete_mypublish");
  296. });
  297. //查询当前的活动是否是当前的用户发布的 xlh
  298. router.post("/selectPublisher", (req, res) => {
  299. postmysql3(req, res, "select_activity_publisher");
  300. });
  301. //报名申请加入 zwb
  302. router.post("/insertActivityEnroll", (req, res) => {
  303. // console.log(req.body);
  304. postmysql3(req, res, "insert_activity_enroll");
  305. // res.send({
  306. // msg: "上传成功",
  307. // });
  308. });
  309. // 查询我的活动 zwb
  310. router.post("/selectActivityEnroll", (req, res) => {
  311. postmysql3(req, res, "select_activity_enroll");
  312. });
  313. //查询用户是否报名 zwb
  314. router.post("/selectActivityEnrollid", (req, res) => {
  315. postmysql3(req, res, "select_activity_enroll_ID");
  316. });
  317. //查询全部活动
  318. router.route("/selectAct").all((req, res, next) => {
  319. // var json = queryString(req.url);
  320. getmysql(req, res, "selectAct");
  321. });
  322. queryString = function (url) {
  323. var a = url.split("?");
  324. var json = querystring.parse(a[1]);
  325. return json;
  326. };
  327. //post存儲過程處理
  328. postmysql = function (req, res, functionname) {
  329. //mode的處理
  330. if (req.body[0]) {
  331. p = Object.values(req.body[0]);
  332. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  333. //執行存儲過程
  334. mysql.usselect(p, function (ret) {
  335. res.end(JSON.stringify(ret));
  336. });
  337. }
  338. };
  339. //post存儲過程處理
  340. postmysql2 = function (req, res, functionname) {
  341. //mode的處理
  342. if (req.body) {
  343. p = Object.values(req.body)[0].split(",");
  344. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  345. //執行存儲過程
  346. mysql.usselect(p, function (ret) {
  347. res.end(JSON.stringify(ret));
  348. });
  349. }
  350. };
  351. //post存儲過程處理
  352. postmysql3 = function (req, res, functionname) {
  353. //mode的處理
  354. if (req.body) {
  355. p = Object.values(req.body);
  356. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  357. //執行存儲過程
  358. mysql.usselect(p, function (ret) {
  359. res.end(JSON.stringify(ret));
  360. });
  361. }
  362. };
  363. //get獲取數據庫信息
  364. getmysql = function (req, res, functionname, ...p) {
  365. p = p || [];
  366. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  367. //執行存儲過程
  368. mysql.usselect(p, function (ret) {
  369. res.end(JSON.stringify(ret));
  370. }); //
  371. };
  372. //post存储过程处理
  373. userpostmysql = function (req, res, functionname) {
  374. //mode的处理
  375. if (req.body.mode) {
  376. p = req.body.mode.split(",");
  377. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  378. //执行存储过程
  379. mysql.usselect(p, function (ret) {
  380. res.end(JSON.stringify(ret));
  381. });
  382. }
  383. };
  384. //get获取数据库信息
  385. usergetmysql = function (req, res, functionname, ...p) {
  386. p = p || [];
  387. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  388. //执行存储过程
  389. mysql.usselect(p, function (ret) {
  390. res.end(JSON.stringify(ret));
  391. }); //
  392. };
  393. module.exports = router;