|
@@ -22,14 +22,20 @@ class OrderService extends CrudService {
|
|
makeOrder_computedShopTotal(list) {
|
|
makeOrder_computedShopTotal(list) {
|
|
for (const i of list) {
|
|
for (const i of list) {
|
|
let goods_total = 0,
|
|
let goods_total = 0,
|
|
- freight_total = 0;
|
|
|
|
|
|
+ freight_total = 0,
|
|
|
|
+ discount = 0;
|
|
for (const g of i.goods) {
|
|
for (const g of i.goods) {
|
|
// 如果有特价,那就使用特价,没有特价就是用正常销售价
|
|
// 如果有特价,那就使用特价,没有特价就是用正常销售价
|
|
goods_total = this.ctx.plus(goods_total, _.get(g, 'price'));
|
|
goods_total = this.ctx.plus(goods_total, _.get(g, 'price'));
|
|
freight_total = this.ctx.plus(freight_total, _.get(g, 'freight'));
|
|
freight_total = this.ctx.plus(freight_total, _.get(g, 'freight'));
|
|
|
|
+ if (_.isArray(g.act)) {
|
|
|
|
+ const actDiscount = g.act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
|
|
|
|
+ discount = this.ctx.plus(discount, actDiscount);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
i.goods_total = goods_total;
|
|
i.goods_total = goods_total;
|
|
i.freight_total = freight_total;
|
|
i.freight_total = freight_total;
|
|
|
|
+ i.discount = discount;
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
@@ -39,11 +45,10 @@ class OrderService extends CrudService {
|
|
* list是经过 getPageData 处理过的数据
|
|
* list是经过 getPageData 处理过的数据
|
|
*/
|
|
*/
|
|
makerOrder_computedOrderTotal(list) {
|
|
makerOrder_computedOrderTotal(list) {
|
|
- const obj = {
|
|
|
|
- goods_total: list.reduce((p, n) => this.ctx.plus(p, n.goods_total), 0),
|
|
|
|
- freight_total: list.reduce((p, n) => this.ctx.plus(p, n.freight_total), 0),
|
|
|
|
- };
|
|
|
|
- return obj;
|
|
|
|
|
|
+ const arr = [];
|
|
|
|
+ arr.push({ key: 'goods_total', zh: '商品总价', money: list.reduce((p, n) => this.ctx.plus(p, n.goods_total), 0) });
|
|
|
|
+ arr.push({ key: 'freight_total', zh: '运费总价', money: list.reduce((p, n) => this.ctx.plus(p, n.freight_total), 0) });
|
|
|
|
+ return arr;
|
|
}
|
|
}
|
|
|
|
|
|
// #endregion
|
|
// #endregion
|
|
@@ -205,13 +210,16 @@ class OrderService extends CrudService {
|
|
*/
|
|
*/
|
|
dealAct_sp(goodsList, actList) {
|
|
dealAct_sp(goodsList, actList) {
|
|
for (const act of actList) {
|
|
for (const act of actList) {
|
|
- const { spec, sp_price } = act;
|
|
|
|
|
|
+ const { spec, sp_price, platform_act_type, platform_act } = act;
|
|
if (!spec) continue;
|
|
if (!spec) continue;
|
|
const goods = goodsList.find(f => f.goodsSpec_id === spec);
|
|
const goods = goodsList.find(f => f.goodsSpec_id === spec);
|
|
if (goods) {
|
|
if (goods) {
|
|
// 默认特价为商品金额
|
|
// 默认特价为商品金额
|
|
goods.sp_price = sp_price;
|
|
goods.sp_price = sp_price;
|
|
goods.price = sp_price;
|
|
goods.price = sp_price;
|
|
|
|
+ const { act = [] } = goods;
|
|
|
|
+ act.push({ platform_act_type, platform_act, sp_price });
|
|
|
|
+ goods.act = act;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -260,11 +268,11 @@ class OrderService extends CrudService {
|
|
const rp = this.getGoodsPayAfterAct(gia);
|
|
const rp = this.getGoodsPayAfterAct(gia);
|
|
const percent = this.ctx.divide(rp, total);
|
|
const percent = this.ctx.divide(rp, total);
|
|
const money = this.ctx.multiply(percent, discountTotal);
|
|
const money = this.ctx.multiply(percent, discountTotal);
|
|
- actResult.push({ platform_act, money, goodsSpec_id });
|
|
|
|
|
|
+ actResult.push({ platform_act, platform_act_type, discount: money, goodsSpec_id });
|
|
} else {
|
|
} else {
|
|
const allready = actResult.reduce((p, n) => this.ctx.plus(p, n.money), 0);
|
|
const allready = actResult.reduce((p, n) => this.ctx.plus(p, n.money), 0);
|
|
const el = this.ctx.minus(discountTotal, allready);
|
|
const el = this.ctx.minus(discountTotal, allready);
|
|
- actResult.push({ platform_act, money: el, goodsSpec_id });
|
|
|
|
|
|
+ actResult.push({ platform_act, platform_act_type, discount: el, goodsSpec_id });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 修改数据
|
|
// 修改数据
|
|
@@ -281,7 +289,7 @@ class OrderService extends CrudService {
|
|
const text = `满${platform_act_type === '6' ? '折' : '减'}活动`;
|
|
const text = `满${platform_act_type === '6' ? '折' : '减'}活动`;
|
|
const actData = await this.platformActModel.findById(platform_act);
|
|
const actData = await this.platformActModel.findById(platform_act);
|
|
act.title = _.get(actData, 'act_time.title', text);
|
|
act.title = _.get(actData, 'act_time.title', text);
|
|
- act.discount = actResult.reduce((p, n) => this.ctx.plus(p, n.money), 0);
|
|
|
|
|
|
+ act.discount = actResult.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -295,12 +303,12 @@ class OrderService extends CrudService {
|
|
*/
|
|
*/
|
|
async dealAct_gift(goodsList, actList) {
|
|
async dealAct_gift(goodsList, actList) {
|
|
for (const act of actList) {
|
|
for (const act of actList) {
|
|
- const { spec, gift, platform_act } = act;
|
|
|
|
|
|
+ const { spec, gift, platform_act, platform_act_type } = act;
|
|
const goodsInAct = await this.getGoodsInAct(goodsList, platform_act);
|
|
const goodsInAct = await this.getGoodsInAct(goodsList, platform_act);
|
|
const actResult = [];
|
|
const actResult = [];
|
|
for (const goods of goodsInAct) {
|
|
for (const goods of goodsInAct) {
|
|
const { goodsSpec_id } = goods;
|
|
const { goodsSpec_id } = goods;
|
|
- if (spec === goodsSpec_id) actResult.push({ platform_act, gift, goodsSpec_id });
|
|
|
|
|
|
+ if (spec === goodsSpec_id) actResult.push({ platform_act, platform_act_type, gift, goodsSpec_id });
|
|
}
|
|
}
|
|
for (const i of actResult) {
|
|
for (const i of actResult) {
|
|
const { goodsSpec_id, ...others } = i;
|
|
const { goodsSpec_id, ...others } = i;
|
|
@@ -338,7 +346,7 @@ class OrderService extends CrudService {
|
|
*/
|
|
*/
|
|
getGoodsPayAfterAct(goods) {
|
|
getGoodsPayAfterAct(goods) {
|
|
const { act = [], price } = goods;
|
|
const { act = [], price } = goods;
|
|
- const actDiscount = act.reduce((p, n) => this.ctx.plus(p, n.money), 0);
|
|
|
|
|
|
+ const actDiscount = act.reduce((p, n) => this.ctx.plus(p, n.discount), 0);
|
|
const rp = this.ctx.minus(price, actDiscount);
|
|
const rp = this.ctx.minus(price, actDiscount);
|
|
return rp;
|
|
return rp;
|
|
}
|
|
}
|