lrf 2 年之前
父節點
當前提交
9ac123145d
共有 3 個文件被更改,包括 27 次插入24 次删除
  1. 1 1
      app/controller/trade/config/.order.js
  2. 9 6
      app/service/trade/order.js
  3. 17 17
      app/service/util/trade.js

+ 1 - 1
app/controller/trade/config/.order.js

@@ -42,6 +42,6 @@ module.exports = {
     requestBody: ['!cart_ids'],
     requestBody: ['!cart_ids'],
   },
   },
   fromGoodsToOrder: {
   fromGoodsToOrder: {
-    requestBody: ['!goods_id', '!goodsSpec_id', '!num'],
+    requestBody: ['!shop', '!goods', '!goodsSpec', '!num'],
   },
   },
 };
 };

+ 9 - 6
app/service/trade/order.js

@@ -22,25 +22,28 @@ class OrderService extends CrudService {
   /**
   /**
    * 从商品页直接购买进入下单页
    * 从商品页直接购买进入下单页
    * @param {Object} body 请求参数
    * @param {Object} body 请求参数
-   * @param body.goods_id 商品id
-   * @param body.goodsSpec_id 商品规格id
+   * @param body.shop 店铺id
+   * @param body.goods 商品id
+   * @param body.goodsSpec 商品规格id
    * @param body.num 购买数量
    * @param body.num 购买数量
    */
    */
-  async fromGoodsToOrder({ goods_id, goodsSpec_id, num }) {
-    const { result, msg } = await this.ctx.service.util.trade.checkCanBuy({ goods_id, goodsSpec_id, num });
+  async fromGoodsToOrder({ shop, goods, goodsSpec, num }) {
+    const { result, msg } = await this.ctx.service.util.trade.checkCanBuy({ shop, goods, goodsSpec, num });
     if (!result) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
     if (!result) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
     // 组装页面的数据
     // 组装页面的数据
     const user = this.ctx.user;
     const user = this.ctx.user;
     const customer = _.get(user, '_id');
     const customer = _.get(user, '_id');
     if (!customer) throw new BusinessError(ErrorCode.NOT_LOGIN, '未找到用户信息');
     if (!customer) throw new BusinessError(ErrorCode.NOT_LOGIN, '未找到用户信息');
+    const data = {};
     // 找到默认地址
     // 找到默认地址
     const address = await this.addressModel.findOne({ customer, is_default: '1' });
     const address = await this.addressModel.findOne({ customer, is_default: '1' });
+    data.address = address;
     // 组装商品数据
     // 组装商品数据
-
+    const { populate } = this.ctx.service.shop.goodsSpec.getRefMods();
     // TODO 优惠券列表 及 其他优惠
     // TODO 优惠券列表 及 其他优惠
   }
   }
 
 
-
+  setOrderGoodsData() {}
 }
 }
 
 
 module.exports = OrderService;
 module.exports = OrderService;

+ 17 - 17
app/service/util/trade.js

@@ -15,54 +15,54 @@ class TradeService extends CrudService {
   /**
   /**
    * 检测是否可以购买该物品
    * 检测是否可以购买该物品
    * @param {Object} param 查询条件
    * @param {Object} param 查询条件
-   * @param param.shop_id 商店id
-   * @param param.goods_id 商品id
-   * @param param.goodsSpec_id 商品规格id
+   * @param param.shop 商店id
+   * @param param.goods 商品id
+   * @param param.goodsSpec 商品规格id
    * @param param.num 购买数量
    * @param param.num 购买数量
    */
    */
-  async checkCanBuy({ shop_id, goods_id, goodsSpec_id, num }) {
-    assert(shop_id, '缺少店铺信息');
-    assert(goods_id, '缺少商品信息');
-    assert(goodsSpec_id, '缺少商品规格信息');
+  async checkCanBuy({ shop, goods, goodsSpec, num }) {
+    assert(shop, '缺少店铺信息');
+    assert(goods, '缺少商品信息');
+    assert(goodsSpec, '缺少商品规格信息');
     assert(num, '缺少购买数量');
     assert(num, '缺少购买数量');
     const result = { result: true };
     const result = { result: true };
     // 1.检查商店是否正常运行
     // 1.检查商店是否正常运行
-    const shop = await this.shopModel.findById(shop_id);
-    if (!shop) {
+    const shopData = await this.shopModel.findById(shop);
+    if (!shopData) {
       result.msg = '未找到店铺';
       result.msg = '未找到店铺';
       result.result = false;
       result.result = false;
       return result;
       return result;
     }
     }
-    if (shop.status !== '1') {
+    if (shopData.status !== '1') {
       result.msg = '店铺不处于营业状态';
       result.msg = '店铺不处于营业状态';
       result.result = false;
       result.result = false;
       return result;
       return result;
     }
     }
     // 2.检查商品是否可以购买
     // 2.检查商品是否可以购买
-    const goods = await this.goodsModel.findById(goods_id);
-    if (!goods) {
+    const goodsData = await this.goodsModel.findById(goods);
+    if (!goodsData) {
       result.msg = '未找到商品';
       result.msg = '未找到商品';
       result.result = false;
       result.result = false;
       return result;
       return result;
     }
     }
-    if (goods.status === '0') {
+    if (goodsData.status === '0') {
       result.msg = '该商品已下架';
       result.msg = '该商品已下架';
       result.result = false;
       result.result = false;
       return result;
       return result;
     }
     }
     // 3.检验该规格是否可以购买
     // 3.检验该规格是否可以购买
-    const goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
-    if (!goodsSpec) {
+    const goodsSpecData = await this.goodsSpecModel.findById(goodsSpec);
+    if (!goodsSpecData) {
       result.msg = '未找到商品的指定规格';
       result.msg = '未找到商品的指定规格';
       result.result = false;
       result.result = false;
       return result;
       return result;
     }
     }
-    if (goods.status !== '0') {
+    if (goodsSpecData.status !== '0') {
       result.msg = '该规格的商品已下架';
       result.msg = '该规格的商品已下架';
       result.result = false;
       result.result = false;
       return result;
       return result;
     }
     }
-    if (goods.num < num) {
+    if (goodsSpecData.num < num) {
       result.msg = '库存量不足';
       result.msg = '库存量不足';
       result.result = false;
       result.result = false;
       return result;
       return result;