Commit a314c3c7 by caiyt

订单明细拆分功能实现

parent c6bee18d
......@@ -52,6 +52,7 @@ public class AppController extends BaseController {
startPage();
List<Order> myOrder = orderService.getMyOrder(openId);
orderService.wrapperOrder(myOrder, true);
myOrder.forEach(order -> orderService.wrapperOrderDetailForApplet(order));
return getDataTable(myOrder);
}
......@@ -77,7 +78,7 @@ public class AppController extends BaseController {
for(int i =0;i<goods.size();i++){
OrderDetail orderDetail = new OrderDetail();
orderDetail.setGoodsId(goods.getJSONObject(i).getLong("goodsId"));
orderDetail.setNum(goods.getJSONObject(i).getString("num"));
orderDetail.setNum(goods.getJSONObject(i).getInteger("num"));
orderDetails.add(orderDetail);
}
String info = orderService.getWaitTime(order);
......
......@@ -67,10 +67,21 @@ public class OrderController extends BaseController {
/**
* 获取订单详细信息
* 获取订单详细信息,供小程序使用
*/
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
public AjaxResult getOrderDetailForApplet(@PathVariable("id") Long id) {
Order order = orderService.selectOrderById(id);
goodsService.resolverGoodsOfOrder(order);
orderService.wrapperOrderDetailForApplet(order);
return AjaxResult.success(order);
}
/**
* 获取订单详细信息,供后台使用
*/
@GetMapping(value = "/back/{id}")
public AjaxResult getOrderDetailForBack(@PathVariable("id") Long id) {
Order order = orderService.selectOrderById(id);
goodsService.resolverGoodsOfOrder(order);
return AjaxResult.success(order);
......@@ -194,14 +205,4 @@ public class OrderController extends BaseController {
public AjaxResult cancel(Long orderId) {
return toAjax(orderService.cancel(orderId));
}
@GetMapping("/init/{id}")
public AjaxResult initPickCode(@PathVariable Long id) {
Order order = orderService.selectById(id);
Assert.notNull(order, "order not exists");
String pickCode = weixinService.generatePickCode(order);
order.setPickCode(pickCode);
orderService.updateById(order);
return AjaxResult.success();
}
}
......@@ -35,7 +35,7 @@ public class MachineSericeImpl {
JSONObject jsonObject = new JSONObject();
jsonObjects.add(jsonObject);
Long skuId = detail.getSkuId();
String num = detail.getNum();
Integer num = detail.getNum();
String amount = detail.getOriAmount().stripTrailingZeros().toString();
String realAmount = detail.getRealAmount().stripTrailingZeros().toString();
jsonObject.put("skuID",skuId);
......
......@@ -52,7 +52,7 @@ public class OrderDetail {
* 数量
*/
@Excel(name = "数量")
private String num;
private Integer num;
/**
* 单价
......
......@@ -41,15 +41,20 @@ public interface OrderDetailMapper {
/**
* 新增订单详情
*
*
* @param orderDetail 订单详情
* @return 结果
*/
public int insertOrderDetail(OrderDetail orderDetail);
/**
* 批量插入
*/
int insertBatch(@Param("details") List<OrderDetail> details);
/**
* 修改订单详情
*
*
* @param orderDetail 订单详情
* @return 结果
*/
......
......@@ -58,5 +58,7 @@ public interface IOrderService
void wrapperOrder(List<Order> orders, boolean snapshotFlag);
void wrapperOrderDetailForApplet(Order order);
int cancel(Long orderId);
}
......@@ -109,13 +109,9 @@ public class GoodsServiceImpl implements IGoodsService {
/** 销量解析 */
List<Long> goodsIds = goodsList.stream().map(Goods::getId).collect(Collectors.toList());
List<OrderDetail> orderDetails = orderDetailMapper.selectGoodsSalesVolume(shopId, goodsIds);
Map<Long, String> goodsVolumeMap = orderDetails.stream().collect(Collectors.toMap(OrderDetail::getGoodsId, OrderDetail::getNum));
Map<Long, Integer> goodsVolumeMap = orderDetails.stream().collect(Collectors.toMap(OrderDetail::getGoodsId, OrderDetail::getNum));
goodsList.forEach(goods -> {
String volumeVal = goodsVolumeMap.get(goods.getId());
Integer volume = StringUtils.isNotEmpty(volumeVal) ? Integer.parseInt(volumeVal) : 0;
goods.setSalesVolume(volume);
});
goodsList.forEach(goods -> goods.setSalesVolume(goodsVolumeMap.containsKey(goods.getId()) ? goodsVolumeMap.get(goods.getId()) : 0));
}
@Override
......
......@@ -183,11 +183,11 @@ public class MachineApiServiceImpl {
JSONObject jsonObject = new JSONObject();
goodsList.add(jsonObject);
jsonObject.put("goodsId", detail.getGoodsId());
jsonObject.put("goodsName",detail.getGoodsName());
jsonObject.put("num",Integer.parseInt(detail.getNum()));
jsonObject.put("amount",detail.getOriAmount());
jsonObject.put("specRuleDetail",detail.getSpecRuleDetail());
jsonObject.put("specRuleIds",detail.getSpecRuleIds());
jsonObject.put("goodsName", detail.getGoodsName());
jsonObject.put("num", detail.getNum());
jsonObject.put("amount", detail.getOriAmount());
jsonObject.put("specRuleDetail", detail.getSpecRuleDetail());
jsonObject.put("specRuleIds", detail.getSpecRuleIds());
jsonObject.put("skuId", detail.getSkuId());
// if("0".equals(detail.getGoodsCategory())){
// jsonObject.put("goodsCategory","今日特惠");
......
......@@ -17,13 +17,13 @@ import com.soss.system.domain.vo.orderTaking.CategoryVo;
import com.soss.system.domain.vo.orderTaking.GoodsVo;
import com.soss.system.domain.vo.orderTaking.OrderTakingVo;
import com.soss.system.domain.vo.orderTaking.SkuVo;
import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
import com.soss.system.mapper.*;
import com.soss.system.service.IOrderService;
import com.soss.system.utils.DistanceUtil;
import com.soss.system.utils.SendSmsUtil;
import com.soss.system.weixin.util.SendMessageUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
......@@ -69,8 +69,6 @@ public class OrderServiceImpl implements IOrderService {
@Autowired
private OrderSnapshotServiceImpl orderSnapshotService;
@Autowired
private JiGuangPushServiceImpl jiGuangPushService;
@Autowired
private WechatMessageServiceImpl wechatMessageService;
@Autowired
private SendMessageUtils sendMessageUtils;
......@@ -94,12 +92,12 @@ public class OrderServiceImpl implements IOrderService {
order.setShop(shopMapper.selectShopById(order.getShopId()));
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
String snapshot = orderSnapshot.getSnapshot();
List<OrderDetail> orderDetails1 = JSONObject.parseArray(snapshot, OrderDetail.class);
List<Long> detailIds = orderDetails1.stream().map(OrderDetail::getId).collect(Collectors.toList());
List<OrderDetail> orderDetails = JSONObject.parseArray(snapshot, OrderDetail.class);
List<Long> detailIds = orderDetails.stream().map(OrderDetail::getId).collect(Collectors.toList());
List<OrderDetail> detailsActual = orderDetailMapper.selectOrderDetailsByIds(detailIds);
Map<Long, Long> refundIdMap = detailsActual.stream().filter(da -> da.getRefundId() != null).collect(Collectors.toMap(OrderDetail::getId, OrderDetail::getRefundId));
orderDetails1.forEach(od -> od.setRefundId(refundIdMap.get(od.getId())));
order.setOrderDetails(orderDetails1);
orderDetails.forEach(od -> od.setRefundId(refundIdMap.get(od.getId())));
order.setOrderDetails(orderDetails);
return order;
}
......@@ -119,12 +117,17 @@ public class OrderServiceImpl implements IOrderService {
*/
@Override
public List<Order> selectOrderList(OrderQuery order) {
if (StringUtils.isNotEmpty(order.getCreateAtEnd())) {
order.setCreateAtEnd(order.getCreateAtEnd() + " 23:59:59");
}
if (StringUtils.isNotEmpty(order.getPayAtEnd())) {
order.setPayAtEnd(order.getPayAtEnd() + " 23:59:59");
}
return orderMapper.selectOrderByQuery(order);
}
public List<Order> selectOrderList(Order order) {
List<Order> orders = orderMapper.selectOrderList(order);
return orders;
}
......@@ -169,17 +172,40 @@ public class OrderServiceImpl implements IOrderService {
}
orderMapper.insertOrder(order);
List<OrderDetail> orderDetails = order.getOrderDetails();
List<OrderDetail> detailsSave = new LinkedList<>();
for (OrderDetail orderDetail : orderDetails) {
orderDetail.setOrderId(order.getId());
orderDetail.setCreatedAt(new Date());
orderDetail.setUpdatedAt(new Date());
orderDetail.setMachineId(machineId);
orderDetail.setNum("1");
for (int i = 0; i < Integer.parseInt(orderDetail.getNum()); i++) {
orderDetailMapper.insertOrderDetail(orderDetail);
BigDecimal amountShould = orderDetail.getAmountShould();
BigDecimal couponAmount = orderDetail.getCouponAmount();
BigDecimal realAmount = orderDetail.getRealAmount();
BigDecimal amountShouldUnit = amountShould.divide(new BigDecimal(orderDetail.getNum()), 2, BigDecimal.ROUND_HALF_UP);
orderDetail.setAmountShould(amountShouldUnit);
BigDecimal couponAmountUnit = couponAmount.divide(new BigDecimal(orderDetail.getNum()), 2, BigDecimal.ROUND_HALF_UP);
orderDetail.setCouponAmount(couponAmountUnit);
BigDecimal realAmountUnit = realAmount.divide(new BigDecimal(orderDetail.getNum()), 2, BigDecimal.ROUND_HALF_UP);
orderDetail.setRealAmount(realAmountUnit);
int skuNum = orderDetail.getNum();
for (int i = 1; i <= skuNum; i++) {
if (i == orderDetail.getNum()) {
OrderDetail orderDetailLst = new OrderDetail();
BeanUtils.copyProperties(orderDetail, orderDetailLst);
orderDetailLst.setAmountShould(amountShould.subtract(amountShouldUnit.multiply(new BigDecimal(i - 1))));
orderDetailLst.setCouponAmount(couponAmount.subtract(couponAmountUnit.multiply(new BigDecimal(i - 1))));
orderDetailLst.setRealAmount(realAmount.subtract(realAmountUnit.multiply(new BigDecimal(i - 1))));
detailsSave.add(orderDetailLst);
} else {
orderDetail.setNum(1);
detailsSave.add(orderDetail);
}
}
}
order.setOrderDetails(detailsSave);
orderDetailMapper.insertBatch(detailsSave);
// 更新用户的优惠券状态
if (couponUserId != null) {
......@@ -451,6 +477,24 @@ public class OrderServiceImpl implements IOrderService {
}
@Override
public void wrapperOrderDetailForApplet(Order order) {
Map<Long, List<OrderDetail>> orderDetailSkuMap = order.getOrderDetails().stream()
.collect(Collectors.groupingBy(OrderDetail::getSkuId, Collectors.toList()));
List<OrderDetail> orderDetails = new ArrayList<>();
for (List<OrderDetail> mapVal : orderDetailSkuMap.values()) {
OrderDetail detail = mapVal.get(0);
if (mapVal.size() > 1) {
detail.setAmountShould(mapVal.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add));
detail.setCouponAmount(mapVal.stream().map(OrderDetail::getCouponAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
detail.setRealAmount(mapVal.stream().map(OrderDetail::getRealAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
detail.setNum(mapVal.size());
}
orderDetails.add(detail);
}
order.setOrderDetails(orderDetails);
}
@Override
@Transactional
public int cancel(Long orderId) {
Order order = orderMapper.selectOrderById(orderId);
......@@ -604,7 +648,7 @@ public class OrderServiceImpl implements IOrderService {
continue;
}
Long takeTime = goods.getTakeTime();
takeTime = Integer.parseInt(orderDetail.getNum()) * takeTime;
takeTime = orderDetail.getNum() * takeTime;
takeTimeCount += takeTime;
}
......@@ -631,13 +675,12 @@ public class OrderServiceImpl implements IOrderService {
Goods goods = goodsMapper.selectGoodsById(orderDetail.getGoodsId());
if (goods != null) {
Long takeTime = goods.getTakeTime();
takeTime = Integer.parseInt(orderDetail.getNum()) * takeTime;
takeTime = orderDetail.getNum() * takeTime;
takeTimeCount += takeTime;
}
}
return String.valueOf((int) (takeTimeCount / 60));
}
......
......@@ -115,6 +115,19 @@
</trim>
</insert>
<insert id="insertBatch">
INSERT INTO order_detail ( order_id, goods_id, goods_name, machine_id, num, unit_price, ori_amount,
amount_should, coupon_amount, real_amount, spec_rule_detail, spec_rule_ids, sku_id, goods_category, created_at,
refund_id, refund_time, updated_at ) VALUES
<foreach collection="details" separator="," item="detail">
( #{detail.orderId}, #{detail.goodsId}, #{detail.goodsName}, #{detail.machineId}, #{detail.num},
#{detail.unitPrice}, #{detail.oriAmount}, #{detail.amountShould}, #{detail.couponAmount},
#{detail.realAmount}, #{detail.specRuleDetail}, #{detail.specRuleIds}, #{detail.skuId},
#{detail.goodsCategory}, #{detail.createdAt}, #{detail.refundId}, #{detail.refundTime}, #{detail.updatedAt}
)
</foreach>
</insert>
<update id="updateOrderDetail" parameterType="OrderDetail">
update order_detail
<trim prefix="SET" suffixOverrides=",">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment