lrf 2 years ago
parent
commit
379ae90dfb

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

@@ -42,4 +42,7 @@ module.exports = {
   checkCanBuy: {
   checkCanBuy: {
     requestBody: ['!shop', '!goods', '!num'],
     requestBody: ['!shop', '!goods', '!num'],
   },
   },
+  toMakeOrder: {
+    requestBody: ['!key'],
+  },
 };
 };

+ 29 - 0
app/model/base/address.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 收货地址
+const address = {
+  customer: { type: String, required: false, zh: '顾客', ref: 'User.User' }, //
+  name: { type: String, required: false, zh: '收货人' }, //
+  phone: { type: String, required: false, zh: '收货人联系电话' }, //
+  province: { type: String, required: false, zh: '省份' }, //
+  city: { type: String, required: false, zh: '市' }, //
+  area: { type: String, required: false, zh: '区' }, //
+  address: { type: String, required: false, zh: '详细地址' }, //
+  is_default: { type: String, required: false, default: '0', zh: '是否默认' }, // 字典:is_default
+};
+const schema = new Schema(address, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ customer: 1 });
+schema.index({ name: 1 });
+schema.index({ phone: 1 });
+schema.index({ is_default: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Address', schema, 'address');
+};

+ 9 - 1
app/service/zrOrder.js

@@ -14,6 +14,7 @@ class ZrOrderService extends CrudService {
     this.goodsModel = this.ctx.model.ZrGoods;
     this.goodsModel = this.ctx.model.ZrGoods;
     this.pointModel = this.ctx.model.Base.Point;
     this.pointModel = this.ctx.model.Base.Point;
     this.shopModel = this.ctx.model.Base.Shop;
     this.shopModel = this.ctx.model.Base.Shop;
+    this.addressModel = this.ctx.model.Base.Address;
   }
   }
   // 进入订单页前,通过函数判断,存储是否可以购买 指定商品 的 指定数量
   // 进入订单页前,通过函数判断,存储是否可以购买 指定商品 的 指定数量
   // 下单,走同样的函数判断.
   // 下单,走同样的函数判断.
@@ -29,7 +30,14 @@ class ZrOrderService extends CrudService {
     const shopInfo = await this.shopModel.findById(shop);
     const shopInfo = await this.shopModel.findById(shop);
     // 商品信息
     // 商品信息
     const goodsInfo = await this.goodsModel.findById(goods);
     const goodsInfo = await this.goodsModel.findById(goods);
-    //
+    // 消耗积分
+    const costTotal = this.ctx.multiply(_.get(goodsInfo, 'cost'), buy_num);
+    // 积分信息
+    const customer = _.get(this.ctx.user, '_id');
+    const points = await this.pointComputedTotal({ customer });
+    // 地址信息
+    const address = await this.addressModel.findOne({ customer, is_default: '1' });
+    return { buy_num, shop: shopInfo, goods: goodsInfo, points, address, costTotal };
   }
   }
 
 
   /**
   /**

+ 1 - 0
app/z_router/zrOrder.js

@@ -7,6 +7,7 @@ const rkey = 'zrOrder';
 const ckey = 'zrOrder';
 const ckey = 'zrOrder';
 const keyZh = '尊荣订单';
 const keyZh = '尊荣订单';
 const routes = [
 const routes = [
+  { method: 'post', path: `${rkey}/toMakeOrder`, controller: `${ckey}.toMakeOrder`, name: `${ckey}toMakeOrder`, zh: `进入订单页面-${keyZh}` },
   { method: 'post', path: `${rkey}/checkCanBuy`, controller: `${ckey}.checkCanBuy`, name: `${ckey}checkCanBuy`, zh: `检查是否可以购买-${keyZh}` },
   { method: 'post', path: `${rkey}/checkCanBuy`, controller: `${ckey}.checkCanBuy`, name: `${ckey}checkCanBuy`, zh: `检查是否可以购买-${keyZh}` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },