lrf 2 년 전
부모
커밋
5e16f52a56

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

@@ -33,8 +33,8 @@ module.exports = {
     service: 'query',
     options: {
       query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
-      desc: true,
+      sort: ['sort'],
+      asc: true,
       count: true,
     },
   },

+ 2 - 2
app/controller/shop/config/.goods.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['sell_money', 'flow_money', 'freight', 'shop', 'name', 'shot_brief', 'send_time', 'specs', 'brief', 'file', 'status'],
+    requestBody: ['shop', 'name', 'shot_brief', 'send_time', 'brief', 'file', 'tags', 'status'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['sell_money', 'flow_money', 'freight', 'shop', 'name', 'shot_brief', 'send_time', 'specs', 'brief', 'file', 'status'],
+    requestBody: ['shop', 'name', 'shot_brief', 'send_time', 'brief', 'file', 'tags', 'status'],
   },
   show: {
     parameters: {

+ 40 - 0
app/controller/shop/config/.goodsSpec.js

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

+ 3 - 2
app/controller/shop/config/.shop.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['name', 'code', 'person', 'phone', 'address', 'file', 'status'],
+    requestBody: ['user', 'logo', 'name', 'code', 'person', 'phone', 'address', 'file', 'status'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['name', 'code', 'person', 'phone', 'address', 'file', 'status'],
+    requestBody: ['user', 'logo', 'name', 'code', 'person', 'phone', 'address', 'file', 'status'],
   },
   show: {
     parameters: {
@@ -21,6 +21,7 @@ module.exports = {
       query: {
         'meta.createdAt@start': 'meta.createdAt@start',
         'meta.createdAt@end': 'meta.createdAt@end',
+        user: 'user',
         name: 'name',
         code: 'code',
         person: 'person',

+ 13 - 0
app/controller/shop/goodsSpec.js

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

+ 3 - 3
app/controller/system/config/.banner.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['name', 'url', 'type', 'to', 'is_use'],
+    requestBody: ['name', 'url', 'type', 'to', 'status'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['name', 'url', 'type', 'to', 'is_use'],
+    requestBody: ['name', 'url', 'type', 'to', 'status'],
   },
   show: {
     parameters: {
@@ -23,7 +23,7 @@ module.exports = {
         'meta.createdAt@end': 'meta.createdAt@end',
         name: 'name',
         type: 'type',
-        is_use: 'is_use',
+        status: 'status',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 2 - 2
app/controller/system/config/.indexModule.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['name', 'to_type', 'to', 'is_use', 'url', 'sort'],
+    requestBody: ['name', 'to_type', 'to', 'status', 'url', 'sort'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['name', 'to_type', 'to', 'is_use', 'url', 'sort'],
+    requestBody: ['name', 'to_type', 'to', 'status', 'url', 'sort'],
   },
   show: {
     parameters: {

+ 5 - 0
app/controller/view/config/.goods.js

@@ -0,0 +1,5 @@
+module.exports = {
+  goodsDetail: {
+    requestBody: ['!id'],
+  },
+};

+ 13 - 0
app/controller/view/goods.js

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

+ 1 - 6
app/model/shop/goods.js

@@ -2,17 +2,15 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
-const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
-
 // 商品信息
 const goods = {
   shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
   name: { type: String, required: false, zh: '商品名称' }, //
   shot_brief: { type: String, required: false, zh: '简短简介' }, // 长度在50以内
   send_time: { type: String, required: false, zh: '发货时间' }, //
-  specs: { type: Array, required: false, zh: '规格' }, // {规格名:[候选规格]}
   brief: { type: String, required: false, zh: '商品介绍' }, //
   file: { type: Array, required: false, zh: '商品图片' }, //
+  tags: { type: Array, required: false, zh: '商品标签' }, //
   status: { type: String, required: false, default: '0', zh: '商品状态' }, // 字典:goods_status
 };
 const schema = new Schema(goods, { toJSON: { getters: true, virtuals: true } });
@@ -23,9 +21,6 @@ schema.index({ name: 1 });
 schema.index({ status: 1 });
 
 schema.plugin(metaPlugin);
-schema.plugin(MoneyPlugin({ zh: '实际销售价格', required: false, key: 'sell_money' }));
-schema.plugin(MoneyPlugin({ zh: '划掉销售价格', required: false, key: 'flow_money' }));
-schema.plugin(MoneyPlugin({ zh: '运费', required: false, key: 'freight' }));
 
 module.exports = app => {
   const { mongoose } = app;

+ 29 - 0
app/model/shop/goodsSpec.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
+
+// 商品规格
+const goodsSpec = {
+  goods: { type: String, required: false, zh: '商品源', ref: 'Shop.Goods' }, //
+  name: { type: String, required: false, zh: '规格名称' }, //
+  num: { type: Number, required: false, zh: '库存' }, //
+  status: { type: String, required: false, default: '0', zh: '状态' }, // 字典status
+};
+const schema = new Schema(goodsSpec, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ goods: 1 });
+schema.index({ name: 1 });
+schema.index({ status: 1 });
+
+schema.plugin(metaPlugin);
+schema.plugin(MoneyPlugin({ zh: '实际销售价格', required: false, key: 'sell_money' }));
+schema.plugin(MoneyPlugin({ zh: '划掉销售价格', required: false, key: 'flow_money' }));
+schema.plugin(MoneyPlugin({ zh: '运费', required: false, key: 'freight' }));
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('GoodsSpec', schema, 'goodsSpec');
+};

+ 3 - 1
app/model/shop/shop.js

@@ -4,7 +4,8 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 商店信息
 const shop = {
-  user: { type: String, required: false, ref: 'User.User', zh: '用户' }, //
+  user: { type: String, required: false, zh: '店铺管理用户', ref: 'User.User' }, //
+  logo: { type: Array, required: false, zh: '店铺logo' }, //
   name: { type: String, required: false, zh: '商店名称' }, //
   code: { type: String, required: false, zh: '店铺编号' }, // 自增,中间件处理
   person: { type: String, required: false, zh: '店主' }, //
@@ -16,6 +17,7 @@ const shop = {
 const schema = new Schema(shop, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
+schema.index({ user: 1 });
 schema.index({ name: 1 });
 schema.index({ code: 1 });
 schema.index({ person: 1 });

+ 2 - 2
app/model/system/banner.js

@@ -8,14 +8,14 @@ const banner = {
   url: { type: Array, required: false, zh: '路径' }, //
   type: { type: String, required: false, zh: '类型' }, // 字典表:banner_type
   to: { type: String, required: false, zh: '跳转至' }, // 填写路径
-  is_use: { type: String, required: false, default: '0', zh: '是否正在使用' }, // 字典:use
+  status: { type: String, required: false, default: '0', zh: '是否正在使用' }, // 字典status
 };
 const schema = new Schema(banner, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ name: 1 });
 schema.index({ type: 1 });
-schema.index({ is_use: 1 });
+schema.index({ status: 1 });
 
 schema.plugin(metaPlugin);
 

+ 1 - 1
app/model/system/goodsTags.js

@@ -8,7 +8,7 @@ const goodsTags = {
   code: { type: String, required: false, zh: '标签编码' }, //
   pid: { type: String, required: false, zh: '上级标签' }, //
   level: { type: Number, required: false, zh: '层级' }, //
-  status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:use
+  status: { type: String, required: false, default: '0', zh: '状态' }, // 字典status
 };
 const schema = new Schema(goodsTags, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });

+ 1 - 1
app/model/system/indexModule.js

@@ -7,7 +7,7 @@ const indexModule = {
   name: { type: String, required: false, zh: '模块名称' }, //
   to_type: { type: String, required: false, zh: '跳转类型' }, // 字典:to_type
   to: { type: String, required: false, zh: '跳转至' }, //
-  is_use: { type: String, required: false, zh: '是否使用' }, // 字典:use
+  status: { type: String, required: false, zh: '是否使用' }, // 字典status
   url: { type: Array, required: false, zh: '图标' }, //
   sort: { type: Number, required: false, zh: '排序' }, //
 };

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

@@ -13,7 +13,7 @@ const user = {
   birth: { type: String, required: false, zh: '生日' }, //
   gender: { type: String, required: false, zh: '性别' }, // 字典:gender
   openid: { type: String, required: false, zh: '微信小程序' }, //
-  status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:user_status
+  status: { type: String, required: false, default: '0', zh: '状态' }, // 字典statusr_status
 };
 const schema = new Schema(user, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });

+ 3 - 0
app/router.js

@@ -11,4 +11,7 @@ module.exports = app => {
   require('./z_router/system/index')(app); // 系统部分
   require('./z_router/shop/index')(app); // 店铺部分
   require('./z_router/trade/index')(app); // 交易部分
+
+
+  require('./z_router/view/index')(app); // 视图部分
 };

+ 15 - 0
app/service/shop/goodsSpec.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 GoodsSpecService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'goodsspec');
+    this.model = this.ctx.model.Shop.GoodsSpec;
+  }
+}
+
+module.exports = GoodsSpecService;

+ 37 - 0
app/service/view/goods.js

@@ -0,0 +1,37 @@
+'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 GoodsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'goods');
+    this.goodsModel = this.ctx.model.Shop.Goods;
+    this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
+  }
+  /**
+   *
+   * @param {Object} query 查询条件
+   * @param query.id 商品数据id
+   */
+  async goodsDetail({ id }) {
+    const { populate } = this.ctx.service.shop.goods.getRefMods();
+    let goods = await this.goodsModel.findById(id, { file: 1, tags: 1, name: 1, shot_brief: 1, brief: 1, send_time: 1, shop: 1 }).populate(populate);
+    if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到商品数据');
+    goods = JSON.parse(JSON.stringify(goods));
+    let specs = await this.goodsSpecModel.find({ goods: id, status: '0' }, { sell_money: 1, flow_money: 1, freight: 1, name: 1, num: 1 });
+    specs = JSON.parse(JSON.stringify(specs));
+    goods = _.omit(goods, [ 'meta', '__v' ]);
+    const shop = _.pick(goods.shop, [ 'logo', 'name', 'person', 'phone' ]);
+    delete goods.shop;
+
+    // goods: 商品信息; specs:商品规格信息; shop:店铺信息
+    const returnData = { goods, specs, shop };
+
+    return returnData;
+  }
+}
+
+module.exports = GoodsService;

+ 19 - 0
app/z_router/shop/goodsSpec.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'goodsSpec';
+const ckey = 'shop.goodsSpec';
+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/shop/index.js

@@ -5,4 +5,5 @@ module.exports = app => {
   require('./shop')(app); // 店铺
   require('./goods')(app); // 商品
   require('./selfShop')(app); // 自营店铺相关
+  require('./goodsSpec')(app); // 商品规格
 };

+ 13 - 0
app/z_router/view/goods.js

@@ -0,0 +1,13 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'viewGoods';
+const ckey = 'view.goods';
+const keyZh = '商品相关视图';
+const routes = [{ method: 'post', path: `${rkey}/goodsDetail`, controller: `${ckey}.goodsDetail`, name: `${ckey}GoodsDetail`, zh: '商品页' }];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};

+ 6 - 0
app/z_router/view/index.js

@@ -0,0 +1,6 @@
+/**
+ * @param {Egg.Application} app - egg application
+ */
+module.exports = app => {
+  require('./goods')(app); // 商品视图
+};

+ 1 - 1
config/config.default.js

@@ -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',