lrf 2 anni fa
parent
commit
a3a5011fbe

+ 18 - 0
app.js

@@ -0,0 +1,18 @@
+'use strict';
+const _ = require('lodash');
+const colors = require('colors');
+class AppBootHook {
+  constructor(app) {
+    this.app = app;
+  }
+
+  async willReady() {}
+
+  async serverDidReady() {
+    // 应用已经启动完毕
+    const ctx = await this.app.createAnonymousContext();
+    ctx.service.util.install.init();
+    // await ctx.service.util.rabbitMq.mission();
+  }
+}
+module.exports = AppBootHook;

+ 3 - 2
app/controller/dev/config/.dictData.js

@@ -1,6 +1,6 @@
 module.exports = {
 module.exports = {
   create: {
   create: {
-    requestBody: ['label', 'value', 'sort', 'status'],
+    requestBody: ['label', 'value', 'sort', 'code', 'status'],
   },
   },
   destroy: {
   destroy: {
     params: ['!id'],
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   },
   update: {
   update: {
     params: ['!id'],
     params: ['!id'],
-    requestBody: ['label', 'value', 'sort', 'status'],
+    requestBody: ['label', 'value', 'sort', 'code', 'status'],
   },
   },
   show: {
   show: {
     parameters: {
     parameters: {
@@ -23,6 +23,7 @@ module.exports = {
         'meta.createdAt@end': 'meta.createdAt@end',
         'meta.createdAt@end': 'meta.createdAt@end',
         label: 'label',
         label: 'label',
         value: 'value',
         value: 'value',
+        code: 'code',
         status: 'status',
         status: 'status',
       },
       },
       // options: {
       // options: {

+ 3 - 1
app/model/dev/dictData.js

@@ -6,7 +6,8 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 const dictData = {
 const dictData = {
   label: { type: String, required: false, zh: '显示内容' }, //
   label: { type: String, required: false, zh: '显示内容' }, //
   value: { type: String, required: false, zh: '值' }, //
   value: { type: String, required: false, zh: '值' }, //
-  sort: { type: Number, required: false, default: '1', zh: '排序' }, //
+  sort: { type: Number, required: false, default: 1, zh: '排序' }, //
+  code: { type: String, required: false, zh: '目录编码' }, //
   status: { type: String, required: false, default: '0', zh: '状态' }, // 0:正常;1停用
   status: { type: String, required: false, default: '0', zh: '状态' }, // 0:正常;1停用
 };
 };
 const schema = new Schema(dictData, { toJSON: { getters: true, virtuals: true } });
 const schema = new Schema(dictData, { toJSON: { getters: true, virtuals: true } });
@@ -14,6 +15,7 @@ schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ label: 1 });
 schema.index({ label: 1 });
 schema.index({ value: 1 });
 schema.index({ value: 1 });
+schema.index({ code: 1 });
 schema.index({ status: 1 });
 schema.index({ status: 1 });
 
 
 schema.plugin(metaPlugin);
 schema.plugin(metaPlugin);

+ 3 - 3
app/model/user/user.js

@@ -5,14 +5,14 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
 const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
 
 
 // 顾客
 // 顾客
-const customer = {
+const user = {
   name: { type: String, required: false, zh: '用户名' }, //
   name: { type: String, required: false, zh: '用户名' }, //
   phone: { type: String, required: false, zh: '手机号' }, //
   phone: { type: String, required: false, zh: '手机号' }, //
   password: { type: Secret, required: false, select: false, zh: '密码' }, //
   password: { type: Secret, required: false, select: false, zh: '密码' }, //
   icon: { type: Array, required: false, zh: '头像' }, //
   icon: { type: Array, required: false, zh: '头像' }, //
   birth: { type: String, required: false, zh: '生日' }, //
   birth: { type: String, required: false, zh: '生日' }, //
 };
 };
-const schema = new Schema(customer, { toJSON: { getters: true, virtuals: true } });
+const schema = new Schema(user, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ name: 1 });
 schema.index({ name: 1 });
@@ -22,5 +22,5 @@ schema.plugin(metaPlugin);
 
 
 module.exports = app => {
 module.exports = app => {
   const { mongoose } = app;
   const { mongoose } = app;
-  return mongoose.model('Customer', schema, 'customer');
+  return mongoose.model('User', schema, 'user');
 };
 };

+ 213 - 0
app/public/defaultData/dict.js

@@ -0,0 +1,213 @@
+module.exports = [
+  {
+    name: '是否使用',
+    code: 'use',
+    status: '0',
+    children: [
+      {
+        label: '使用中',
+        value: '0',
+        sort: 1,
+        status: '0',
+      },
+      {
+        label: '已禁用',
+        value: '1',
+        sort: 2,
+        status: '0',
+      },
+    ],
+  },
+  {
+    name: '店铺状态',
+    code: 'shop_status',
+    status: '0',
+    children: [
+      {
+        label: '审核中',
+        value: '0',
+        sort: 1,
+        status: '0',
+      },
+      {
+        label: '审核通过',
+        value: '1',
+        sort: 2,
+        status: '0',
+      },
+      {
+        label: '审核拒绝',
+        value: '-1',
+        sort: 3,
+        status: '0',
+      },
+      {
+        label: '冻结中',
+        value: '-2',
+        sort: 4,
+        status: '0',
+      },
+    ],
+  },
+  {
+    name: '广告图类型',
+    code: 'banner_type',
+    status: '0',
+    children: [
+      {
+        label: '无事件',
+        value: '0',
+        sort: 1,
+        status: '0',
+      },
+      {
+        label: '跳转',
+        value: '1',
+        sort: 2,
+        status: '0',
+      },
+    ],
+  },
+  {
+    name: '跳转类型',
+    code: 'to_type',
+    status: '0',
+    children: [
+      {
+        label: '商品跳转',
+        value: '0',
+        sort: 1,
+        status: '0',
+      },
+      {
+        label: '自定义跳转',
+        value: '1',
+        sort: 2,
+        status: '0',
+      },
+    ],
+  },
+  {
+    name: '售后类型',
+    code: 'afterSale_type',
+    status: '0',
+    children: [
+      {
+        label: '退款',
+        value: '0',
+        sort: 1,
+        status: '0',
+      },
+      {
+        label: '换货',
+        value: '1',
+        sort: 2,
+        status: '0',
+      },
+      {
+        label: '维修',
+        value: '2',
+        sort: 3,
+        status: '0',
+      },
+    ],
+  },
+  {
+    name: '售后状态',
+    code: 'afterSale_status',
+    status: '0',
+    children: [
+      {
+        label: '申请售后',
+        value: '0',
+        sort: 1,
+        status: '0',
+      },
+      {
+        label: '正在审核',
+        value: '1',
+        sort: 2,
+        status: '0',
+      },
+      {
+        label: '已退款',
+        value: '-1',
+        sort: 3,
+        status: '0',
+      },
+      {
+        label: '已换货',
+        value: '-2',
+        sort: 4,
+        status: '0',
+      },
+      {
+        label: '正在维修',
+        value: '2',
+        sort: 5,
+        status: '0',
+      },
+      {
+        label: '已维修',
+        value: '-2',
+        sort: 6,
+        status: '0',
+      },
+    ],
+  },
+  {
+    name: '订单状态',
+    code: 'order_process',
+    status: '0',
+    children: [
+      {
+        label: '已下单',
+        value: '0',
+        sort: 1,
+        status: '0',
+      },
+      {
+        label: '邮寄中',
+        value: '1',
+        sort: 2,
+        status: '0',
+      },
+      {
+        label: '已收货',
+        value: '2',
+        sort: 3,
+        status: '0',
+      },
+      {
+        label: '取消订单',
+        value: '-1',
+        sort: 4,
+        status: '0',
+      },
+      {
+        label: '已退款',
+        value: '-2',
+        sort: 5,
+        status: '0',
+      },
+      {
+        label: '申请售后',
+        value: '-3',
+        sort: 6,
+        status: '0',
+      },
+      {
+        label: '正在售后中',
+        value: '-4',
+        sort: 7,
+        status: '0',
+      },
+      {
+        label: '售后已结束',
+        value: '-5',
+        sort: 8,
+        status: '0',
+      },
+    ],
+  },
+];

+ 20 - 50
app/service/util/install.js

@@ -11,60 +11,30 @@ class InstallService extends CrudService {
     super(ctx, 'install');
     super(ctx, 'install');
     this.dataIndex = path.resolve('app', 'public', 'defaultData');
     this.dataIndex = path.resolve('app', 'public', 'defaultData');
   }
   }
+
   async init() {
   async init() {
-    await this.initRole();
-    await this.initAdmin();
-    await this.initTestBasic();
-  }
-  /**
-   * 初始化角色数据
-   */
-  async initRole() {
-    const model = this.ctx.model.System.Role;
-    const num = await model.count();
-    if (num > 0) return;
-    const dataPath = path.resolve(this.dataIndex, 'role.js');
-    const list = require(dataPath);
-    await model.insertMany(list);
-  }
-  /**
-   * 初始化管理员
-   */
-  async initAdmin() {
-    const model = this.ctx.model.System.User;
-    const roleModel = this.ctx.model.System.Role;
-    const num = await model.count();
-    if (num > 0) return;
-    // 需要将role中menu的mode为all的数据取出来,这是超级管理员的角色信息
-    const roleData = await roleModel.findOne({ code: 'sadmin' });
-    if (!roleData) return;
-    const { _id: role } = roleData;
-    const dataPath = path.resolve(this.dataIndex, 'user.js');
-    let list = require(dataPath);
-    list = list.map(i => ({ ...i, role }));
-    await model.insertMany(list);
+    await this.initDict();
+  //   await this.initSelfShop();
+  //   await this.initTestCustomer();
+  //   await this.initTestGoods();
+  //   await this.initServiceContact();
   }
   }
   /**
   /**
-   * 初始化测试用户
+   * 初始化字典
    */
    */
-  async initTestBasic() {
-    const model = this.ctx.model.Basic;
-    const roleModel = this.ctx.model.System.Role;
-    const userModel = this.ctx.model.System.User;
-    const num = await model.count();
-    if (num > 0) return;
-    const roleData = await roleModel.findOne({ code: 'user' });
-    if (!roleData) return;
-    const { _id: role } = roleData;
-    const dataPath = path.resolve(this.dataIndex, 'basic.js');
-    const list = require(dataPath);
-    const basicList = await model.insertMany(list);
-    const users = basicList.map(i => {
-      const { _id: basic, name, phone } = i;
-      const obj = { role, basic, phone, name, account: name, password: { secret: '111111' } };
-      return obj;
-    });
-    await userModel.insertMany(users);
+  async initDict() {
+    const indexModel = this.ctx.model.Dev.DictIndex;
+    const dataModel = this.ctx.model.Dev.DictData;
+    const p = path.resolve(this.dataIndex, 'dict.js');
+    const data = require(p);
+    for (const i of data) {
+      const { children, ...others } = i;
+      const num = await indexModel.count({ code: others.code });
+      if (num > 0) continue;
+      await indexModel.create(others);
+      const newChildren = children.map(i => ({ ...i, code: others.code }));
+      await dataModel.insertMany(newChildren);
+    }
   }
   }
 }
 }