Kaynağa Gözat

科技超市服务端更新

reloaded 5 yıl önce
ebeveyn
işleme
4d8ea1ef8b

+ 12 - 0
.travis.yml

@@ -0,0 +1,12 @@
+sudo: false
+language: node_js
+node_js:
+  - '10'
+before_install:
+  - npm i npminstall -g
+install:
+  - npminstall
+script:
+  - npm run ci
+after_script:
+  - npminstall codecov && codecov

+ 46 - 0
app/controller/.proaudit.js

@@ -0,0 +1,46 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!product_id',
+      '!userid',
+      '!result',
+      'description'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'product_id',
+      'userid',
+      'result',
+      'description'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        product_id :'product_id',
+        userid :'userid',
+        result :'result',
+        description :'description'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 103 - 0
app/controller/.product.js

@@ -0,0 +1,103 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+      '!userid',
+      '!totaltype',
+      'product_type_id',
+      'product_type_name',
+      'introduction',
+      'price',
+      'priceunit',
+      'image',
+      'product_args',
+      'business',
+      'phase',
+      'field',
+      'prospect',
+      'contract',
+      'gxtype',
+      'scope',
+      'description',
+      'property',
+      'state',
+      'is_del',
+      'contact_user',
+      'contact_tel'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'name',
+      'userid',
+      'totaltype',
+      'product_type_id',
+      'product_type_name',
+      'introduction',
+      'price',
+      'priceunit',
+      'image',
+      'product_args',
+      'business',
+      'phase',
+      'field',
+      'prospect',
+      'contract',
+      'gxtype',
+      'scope',
+      'description',
+      'property',
+      'state',
+      'is_del',
+      'contact_user',
+      'contact_tel'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name:'name',
+        userid:'userid',
+        totaltype:'totaltype',
+        product_type_id :'product_type_id',
+        product_type_name :'product_type_name',
+        introduction  :'introduction',
+        price :'price',
+        priceunit :'priceunit',
+        image :'image',
+        product_args :'product_args',
+        business :'business',
+        phase :'phase',
+        field :'field',
+        prospect :'prospect',
+        contract :'contract',
+        gxtype :'gxtype',
+        scope :'scope',
+        description :'description',
+        property:'property',
+        state :'state',
+        is_del :'is_del',
+        contact_user :'contact_user',
+        contact_tel:'contact_tel'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 37 - 0
app/controller/.protype.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      '!name',
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name: 'name',
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 49 - 0
app/controller/.tranaudit.js

@@ -0,0 +1,49 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!transaction_id',
+      '!product_id',
+      '!userid',
+      '!result',
+      'description'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'transaction_id',
+      'product_id',
+      'userid',
+      'result',
+      'description'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        transaction_id : 'transaction_id',
+        product_id :'product_id',
+        userid :'userid',
+        result :'result',
+        description :'description'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 49 - 0
app/controller/.transaction.js

@@ -0,0 +1,49 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!product_id',
+      '!userid',
+      '!market_userid',
+      'description',
+      '!status'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'product_id',
+      'userid',
+      'market_userid',
+      'description',
+      'status'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        product_id :'product_id',
+        userid :'userid',
+        market_userid :'!market_userid',
+        status :'!status',
+        description :'description'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 103 - 0
app/controller/.user.js

@@ -0,0 +1,103 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+      '!password',
+      'cardnumber',
+      'phone',
+      'email',
+      'addr',
+      'img_path',
+      'is_qy',
+      'cardfile_a',
+      'cardfile_b',
+      'img_qy',
+      'resume',
+      'major',
+      'institution_type',
+      'institution_name',
+      'institution_code',
+      'institution_nature',
+      'office_phone',
+      'profession',
+      'status',
+      'is_del',
+      'role',
+      'token'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      '!name',
+      '!password',
+      'cardnumber',
+      'phone',
+      'email',
+      'addr',
+      'img_path',
+      'is_qy',
+      'cardfile_a',
+      'cardfile_b',
+      'img_qy',
+      'resume',
+      'major',
+      'institution_type',
+      'institution_name',
+      'institution_code',
+      'institution_nature',
+      'office_phone',
+      'profession',
+      'status',
+      'is_del',
+      'role',
+      'token'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name :'!name',
+        password :'!password',
+        cardnumber :'cardnumber',
+        phone :'phone',
+        email :'email',
+        addr :'addr',
+        img_path :'img_path',
+        is_qy :'is_qy',
+        cardfile_a :'cardfile_a',
+        cardfile_b :'cardfile_b',
+        img_qy :'img_qy',
+        resume :'resume',
+        major :'major',
+        institution_type :'institution_type',
+        institution_name :'institution_name',
+        institution_code :'institution_code',
+        institution_nature :'institution_nature',
+        office_phone :'office_phone',
+        profession:'profession',
+        status :'status',
+        is_del :'is_del',
+        role :'role',
+        token :'token'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 19 - 0
app/controller/proaudit.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.proaudit.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 产品审核表管理
+class ProauditController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.proaudit;
+  }
+
+
+}
+
+module.exports = CrudController(ProauditController, meta);

+ 19 - 0
app/controller/product.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.product.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 产品信息管理
+class ProductController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.product;
+  }
+
+
+}
+
+module.exports = CrudController(ProductController, meta);

+ 19 - 0
app/controller/protype.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.protype.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 产品类型管理
+class ProtypeController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.protype;
+  }
+
+
+}
+
+module.exports = CrudController(ProtypeController, meta);

+ 19 - 0
app/controller/tranaudit.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.tranaudit.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 产品审核表管理
+class TranauditController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.tranaudit;
+  }
+
+
+}
+
+module.exports = CrudController(TranauditController, meta);

+ 19 - 0
app/controller/transaction.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.transaction.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 交易记录表管理
+class TransactionController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.transaction;
+  }
+
+
+}
+
+module.exports = CrudController(TransactionController, meta);

+ 19 - 0
app/controller/user.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.user.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科技超市用户管理
+class UserController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.user;
+  }
+
+
+}
+
+module.exports = CrudController(UserController, meta);

+ 20 - 0
app/model/proaudit.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 产品审核表
+const ProauditSchema = {
+  product_id: { type: String, required: true, maxLength: 500 }, // 产品ID
+  userid: { type: String, required: true, maxLength: 500 }, // 审核人ID
+  result: { type: String, required: true, maxLength: 200 }, // 结果,1:通过审核 2:审核拒绝
+  description: { type: String, required: false }, // 审核说明
+};
+
+const schema = new Schema(ProauditSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Proaudit', schema, 'market_proaudit');
+};

+ 51 - 0
app/model/product.js

@@ -0,0 +1,51 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 产品图片表
+const images = new Schema({
+  url: { type: String, required: true, maxLength: 500 }, // 图片路径
+});
+
+// 产品参数表
+const args = new Schema({
+  arg_name: { type: String, required: true, maxLength: 200 }, // 参数名称
+  memo: { type: String, required: true, maxLength: 200 }, // 内容
+});
+
+// 科技超市产品表
+const ProductSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 名称
+  userid: { type: String, required: true, maxLength: 500 }, // 创建人id
+  totaltype: { type: String, required: true, maxLength: 200 }, // 总分类(0.技术 1.产品 2.服务)
+  product_type_id: { type: String, required: false, maxLength: 200 }, // 类型id
+  product_type_name: { type: String, required: false, maxLength: 200 }, // 类型名称
+  introduction: { type: String, required: false }, // 简介
+  price: { type: String, required: false, maxLength: 200 }, // 单价
+  priceunit: { type: String, required: false, maxLength: 200 }, // 单位
+  image: { type: [ images ], select: true }, // 产品图片
+  product_args: { type: [ args ], select: true }, // 产品参数
+  business: { type: String, required: false, maxLength: 200 }, // 交易方式,0-公用,1-转让,2-竞价
+  phase: { type: String, required: false, maxLength: 200 }, // 研发阶段,1-阶段成果,2-最终成果
+  field: { type: String, required: false, maxLength: 500 }, // 应用领域
+  prospect: { type: String, required: false, maxLength: 500 }, // 市场前景
+  contract: { type: String, required: false, maxLength: 500 }, // 电子合同
+  gxtype: { type: String, required: false, maxLength: 500 }, // 0-需,1-供
+  scope: { type: String, required: false, maxLength: 500 }, // 服务范围
+  description: { type: String, required: false }, // 描述
+  property: { type: String, required: false, maxLength: 500 }, // 知识产权
+  state: { type: String, required: false, maxLength: 200 }, // 状态(0:待审核 1:通过审核 2:审核拒绝)
+  is_del: { type: String, required: false, maxLength: 200 }, // 是否删除,0-否,1-是
+  contact_user: { type: String, required: false, maxLength: 200 }, // 联系人
+  contact_tel: { type: String, required: false, maxLength: 500 }, // 联系电话
+};
+
+
+const schema = new Schema(ProductSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Product', schema, 'market_product');
+};

+ 17 - 0
app/model/protype.js

@@ -0,0 +1,17 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 产品类型表
+const ProtypeSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 类别名称
+};
+
+const schema = new Schema(ProtypeSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Protype', schema, 'market_protype');
+};

+ 21 - 0
app/model/tranaudit.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 交易审核表
+const TranauditSchema = {
+  transaction_id: { type: String, required: true, maxLength: 500 }, // 交易主表ID
+  product_id: { type: String, required: true, maxLength: 500 }, // 产品ID
+  userid: { type: String, required: true, maxLength: 500 }, // 审核人ID
+  result: { type: String, required: true, maxLength: 200 }, // 结果,1:通过审核 2:审核拒绝
+  description: { type: String, required: false }, // 审核说明
+};
+
+const schema = new Schema(TranauditSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Tranaudit', schema, 'market_tranaudit');
+};

+ 20 - 0
app/model/transaction.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 交易记录表
+const TransactionSchema = {
+  userid: { type: String, required: true, maxLength: 500 }, // 购买人ID
+  product_id: { type: String, required: true, maxLength: 500 }, // 产品ID
+  market_userid: { type: String, required: true, maxLength: 500 }, // 营销人ID
+  description: { type: String, required: false, maxLength: 500 }, // 说明
+  status: { type: String, required: true, maxLength: 500 }, // 交易状态,0-发起交易,1-交易中,2-交易成功,3-交易取消
+};
+const schema = new Schema(TransactionSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Transaction', schema, 'market_transaction');
+};

+ 41 - 0
app/model/user.js

@@ -0,0 +1,41 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+
+// 科技超市用户表
+const UserSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 用户名
+  password: { type: Secret, select: false }, // 登录密码
+  cardnumber: { type: String, required: false, maxLength: 500 }, // 身份证号
+  phone: { type: String, required: false, maxLength: 200 }, // 电话号码
+  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  addr: { type: String, required: false, maxLength: 500 }, // 地址
+  img_path: { type: String, required: false }, // 头像图片
+  is_qy: { type: String, required: false, maxLength: 500 }, // 个人或法人,0-个人1-法人
+  cardfile_a: { type: String, required: false }, // 身份证正面
+  cardfile_b: { type: String, required: false }, // 身份证背面
+  img_qy: { type: String, required: false }, // 组织机构图片
+  resume: { type: String, required: false }, // 个人简介
+  major: { type: String, required: false }, // 专业领域
+  institution_type: { type: String, required: false, maxLength: 500 }, // 机构类型
+  institution_name: { type: String, required: false, maxLength: 500 }, // 机构名称
+  institution_code: { type: String, required: false, maxLength: 500 }, // 机构代码
+  institution_nature: { type: String, required: false, maxLength: 500 }, // 机构性质
+  office_phone: { type: String, required: false, maxLength: 500 }, // 办公电话
+  profession: { type: String, required: false, maxLength: 500 }, // 所属行业
+  status: { type: String, required: false, maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
+  is_del: { type: String, required: false, maxLength: 200 }, // 是否删除,0-否,1-是
+  role: { type: String, required: false, maxLength: 200 }, // 1-管理员,2-个人,3-企业管理员
+  token: { type: String, required: false, maxLength: 500 }, // 令牌
+};
+
+
+const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('User', schema, 'market_user');
+};

+ 24 - 0
app/router.js

@@ -6,4 +6,28 @@
 module.exports = app => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
+
+  // 科技超市用户表设置路由
+  router.resources('user', '/api/market/user', controller.user); // index、create、show、destroy
+  router.post('user', '/api/market/user/update/:id', controller.user.update);
+
+  // 产品信息表设置路由
+  router.resources('product', '/api/market/product', controller.product); // index、create、show、destroy
+  router.post('product', '/api/market/product/update/:id', controller.product.update);
+
+  // 产品类型表设置路由
+  router.resources('protype', '/api/market/protype', controller.protype); // index、create、show、destroy
+  router.post('protype', '/api/market/protype/update/:id', controller.protype.update);
+
+  // 产品审核表设置路由
+  router.resources('proaudit', '/api/market/proaudit', controller.proaudit); // index、create、show、destroy
+  router.post('proaudit', '/api/market/proaudit/update/:id', controller.proaudit.update);
+
+  // 交易记录表设置路由
+  router.resources('transaction', '/api/market/transaction', controller.transaction); // index、create、show、destroy
+  router.post('transaction', '/api/market/transaction/update/:id', controller.transaction.update);
+
+  // 交易审核表设置路由
+  router.resources('tranaudit', '/api/market/tranaudit', controller.tranaudit); // index、create、show、destroy
+  router.post('tranaudit', '/api/market/tranaudit/update/:id', controller.tranaudit.update);
 };

+ 18 - 0
app/service/proaudit.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class ProauditService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'proaudit');
+    this.model = this.ctx.model.Proaudit;
+  }
+
+}
+
+module.exports = ProauditService;

+ 17 - 0
app/service/product.js

@@ -0,0 +1,17 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+
+class ProductService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'product');
+    this.model = this.ctx.model.Product;
+  }
+}
+
+module.exports = ProductService;

+ 18 - 0
app/service/protype.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class ProtypeService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'protype');
+    this.model = this.ctx.model.Protype;
+  }
+
+}
+
+module.exports = ProtypeService;

+ 18 - 0
app/service/tranaudit.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class TranauditService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'tranaudit');
+    this.model = this.ctx.model.Tranaudit;
+  }
+
+}
+
+module.exports = TranauditService;

+ 18 - 0
app/service/transaction.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class TransactionService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'transaction');
+    this.model = this.ctx.model.Transaction;
+  }
+
+}
+
+module.exports = TransactionService;

+ 59 - 0
app/service/user.js

@@ -0,0 +1,59 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class UserService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'user');
+    this.model = this.ctx.model.User;
+  }
+
+  async create(data) {
+    const { name,password } = data;
+    assert(name, '用户名不能为空');
+    assert(password, '密码不能为空');
+    const newdata = data;
+    newdata.password = { secret: password };
+    return await this.model.create(newdata);
+  }
+
+  async update({id},data) {
+    const user=await this.model.findById(id);
+    if (data.name) {
+      user.name = data.name;
+    }
+    if (data.password) {
+      user.password = { secret: data.password };
+    }
+    user.cardnumber = data.cardnumber;
+    user.phone = data.phone;
+    user.email = data.email;
+    user.addr = data.addr;
+    user.img_path = data.img_path;
+    user.is_qy = data.is_qy;
+    user.cardfile_a = data.cardfile_a;
+    user.cardfile_b = data.cardfile_b;
+    user.img_qy = data.img_qy;
+    user.resume = data.resume;
+    user.major = data.major;
+    user.institution_type = data.institution_type;
+    user.institution_name = data.institution_name;
+    user.institution_code = data.institution_code;
+    user.institution_nature = data.institution_nature;
+    user.office_phone = data.office_phone;
+    user.profession = data.profession;
+    user.status = data.status;
+    user.is_del = data.is_del;
+    user.role = data.role;
+    user.token = data.token;
+
+    return await user.save();
+  }
+}
+
+module.exports = UserService;

+ 14 - 0
appveyor.yml

@@ -0,0 +1,14 @@
+environment:
+  matrix:
+    - nodejs_version: '10'
+
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm i npminstall && node_modules\.bin\npminstall
+
+test_script:
+  - node --version
+  - npm --version
+  - npm run test
+
+build: off

+ 1 - 1
config/config.default.js

@@ -31,7 +31,7 @@ module.exports = appInfo => {
   };
 
   config.mongoose = {
-    url: 'mongodb://localhost:27017/market',
+    url: 'mongodb://localhost:27017/platform',
     options: {
       user: 'demo',
       pass: 'demo',

+ 1 - 1
config/config.local.js

@@ -9,7 +9,7 @@ module.exports = () => {
   };
 
   config.mongoose = {
-    url: 'mongodb://localhost:27017/market',
+    url: 'mongodb://localhost:27017/platform',
     options: {
       user: 'demo',
       pass: 'demo',