emailTemplate.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. const sendEmail = require('./Email')
  2. class emailTemplate {
  3. stramptoTime(time) {
  4. if (time < 10)
  5. return '';
  6. return new Date(+time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });
  7. }
  8. async checkEmail(email, code) {
  9. const time = new Date().getTime()
  10. await sendEmail(email, 'RunForge - 邮箱验证码',
  11. `<html lang="zh-CN">
  12. <head>
  13. <meta charset="UTF-8">
  14. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  15. <title>RunForge - 邮箱验证码</title>
  16. <style>
  17. body {
  18. font-family: Arial, sans-serif;
  19. background-color: #f4f4f4;
  20. margin: 0;
  21. padding: 0;
  22. }
  23. .container {
  24. width: 80%;
  25. margin: 20px auto;
  26. background-color: #fff;
  27. padding: 20px;
  28. border-radius: 8px;
  29. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  30. }
  31. .head {
  32. display: flex;
  33. justify-content: center;
  34. align-items: center;
  35. gap:10px;
  36. color: #2c3e50;
  37. }
  38. p {
  39. font-size: 16px;
  40. color: #34495e;
  41. line-height: 1.6;
  42. text-indent: 2em;
  43. }
  44. .code {
  45. margin: 20px 0;
  46. font-size: 1.5em;
  47. text-align: center;
  48. font-weight: bold;
  49. }
  50. .important {
  51. color: #e74c3c;
  52. font-weight: bold;
  53. }
  54. .footer {
  55. font-size: 14px;
  56. text-align: center;
  57. color: #7f8c8d;
  58. margin-top: 50px;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="container">
  64. <div class="head">
  65. <h2>RunForge - 邮箱验证码</h2>
  66. </div>
  67. <p>尊敬的用户:</p>
  68. <p>您正在本站进行邮箱验证操作,如非您本人操作,请忽略此邮件。</p>
  69. <p>您的验证码为:</p>
  70. <div class="code">
  71. ${code}
  72. </div>
  73. <p class="important">验证码5分钟内有效,超时请重新获取</p>
  74. <p class="footer">Copyright © 2025 RunForge</p>
  75. </div>
  76. </body>
  77. </html>`
  78. )
  79. }
  80. async registerSuccess(email, username) {
  81. const time = new Date().getTime()
  82. await sendEmail(email, '您已成功注册RunForge账号',
  83. `<html lang="zh-CN">
  84. <head>
  85. <meta charset="UTF-8">
  86. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  87. <title>RunForge - 注册成功提醒</title>
  88. <style>
  89. body {
  90. font-family: Arial, sans-serif;
  91. background-color: #f4f4f4;
  92. margin: 0;
  93. padding: 0;
  94. }
  95. .container {
  96. width: 80%;
  97. margin: 20px auto;
  98. background-color: #fff;
  99. padding: 20px;
  100. border-radius: 8px;
  101. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  102. }
  103. .head {
  104. display: flex;
  105. justify-content: center;
  106. align-items: center;
  107. gap: 10px;
  108. color: #2c3e50;
  109. }
  110. p {
  111. font-size: 16px;
  112. color: #34495e;
  113. line-height: 1.6;
  114. text-indent: 2em;
  115. }
  116. .info {
  117. background-color: #ecf0f1;
  118. padding: 15px;
  119. border-radius: 5px;
  120. margin: 20px 0;
  121. }
  122. .info p {
  123. margin: 5px 0;
  124. }
  125. .important {
  126. color: #e74c3c;
  127. font-weight: bold;
  128. }
  129. .footer {
  130. font-size: 14px;
  131. text-align: center;
  132. color: #7f8c8d;
  133. margin-top: 50px;
  134. }
  135. </style>
  136. </head>
  137. <body>
  138. <div class="container">
  139. <div class="head">
  140. <h2>RunForge - 注册成功提醒</h2>
  141. </div>
  142. <p>尊敬的 ${username}:</p>
  143. <p>您已成功注册RunForge账号:</p>
  144. <div class="info">
  145. <p><strong>用户名:</strong> ${username}</p>
  146. <p><strong>注册时间:</strong> ${this.stramptoTime(time)}</p>
  147. </div>
  148. <p class="footer">Copyright © 2025 RunForge</p>
  149. </div>
  150. </body>
  151. </html>`
  152. )
  153. }
  154. async lepaoOver(email, data) {
  155. await sendEmail(email, '🎉乐跑完成祝贺',
  156. `<!DOCTYPE html>
  157. <html lang="zh-CN">
  158. <head>
  159. <meta charset="UTF-8">
  160. <title>🎉 RunForge - 乐跑完成祝贺</title>
  161. <style>
  162. body {
  163. background-color: #fffaf4;
  164. margin: 0;
  165. padding: 0;
  166. font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  167. }
  168. .container {
  169. max-width: 620px;
  170. margin: 40px auto;
  171. padding: 30px;
  172. background-color: #fff;
  173. border-radius: 14px;
  174. box-shadow: 0 8px 25px rgba(255, 183, 77, 0.2);
  175. border: 2px dashed #ffe0b2;
  176. }
  177. .head {
  178. text-align: center;
  179. margin-bottom: 30px;
  180. }
  181. .head h2 {
  182. color: #ff7043;
  183. font-size: 26px;
  184. margin: 0;
  185. }
  186. p {
  187. color: #444;
  188. font-size: 16px;
  189. line-height: 1.8;
  190. }
  191. .info {
  192. background-color: #fff3e0;
  193. border-left: 5px solid #ffb74d;
  194. padding: 15px 20px;
  195. margin: 25px 0;
  196. border-radius: 10px;
  197. }
  198. .info p {
  199. margin: 8px 0;
  200. }
  201. .footer {
  202. text-align: center;
  203. color: #bbb;
  204. font-size: 14px;
  205. margin-top: 40px;
  206. }
  207. .highlight {
  208. color: #ff5722;
  209. font-weight: bold;
  210. }
  211. </style>
  212. </head>
  213. <body>
  214. <div class="container">
  215. <div class="head">
  216. <h2>🏃‍♀️RunForge - 乐跑目标完成🎉</h2>
  217. </div>
  218. <p>亲爱的 <span class="highlight">${data.name}</span> 宝宝 ꒰。•ᴗ•。꒱:</p>
  219. <p>
  220. ✨恭喜恭喜~你已经火力全开地完成了设定乐跑目标啦!🎊<br>
  221. 不得不说,你就是我们心中的 <strong>小跑神</strong> 🌟💨,坚持到最后真的超级棒!💪( •̀ᄇ• ́)و
  222. </p>
  223. <p>
  224. 跑过的风,晒过的阳,每一步都是你努力的见证!🌤️🍃<br>
  225. 我们在远程为你打Call中 📣📣📣 ~真的好佩服佩服你!
  226. </p>
  227. <p>
  228. 这一学期和你一起“并肩作战”,我们感到非常幸运!🧡<br>
  229. 希望你收获了健康,也收获了快乐~o(≧▽≦)o
  230. </p>
  231. <p>
  232. 📬 如果有任何问题,随时给我们戳小窗~我们在线等你哟 (´▽`)ノ♪
  233. </p>
  234. <p>
  235. 🥳 祝你假期躺赢、学习加buff、每天都开心到冒泡泡!✧*。٩(ˊᗜˋ*)و✧*。<br>
  236. 📚 新学期我们一起继续加速奔跑吧~Let's gooo!🔥🔥
  237. </p>
  238. <p>
  239. 🧡我们已经为您关闭了自动乐跑功能,如您需要继续乐跑,还可前往RunForge自行开启哦!
  240. </p>
  241. <p class="footer">Copyright © 2025 RunForge</p>
  242. </div>
  243. </body>
  244. </html>
  245. `
  246. )
  247. }
  248. async lepaoSuccess(email, data) {
  249. await sendEmail(email, '乐跑成功提醒',
  250. `<html lang="zh-CN">
  251. <head>
  252. <meta charset="UTF-8">
  253. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  254. <title>RunForge - 乐跑成功提醒</title>
  255. <style>
  256. body {
  257. font-family: Arial, sans-serif;
  258. background-color: #f4f4f4;
  259. margin: 0;
  260. padding: 0;
  261. }
  262. .container {
  263. width: 80%;
  264. margin: 20px auto;
  265. background-color: #fff;
  266. padding: 20px;
  267. border-radius: 8px;
  268. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  269. }
  270. .head {
  271. display: flex;
  272. justify-content: center;
  273. align-items: center;
  274. gap: 10px;
  275. color: #2c3e50;
  276. }
  277. p {
  278. font-size: 16px;
  279. color: #34495e;
  280. line-height: 1.6;
  281. text-indent: 2em;
  282. }
  283. .info {
  284. background-color: #ecf0f1;
  285. padding: 15px;
  286. border-radius: 5px;
  287. margin: 20px 0;
  288. }
  289. .info p {
  290. margin: 5px 0;
  291. }
  292. .important {
  293. color: #e74c3c;
  294. font-weight: bold;
  295. }
  296. .footer {
  297. font-size: 14px;
  298. text-align: center;
  299. color: #7f8c8d;
  300. margin-top: 50px;
  301. }
  302. </style>
  303. </head>
  304. <body>
  305. <div class="container">
  306. <div class="head">
  307. <h2>RunForge - 乐跑成功啦 🎉💖</h2>
  308. </div>
  309. <p>亲爱的 ${data.name} 宝宝:</p>
  310. <p>耶耶耶~ 我们已经乖乖帮你完成了一次乐跑啦 ✨🏃‍♀️💨</p>
  311. <div class="info">
  312. <p><strong>学号:</strong> ${data.account}</p>
  313. <p><strong>跑区:</strong> ${data.area} 🌈</p>
  314. <p><strong>跑步时长:</strong> ${this.formatSecondsToMinSec(data.time)} ⏱️</p>
  315. <p><strong>平均配速:</strong> ${this.calculatePace(data.time, data.distance)} 🐇</p>
  316. <p><strong>跑步距离:</strong> ${Number(data.distance).toFixed(2)} Km 💕</p>
  317. <p><strong>累计次数:</strong> ${data.total_num} 次 ✨</p>
  318. <p><strong>开始时间:</strong> ${data.startTime} 🎯</p>
  319. <p><strong>结束时间:</strong> ${data.endTime} 💨</p>
  320. </div>
  321. <p class="important">有问题随时找RunForge客服小可爱呀 💌 我们会陪你耐心解决的~</p>
  322. <p class="footer">Copyright © 2025 RunForge ✨</p>
  323. </div>
  324. </body>
  325. </html>`
  326. )
  327. }
  328. async lepaoFail(email, data) {
  329. const time = new Date().getTime()
  330. await sendEmail(email, '乐跑失败提醒',
  331. `<html lang="zh-CN">
  332. <head>
  333. <meta charset="UTF-8">
  334. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  335. <title>RunForge - 乐跑失败提醒</title>
  336. <style>
  337. body {
  338. font-family: Arial, sans-serif;
  339. background-color: #f4f4f4;
  340. margin: 0;
  341. padding: 0;
  342. }
  343. .container {
  344. width: 80%;
  345. margin: 20px auto;
  346. background-color: #fff;
  347. padding: 20px;
  348. border-radius: 8px;
  349. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  350. }
  351. .head {
  352. display: flex;
  353. justify-content: center;
  354. align-items: center;
  355. gap: 10px;
  356. color: #2c3e50;
  357. }
  358. p {
  359. font-size: 16px;
  360. color: #34495e;
  361. line-height: 1.6;
  362. text-indent: 2em;
  363. }
  364. .info {
  365. background-color: #ecf0f1;
  366. padding: 15px;
  367. border-radius: 5px;
  368. margin: 20px 0;
  369. }
  370. .info p {
  371. margin: 5px 0;
  372. }
  373. .important {
  374. color: #e74c3c;
  375. font-weight: bold;
  376. }
  377. .footer {
  378. font-size: 14px;
  379. text-align: center;
  380. color: #7f8c8d;
  381. margin-top: 50px;
  382. }
  383. </style>
  384. </head>
  385. <body>
  386. <div class="container">
  387. <div class="head">
  388. <h2>RunForge - 乐跑没有成功呢 😢💦</h2>
  389. </div>
  390. <p>亲爱的 ${data.name ?? data.account} 宝宝 🌸:</p>
  391. <p>我们刚刚尝试帮你完成乐跑的时候,遇到了一点小意外呢 💔💦:</p>
  392. <div class="info">
  393. <p><strong>学号:</strong> ${data.account} 🎓</p>
  394. <p><strong>时间:</strong> ${this.stramptoTime(time)} ⏰</p>
  395. <p><strong>失败原因:</strong> ${data.reason} 😭</p>
  396. </div>
  397. <p class="important">宝宝随时可以来找RunForge客服小可爱哟 💌 我们会耐心陪宝宝解决问题的 🌈🥰</p>
  398. <p class="footer">Copyright © 2025 RunForge 💖</p>
  399. </div>
  400. </body>
  401. </html>`
  402. )
  403. }
  404. async orderNewReply(email, data) {
  405. await sendEmail(email, 'RunForge - 工单状态更新提醒',
  406. `<html lang="zh-CN">
  407. <head>
  408. <meta charset="UTF-8">
  409. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  410. <title>RunForge - 工单状态更新提醒</title>
  411. <style>
  412. body {
  413. font-family: Arial, sans-serif;
  414. background-color: #f4f4f4;
  415. margin: 0;
  416. padding: 0;
  417. }
  418. .container {
  419. width: 80%;
  420. margin: 20px auto;
  421. background-color: #fff;
  422. padding: 20px;
  423. border-radius: 8px;
  424. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  425. }
  426. .head {
  427. display: flex;
  428. justify-content: center;
  429. align-items: center;
  430. gap: 10px;
  431. color: #2c3e50;
  432. }
  433. p {
  434. font-size: 16px;
  435. color: #34495e;
  436. line-height: 1.6;
  437. text-indent: 2em;
  438. }
  439. .info {
  440. background-color: #ecf0f1;
  441. padding: 15px;
  442. border-radius: 5px;
  443. margin: 20px 0;
  444. }
  445. .info p {
  446. margin: 5px 0;
  447. }
  448. .important {
  449. color: #e74c3c;
  450. font-weight: bold;
  451. }
  452. .footer {
  453. font-size: 14px;
  454. text-align: center;
  455. color: #7f8c8d;
  456. margin-top: 50px;
  457. }
  458. </style>
  459. </head>
  460. <body>
  461. <div class="container">
  462. <div class="head">
  463. <h2>RunForge - 工单状态更新提醒</h2>
  464. </div>
  465. <p>尊敬的用户:</p>
  466. <p>您编号为${data.id}的工单有新的回复:</p>
  467. <div class="info">
  468. <p><strong>回复内容:</strong> ${data.content}</p>
  469. <p><strong>回复时间:</strong> ${this.stramptoTime(new Date().getTime())}</p>
  470. </div>
  471. <p class="important">${data.files.length > 0 ? '当前回复内含有附件,前往RunForge官网内查看' : ''}</p>
  472. <p class="important">请前往RunForge官网回复工单,请勿直接回复邮件。</p>
  473. <p class="footer">Copyright © 2025 RunForge</p>
  474. </div>
  475. </body>
  476. </html>`
  477. )
  478. }
  479. // 时长计算
  480. formatSecondsToMinSec(totalSeconds) {
  481. const minutes = Math.floor(totalSeconds / 60);
  482. const seconds = totalSeconds % 60;
  483. return `${minutes}分${seconds.toString().padStart(2, '0')}秒`;
  484. }
  485. // 配速计算
  486. calculatePace(seconds, kilometers) {
  487. const paceInSeconds = seconds / kilometers;
  488. const minutes = Math.floor(paceInSeconds / 60);
  489. const remainingSeconds = Math.round(paceInSeconds % 60);
  490. return `${minutes}'${remainingSeconds.toString().padStart(2, '0')}''`;
  491. }
  492. }
  493. const EmailTemplate = new emailTemplate()
  494. module.exports = EmailTemplate