q-koa 8.8.1 → 8.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -417,6 +417,24 @@ exports.express = async (ctx) => {
417
417
  .slice(express_mobile.length - 4, express_mobile.length)
418
418
  .join('')
419
419
 
420
+ let history = null
421
+ if (app.model.express_record) {
422
+ history = await app.model.express_record.findOne({
423
+ where: {
424
+ express_number,
425
+ },
426
+ })
427
+ if (history) {
428
+ const diffNoLong = moment().diff(moment(history.updated_at), 'hours') < 1
429
+ const isTooLong =
430
+ moment().diff(moment(history.result.updateTime), 'days') > 30
431
+
432
+ if (diffNoLong || isTooLong) {
433
+ return ctx.SUCCESS(history.result)
434
+ }
435
+ }
436
+ }
437
+
420
438
  try {
421
439
  const express = new Express({
422
440
  app_code,
@@ -427,6 +445,21 @@ exports.express = async (ctx) => {
427
445
  ? `${express_number}:${lastFour}`
428
446
  : express_number,
429
447
  })
448
+
449
+ if (app.model.express_record) {
450
+ if (!history) {
451
+ app.model.express_record.upsert({
452
+ express_number,
453
+ result,
454
+ })
455
+ } else {
456
+ app.model.express_record.upsert({
457
+ id: history.id,
458
+ result,
459
+ })
460
+ }
461
+ }
462
+
430
463
  ctx.SUCCESS(result)
431
464
  } catch (e) {
432
465
  return ctx.SUCCESS(null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.8.1",
3
+ "version": "8.8.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {