12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- //
- class OrderService extends CrudService {
- constructor(ctx) {
- super(ctx, 'order');
- this.model = this.ctx.model.Trade.Order;
- this.goodsModel = this.ctx.model.Shop.Goods;
- this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
- this.addressModel = this.ctx.model.User.Address;
- }
- /**
- * 从购物车页进入下单页面
- * @param {Object} body 请求参数
- */
- async fromCartToOrder(body) {}
- /**
- * 从商品页直接购买进入下单页
- * @param {Object} body 请求参数
- * @param body.goods_id 商品id
- * @param body.goodsSpec_id 商品规格id
- * @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 });
- if (!result) throw new BusinessError(ErrorCode.SERVICE_FAULT, msg);
- // 组装页面的数据
- const user = this.ctx.user;
- const customer = _.get(user, '_id');
- if (!customer) throw new BusinessError(ErrorCode.NOT_LOGIN, '未找到用户信息');
- // 找到默认地址
- const address = await this.addressModel.findOne({ customer, is_default: '1' });
- // 组装商品数据
- // TODO 优惠券列表 及 其他优惠
- }
- }
- module.exports = OrderService;
|