guhongwei 2 lat temu
rodzic
commit
3693911e85

+ 59 - 0
app/controller/config/.moneylog.js

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

+ 9 - 0
app/controller/config/.user.js

@@ -7,6 +7,9 @@ module.exports = {
       "nick_name",
       "gender",
       "logo_url",
+      "is_vip",
+      "vip_start_time",
+      "vip_end_time",
     ],
   },
   destroy: {
@@ -22,6 +25,9 @@ module.exports = {
       "nick_name",
       "gender",
       "logo_url",
+      "is_vip",
+      "vip_start_time",
+      "vip_end_time",
     ],
   },
   show: {
@@ -39,6 +45,9 @@ module.exports = {
         phone: "phone",
         nick_name: "nick_name",
         gender: "gender",
+        is_vip: "is_vip",
+        vip_start_time: "vip_start_time",
+        vip_end_time: "vip_end_time",
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 3 - 0
app/controller/config/.videos.js

@@ -16,6 +16,7 @@ module.exports = {
       "view_num",
       "is_use",
       "is_hot",
+      "is_vip",
     ],
   },
   destroy: {
@@ -40,6 +41,7 @@ module.exports = {
       "view_num",
       "is_use",
       "is_hot",
+      "is_vip",
     ],
   },
   show: {
@@ -65,6 +67,7 @@ module.exports = {
         view_num: "view_num",
         is_use: "is_use",
         is_hot: "is_hot",
+        is_vip: "is_vip",
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 40 - 0
app/controller/config/.vipsetting.js

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

+ 13 - 0
app/controller/moneylog.js

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

+ 13 - 0
app/controller/vipsetting.js

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

+ 31 - 0
app/model/moneylog.js

@@ -0,0 +1,31 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+
+// 消费记录
+const moneylog = {
+  user_id: { type: String, required: false, zh: '用户id' }, //
+  user_name: { type: String, required: false, zh: '用户名称' }, //
+  money_no: { type: String, required: false, zh: '订单号' }, //
+  type: { type: String, required: false, zh: '交易类型' }, //
+  create_time: { type: String, required: false, zh: '交易时间' }, //
+  money: { type: String, required: false, zh: '交易金额' }, //
+  remark: { type: String, required: false, zh: '备注' }, //
+};
+const schema = new Schema(moneylog, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ user_id: 1 });
+schema.index({ user_name: 1 });
+schema.index({ money_no: 1 });
+schema.index({ type: 1 });
+schema.index({ create_time: 1 });
+schema.index({ money: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Moneylog', schema, 'moneylog');
+};

+ 6 - 0
app/model/user.js

@@ -12,6 +12,9 @@ const user = {
   nick_name: { type: String, required: false, zh: '昵称' }, //
   gender: { type: String, required: false, zh: '性别' }, //
   logo_url: { type: Array, required: false, zh: '头像' }, //
+  is_vip: { type: String, required: false, default: '0', zh: '是否为vip' }, //
+  vip_start_time: { type: String, required: false, zh: 'vip开始时间' }, //
+  vip_end_time: { type: String, required: false, zh: 'vip结束时间' }, //
 };
 const schema = new Schema(user, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
@@ -20,6 +23,9 @@ schema.index({ account: 1 });
 schema.index({ phone: 1 });
 schema.index({ nick_name: 1 });
 schema.index({ gender: 1 });
+schema.index({ is_vip: 1 });
+schema.index({ vip_start_time: 1 });
+schema.index({ vip_end_time: 1 });
 
 schema.plugin(metaPlugin);
 

+ 32 - 30
app/model/videos.js

@@ -3,39 +3,42 @@ const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 
+
 // 视频信息
-const videos = {
-  title: { type: String, required: false, zh: '名称' }, //
-  brief: { type: String, required: false, zh: '简介' }, //
-  time_num: { type: String, required: false, zh: '时长' }, //
-  origin: { type: String, required: false, zh: '来源' }, //
-  firm_id: { type: String, required: false, zh: '厂商' }, //
-  type_id: { type: String, required: false, zh: '类型' }, //
-  place_id: { type: String, required: false, zh: '产地' }, //
-  year: { type: String, required: false, zh: '年份' }, //
-  head_actor: { type: String, required: false, zh: '领衔演员' }, //
-  actor: { type: Array, required: false, zh: '演员' }, //
-  img_url: { type: Array, required: false, zh: '图片' }, //
-  video_url: { type: Array, required: false, zh: '视频路径' }, //
-  view_num: { type: Number, required: false, default: '0', zh: '观看次数' }, //
-  is_use: { type: String, required: false, default: '0', zh: '是否启用' }, //
-  is_hot: { type: String, required: false, default: '0', zh: '是否热推' }, //
-};
+const videos = { 
+  title: { type: String, required: false  , zh: '名称' }, //  
+  brief: { type: String, required: false  , zh: '简介' }, //  
+  time_num: { type: String, required: false  , zh: '时长' }, //  
+  origin: { type: String, required: false  , zh: '来源' }, //  
+  firm_id: { type: String, required: false  , zh: '厂商' }, //  
+  type_id: { type: String, required: false  , zh: '类型' }, //  
+  place_id: { type: String, required: false  , zh: '产地' }, //  
+  year: { type: String, required: false  , zh: '年份' }, //  
+  head_actor: { type: String, required: false  , zh: '领衔演员' }, //  
+  actor: { type: Array, required: false  , zh: '演员' }, //  
+  img_url: { type: Array, required: false  , zh: '图片' }, //  
+  video_url: { type: Array, required: false  , zh: '视频路径' }, //  
+  view_num: { type: Number, required: false  , default: '0', zh: '观看次数' }, //  
+  is_use: { type: String, required: false  , default: '0', zh: '是否启用' }, //  
+  is_hot: { type: String, required: false  , default: '0', zh: '是否热推' }, //  
+  is_vip: { type: String, required: false  , default: '0', zh: '是否为vip' }, //  
+}
 const schema = new Schema(videos, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
-schema.index({ title: 1 });
-schema.index({ brief: 1 });
-schema.index({ time_num: 1 });
-schema.index({ origin: 1 });
-schema.index({ firm_id: 1 });
-schema.index({ type_id: 1 });
-schema.index({ place_id: 1 });
-schema.index({ year: 1 });
-schema.index({ head_actor: 1 });
-schema.index({ view_num: 1 });
-schema.index({ is_use: 1 });
-schema.index({ is_hot: 1 });
+schema.index({ 'title': 1 });
+schema.index({ 'brief': 1 });
+schema.index({ 'time_num': 1 });
+schema.index({ 'origin': 1 });
+schema.index({ 'firm_id': 1 });
+schema.index({ 'type_id': 1 });
+schema.index({ 'place_id': 1 });
+schema.index({ 'year': 1 });
+schema.index({ 'head_actor': 1 });
+schema.index({ 'view_num': 1 });
+schema.index({ 'is_use': 1 });
+schema.index({ 'is_hot': 1 });
+schema.index({ 'is_vip': 1 });
 
 schema.plugin(metaPlugin);
 
@@ -43,4 +46,3 @@ module.exports = app => {
   const { mongoose } = app;
   return mongoose.model('Videos', schema, 'videos');
 };
-

+ 26 - 0
app/model/vipsetting.js

@@ -0,0 +1,26 @@
+'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');
+
+// vip设置
+const vipsetting = {
+  title: { type: String, required: false, zh: '名称' }, //
+  brief: { type: String, required: false, zh: '简介' }, //
+  days: { type: Number, required: false, zh: '天数' }, //
+  sort: { type: Number, required: false, default: '0', zh: '排序' }, //
+  is_use: { type: String, required: false, default: '0', zh: '是否启用' }, //
+};
+const schema = new Schema(vipsetting, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ title: 1 });
+schema.index({ sort: 1 });
+schema.index({ is_use: 1 });
+schema.plugin(metaPlugin);
+schema.plugin(MoneyPlugin({ zh: '金额', required: false, key: 'money' }));
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Vipsetting', schema, 'vipsetting');
+};

+ 2 - 0
app/router.js

@@ -29,4 +29,6 @@ module.exports = app => {
   require('./z_router/likes')(app); // 我的喜欢
   require('./z_router/collects')(app); // 我的收藏
   require('./z_router/discuss')(app); // 讨论
+  require('./z_router/vipsetting')(app); // vip设置
+  require('./z_router/moneylog')(app); // 消费记录
 };

+ 15 - 0
app/service/moneylog.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 moneylogService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'moneylog');
+    this.model = this.ctx.model.Moneylog;
+  }
+}
+
+module.exports = moneylogService;

+ 15 - 0
app/service/vipsetting.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');
+
+// vip设置
+class vipsettingService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'vipsetting');
+    this.model = this.ctx.model.Vipsetting;
+  }
+}
+
+module.exports = vipsettingService;

+ 28 - 0
app/z_router/moneylog.js

@@ -0,0 +1,28 @@
+'use strict';
+// 测试接口
+const rKey = 'moneylog'; // routerKey,路由前缀变量
+const cKey = 'moneylog'; // controllerKey,controller名
+const zhKey = '消费记录';
+const routes = [
+  { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
+  { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 28 - 0
app/z_router/vipsetting.js

@@ -0,0 +1,28 @@
+'use strict';
+// 测试接口
+const rKey = 'vipsetting'; // routerKey,路由前缀变量
+const cKey = 'vipsetting'; // controllerKey,controller名
+const zhKey = 'vip设置';
+const routes = [
+  { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
+  { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};