Quellcode durchsuchen

Merge branch 'master' into dev

lrf vor 2 Jahren
Ursprung
Commit
ad7c54a2d4
5 geänderte Dateien mit 177 neuen und 38 gelöschten Zeilen
  1. 0 1
      .gitignore
  2. 20 1
      app/service/shop/goods.js
  3. 22 25
      config/config.default.js
  4. 124 0
      config/config.dev.js
  5. 11 11
      config/config.prod.js

+ 0 - 1
.gitignore

@@ -1,4 +1,3 @@
-/config/*
 logs/
 npm-debug.log
 yarn-error.log

+ 20 - 1
app/service/shop/goods.js

@@ -17,9 +17,15 @@ class GoodsService extends CrudService {
   async beforeCreate(data) {
     // 为商品随机生成不重复的code
     if (!data.code) data.code = await this.makeCode();
+    await this.checkCode(data.code);
     return data;
   }
-
+  async beforeUpdate(filter, update) {
+    const id = _.get(filter, 'id', _.get(filter, '_id'));
+    const code = _.get(update, 'code');
+    await this.checkCode(code, id);
+    return { filter, update };
+  }
 
   // 标签查询
   async beforeQuery(filter) {
@@ -29,6 +35,19 @@ class GoodsService extends CrudService {
     }
     return filter;
   }
+  /**
+   * 检查商品编码是否唯一,若传id,则将该id排除在外
+   * @param {String} code 商品唯一编码
+   * @param {String} id 商品id
+   */
+  async checkCode(code, id) {
+    if (!code) return;
+    const query = { code };
+    if (id) query.id = { $ne: id };
+    const num = await this.model.find(query);
+    if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该编码已被其他商品使用');
+    return;
+  }
 
   // 生成商品编码
   async makeCode() {

+ 22 - 25
config/config.default.js

@@ -1,5 +1,3 @@
-/* eslint valid-jsdoc: "off" */
-
 'use strict';
 
 /**
@@ -29,13 +27,13 @@ module.exports = appInfo => {
   // 进程设置
   config.cluster = {
     listen: {
-      port: 12211,
+      port: 12111,
     },
   };
   // 数据库设置
-  config.dbName = 'point_shopping-dev';
+  config.dbName = 'point_shopping';
   config.mongoose = {
-    url: `mongodb://120.48.146.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
+    url: `mongodb://127.0.0.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
     options: {
       user: 'admin',
       pass: 'admin',
@@ -57,53 +55,52 @@ module.exports = appInfo => {
   config.redis = {
     client: {
       port: 6379, // Redis port
-      host: '120.48.146.1', // Redis host
+      host: '127.0.0.1', // Redis host
       password: '123456',
-      db: 2,
+      db: 1,
     },
   };
   // mq设置
   config.amqp = {
     client: {
-      hostname: '120.48.146.1',
-      username: 'tehqDev',
-      password: 'tehqDev',
-      vhost: 'tehqDev',
+      hostname: '127.0.0.1',
+      username: 'tehq',
+      password: 'tehq',
+      vhost: 'tehq',
     },
     app: true,
     agent: true,
   };
   // 定时任务机制设置
   config.taskMqConfig = {
-    ex: 'taskDevLocal',
-    queue: 'taskDevLocal',
-    routingKey: 'trDevLocal',
-    deadEx: 'deadTaskDevLocal',
-    deadQueue: 'deadTaskQueueDevLocal',
-    deadLetterRoutingKey: 'deadTrDevLocal',
+    ex: 'task',
+    queue: 'task',
+    routingKey: 'tr',
+    deadEx: 'deadTask',
+    deadQueue: 'deadTaskQueue',
+    deadLetterRoutingKey: 'deadTr',
   };
 
-
   // 路由设置
-  config.routePrefix = '/dev/point/v1/api';
+  config.routePrefix = '/point/v1/api';
   // 支付路由回调设置
   config.payReturn = {
-    order: '/dev/point/v1/api/pay/order',
+    order: '/point/v1/api/pay/order',
   };
 
   // http请求前缀
   config.httpPrefix = {
-    wechat: 'http://127.0.0.1:14001/wechat/api',
-    // wechat: 'https://broadcast.waityou24.cn/wechat/api',
+    // wechat: 'http://127.0.0.1:14001/wechat/api',
+    wechat: 'https://broadcast.waityou24.cn/wechat/api',
     // email: 'http://broadcast.waityou24.cn/semail/api',
     email: 'http://127.0.0.1:14002/semail/api',
     sms: 'http://127.0.0.1:14003/sms/api',
   };
   config.emailConfig = {
-    config: 'free',
+    config: 'tehq',
   };
   config.smsConfig = {
-    config: 'free',
+    config: 'tehq',
   };
   // 中间件
   config.requestLog = {
@@ -117,7 +114,7 @@ module.exports = appInfo => {
   config.errcode = {
     groupJoinRefund: -111,
   };
-  config.wxPayConfig = 'pointApp';
+  config.wxPayConfig = 'tehqApp';
   return {
     ...config,
     ...userConfig,

+ 124 - 0
config/config.dev.js

@@ -0,0 +1,124 @@
+/* eslint valid-jsdoc: "off" */
+
+'use strict';
+
+/**
+ * @param {Egg.EggAppInfo} appInfo app info
+ */
+const { jwt } = require('./config.secret');
+module.exports = appInfo => {
+  /**
+   * built-in config
+   * @type {Egg.EggAppConfig}
+   **/
+  const config = (exports = {});
+
+  // use for cookie sign key, should change to your own and keep security
+  config.keys = appInfo.name + '_1664237342649_2194';
+  config.appName = '天恩活泉商城-服务';
+  // add your middleware config here
+  config.middleware = [ 'errorEmail', 'setUserFromToken', 'checkLogin', 'checkUserRK' ]; // , 'checkLogin'
+
+  // add your user config here
+  const userConfig = {
+    // myAppName: 'egg',
+  };
+  config.checkToken = {
+    enable: false,
+  };
+  // 进程设置
+  config.cluster = {
+    listen: {
+      port: 12211,
+    },
+  };
+  // 数据库设置
+  config.dbName = 'point_shopping-dev';
+  config.mongoose = {
+    url: `mongodb://120.48.146.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
+    options: {
+      user: 'admin',
+      pass: 'admin',
+      authSource: 'admin',
+      useNewUrlParser: true,
+      useCreateIndex: true,
+      useFindAndModify: true,
+      allowDiskUse: true,
+    },
+  };
+  // jwt设置
+  config.jwt = {
+    ...jwt,
+    expiresIn: '1d',
+    issuer: 'shopping',
+  };
+
+  // redis设置
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '120.48.146.1', // Redis host
+      password: '123456',
+      db: 2,
+    },
+  };
+  // mq设置
+  config.amqp = {
+    client: {
+      hostname: '120.48.146.1',
+      username: 'tehqDev',
+      password: 'tehqDev',
+      vhost: 'tehqDev',
+    },
+    app: true,
+    agent: true,
+  };
+  // 定时任务机制设置
+  config.taskMqConfig = {
+    ex: 'taskDevLocal',
+    queue: 'taskDevLocal',
+    routingKey: 'trDevLocal',
+    deadEx: 'deadTaskDevLocal',
+    deadQueue: 'deadTaskQueueDevLocal',
+    deadLetterRoutingKey: 'deadTrDevLocal',
+  };
+
+  // 路由设置
+  config.routePrefix = '/dev/point/v1/api';
+  // 支付路由回调设置
+  config.payReturn = {
+    order: '/dev/point/v1/api/pay/order',
+  };
+
+  // http请求前缀
+  config.httpPrefix = {
+    // wechat: 'http://127.0.0.1:14001/wechat/api',
+    wechat: 'https://broadcast.waityou24.cn/wechat/api',
+    // email: 'http://broadcast.waityou24.cn/semail/api',
+    email: 'http://127.0.0.1:14002/semail/api',
+    sms: 'http://127.0.0.1:14003/sms/api',
+  };
+  config.emailConfig = {
+    config: 'free',
+  };
+  config.smsConfig = {
+    config: 'free',
+  };
+  // 中间件
+  config.requestLog = {
+    toMongoDB: true,
+  };
+
+  config.redisKey = {
+    orderKeyPrefix: 'orderKey:',
+  };
+  config.redisTimeout = 3600;
+  config.errcode = {
+    groupJoinRefund: -111,
+  };
+  config.wxPayConfig = 'pointApp';
+  return {
+    ...config,
+    ...userConfig,
+  };
+};

+ 11 - 11
config/config.prod.js

@@ -2,7 +2,7 @@
 module.exports = appInfo => {
   const config = (exports = {});
   // 数据库设置
-  config.dbName = 'point_shopping-dev';
+  config.dbName = 'point_shopping';
   config.mongoose = {
     url: `mongodb://127.0.0.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
     options: {
@@ -20,28 +20,28 @@ module.exports = appInfo => {
       port: 6379, // Redis port
       host: '127.0.0.1', // Redis host
       password: '123456',
-      db: 2,
+      db: 1,
     },
   };
   // mq设置
   config.amqp = {
     client: {
       hostname: '127.0.0.1',
-      username: 'tehqDev',
-      password: 'tehqDev',
-      vhost: 'tehqDev',
+      username: 'tehq',
+      password: 'tehq',
+      vhost: 'tehq',
     },
     app: true,
     agent: true,
   };
   // 定时任务机制设置
   config.taskMqConfig = {
-    ex: 'taskDev',
-    queue: 'taskDev',
-    routingKey: 'trDev',
-    deadEx: 'deadTaskDev',
-    deadQueue: 'deadTaskQueueDev',
-    deadLetterRoutingKey: 'deadTrDev',
+    ex: 'task',
+    queue: 'task',
+    routingKey: 'tr',
+    deadEx: 'deadTask',
+    deadQueue: 'deadTaskQueue',
+    deadLetterRoutingKey: 'deadTr',
   };
   config.logger = {
     level: 'NONE',