123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929 |
- package com.shop.service;/**
- * Created by 17173 on 2018/3/13.
- */
- import com.alibaba.fastjson.JSON;
- import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
- import com.github.miemiedev.mybatis.paginator.domain.PageList;
- import com.github.miemiedev.mybatis.paginator.domain.Paginator;
- import com.shop.constant.DmConstant;
- import com.shop.constant.MessageModel;
- import com.shop.dao.OrderDao;
- import com.shop.dao.ProductDao;
- import com.shop.exception.ParamException;
- import com.shop.gto.IndexDto;
- import com.shop.gto.OrderDto;
- import com.shop.model.*;
- import com.shop.util.AssertUtil;
- import com.shop.util.MessageModelUtil;
- import com.shop.vo.LoginIdentity;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.*;
- /**
- * @author DY
- * @create 2018-03-13 18:20
- **/
- @Service
- @Transactional
- public class OrderService {
- @Autowired
- private OrderDao orderDao;
- @Autowired
- private ProductDao productDao;
- /**
- * @author DY
- * @create 2018/3/13 19:43
- * 订单总数,销售总额,昨日销售总额,近七天销售总额接口接口
- */
- public MessageModel order_total_amount(LoginIdentity loginIdentity) {
- MessageModel messageModel = new MessageModel();
- Map map = new HashMap();
- OrderDto orderDto = getOrderDto(loginIdentity, DmConstant.VERSION_ONE);
- //拿到今日订单总数和订单总额
- orderDto.setTime(0);
- IndexDto indexDto = orderDao.queryOrderCountAmountTotalByUserId(orderDto);
- map.put("orderTotalCount", indexDto.getOrderTotalCount());
- map.put("orderTotalPriceToday", indexDto.getOrderTotalPrice());
- //拿到昨日销售总额
- orderDto.setTime(1);
- indexDto = orderDao.queryOrderCountAmountTotalByUserId(orderDto);
- map.put("orderTotalPriceYesterday", indexDto.getOrderTotalPrice());
- //拿到近7天销售总额
- orderDto.setTime(7);
- indexDto = orderDao.queryOrderAmountTotalByUserId(orderDto);
- BigDecimal totalPriceAweek = indexDto.getOrderTotalPrice();
- map.put("orderTotalPriceAweek", totalPriceAweek);
- messageModel.setCode(DmConstant.OPS_SUCCESS_CODE);
- messageModel.setMsg(DmConstant.OPS_SUCCESS_MSG);
- messageModel.setData(map);
- return messageModel;
- }
- private OrderDto getOrderDto(LoginIdentity loginIdentity, Integer version) {
- Integer store = loginIdentity.getStore();
- Integer type = loginIdentity.getType();
- OrderDto orderDto = new OrderDto();
- orderDto.setStore(store);
- orderDto.setVersion(version);
- orderDto.setType(type);
- return orderDto;
- }
- private OrderDto getOrderDto(OrderDto orderDto, LoginIdentity loginIdentity) {
- Integer store = loginIdentity.getStore();
- Integer type = loginIdentity.getType();
- orderDto.setStore(store);
- orderDto.setType(type);
- return orderDto;
- }
- /**
- * @author DY
- * @create 2018/3/14 17:08
- * 统计各个订单状态数量
- */
- public MessageModel query_order_status(LoginIdentity loginIdentity) {
- MessageModel messageModel = new MessageModel();
- Map map = new HashMap();
- OrderDto orderDto = getOrderDto(loginIdentity, null);
- //查询订单个数以status分组统计
- List<OrderStatus> orders = orderDao.query_order_status(orderDto);
- AssertUtil.listIsNotEmpty(orders, "你还没订单哦...");
- Integer total_order = 0;
- Integer un_pay_order = 0;
- Integer have_pay_order = 0;
- Integer wait_receive_order = 0;
- Integer wait_show_order = 0;
- Integer have_show_order = 0;
- Integer close_order = 0;
- Integer refund_order = 0;
- Integer refund_order_over = 0;
- for (int i = 0; i < orders.size(); i++) {
- OrderStatus orderStatus = orders.get(i);
- total_order += orderStatus.getOrderTotalCount();
- //查询待付款订单个数
- if (orderStatus.getStatus().equals(DmConstant.UN_PAID_CODE)
- && orderStatus.getVersion().equals(1)
- && orderStatus.getExpire().after(new Date(System.currentTimeMillis()))
- && orderStatus.getRefundCode().equals(0)
- ) {
- un_pay_order += 1;
- }
- //拿到已付款订单
- if (orderStatus.getStatus().equals(DmConstant.UN_DELIVERY_CODE)
- && orderStatus.getVersion().equals(1)
- && (orderStatus.getRefundCode().equals(0)
- || orderStatus.getRefundCode().equals(4)
- || orderStatus.getRefundCode().equals(10))
- ) {
- have_pay_order += 1;
- }
- //拿到已发货订单
- if (orderStatus.getStatus().equals(DmConstant.UN_RECEIVE_CODE)
- && orderStatus.getVersion().equals(1)
- && (orderStatus.getRefundCode().equals(0)
- || orderStatus.getRefundCode().equals(4)
- || orderStatus.getRefundCode().equals(10))
- ) {
- wait_receive_order += 1;
- }
- //拿到待晒单订单
- if (orderStatus.getStatus().equals(DmConstant.UN_SHOW_CODE)
- && orderStatus.getVersion().equals(1)
- && (orderStatus.getRefundCode().equals(0)
- || orderStatus.getRefundCode().equals(4)
- || orderStatus.getRefundCode().equals(10))
- ) {
- wait_show_order += 1;
- }
- //拿到已晒单订单
- if (orderStatus.getStatus().equals(DmConstant.HAVE_SHOW_CODE)
- && orderStatus.getVersion().equals(1)
- && (orderStatus.getRefundCode().equals(0)
- || orderStatus.getRefundCode().equals(4)
- || orderStatus.getRefundCode().equals(10))
- ) {
- have_show_order += 1;
- }
- //拿到已关闭订单(主动取消或者过期订单)
- if (orderStatus.getVersion().equals(DmConstant.VERSION_CANCEL_ORDER)
- ) {
- close_order += 1;
- }
- //拿到退款订单
- if (orderStatus.getVersion().equals(1)
- && (
- orderStatus.getRefundCode().equals(1)
- || orderStatus.getRefundCode().equals(2)
- || orderStatus.getRefundCode().equals(3)
- || orderStatus.getRefundCode().equals(5)
- || orderStatus.getRefundCode().equals(8)
- || orderStatus.getRefundCode().equals(9)
- )
- ) {
- refund_order += 1;
- }
- //拿到退款完成订单
- if (orderStatus.getVersion().equals(1)
- && (orderStatus.getRefundCode().equals(6)
- || orderStatus.getRefundCode().equals(7)
- )
- ) {
- refund_order_over += 1;
- }
- }
- map.put("refund_order", refund_order);
- map.put("refund_order_over", refund_order_over);
- map.put("close_order", close_order);
- map.put("have_show_order", have_show_order);
- map.put("wait_show_order", wait_show_order);
- map.put("wait_receive_order", wait_receive_order);
- map.put("have_pay_order", have_pay_order);
- map.put("un_pay_order", un_pay_order);
- //总订单数
- map.put("total_order", total_order);
- messageModel.setCode(DmConstant.OPS_SUCCESS_CODE);
- messageModel.setMsg(DmConstant.OPS_SUCCESS_MSG);
- messageModel.setData(map);
- return messageModel;
- }
- /**
- * @author DY
- * @create 2018/3/19 14:22
- * 查看订单
- */
- public MessageModel showObligationOrder(OrderDto orderDto, LoginIdentity loginIdentity) {
- MessageModel messageModel = new MessageModel();
- orderDto = getOrderDto(orderDto, loginIdentity);
- Integer status = orderDto.getStatus();
- //默认refundCode=-1
- orderDto.setRefundCode(-1);
- //status 为null 时 查全部
- if (status == null) {
- } else {
- //status=0时 查待付款 筛选过期和退款订单
- if (status == 0) {
- orderDto.setRefundCode(0);
- orderDto.setExpire(1);
- orderDto.setVersion(1);
- }
- //status=1时 查已付款待发货 筛选过期和退款订单
- if (status == 1) {
- orderDto.setRefundCode(0);
- orderDto.setVersion(1);
- }
- //status=2时 查已发货待收货 筛选过期和退款订单
- if (status == 2) {
- orderDto.setRefundCode(0);
- orderDto.setVersion(1);
- }
- //status=3时 查已收货待晒单 筛选过期和退款订单
- if (status == 3) {
- orderDto.setRefundCode(0);
- orderDto.setVersion(1);
- }
- //status=4时 查晒单 筛选过期和退款订单
- if (status == 4) {
- orderDto.setRefundCode(0);
- orderDto.setVersion(1);
- }
- //status=5时 查已关闭订单
- if (status == 5) {
- orderDto.setStatus(-1);
- orderDto.setVersion(-1);
- }
- //status=6时 查退款订单
- if (status == 6) {
- orderDto.setStatus(null);
- orderDto.setRefundCode(1);
- orderDto.setVersion(1);
- }
- //status=7时 查退款完成订单
- if (status == 7) {
- orderDto.setStatus(null);
- orderDto.setRefundCode(2);
- }
- }
- Map map = new HashMap();
- // 構建pageBounds
- PageBounds pageBounds = orderDto.buildPageBounds();
- //此时拿到所有订单明细然后根据定制明细进行分类
- List<OrderDetail> order = orderDao.findOrderItemByUserId(orderDto, pageBounds);
- // 構建返回結果
- PageList<OrderDetail> orderListStr = (PageList<OrderDetail>) order;
- List<List<OrderDetail>> newOrderItem = getList(orderListStr);
- //構建paginator對象返回
- Paginator paginator = orderListStr.getPaginator();
- map.put("paginator", paginator);
- //当是未支付订单和全部订单时的时候把使用优惠券的大订单放在一起(暂时先把待支付放在一起)
- messageModel.setCode(DmConstant.OPS_SUCCESS_CODE);
- messageModel.setMsg(DmConstant.OPS_SUCCESS_MSG);
- map.put("listOrder", newOrderItem);
- messageModel.setData(map);
- return messageModel;
- }
- private List<List<OrderDetail>> getList(List<OrderDetail> orders) {
- Map<Integer, List> map = new LinkedHashMap();
- for (int i = 0; i < orders.size(); i++) {
- OrderDetail item = orders.get(i);
- //构建退款申请最晚同意时间和买家发货之后卖家最晚打款时间
- Integer refundCode = item.getOrderItemRefundCode();
- Date refundTime = item.getRefundTime();
- if (refundCode == DmConstant.REFUND_CODE_APPLY) {
- Date refundLateTime = new Date(refundTime.getTime() + DmConstant.APPLY_REFUND_IN_REFUND_APPLY);
- item.setAgreeTimeRefundTime(refundLateTime);
- }
- if (refundCode == DmConstant.REFUND_CODE_EXPRESS_NUMBER) {
- Date refundLateTime = new Date(refundTime.getTime() + DmConstant.APPLY_REFUND_IN_REFUND_HAVE_SEND_REFUND_GOODS);
- item.setAgreeConfirmTimeRefundTime(refundLateTime);
- }
- //构建自动确认收货时间
- Boolean isExtend = item.getIsExtend();
- if (item.getDeliveryTime() != null && (refundCode == DmConstant.REFUND_CODE_DEFAULT || refundCode == DmConstant.REFUND_CODE_CANCEL)) {
- Date time = new Date(item.getDeliveryTime().getTime() + DmConstant.AUTOMATICRECEIVING);
- if (isExtend) {
- time = new Date(time.getTime() + DmConstant.EXTENDTHERECEIVING * 24 * 60 * 60 * 1000);
- }
- item.setAutomaticReceivingDate(time);
- }
- Integer status = item.getOrderItemStatus();
- if (refundCode == DmConstant.REFUND_CODE_AGREE && status != 1) {
- item.setRefundSendDate(new Date(item.getModifyDate().getTime() + DmConstant.APPLY_REFUND_IN_REFUND_AGREE));
- }
- Integer key = item.getId();
- //当且仅当集合里有过 1//1才会进这个集合,第一次也不会进,第二次才会进
- if (map.containsKey(key)) {
- map.get(key).add(item);
- } else {
- List list = new ArrayList();
- list.add(item);
- map.put(key, list);
- }
- }
- List<List<OrderDetail>> data = new PageList<>();
- for (Map.Entry<Integer, List> entry : map.entrySet()) {
- data.add(entry.getValue());
- }
- return data;
- }
- public void update_receive_address (ReceiveAddress receiveAddress) {
- AssertUtil.intIsNotEmpty(receiveAddress.getId(), "请选择要修改的订单...");
- Integer code = orderDao.updateOrderReceiveAddressById(receiveAddress);
- AssertUtil.intIsNotEmpty(code, "修改失败,请联系客服....");
- }
- /* *//**
- * @author DY
- * @create 2018/3/27 18:31
- * 修改订单商品信息
- *//*
- public MessageModel update_order_property(ProductUpdate productNew) {
- //参数判断
- checkParams(productNew);
- //拿到修改之前订单明细表里的属性
- ProductUpdate productOld = orderDao.queryProductByOrderItemId(productNew.getOrderItemId());
- AssertUtil.notNull(productOld, "所查询的商品不存在");
- Boolean quantity = productNew.getQuantity().equals(productOld.getQuantity());
- //修改custom属性订单
- if (StringUtils.isNotBlank(productOld.getCustomNames())) {
- AssertUtil.isNotEmpty(productNew.getCustomIds(), "请传入定制ids");
- //默认全部修改--更新订单详情price quantity,custom_names 更改带大订单的价格,数量
- //拿到新定制的价格
- List<ProductCustom> productCustoms = orderDao.queryCustomsByCustomId(productNew.getCustomIds());
- BigDecimal customTotalPrice = BigDecimal.ZERO;
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < productCustoms.size(); i++) {
- ProductCustom productCustom = productCustoms.get(i);
- customTotalPrice = customTotalPrice.add(productCustom.getPrice());
- sb.append(" " + productCustom.getName());
- }
- String customNames = sb.toString();
- //价格=默认价格+新定制价格
- BigDecimal defaultProductPrice = orderDao.queryDefaultProductPriceByProductId(productOld.getProduct());
- AssertUtil.notNull(defaultProductPrice, "默认商品不存在,请联系客服...");
- BigDecimal newPriceOrderItem = defaultProductPrice.add(customTotalPrice);
- //更新订单详情表
- Integer code = orderDao.updateOrderItemCustom(newPriceOrderItem, productNew.getQuantity(), customNames, productNew.getOrderItemId());
- AssertUtil.intIsNotEmpty(code, "更新子订单属性失败,请联系客服....");
- //更新大订单--差价 差量
- BigDecimal newPriceTotal = newPriceOrderItem.multiply(new BigDecimal(productNew.getQuantity()));
- BigDecimal oldPriceTotal = productOld.getPrice().multiply(new BigDecimal(productOld.getQuantity()));
- BigDecimal differentPrice = newPriceTotal.subtract(oldPriceTotal);
- Integer differentQuantity = productNew.getQuantity() - productOld.getQuantity();
- //初始化订单修改对象
- UpdateOrderParams updateOrderParams = new UpdateOrderParams();
- updateOrderParams.setOrderId(productOld.getOrders());
- updateOrderParams.setAmountUpdate(differentPrice);
- updateOrderParams.setQuantityUpdate(differentQuantity);
- updateOrderPriceQuantity(updateOrderParams);
- Map map = new HashMap();
- map.put("price", newPriceOrderItem);
- map.put("quantity", productNew.getQuantity());
- return MessageModelUtil.getSuccessMessageModel(newPriceOrderItem);
- }
- //判断修改的是哪一项或者哪几项
- Boolean scm = productNew.getSize().equals(productOld.getSize()) && productNew.getColor().equals(productOld.getColor())
- && productNew.getMaterial().equals(productOld.getMaterial());
- //无任何操作
- if (scm && quantity) {
- return MessageModelUtil.getSuccessMessageModel();
- }
- //初始化订单修改对象
- UpdateOrderParams updateOrderParams = new UpdateOrderParams();
- updateOrderParams.setOrderId(productOld.getOrders());
- //初始化订单明细修改对象
- ProductUpdate productUpdate = new ProductUpdate();
- Integer orderItemId = productNew.getOrderItemId();
- productUpdate.setOrderItemId(orderItemId);
- //只修改属性
- if (!scm && quantity) {
- //拿到修改后的具体商品
- Product productGetByAttribute = updateProductAttribute(productOld, productNew);
- //把要修改的属性放进修改对象里
- productUpdate = updateOrderItemAttribute(productGetByAttribute, orderItemId);
- updateOrderItem(productUpdate);
- //单价改变修改大订单价格
- if (productOld.getPrice().compareTo(productGetByAttribute.getPrice()) != 0) {
- //拿到差价...
- BigDecimal differentPriceAmount = productGetByAttribute.getPrice().subtract(productOld.getPrice()).multiply(new BigDecimal(productOld.getQuantity()));
- //更新大订单的差价
- updateOrderParams.setAmountUpdate(differentPriceAmount);
- updateOrderPriceQuantity(updateOrderParams);
- }
- Map map = new HashMap();
- map.put("price", productGetByAttribute.getPrice());
- map.put("quantity", productNew.getQuantity());
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- //只修改数量--修改子订单数量和大订单数量,金额
- if (scm && !quantity) {
- productUpdate.setQuantity(productNew.getQuantity());
- updateOrderItem(productUpdate);
- Integer differentQuantity = productNew.getQuantity() - productOld.getQuantity();
- //修改库存
- updateQuantityProduct(productOld.getProduct(), differentQuantity);
- BigDecimal differentPriceAmount = productOld.getPrice().multiply(new BigDecimal(differentQuantity));
- updateOrderParams.setAmountUpdate(differentPriceAmount);
- updateOrderParams.setQuantityUpdate(differentQuantity);
- updateOrderPriceQuantity(updateOrderParams);
- Map map = new HashMap();
- map.put("price", productOld.getPrice());
- map.put("quantity", productNew.getQuantity());
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- //只修改属性和数量
- if (!scm && !quantity) {
- //拿到修改后的具体商品
- Product productGetByAttribute = updateProductAttribute(productOld, productNew);
- //把要修改的属性放进修改对象里
- productUpdate = updateOrderItemAttribute(productGetByAttribute, orderItemId);
- productUpdate.setQuantity(productNew.getQuantity());
- updateOrderItem(productUpdate);
- Integer differentQuantity = productNew.getQuantity() - productOld.getQuantity();
- //拿到修改后的价格
- BigDecimal priceNew = productGetByAttribute.getPrice().multiply(new BigDecimal(productNew.getQuantity()));
- //修改前的价格
- BigDecimal priceOld = productOld.getPrice().multiply(new BigDecimal(productOld.getQuantity()));
- BigDecimal differentPriceAmount = priceNew.subtract(priceOld);
- updateOrderParams.setAmountUpdate(differentPriceAmount);
- updateOrderParams.setQuantityUpdate(differentQuantity);
- updateOrderPriceQuantity(updateOrderParams);
- Map map = new HashMap();
- map.put("price", productGetByAttribute.getPrice());
- map.put("quantity", productNew.getQuantity());
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- return MessageModelUtil.getSuccessMessageModel();
- }*/
- /**
- * @author DY
- * @create 2018/3/27 18:31
- * 修改订单商品信息--更改
- */
- public MessageModel update_order_property(ProductUpdate productNew) {
- //参数判断
- checkParams(productNew);
- Map map = new HashMap();
- //拿到修改之前订单明细表里的属性
- ProductUpdate productOld = orderDao.queryProductByOrderItemId(productNew.getOrderItemId());
- AssertUtil.notNull(productOld, "所查询的商品不存在");
- if (productOld.getIsCustom()) {
- Integer a = 0;
- if (null != productNew.getMeasureId()) {
- a = a + 1;
- }
- if (StringUtils.isNotBlank(productNew.getSize())) {
- a = a + 1;
- }
- AssertUtil.isTrue(a == 2, "定制尺码和套码只能而二选一");
- }
- Boolean quantity = productNew.getQuantity() == productOld.getQuantity();
- //判断是否修改细节定制
- Boolean scmDetail = false;
- if (StringUtils.isNotBlank(productNew.getCustomNamesIds())) {
- scmDetail = productNew.getCustomNamesIds().equals(productOld.getCustomNamesIds());
- }
- // 1).定制修改(当且仅当含有细节定制走这一块)
- if (scmDetail == false) {
- //默认全部修改--更新订单详情price quantity,custom_names 更改带大订单的价格,数量
- //拿到细节定制的新价格
- String customNames = null;
- BigDecimal customTotalPriceOld = BigDecimal.ZERO;
- BigDecimal customTotalPriceNew = BigDecimal.ZERO;
- if (productOld.getCustomNamesIds() != null) {
- List<ProductCustom> productCustomsOld = orderDao.queryCustomsByCustomId(productOld.getCustomNamesIds());
- //拿到细节定制的新价格
- List<ProductCustom> productCustomsNew = orderDao.queryCustomsByCustomId(productNew.getCustomNamesIds());
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < productCustomsOld.size(); i++) {
- ProductCustom productCustom = productCustomsOld.get(i);
- customTotalPriceOld = customTotalPriceOld.add(productCustom.getPrice());
- }
- for (int i = 0; i < productCustomsNew.size(); i++) {
- ProductCustom productCustom = productCustomsNew.get(i);
- customTotalPriceNew = customTotalPriceNew.add(productCustom.getPrice());
- sb.append(" " + productCustom.getName());
- }
- customNames = sb.toString();
- }
- //初始化订单修改对象
- UpdateOrderParams updateOrderParams = new UpdateOrderParams();
- updateOrderParams.setOrderId(productOld.getOrders());
- //初始化订单明细修改对象
- ProductUpdate productUpdate = new ProductUpdate();
- Integer orderItemId = productNew.getOrderItemId();
- productUpdate.setOrderItemId(orderItemId);
- //拿到修改后的具体商品
- Product newProductUpdate = updateProductAttribute(productOld, productNew);
- //把要修改的属性放进修改对象里
- productUpdate = updateOrderItemAttribute(newProductUpdate, orderItemId);
- productUpdate.setQuantity(productNew.getQuantity());
- productUpdate.setCustomNames(customNames);
- productUpdate.setCustomNamesIds(productNew.getCustomNamesIds());
- productUpdate.setCustomDetailPrice(customTotalPriceNew);
- //若定制修改量身Id把size置为空,反之亦然
- if (StringUtils.isNotBlank(productNew.getSize())) {
- productUpdate.setMeasureId(null);
- }
- if (productNew.getMeasureId() != null) {
- productUpdate.setSize(null);
- }
- updateOrderItem(productUpdate);
- Integer differentQuantity = productNew.getQuantity() - productOld.getQuantity();
- //拿到修改后的价格
- BigDecimal priceNew = (newProductUpdate.getPrice().add(customTotalPriceNew)).multiply(new BigDecimal(productNew.getQuantity()));
- //修改前的价格
- BigDecimal priceOld = (productOld.getPrice().add(customTotalPriceOld)).multiply(new BigDecimal(productOld.getQuantity()));
- BigDecimal differentPriceAmount = priceNew.subtract(priceOld);
- updateOrderParams.setAmountUpdate(differentPriceAmount);
- updateOrderParams.setQuantityUpdate(differentQuantity);
- updateOrderPriceQuantity(updateOrderParams);
- map.put("price", newProductUpdate.getPrice().add(customTotalPriceNew));
- map.put("quantity", productNew.getQuantity());
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- //判断修改的是哪一项或者哪几项
- Boolean scm = productNew.getSize().equals(productOld.getSize()) && productNew.getColor().equals(productOld.getColor());
- //无任何操作
- if (scm && quantity) {
- map.put("price", productOld.getPrice());
- map.put("quantity", productOld.getQuantity());
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- //只修改属性
- if (!scm && quantity) {
- map = updateAttributeProductOnly(productNew, productOld);
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- //只修改数量--修改子订单数量和大订单数量,金额
- if (scm && !quantity) {
- map = updateQuantityProductOnly(productNew, productOld);
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- if (!scm && !quantity) {
- map = updateAttributeAndQuantityProductOnly(productNew, productOld);
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- return MessageModelUtil.getSuccessMessageModel();
- }
- private Map updateAttributeProductOnly(ProductUpdate productNew, ProductUpdate productOld) {
- //初始化订单修改对象
- UpdateOrderParams updateOrderParams = new UpdateOrderParams();
- updateOrderParams.setOrderId(productOld.getOrders());
- //初始化订单明细修改对象
- ProductUpdate productUpdate = new ProductUpdate();
- Integer orderItemId = productNew.getOrderItemId();
- productUpdate.setOrderItemId(orderItemId);
- //拿到修改后的具体商品
- Product newProductUpdate = updateProductAttribute(productOld, productNew);
- //把要修改的属性放进修改对象里
- productUpdate = updateOrderItemAttribute(newProductUpdate, orderItemId);
- productUpdate.setMeasureId(productNew.getMeasureId());
- //若定制修改量身Id把size置为空,反之亦然
- if (StringUtils.isNotBlank(productNew.getSize())) {
- productUpdate.setMeasureId(null);
- }
- if (productNew.getMeasureId() != null) {
- productUpdate.setSize(null);
- }
- updateOrderItem(productUpdate);
- //单价改变修改大订单价格
- if (productOld.getPrice().compareTo(newProductUpdate.getPrice()) != 0) {
- //拿到差价...
- BigDecimal differentPriceAmount = newProductUpdate.getPrice().subtract(productOld.getPrice()).multiply(new BigDecimal(productOld.getQuantity()));
- //更新大订单的差价
- updateOrderParams.setAmountUpdate(differentPriceAmount);
- updateOrderPriceQuantity(updateOrderParams);
- }
- Map map = new HashMap();
- map.put("price", newProductUpdate.getPrice());
- map.put("quantity", productNew.getQuantity());
- return map;
- }
- private Map updateQuantityProductOnly(ProductUpdate productNew, ProductUpdate productOld) {
- //初始化订单修改对象
- UpdateOrderParams updateOrderParams = new UpdateOrderParams();
- updateOrderParams.setOrderId(productOld.getOrders());
- //初始化订单明细修改对象
- ProductUpdate productUpdate = new ProductUpdate();
- Integer orderItemId = productNew.getOrderItemId();
- productUpdate.setOrderItemId(orderItemId);
- productUpdate.setQuantity(productNew.getQuantity());
- productUpdate.setMeasureId(productNew.getMeasureId());
- updateOrderItem(productUpdate);
- Integer differentQuantity = productNew.getQuantity() - productOld.getQuantity();
- //套码修改库存
- if (productOld.getIsCustom() == false) {
- updateQuantityProduct(productOld.getProduct(), differentQuantity);
- }
- BigDecimal differentPriceAmount = productOld.getPrice().multiply(new BigDecimal(differentQuantity));
- updateOrderParams.setAmountUpdate(differentPriceAmount);
- updateOrderParams.setQuantityUpdate(differentQuantity);
- updateOrderPriceQuantity(updateOrderParams);
- Map map = new HashMap();
- map.put("price", productOld.getPrice());
- map.put("quantity", productNew.getQuantity());
- return map;
- }
- private Map updateAttributeAndQuantityProductOnly(ProductUpdate productNew, ProductUpdate productOld) {
- //初始化订单修改对象
- UpdateOrderParams updateOrderParams = new UpdateOrderParams();
- updateOrderParams.setOrderId(productOld.getOrders());
- //初始化订单明细修改对象
- ProductUpdate productUpdate = new ProductUpdate();
- Integer orderItemId = productNew.getOrderItemId();
- productUpdate.setOrderItemId(orderItemId);
- //拿到修改后的具体商品
- Product newProductUpdate = updateProductAttribute(productOld, productNew);
- //把要修改的属性放进修改对象里
- productUpdate = updateOrderItemAttribute(newProductUpdate, orderItemId);
- productUpdate.setQuantity(productNew.getQuantity());
- productUpdate.setMeasureId(productNew.getMeasureId());
- //若定制修改量身Id把size置为空,反之亦然
- if (StringUtils.isNotBlank(productNew.getSize())) {
- productUpdate.setMeasureId(null);
- }
- if (productNew.getMeasureId() != null) {
- productUpdate.setSize(null);
- }
- updateOrderItem(productUpdate);
- Integer differentQuantity = productNew.getQuantity() - productOld.getQuantity();
- //拿到修改后的价格
- BigDecimal priceNew = newProductUpdate.getPrice().multiply(new BigDecimal(productNew.getQuantity()));
- //修改前的价格
- BigDecimal priceOld = productOld.getPrice().multiply(new BigDecimal(productOld.getQuantity()));
- BigDecimal differentPriceAmount = priceNew.subtract(priceOld);
- updateOrderParams.setAmountUpdate(differentPriceAmount);
- updateOrderParams.setQuantityUpdate(differentQuantity);
- updateOrderPriceQuantity(updateOrderParams);
- Map map = new HashMap();
- map.put("price", newProductUpdate.getPrice());
- map.put("quantity", productNew.getQuantity());
- return map;
- }
- private void updateQuantityProduct(Integer productId, Integer quantity) {
- Integer code = productDao.updateStockOldProduct(productId, quantity);
- AssertUtil.intIsNotEmpty(code, "修改数量失败....");
- }
- private void updateOrderItem(ProductUpdate productUpdate) {
- //更改子订单
- Integer updateOrderItemCode = orderDao.updateOrderItemByProduct(productUpdate);
- AssertUtil.intIsNotEmpty(updateOrderItemCode, "更改子订单属性smc失败...");
- }
- private void updateOrderPriceQuantity(UpdateOrderParams updateOrderParams) {
- Integer updateOrderCode = orderDao.updateOrderByProduct(updateOrderParams);
- AssertUtil.intIsNotEmpty(updateOrderCode, "修改失败,请联系客服....");
- }
- private ProductUpdate updateOrderItemAttribute(Product productGetByAttribute, Integer orderItemId) {
- ProductUpdate productUpdate = new ProductUpdate();
- productUpdate.setProduct(productGetByAttribute.getId());
- productUpdate.setOrderItemId(orderItemId);
- productUpdate.setPrice(productGetByAttribute.getPrice());
- productUpdate.setColor(productGetByAttribute.getColor());
- productUpdate.setSize(productGetByAttribute.getSize());
- return productUpdate;
- }
- private Product updateProductAttribute(ProductUpdate productOld, ProductUpdate productNew) {
- Integer quantityOld = productOld.getQuantity();
- Integer quantityNew = productNew.getQuantity();
- //拿到商品原信息
- List<Product> updateProduct = null;
- Product product = null;
- //套码
- Boolean isCustom = productNew.getIsCustom();
- //定制的话尺寸置为空
- if (isCustom) {
- String size = productNew.getSize();
- productNew.setSize(null);
- updateProduct = productDao.queryProductBySMC(productNew);
- AssertUtil.isTrue(updateProduct.isEmpty(), "更改的商品不存在,请稍后重试...");
- product = updateProduct.get(0);
- product.setSize(size);
- } else {
- updateProduct = productDao.queryProductBySMC(productNew);
- AssertUtil.isTrue(updateProduct.isEmpty(), "更改的商品不存在,请稍后重试...");
- product = updateProduct.get(0);
- //回滚元商品库存,扣去现在商品库存
- Integer codeOld = productDao.updateStockOldProduct(productOld.getProduct(), -quantityOld);
- AssertUtil.intIsNotEmpty(codeOld, "回滚库存失败,请联系客服...");
- Integer codeNew = productDao.updateStockOldProduct(product.getId(), quantityNew);
- AssertUtil.intIsNotEmpty(codeNew, "扣除库存失败,请联系客服...");
- }
- return product;
- }
- private void checkParams(ProductUpdate product) {
- AssertUtil.intIsNotEmpty(product.getOrderItemId(), "请传入订单明细id...");
- AssertUtil.intIsNotEmpty(product.getQuantity(), "请传入修改之后的数量...");
- }
- public void update_order_totalPrice(BigDecimal totalPrice, Integer id) {
- AssertUtil.intIsNotEmpty(id, "请选择订单...");
- AssertUtil.notNull(totalPrice, "请传入要修改的价格...");
- Integer code = orderDao.updateOrderPriceByPrice(totalPrice, id);
- AssertUtil.intIsNotEmpty(code, "价格修改失败,请联系客服.....");
- }
- public void updateOrderStatusToSend(String deliverySend) {
- AssertUtil.isNotEmpty(deliverySend, "请传入发货信息...");
- //格式化发货大字段
- List<DeliverySend> deliverySends = null;
- if (StringUtils.isNotBlank(deliverySend)) {
- deliverySends = JSON.parseArray(deliverySend, DeliverySend.class);
- }
- //更改子订单
- Integer codeOrderItem = orderDao.updateOrderItemStatusCode(deliverySends);
- AssertUtil.intIsNotEmpty(codeOrderItem, "更改订单状态失败,请联系客服...");
- //更改大订单状态,若有多个小订单判断是否全部发货,有一个未发货都不更改大订单
- for (int i = 0; i < deliverySends.size(); i++) {
- Integer orderId=deliverySends.get(i).getOrderId();
- AssertUtil.intIsNotEmpty(orderId, "请传入父订单Id...");
- Integer isHaveNoSend=orderDao.findOrdersNoSend(orderId,DmConstant.UN_DELIVERY_CODE);
- if(isHaveNoSend==null||isHaveNoSend<0){
- Integer code = orderDao.updateOrderStatusAndDelivery(orderId,DmConstant.UN_RECEIVE_CODE);
- AssertUtil.intIsNotEmpty(code, "更新父订单失败,请稍后重试..."+orderId);
- }
- }
- }
- /*private void updateOrderStatus(Integer orderId, Integer unReceiveCode) {
- //更改大订单状态
- Integer codeOrder=orderDao.updateOrderStatus(unReceiveCode,orderId);
- AssertUtil.intIsNotEmpty(codeOrder,"更改订单状态失败,请联系客服...");
- //更改子订单
- Integer codeOrderItem=orderDao.updateOrderItemStatusCode(unReceiveCode,orderId);
- AssertUtil.intIsNotEmpty(codeOrderItem,"更改订单状态失败,请联系客服...");
- }*/
- public List<DeliveryCode> query_delivery_code() {
- List<DeliveryCode> deliveryCodeList = orderDao.queryDeliveryCode();
- return deliveryCodeList;
- }
- public void deal_with_return_order(Integer orderItemId, Boolean isAgree,Integer refundCodeF) {
- AssertUtil.intIsNotEmpty(orderItemId, "请选择带操作的订单");
- AssertUtil.intIsNotEmpty(refundCodeF, "请传入待退款订单的状态refundCode");
- AssertUtil.notNull(isAgree, "请选择同意或者拒绝...");
- Integer refundCode = null;
- if (isAgree) {
- refundCode = DmConstant.REFUND_CODE_AGREE;
- // 3.更新库存
- //查询待更新订单数量
- OrderItemDetail orderDetail1 = orderDao.findOrderItemById(orderItemId);
- //拿到定制类属性,若为空则是套码更新库存,否则不更新
- Boolean isCustom = orderDetail1.getIsCustom();
- //套码回滚库存...
- if (isCustom == false) {
- Integer quantity = orderDetail1.getQuantity();
- Integer product = orderDetail1.getProduct();
- Integer updateProductStock = orderDao.updateProductStock(-quantity, product);
- AssertUtil.intIsNotEmpty(updateProductStock, "取消订单失败003,请联系客服...");
- }
- } else {
- if(refundCodeF==DmConstant.REFUND_CODE_APPLY||refundCodeF==DmConstant.REFUND_CODE_APPLY_CANCEL_AGAIN){
- refundCode = DmConstant.REFUND_CODE_REFUSE;
- }
- if(refundCodeF==DmConstant.REFUND_CODE_APPLY_REFUSE_AGAIN){
- refundCode = DmConstant.REFUND_CODE_REFUSE_AGAIN;
- }
- }
- Integer code = orderDao.updateOrderItemRefundStatus(orderItemId, refundCode);
- AssertUtil.intIsNotEmpty(code, "操作失败,请联系客服...");
- }
- public void updateOrderStatusToAgree() {
- //更新到期退款时间订单
- OrderDto orderDto = new OrderDto();
- orderDto.setRefundCode(DmConstant.REFUND_CODE_AGREE);
- orderDto.setRefundTime(DmConstant.REFUND_AGREE_TIME);
- //更新子订单
- orderDao.updateOrderItemStatusToAgree(orderDto);
- //查询待退款订单 refundCode=3子订单
- orderDto.setRefundCode(DmConstant.REFUND_CODE_AGREE);
- List<OrderItemQuery> orderDetails = orderDao.findOrderItemByOrderDto(orderDto);
- //AssertUtil.listIsNotEmpty(orderDetails, "查询失败,请联系客服...");
- //回滚库存
- /* for (int i = 0; i < orderDetails.size(); i++) {
- OrderItemQuery orderItemQuery = orderDetails.get(i);
- //拿到定制类属性,若为空则是套码更新库存,否则不更新
- Boolean isCustom = orderItemQuery.getIsCustom();
- //套码回滚库存...
- if (isCustom == false) {
- Integer quantity = orderItemQuery.getOrderItemQuantity();
- Integer product = orderItemQuery.getProduct();
- Integer updateProductStock = orderDao.updateProductStock(-quantity, product);
- AssertUtil.intIsNotEmpty(updateProductStock, "取消订单失败003,请联系客服...");
- }
- }*/
- StringBuffer orders = new StringBuffer();
- if (orderDetails.size() != 0) {
- for (int i = 0; i < orderDetails.size(); i++) {
- OrderItemQuery orderItemQuery = orderDetails.get(i);
- Integer orderId = orderItemQuery.getOrderId();
- //第一步过滤
- if (orderItemQuery.getOrderQuantity().equals(orderItemQuery.getOrderItemQuantity())) {
- orders.append(orderId + ",");
- } else {
- //查询大订单下子订单是否都是已同意状态,是的话把大订单更改为已同意
- String refundCodes = DmConstant.REFUND_CODE_APPLY + "," + DmConstant.REFUND_CODE_REFUSE;
- List<Integer> integers = orderDao.findOrderItemByOrderId(orderId, refundCodes);
- if (integers.size() == 0) {
- orders.append(orderId + ",");
- }
- }
- }
- }
- orders.deleteCharAt(orders.length() - 1);
- String ordersStr = orders.toString();
- //批量更新大订单状态
- orderDao.updateOrderStatusToAgree(ordersStr, DmConstant.REFUND_CODE_AGREE);
- }
- public Integer query_order_refund_status(LoginIdentity loginIdentity) {
- OrderDto orderDto = getOrderDto(loginIdentity, null);
- //拿到退款退货订单
- List<Integer> return_order = orderDao.queryReturnOrder(orderDto);
- return return_order.size();
- }
- public void return_order_to_last(Integer orderId,Integer orderItemId,Integer isAgree) {
- AssertUtil.intIsNotEmpty(orderId, "请确认打款的父订单...");
- AssertUtil.intIsNotEmpty(orderItemId, "请确认打款的子订单...");
- AssertUtil.intIsNotEmpty(isAgree, "请确认是否同意...");
- Integer refundCode=null;
- if(isAgree==1){
- refundCode=DmConstant.REFUND_CODE_CONFIRM_RECEIVING;
- }
- else if(isAgree==2){
- refundCode=DmConstant.REFUND_CODE_REFUSE_AGAIN;
- }
- else{
- throw new ParamException("请传入正确的状态值");
- }
- //更新订单状态
- Integer code=orderDao.updateOrderItemRefundStatus(orderItemId,refundCode);
- AssertUtil.intIsNotEmpty(code,"子订单更新失败");
- if(isAgree==1){
- //同步大订单状态
- String refundCodes="1,2,3,5,6,8,9,11";
- Integer code2=orderDao.findIsHaveRefundOrder(orderId,refundCodes);
- //没有退款处理中订单更新大订单状态
- if(code2==null||code2<0){
- Integer code3=orderDao.updateOrderRefundStatus(orderId,refundCode);
- AssertUtil.intIsNotEmpty(code3,"父订单更新失败");
- }
- }
- }
- }
|