lrf402788946 4 lat temu
rodzic
commit
373d6deb20

+ 61 - 16
app/controller/.card.js

@@ -1,37 +1,82 @@
 module.exports = {
   create: {
-    requestBody: []
+    requestBody: [
+      "!mobile",
+      "!password",
+      "!province",
+      "!city",
+      "!set",
+      "pay_type",
+      "!name",
+      "id_card",
+      "level",
+      "points",
+      "recommend",
+      "r_mobile",
+      "zf",
+      "create_time",
+    ],
   },
   destory: {
-    params: ["id"],
-    service: "delete"
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ["id"],
-    requestBody:[]
+    params: ["!id"],
+    requestBody: [
+      "!mobile",
+      "!password",
+      "!province",
+      "!city",
+      "!set",
+      "pay_type",
+      "!name",
+      "id_card",
+      "level",
+      "points",
+      "recommend",
+      "r_mobile",
+      "zf",
+      "create_time",
+    ],
   },
   show: {
     parameters: {
-      params: ["id"]
+      params: ["!id"],
     },
-    service: "fetch"
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
+        mobile: "mobile",
+        province: "province",
+        city: "city",
+        pay_type: "pay_type",
+        name: "name",
+        id_card: "id_card",
+        level: "level",
+        recommend: "%recommend%",
+        r_mobile: "r_mobile",
         "create_time@start": "create_time@start",
         "create_time@end": "create_time@end",
       },
       options: {
-        "meta.status": 0 // 默认条件
+        "meta.status": 0, // 默认条件
       },
     },
-   service: "query",
-   options: {
-     query: ["skip", "limit"],
-     sort: ["meta.createdAt"],
-     desc: true,
-     count: true,
-   },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  // 修改密码
+  passwd: {
+    params: ["!id"],
+    requestBody: ["!password"],
+    service: "passwd",
   },
-}
+};

+ 56 - 0
app/controller/.cash.js

@@ -0,0 +1,56 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!account",
+      "!name",
+      "!mobile",
+      "b_point",
+      "i_point",
+      "e_point",
+      "remark",
+    ],
+  },
+  destory: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "!account",
+      "!name",
+      "!mobile",
+      "b_point",
+      "i_point",
+      "e_point",
+      "remark",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        account: "account",
+        name: "%name%",
+        mobile: "mobile",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      options: {
+        "meta.status": 0, // 默认条件
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/cash.js

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

+ 16 - 0
app/controller/login.js

@@ -0,0 +1,16 @@
+'use strict';
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 登陆
+class LoginController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.login;
+  }
+  async login() {
+    const res = await this.service.login(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+}
+module.exports = CrudController(LoginController, {});

+ 5 - 5
app/model/card.js

@@ -19,11 +19,11 @@ const card = {
   set: { type: String, required: true }, // 169/129 套餐
   pay_type: { type: String }, // 支付方式
   name: { type: String, required: true }, // 姓名
-  id_card: { type: String, required: true }, // 身份证
-  level: { type: String, required: true }, // 等级
-  points: { type: String, required: true }, // 积分
-  recommend: { type: String, required: true }, // 推荐人
-  r_mobile: { type: String, required: true }, // 推荐人电话
+  id_card: { type: String, required: true, lowercase: true }, // 身份证
+  level: { type: String, required: true, default: '1' }, // 等级
+  points: { type: Number, default: 600 }, // 积分
+  recommend: { type: String }, // 推荐人
+  r_mobile: { type: String }, // 推荐人电话
   zf: { type: zf }, // 支付设置
   create_time: {
     type: String,

+ 25 - 0
app/model/cash.js

@@ -0,0 +1,25 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+// 提现表
+const cash = {
+  account: { type: String, required: true }, // 账户
+  name: { type: String, required: true }, // 用户名
+  mobile: { type: String, required: true }, // 手机号
+  b_point: { type: Number }, // 提现前积分
+  i_point: { type: Number }, // 本次提现积分
+  e_point: { type: Number }, // 剩余积分, 计算公式:b_p - (i_p+ _.ceil(i_p*0.06)) 收取6%手续费, 不足1积分按1积分计算
+  remark: { type: String, maxLength: 200 },
+  create_time: {
+    type: String,
+    default: moment().format('YYYY-MM-DD HH:mm:ss'),
+  },
+};
+const schema = new Schema(cash, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Cash', schema, 'cash');
+};

+ 4 - 0
app/router.js

@@ -5,5 +5,9 @@
  */
 module.exports = app => {
   const { router, controller } = app;
+  const prefix = '/api/htyd';
   router.get('/', controller.home.index);
+  router.post(`${prefix}/login`, controller.login.login);
+  require('./router/card')(app); // 办卡
+  require('./router/cash')(app); // 提现
 };

+ 12 - 0
app/router/card.js

@@ -0,0 +1,12 @@
+'use strict';
+/**
+ * @param {Egg.Application} app - egg application
+ */
+module.exports = app => {
+  const prefix = '/api/htyd';
+  const index = 'card';
+  const { router, controller } = app;
+  router.post(index, `${prefix}/${index}/passwd/:id`, controller[index].passwd);
+  router.resources(index, `${prefix}/${index}`, controller[index]); // index、create、show、destroy
+  router.post(index, `${prefix}/${index}/update/:id`, controller[index].update);
+};

+ 11 - 0
app/router/cash.js

@@ -0,0 +1,11 @@
+'use strict';
+/**
+ * @param {Egg.Application} app - egg application
+ */
+module.exports = app => {
+  const prefix = '/api/htyd';
+  const index = 'cash';
+  const { router, controller } = app;
+  router.resources(index, `${prefix}/${index}`, controller[index]); // index、create、show、destroy
+  router.post(index, `${prefix}/${index}/update/:id`, controller[index].update);
+};

+ 15 - 0
app/service/card.js

@@ -1,12 +1,27 @@
 'use strict';
 const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const { ObjectId } = require('mongoose').Types;
 
 class CardService extends CrudService {
   constructor(ctx) {
     super(ctx, 'card');
     this.model = this.ctx.model.Card;
   }
+  async create(data) {
+    const { password, mobile } = data;
+    const is_exists = await this.model.count({ mobile });
+    if (is_exists) throw new BusinessError(ErrorCode.DATA_EXISTED, '手机号已存在');
+    data.password = { secret: password };
+    const res = await this.model.create(data);
+    return res;
+  }
 
+  async passwd({ id, password }) {
+    password = { secret: password };
+    const res = await this.model.update({ _id: ObjectId(id) }, { password });
+    return res;
+  }
 }
 
 module.exports = CardService;

+ 12 - 0
app/service/cash.js

@@ -0,0 +1,12 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+
+// 提现
+class CashService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'cash');
+    this.model = this.ctx.model.Cash;
+  }
+}
+
+module.exports = CashService;

+ 26 - 0
app/service/login.js

@@ -0,0 +1,26 @@
+'use strict';
+const _ = require('lodash');
+const assert = require('assert');
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+// 登陆
+class LoginService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'login');
+    this.model = this.ctx.model.Card;
+  }
+  async login({ mobile, password }) {
+    assert(mobile, '请填写手机号');
+    assert(password, '请填写密码');
+    let user = await this.model.findOne({ mobile }, '+password');
+    if (!user) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '为找到该手机号的用户');
+    user = JSON.parse(JSON.stringify(user));
+    const { password: up, meta, __v, ...userInfo } = user;
+    const { secret } = up;
+    if (!_.isEqual(secret, password)) throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误!');
+    return userInfo;
+  }
+}
+
+module.exports = LoginService;

+ 5 - 5
config/config.default.js

@@ -20,11 +20,11 @@ module.exports = appInfo => {
   config.mongoose = {
     url: 'mongodb://localhost:27017/htyd',
     options: {
-      // user: 'admin',
-      // pass: 'admin',
-      // authSource: 'admin',
-      // useNewUrlParser: true,
-      // useCreateIndex: true,
+      user: 'admin',
+      pass: '111111',
+      authSource: 'admin',
+      useNewUrlParser: true,
+      useCreateIndex: true,
     },
   };