|
@@ -16,6 +16,7 @@ class AfterSaleService extends CrudService {
|
|
this.orderModel = this.ctx.model.Trade.Order;
|
|
this.orderModel = this.ctx.model.Trade.Order;
|
|
this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
|
|
this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
|
|
this.configModel = this.ctx.model.System.Config;
|
|
this.configModel = this.ctx.model.System.Config;
|
|
|
|
+ this.orderDetailService = this.ctx.service.util.orderDetail;
|
|
this.tran = new Transaction();
|
|
this.tran = new Transaction();
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -29,19 +30,31 @@ class AfterSaleService extends CrudService {
|
|
* @param {Object} body 售后信息
|
|
* @param {Object} body 售后信息
|
|
*/
|
|
*/
|
|
async create(body) {
|
|
async create(body) {
|
|
- const { order_detail, goods: goods_id, type, ...others } = body;
|
|
|
|
|
|
+ const { order_detail, goods: goods_id, set_id, type, ...others } = body;
|
|
if (!order_detail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
|
|
if (!order_detail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
|
|
const orderDetail = await this.orderDetailModel.findById(order_detail);
|
|
const orderDetail = await this.orderDetailModel.findById(order_detail);
|
|
if (!orderDetail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
|
|
if (!orderDetail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
|
|
// 查看该商品是否已经申请售后
|
|
// 查看该商品是否已经申请售后
|
|
let goods;
|
|
let goods;
|
|
- const hasData = await this.model.count({ order_detail, 'goods._id': goods_id, status: { $nin: [ '!1', '!2', '!3', '!4', '!5' ] } });
|
|
|
|
- if (hasData > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该商品已有正在处理中的售后申请.请勿重复申请');
|
|
|
|
|
|
+ const aData = await this.model.findOne({ order_detail, set_id, 'goods._id': goods_id, status: { $nin: [ '!1', '!2', '!3', '!4', '!5' ] } });
|
|
|
|
+ if (aData) throw new BusinessError(ErrorCode.DATA_EXISTED, '该商品已有正在处理中的售后申请.请勿重复申请');
|
|
if (type !== '4' && type !== '5') {
|
|
if (type !== '4' && type !== '5') {
|
|
const { goods: goodsList } = orderDetail;
|
|
const { goods: goodsList } = orderDetail;
|
|
goods = goodsList.find(f => {
|
|
goods = goodsList.find(f => {
|
|
- return ObjectId(f._id).equals(goods_id);
|
|
|
|
|
|
+ const { is_set = '1' } = f;
|
|
|
|
+ if (!set_id && is_set === '1') return ObjectId(f._id).equals(goods_id);
|
|
|
|
+ return set_id === f.set_id;
|
|
});
|
|
});
|
|
|
|
+ // 套装的数据处理
|
|
|
|
+ if (set_id && _.get(goods, 'set_id') === set_id) {
|
|
|
|
+ const setData = goods.goods.find(f => _.get(f, 'spec._id') === goods_id);
|
|
|
|
+ if (setData) {
|
|
|
|
+ const { spec, goods: sg } = setData;
|
|
|
|
+ const newGoods = { ...spec, goods: sg };
|
|
|
|
+ goods = newGoods;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未在当前订单中搜索到要售后的商品');
|
|
if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未在当前订单中搜索到要售后的商品');
|
|
} else {
|
|
} else {
|
|
const realPay = await this.ctx.service.util.orderDetail.computedRealPay(orderDetail);
|
|
const realPay = await this.ctx.service.util.orderDetail.computedRealPay(orderDetail);
|
|
@@ -50,7 +63,8 @@ class AfterSaleService extends CrudService {
|
|
}
|
|
}
|
|
const { shop, customer } = orderDetail;
|
|
const { shop, customer } = orderDetail;
|
|
const apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
const apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
- const obj = { order_detail, customer, shop, goods, type, ...others, apply_time, status: '0' };
|
|
|
|
|
|
+ this.orderDetailService.turn$numberDecimalToNumber(goods);
|
|
|
|
+ const obj = { order_detail, customer, shop, goods, type, ...others, apply_time, status: '0', set_id };
|
|
const res = await this.model.create(obj);
|
|
const res = await this.model.create(obj);
|
|
const msgData = { source_id: res._id, type: '0' };
|
|
const msgData = { source_id: res._id, type: '0' };
|
|
try {
|
|
try {
|
|
@@ -184,9 +198,7 @@ class AfterSaleService extends CrudService {
|
|
// 取出订单详情的每种商品规格的价格明细
|
|
// 取出订单详情的每种商品规格的价格明细
|
|
const moneyDetail = this.ctx.service.util.orderDetail.moneyDetail(orderDetail);
|
|
const moneyDetail = this.ctx.service.util.orderDetail.moneyDetail(orderDetail);
|
|
// 根据订单类型使用价格的key
|
|
// 根据订单类型使用价格的key
|
|
- let priceKey;
|
|
|
|
- if (_.get(orderDetail, 'type', '0') === '1') priceKey = 'ggrp';
|
|
|
|
- else priceKey = 'grp';
|
|
|
|
|
|
+ const priceKey = 'grp';
|
|
// 商品实际支付的金额
|
|
// 商品实际支付的金额
|
|
const goodsRealPay = _.get(moneyDetail, `${goods._id}.${priceKey}`);
|
|
const goodsRealPay = _.get(moneyDetail, `${goods._id}.${priceKey}`);
|
|
// 需要退还的金额,如果传来的数据有金额,就使用传来的,没有的话就用原来的
|
|
// 需要退还的金额,如果传来的数据有金额,就使用传来的,没有的话就用原来的
|
|
@@ -387,7 +399,7 @@ class AfterSaleService extends CrudService {
|
|
* 计算商品退货的金额最大值
|
|
* 计算商品退货的金额最大值
|
|
* @param {Object} body 参数体
|
|
* @param {Object} body 参数体
|
|
* @param body.order_detail 订单详情id
|
|
* @param body.order_detail 订单详情id
|
|
- * @param body.goods_id 商品id
|
|
|
|
|
|
+ * @param body.goods_id 商品id/套装id
|
|
*/
|
|
*/
|
|
async computedGoodsForRefund({ order_detail, goods_id }) {
|
|
async computedGoodsForRefund({ order_detail, goods_id }) {
|
|
const orderDetail = await this.orderDetailModel.findById(order_detail);
|
|
const orderDetail = await this.orderDetailModel.findById(order_detail);
|
|
@@ -395,13 +407,8 @@ class AfterSaleService extends CrudService {
|
|
const moneyDetail = this.ctx.service.util.orderDetail.moneyDetail(orderDetail);
|
|
const moneyDetail = this.ctx.service.util.orderDetail.moneyDetail(orderDetail);
|
|
const gmd = _.get(moneyDetail, goods_id);
|
|
const gmd = _.get(moneyDetail, goods_id);
|
|
const obj = {};
|
|
const obj = {};
|
|
- if (_.get(orderDetail, 'type', '0') === '1') {
|
|
|
|
- obj.payTotal = _.get(gmd, 'ggrp');
|
|
|
|
- obj.goodsTotal = _.get(gmd, 'gst');
|
|
|
|
- } else {
|
|
|
|
- obj.payTotal = _.get(gmd, 'grp');
|
|
|
|
- obj.goodsTotal = _.get(gmd, 'st');
|
|
|
|
- }
|
|
|
|
|
|
+ obj.payTotal = _.get(gmd, 'grp');
|
|
|
|
+ obj.goodsTotal = _.get(gmd, 'st');
|
|
obj.freightTotal = _.get(gmd, 'ft');
|
|
obj.freightTotal = _.get(gmd, 'ft');
|
|
obj.discountTotal = _.get(gmd, 'dt');
|
|
obj.discountTotal = _.get(gmd, 'dt');
|
|
return obj;
|
|
return obj;
|