lrf 2 年之前
父節點
當前提交
94c14fbec8
共有 2 個文件被更改,包括 8 次插入4 次删除
  1. 4 4
      app/service/util/trade.js
  2. 4 0
      config/config.default.js

+ 4 - 4
app/service/util/trade.js

@@ -9,11 +9,10 @@ class TradeService extends CrudService {
   constructor(ctx) {
     super(ctx, 'trade');
     this.redis = this.app.redis;
+    this.redisKey = this.app.config.redisKey;
     this.shopModel = this.ctx.model.Shop.Shop;
     this.goodsModel = this.ctx.model.Shop.Goods;
     this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
-
-    this.orderKeyPrefix = 'orderKey:';
   }
   /**
    * 检测是否可以购买该物品
@@ -70,10 +69,11 @@ class TradeService extends CrudService {
       result.result = false;
       return result;
     }
-    const key = `${this.orderKeyPrefix}${this.createNonceStr()}`;
+    const str = this.createNonceStr();
+    const key = `${this.redisKey.orderKeyPrefix}${str}`;
     const value = JSON.stringify({ shop, goods, goodsSpec, num });
     await this.redis.set(key, value, 'EX', 180);
-    result.key = key;
+    result.key = str;
     return result;
   }
   // 随机字符串产生函数

+ 4 - 0
config/config.default.js

@@ -67,6 +67,10 @@ module.exports = appInfo => {
     toMongoDB: true,
   };
 
+  config.redisKey = {
+    orderKeyPrefix: 'orderKey:',
+  };
+
   return {
     ...config,
     ...userConfig,