lrf 2 lat temu
rodzic
commit
18a1433507

+ 13 - 0
app/controller/system/config.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.config.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 
+class ConfigController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.system.config;
+  }
+}
+module.exports = CrudController(ConfigController, meta);

+ 37 - 0
app/controller/system/config/.config.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: ['title', 'config'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['title', 'config'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 20 - 2
app/controller/trade/config/.afterSale.js

@@ -1,6 +1,23 @@
 module.exports = {
   create: {
-    requestBody: ['money', 'order_detail', 'goods_id', 'customer', 'shop', 'goods', 'type', 'reason', 'desc', 'file', 'transport', 'apply_time', 'end_time', 'status', 'result'],
+    requestBody: [
+      'deal_person',
+      'money',
+      'order_detail',
+      'goods_id',
+      'customer',
+      'shop',
+      'goods',
+      'type',
+      'reason',
+      'desc',
+      'file',
+      'transport',
+      'apply_time',
+      'end_time',
+      'status',
+      'result',
+    ],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +25,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['money', 'order_detail', 'customer', 'shop', 'goods', 'type', 'reason', 'desc', 'file', 'transport', 'apply_time', 'end_time', 'status', 'result'],
+    requestBody: ['deal_person', 'money', 'order_detail', 'customer', 'shop', 'goods', 'type', 'reason', 'desc', 'file', 'transport', 'apply_time', 'end_time', 'status', 'result'],
   },
   show: {
     parameters: {
@@ -28,6 +45,7 @@ module.exports = {
         'end_time@start': 'end_time@start',
         'end_time@end': 'end_time@end',
         status: 'status',
+        deal_person: 'deal_person',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 1 - 1
app/middleware/checkLogin.js

@@ -3,7 +3,7 @@ const _ = require('lodash');
 const whiteList = [];
 module.exports = options => {
   return async function checklogin(ctx, next) {
-    console.log(ctx.request.url);
+    console.log(ctx.admin);
     await next();
   };
 };

+ 6 - 0
app/middleware/setUserFromToken.js

@@ -7,6 +7,12 @@ module.exports = options => {
       const data = ctx.service.util.jwt.decode(token);
       if (data) ctx.user = data;
     }
+    // 添加管理员身份
+    const adminToken = _.get(ctx.request, 'header.admin-token');
+    if (adminToken) {
+      const data = ctx.service.util.jwt.decode(adminToken);
+      if (data) ctx.admin = data;
+    }
     await next();
   };
 };

+ 24 - 0
app/model/system/config.js

@@ -0,0 +1,24 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+const configProp = {
+  logo: { type: Array, zh: 'logo' },
+  share: { type: Array, zh: '分享图片' },
+  buyPoint: { type: Number, zh: '购物赠送积分' },
+  pointPlan: { type: Array, zh: '积分计划' }, // 后续有待制作,目前全靠新写
+};
+// 系统设置
+const config = {
+  title: { type: String, required: false, zh: '系统名称' }, //
+  config: { type: Object, required: false, zh: '设置' }, //
+};
+const schema = new Schema(config, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Config', schema, 'config');
+};

+ 2 - 0
app/model/trade/afterSale.js

@@ -18,6 +18,7 @@ const afterSale = {
   end_time: { type: String, required: false, zh: '售后结束时间' }, //
   status: { type: String, required: false, zh: '售后状态' }, // 字典:afterSale_status
   result: { type: Object, required: false, zh: '售后结果' }, // 售后完成后需要补充的内容,例如:退款的金额
+  deal_person: { type: String, required: false, zh: '处理人', ref: 'User.Admin' }, //
 };
 const schema = new Schema(afterSale, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
@@ -25,6 +26,7 @@ schema.index({ 'meta.createdAt': 1 });
 schema.index({ type: 1 });
 schema.index({ apply_time: 1 });
 schema.index({ end_time: 1 });
+schema.index({ deal_person: 1 });
 
 schema.plugin(metaPlugin);
 schema.plugin(MoneyPlugin({ zh: '退款金额', required: false, key: 'money' }));

+ 15 - 0
app/service/system/config.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 
+class ConfigService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'config');
+    this.model = this.ctx.model.System.Config;
+  }
+}
+
+module.exports = ConfigService;

+ 7 - 0
app/service/trade/afterSale.js

@@ -52,6 +52,13 @@ class AfterSaleService extends CrudService {
       if (type !== '2' && (status === '1' || status === '2')) {
         await this.toRefund({ afterSale_id: entity._id, goods_id: _.get(entity, 'goods._id') }, this.tran);
       }
+      // 2022-10-17 需求8:标记处理售后的人
+      if (entity.status === '0' && update.status !== '0') {
+        // 将状态从 审核中 变为不是 审核中的操作人
+        const admin = this.ctx.Admin;
+        if (!admin) throw new BusinessError(ErrorCode.DATA_INVALID, '未找到管理人员的信息,无法进行操作');
+        this.tran.update('AfterSale', entity._id, { deal_person: admin._id });
+      }
       await this.tran.run();
     } catch (error) {
       console.error(error);

+ 19 - 0
app/z_router/system/config.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'config';
+const ckey = 'system.config';
+const keyZh = '系统设置';
+const routes = [
+  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
+  // { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
+  // { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
+  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  // { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};

+ 1 - 0
app/z_router/system/index.js

@@ -7,4 +7,5 @@ module.exports = app => {
   require('./serviceContact')(app); // 客服信息
   require('./goodsTags')(app); // 商品标签
   require('./actTags')(app); // 活动标签
+  require('./config')(app); // 系统设置
 };

+ 2 - 2
config/config.default.js

@@ -17,7 +17,7 @@ module.exports = appInfo => {
   config.keys = appInfo.name + '_1664237342649_2194';
 
   // add your middleware config here
-  config.middleware = [ 'setUserFromToken' ]; // , 'checkLogin'
+  config.middleware = [ 'setUserFromToken', 'checkLogin' ]; // , 'checkLogin'
 
   // add your user config here
   const userConfig = {
@@ -35,7 +35,7 @@ module.exports = appInfo => {
   // 数据库设置
   config.dbName = 'point_shopping';
   config.mongoose = {
-    url: `mongodb://127.0.0.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
+    url: `mongodb://120.48.146.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
     options: {
       user: 'admin',
       pass: 'admin',