guhongwei преди 4 години
родител
ревизия
3255faa7c8
променени са 2 файла, в които са добавени 23 реда и са изтрити 7 реда
  1. 17 1
      app/service/user.js
  2. 6 6
      config/config.default.js

+ 17 - 1
app/service/user.js

@@ -7,6 +7,22 @@ const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const jwt = require('jsonwebtoken');
 
+
+
+const mongoose = require('mongose')
+ 
+mongoose.connect('mongodb://localhost/platform') //第一步,建立与shop数据库的连接
+ 
+var Schema = mongoose.Schema;//第二步,通过mongoose的Schema实例化一个集合对象
+ 
+const goodsSchema = new Schema({
+  categoryId: Number,//种类
+  characteristic: String,//描述
+  dateAdd: String,//上架时间
+}
+ 
+const Product = mongoose.model('product',goodsSchema);//第三步,返回数据库模型,会自动对应数据库中名字为 product 的表
+
 class UserService extends CrudService {
   constructor(ctx) {
     super(ctx, 'user');
@@ -182,7 +198,7 @@ class UserService extends CrudService {
   async delete({ id }) {
     const res = await this.model.update({ _id: ObjectId(id) }, { isdel: '1' });
     if (res) {
-      const arr = await this.ctx.app.config.axios.model.product.updateMany({ userid: ObjectId(id) }, { isdel: '1' });
+      const arr = await Product.update({ userid: id }, { isdel: '1' });
       if (arr) {
         return arr;
       }

+ 6 - 6
config/config.default.js

@@ -32,12 +32,12 @@ module.exports = appInfo => {
     },
   };
   // axios service config
-  config.axios = {
-    product: {
-      // 产品
-      baseUrl: 'http://localhost:9004/api/market/product',
-    },
-  };
+  // config.axios = {
+  //   product: {
+  //     // 产品
+  //     baseUrl: 'http://localhost:9004/api/market/product',
+  //   },
+  // };
 
   config.wxapi = {
     appid: 'wxdf3ed83c095be97a', // 微信公众号APPID