lrf 2 gadi atpakaļ
vecāks
revīzija
ff0ff80cfd

+ 3 - 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'],
+    requestBody: ['sell_money', 'flow_money', 'freight', 'shop', 'name', 'shot_brief', 'send_time', 'specs', 'brief', 'file', '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'],
+    requestBody: ['sell_money', 'flow_money', 'freight', 'shop', 'name', 'shot_brief', 'send_time', 'specs', 'brief', 'file', 'status'],
   },
   show: {
     parameters: {
@@ -23,6 +23,7 @@ module.exports = {
         'meta.createdAt@end': 'meta.createdAt@end',
         shop: 'shop',
         name: 'name',
+        status: 'status',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 31 - 0
app/controller/shop/config/.selfShop.js

@@ -0,0 +1,31 @@
+module.exports = {
+  update: {
+    params: ['!id'],
+    requestBody: ['name', 'code', 'person', 'phone', 'address', 'file', 'status'],
+  },
+  index: {
+    parameters: {
+      query: {},
+    },
+  },
+  goods: {
+    parameters: {
+      query: {
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+        name: 'name',
+        status: 'status',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'goods',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

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

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

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

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['name', 'phone', 'password', 'icon', 'birth', 'openid', 'status'],
+    requestBody: ['name', 'phone', 'password', 'icon', 'birth', 'gender', 'openid', 'status'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['name', 'phone', 'password', 'icon', 'birth', 'openid', 'status'],
+    requestBody: ['name', 'phone', 'password', 'icon', 'birth', 'gender', 'openid', 'status'],
   },
   show: {
     parameters: {
@@ -23,6 +23,7 @@ module.exports = {
         'meta.createdAt@end': 'meta.createdAt@end',
         name: 'name',
         phone: 'phone',
+        gender: 'gender',
         openid: 'openid',
         status: 'status',
       },

+ 11 - 0
app/middleware/dealQuery.js

@@ -0,0 +1,11 @@
+'use strict';
+const _ = require('lodash');
+// 将特殊的查询,service返回为{data,total}的情况转换为通常查询结果:即把{}展开
+module.exports = options => {
+  return async function dealquery(ctx, next) {
+    await next();
+    const body = ctx.response.body;
+    const { data, errcode, errmsg } = body;
+    ctx.response.body = { ...data, errcode, errmsg };
+  };
+};

+ 2 - 0
app/model/shop/goods.js

@@ -13,12 +13,14 @@ const goods = {
   specs: { type: Object, required: false, zh: '规格' }, // {规格名:[候选规格]}
   brief: { type: String, required: false, zh: '商品介绍' }, //
   file: { 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 } });
 schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ shop: 1 });
 schema.index({ name: 1 });
+schema.index({ status: 1 });
 
 schema.plugin(metaPlugin);
 schema.plugin(MoneyPlugin({ zh: '实际销售价格', required: false, key: 'sell_money' }));

+ 2 - 0
app/model/user/user.js

@@ -11,6 +11,7 @@ const user = {
   password: { type: Secret, required: false, select: false, zh: '密码' }, //
   icon: { type: Array, required: false, zh: '头像' }, //
   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_type
 };
@@ -19,6 +20,7 @@ schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ name: 1 });
 schema.index({ phone: 1 });
+schema.index({ gender: 1 });
 schema.index({ openid: 1 });
 schema.index({ status: 1 });
 

+ 29 - 0
app/service/shop/selfShop.js

@@ -0,0 +1,29 @@
+'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 SelfShopService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'selfshop');
+    this.model = this.ctx.model.Shop.Shop;
+  }
+
+  async index() {
+    const data = await this.model.findOne({ user: { $exists: false } });
+    return data;
+  }
+  async goods(query, options) {
+    const selfShop = await this.index();
+    const shop = _.get(selfShop, '_id');
+    if (!shop) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到自营店铺信息,请联系开发人员');
+    query.shop = shop;
+    const data = await this.ctx.service.shop.goods.query(query, options);
+    const total = await this.ctx.service.shop.goods.count(query, options);
+    return { data, total };
+  }
+}
+
+module.exports = SelfShopService;

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

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'goods';
+const ckey = 'shop.goods';
+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`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
+  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, middleware: [ 'password' ], 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);
+};

+ 2 - 0
app/z_router/shop/index.js

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

+ 17 - 0
app/z_router/shop/selfShop.js

@@ -0,0 +1,17 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'selfShop';
+const ckey = 'shop.selfShop';
+const keyZh = '自营店铺';
+const routes = [
+  { method: 'get', path: `${rkey}/goods`, controller: `${ckey}.goods`, middleware: [ 'dealQuery' ], name: `${ckey}Goods`, zh: `${keyZh}商品查询` },
+  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}查询` },
+  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, middleware: [ 'password' ], name: `${ckey}Update`, zh: `修改${keyZh}` },
+];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};