|
@@ -35,11 +35,11 @@ class AfterSaleService extends CrudService {
|
|
|
if (!orderDetail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
|
|
|
// 查看该商品是否已经申请售后
|
|
|
let goods;
|
|
|
- const hasData = await this.model.count({ order_detail, 'goods._id': goods_id, status: { $nin: ['!1', '!2', '!3', '!4', '!5'] } });
|
|
|
+ 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, '该商品已有正在处理中的售后申请.请勿重复申请');
|
|
|
if (type !== '4' && type !== '5') {
|
|
|
const { goods: goodsList } = orderDetail;
|
|
|
- goods = goodsList.find((f) => {
|
|
|
+ goods = goodsList.find(f => {
|
|
|
return ObjectId(f._id).equals(goods_id);
|
|
|
});
|
|
|
if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未在当前订单中搜索到要售后的商品');
|
|
@@ -51,7 +51,14 @@ class AfterSaleService extends CrudService {
|
|
|
const { shop, customer } = orderDetail;
|
|
|
const apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
const obj = { order_detail, customer, shop, goods, type, ...others, apply_time, status: '0' };
|
|
|
- await this.model.create(obj);
|
|
|
+ const res = await this.model.create(obj);
|
|
|
+ const msgData = { source_id: res._id, type: '0' };
|
|
|
+ try {
|
|
|
+ await this.ctx.service.shop.shopNotice.remindToAfterSale(msgData);
|
|
|
+ } catch (error) {
|
|
|
+ const errobj = error;
|
|
|
+ await this.ctx.service.util.email.errorEmail(errobj);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async update(filter, update, { projection } = {}) {
|
|
@@ -219,7 +226,7 @@ class AfterSaleService extends CrudService {
|
|
|
// 已退款记录
|
|
|
const goodsRefundList = [];
|
|
|
// 在下面处理已退款记录中,应该把当前的这个售后项,作为已处理售后
|
|
|
- const tasq = { order_detail: data.order_detail, 'goods._id': _.get(data, 'goods._id'), status: ['-1', '-2'] };
|
|
|
+ const tasq = { order_detail: data.order_detail, 'goods._id': _.get(data, 'goods._id'), status: [ '-1', '-2' ] };
|
|
|
const asdd = JSON.parse(JSON.stringify(data));
|
|
|
if (_.get(update, 'money')) asdd.money = _.get(update, 'money');
|
|
|
const tr = await this.checkIsAllRefund(data);
|
|
@@ -230,7 +237,7 @@ class AfterSaleService extends CrudService {
|
|
|
const { goods, _id: order_detail } = od;
|
|
|
// 组合成查售后的条件
|
|
|
// 然后查这些商品有没有退款审核成功的记录, 且只有退全款的商品才能退券
|
|
|
- const afterSaleQuerys = goods.map((i) => ({ order_detail, 'goods._id': i._id, status: ['-1', '-2'] }));
|
|
|
+ const afterSaleQuerys = goods.map(i => ({ order_detail, 'goods._id': i._id, status: [ '-1', '-2' ] }));
|
|
|
for (const asq of afterSaleQuerys) {
|
|
|
const asd = await this.model.findOne(asq);
|
|
|
if (asd) {
|
|
@@ -246,7 +253,7 @@ class AfterSaleService extends CrudService {
|
|
|
// 该优惠券影响的商品id列表
|
|
|
const goodsIds = Object.keys(_.get(dd, uc_id, {}));
|
|
|
// 然后在已退款/退货记录中找,这个优惠券影响的商品是否都退款了.退全额
|
|
|
- const r = goodsIds.every((i) => goodsRefundList.find((f) => i === f['goods._id']));
|
|
|
+ const r = goodsIds.every(i => goodsRefundList.find(f => i === f['goods._id']));
|
|
|
if (r) {
|
|
|
// 说明这个优惠券影响的商品都退了,这个优惠券也就能退了
|
|
|
tran.update('UserCoupon', uc_id, { status: '0' });
|
|
@@ -265,15 +272,15 @@ class AfterSaleService extends CrudService {
|
|
|
// 获取拆分订单的数据,并找到商品列表
|
|
|
const goodsList = _.get(orderDetail, 'goods');
|
|
|
// 依次找这些商品是否都售后完成,都售后完成,就改订单状态
|
|
|
- const asList = await this.model.find({ order_detail, status: { $nin: ['0', '!1', '!2', '!3', '!4', '!5'] } });
|
|
|
+ const asList = await this.model.find({ order_detail, status: { $nin: [ '0', '!1', '!2', '!3', '!4', '!5' ] } });
|
|
|
let status;
|
|
|
let fl = [];
|
|
|
// 将当前数据添加进去
|
|
|
fl.push({ goods: _.get(data, 'goods._id'), status: 'finish' });
|
|
|
for (const gs of goodsList) {
|
|
|
- const r = asList.find((f) => ObjectId(_.get(f, 'goods._id')).equals(_.get(gs, '_id')));
|
|
|
+ const r = asList.find(f => ObjectId(_.get(f, 'goods._id')).equals(_.get(gs, '_id')));
|
|
|
if (r) {
|
|
|
- const finishList = ['-1', '-2', '-3', '-4', '-5'];
|
|
|
+ const finishList = [ '-1', '-2', '-3', '-4', '-5' ];
|
|
|
if (finishList.includes(r.status)) fl.push({ goods: gs._id, status: 'finish' });
|
|
|
}
|
|
|
}
|
|
@@ -321,7 +328,7 @@ class AfterSaleService extends CrudService {
|
|
|
const { goods, _id: order_detail } = od;
|
|
|
// 组合成查售后的条件
|
|
|
// 然后查这些商品有没有退款审核成功的记录, 且只有退全款的商品才能退券
|
|
|
- const afterSaleQuerys = goods.map((i) => ({ order_detail, 'goods._id': i._id, status: ['-1', '-2'] }));
|
|
|
+ const afterSaleQuerys = goods.map(i => ({ order_detail, 'goods._id': i._id, status: [ '-1', '-2' ] }));
|
|
|
for (const asq of afterSaleQuerys) {
|
|
|
const asd = await this.model.findOne(asq);
|
|
|
if (asd) {
|
|
@@ -337,7 +344,7 @@ class AfterSaleService extends CrudService {
|
|
|
// 该优惠券影响的商品id列表
|
|
|
const goodsIds = Object.keys(_.get(dd, uc_id, {}));
|
|
|
// 然后在已退款/退货记录中找,这个优惠券影响的商品是否都退款了.退全额
|
|
|
- const r = goodsIds.every((i) => goodsRefundList.find((f) => i === f['goods._id']));
|
|
|
+ const r = goodsIds.every(i => goodsRefundList.find(f => i === f['goods._id']));
|
|
|
if (r) {
|
|
|
// 说明这个优惠券影响的商品都退了,这个优惠券也就能退了
|
|
|
tran.update('UserCoupon', uc_id, { status: '0' });
|