瀏覽代碼

添加商城字段

asd123a20 2 年之前
父節點
當前提交
df079a05cd
共有 2 個文件被更改,包括 7 次插入4 次删除
  1. 2 0
      service-market/app/model/market.js
  2. 5 4
      service-market/app/service/market.js

+ 2 - 0
service-market/app/model/market.js

@@ -13,6 +13,8 @@ const SchemaDefine = {
   money: { type: Number, required: true },
   // 积分
   integral: { type: Number, required: true },
+  // 图片
+  thumbnail: { type: String, required: true },
 };
 const schema = new Schema(SchemaDefine);
 module.exports = app => {

+ 5 - 4
service-market/app/service/market.js

@@ -7,23 +7,24 @@ class MarketService extends Service {
     super(ctx);
     this.model = this.ctx.model.Market;
   }
-  async create({ name, type, bindId, status, money, integral }) {
+  async create({ name, type, bindId, status, money, integral, thumbnail }) {
     assert(name, '商品名称不存在');
     assert(type, '商品类型不存在');
     assert(bindId, '货品ID不存在');
     assert(status, '商品状态不存在');
     assert(money, '价格不存在');
+    assert(thumbnail, '图片不存在');
     try {
-      const res = await this.model.create({ name, type, bindId, status, money, integral });
+      const res = await this.model.create({ name, type, bindId, status, money, integral, thumbnail });
       return { errcode: 0, errmsg: 'ok', data: res };
     } catch (error) {
       throw error;
     }
   }
-  async update({ id, name, type, bindId, status, money, integral }) {
+  async update({ id, name, type, bindId, status, money, integral, thumbnail }) {
     assert(id, 'id不存在');
     try {
-      await this.model.updateOne({ _id: id }, { name, type, bindId, status, money, integral });
+      await this.model.updateOne({ _id: id }, { name, type, bindId, status, money, integral, thumbnail });
       return { errcode: 0, errmsg: 'ok', data: '' };
     } catch (error) {
       throw error;