|
@@ -4,13 +4,19 @@ import com.caimei365.order.components.ProductService;
|
|
import com.caimei365.order.mapper.BaseMapper;
|
|
import com.caimei365.order.mapper.BaseMapper;
|
|
import com.caimei365.order.mapper.OrderClubMapper;
|
|
import com.caimei365.order.mapper.OrderClubMapper;
|
|
import com.caimei365.order.model.ResponseJson;
|
|
import com.caimei365.order.model.ResponseJson;
|
|
|
|
+import com.caimei365.order.model.enums.ReceivablesType;
|
|
import com.caimei365.order.model.po.BalanceRecordPo;
|
|
import com.caimei365.order.model.po.BalanceRecordPo;
|
|
import com.caimei365.order.model.po.OrderPo;
|
|
import com.caimei365.order.model.po.OrderPo;
|
|
import com.caimei365.order.model.po.OrderProductPo;
|
|
import com.caimei365.order.model.po.OrderProductPo;
|
|
import com.caimei365.order.model.po.UserBeansHistoryPo;
|
|
import com.caimei365.order.model.po.UserBeansHistoryPo;
|
|
|
|
+import com.caimei365.order.model.vo.*;
|
|
import com.caimei365.order.service.MessagePushService;
|
|
import com.caimei365.order.service.MessagePushService;
|
|
import com.caimei365.order.service.OrderClubService;
|
|
import com.caimei365.order.service.OrderClubService;
|
|
|
|
+import com.caimei365.order.utils.ImageUtil;
|
|
import com.caimei365.order.utils.MathUtil;
|
|
import com.caimei365.order.utils.MathUtil;
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
+import com.google.common.util.concurrent.AtomicDouble;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -43,6 +49,145 @@ public class OrderClubServiceImpl implements OrderClubService {
|
|
@Value("${caimei.wwwDomain}")
|
|
@Value("${caimei.wwwDomain}")
|
|
private String domain;
|
|
private String domain;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 机构订单列表
|
|
|
|
+ *
|
|
|
|
+ * @param userId 用户Id
|
|
|
|
+ * @param orderState 1:待确认,2:待付款,3:待发货,4:已发货,5:退货款
|
|
|
|
+ * @param orderNo 订单编号
|
|
|
|
+ * @param beginTime 开始时间
|
|
|
|
+ * @param endTime 截止时间
|
|
|
|
+ * @param pageNum 页码
|
|
|
|
+ * @param pageSize 每页数量
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<PageInfo<OrderVo>> getOrderList(Integer userId, Integer orderState, String orderNo, String beginTime, String endTime, int pageNum, int pageSize) {
|
|
|
|
+ // 分页请求数据
|
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
|
+ List<OrderVo> orderList = orderClubMapper.getOrderList(userId, orderState, orderNo, beginTime, endTime);
|
|
|
|
+ for (OrderVo order : orderList) {
|
|
|
|
+ // 111, 待付待收待发
|
|
|
|
+ if (11 == order.getStatus() && 1 == order.getPayStatus()) {
|
|
|
|
+ order.setStatus(111);
|
|
|
|
+ }
|
|
|
|
+ // 判断交易全退情况下,是否发过货,77,交易全退可以查看物流
|
|
|
|
+ int logisticsCount = orderClubMapper.countLogisticsBatch(order.getOrderId());
|
|
|
|
+ if (7 == order.getStatus() && logisticsCount > 0) {
|
|
|
|
+ order.setStatus(77);
|
|
|
|
+ }
|
|
|
|
+ // 判断二手订单情况下,若部分付款和已付款,排除退货/款的情况,且未确认打款供应商,10,添加确认打款供应商按钮
|
|
|
|
+ if (1 == order.getSecondHandOrderFlag() && 0 == order.getRefundType() && 0 == order.getAffirmPaymentFlag()) {
|
|
|
|
+ if (order.getStatus().toString().startsWith("2") || order.getStatus().toString().startsWith("3")) {
|
|
|
|
+ // 之前是 “00”
|
|
|
|
+ order.setAffirmPaymentFlag(10);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 子订单
|
|
|
|
+ String[] shopOrderIdArr = order.getShopOrderIds().split(",");
|
|
|
|
+ List<String> shopOrderIds = Arrays.asList(shopOrderIdArr);
|
|
|
|
+ List<ShopOrderVo> shopOrderList = orderClubMapper.getShopOrderList(shopOrderIds);
|
|
|
|
+ shopOrderList.forEach(shopOrder -> {
|
|
|
|
+ // 店铺促销活动
|
|
|
|
+ PromotionsVo shopPromotion = null;
|
|
|
|
+ if (null != shopOrder.getOrderPromotionsId() && shopOrder.getOrderPromotionsId() > 0) {
|
|
|
|
+ shopPromotion = orderClubMapper.getOrderPromotionsById(shopOrder.getOrderPromotionsId());
|
|
|
|
+ shopOrder.setShopPromotion(shopPromotion);
|
|
|
|
+ }
|
|
|
|
+ List<OrderProductVo> orderProductList = orderClubMapper.getShopOrderProduct(shopOrder.getShopOrderId());
|
|
|
|
+ for (OrderProductVo orderProduct : orderProductList) {
|
|
|
|
+ boolean taxFlag = (0 == orderProduct.getIncludedTax() && (1 == orderProduct.getInvoiceType() || 2 == orderProduct.getInvoiceType()));
|
|
|
|
+ if (taxFlag) {
|
|
|
|
+ orderProduct.setPrice(MathUtil.add(orderProduct.getPrice(), orderProduct.getAddedValueTax()).doubleValue());
|
|
|
|
+ orderProduct.setDiscountPrice(MathUtil.add(orderProduct.getPrice(), orderProduct.getAddedValueTax()).doubleValue());
|
|
|
|
+ }
|
|
|
|
+ orderProduct.setImage(ImageUtil.getImageUrl("product", orderProduct.getImage(), domain));
|
|
|
|
+ // 查询订单下商品的促销活动
|
|
|
|
+ if (null != orderProduct.getOrderPromotionsId() && orderProduct.getOrderPromotionsId() > 0) {
|
|
|
|
+ PromotionsVo promotions = orderClubMapper.getOrderPromotionsById(orderProduct.getOrderPromotionsId());
|
|
|
|
+ if (null != promotions) {
|
|
|
|
+ if (1 == promotions.getType() && 1 == promotions.getMode()) {
|
|
|
|
+ promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(), MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), orderProduct.getTaxRate()), 100)).doubleValue());
|
|
|
|
+ }
|
|
|
|
+ orderProduct.setProductPromotion(promotions);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ shopOrder.setOrderProductList(orderProductList);
|
|
|
|
+ shopOrder.setShopLogo(ImageUtil.getImageUrl("shopLogo", shopOrder.getShopLogo(), domain));
|
|
|
|
+ });
|
|
|
|
+ // 过滤运费商品
|
|
|
|
+ shopOrderList.removeIf(shopOrder -> shopOrder.getShopId() == 998);
|
|
|
|
+ order.setShopOrderList(shopOrderList);
|
|
|
|
+ // 设置付款金额
|
|
|
|
+ getDiscernReceiptAndSetOrder(order);
|
|
|
|
+ }
|
|
|
|
+ PageInfo<OrderVo> pageInfo = new PageInfo(orderList);
|
|
|
|
+ return ResponseJson.success(pageInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置付款金额
|
|
|
|
+ * @param order OrderVo
|
|
|
|
+ */
|
|
|
|
+ private List<DiscernReceiptVo> getDiscernReceiptAndSetOrder(OrderVo order) {
|
|
|
|
+ // 支付记录
|
|
|
|
+ List<DiscernReceiptVo> discernReceiptList = orderClubMapper.getDiscernReceipt(order.getOrderId());
|
|
|
|
+ Double receiptAmount = 0d;
|
|
|
|
+ // 订单款
|
|
|
|
+ if (!discernReceiptList.isEmpty()) {
|
|
|
|
+ AtomicDouble finalReceiptAmount = new AtomicDouble(0d);
|
|
|
|
+ discernReceiptList.forEach(discernReceipt -> {
|
|
|
|
+ finalReceiptAmount.set(MathUtil.add(finalReceiptAmount.get(), discernReceipt.getAssociateAmount()).doubleValue());
|
|
|
|
+ if (null != discernReceipt.getPayType()) {
|
|
|
|
+ discernReceipt.setPayTypeStr(ReceivablesType.getReceivablesType(discernReceipt.getPayType()));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ receiptAmount = finalReceiptAmount.get();
|
|
|
|
+ } else {
|
|
|
|
+ //返佣款
|
|
|
|
+ if (!order.getShopOrderIds().contains(",")) {
|
|
|
|
+ Double tempAmount = orderClubMapper.getRebateAmountByShopOrder(Integer.parseInt(order.getShopOrderIds()));
|
|
|
|
+ if (null == tempAmount) {
|
|
|
|
+ order.setOnlinePayFlag(0);
|
|
|
|
+ } else {
|
|
|
|
+ order.setOnlinePayFlag(1);
|
|
|
|
+ receiptAmount = tempAmount;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 判断是否可以走线上支付
|
|
|
|
+ int offlineCount = orderClubMapper.countOfflinePayment(order.getOrderId());
|
|
|
|
+ if (offlineCount > 0) {
|
|
|
|
+ order.setOnlinePayFlag(1);
|
|
|
|
+ } else {
|
|
|
|
+ order.setOnlinePayFlag(0);
|
|
|
|
+ }
|
|
|
|
+ //付供应商总金额 + 默认手续费 > 订单总金额
|
|
|
|
+ Double payTotalFee = order.getPayTotalFee();
|
|
|
|
+ Double handlingFee = MathUtil.mul(payTotalFee, 0.0038, 2).doubleValue();
|
|
|
|
+ if (MathUtil.compare(handlingFee, 8) < 0) {
|
|
|
|
+ handlingFee = 8d;
|
|
|
|
+ }
|
|
|
|
+ List<Double> shouldPayShopAmount = orderClubMapper.getShouldPayShopAmountList(order.getOrderId());
|
|
|
|
+ if (!shouldPayShopAmount.isEmpty()) {
|
|
|
|
+ AtomicDouble finalHandlingFee = new AtomicDouble(handlingFee);
|
|
|
|
+ shouldPayShopAmount.forEach(amount -> {
|
|
|
|
+ finalHandlingFee.set(MathUtil.add(finalHandlingFee.get(), amount).doubleValue());
|
|
|
|
+ });
|
|
|
|
+ handlingFee = finalHandlingFee.get();
|
|
|
|
+ }
|
|
|
|
+ if (MathUtil.compare(payTotalFee, handlingFee) < 0) {
|
|
|
|
+ order.setPayButton(true);
|
|
|
|
+ } else {
|
|
|
|
+ order.setPayButton(false);
|
|
|
|
+ }
|
|
|
|
+ //待付总金额
|
|
|
|
+ order.setPendingPayments(MathUtil.sub(order.getPayableAmount(), receiptAmount).doubleValue());
|
|
|
|
+ //支付总金额
|
|
|
|
+ order.setReceiptAmount(receiptAmount);
|
|
|
|
+ return discernReceiptList;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 机构确认订单
|
|
* 机构确认订单
|
|
*
|
|
*
|
|
@@ -124,7 +269,7 @@ public class OrderClubServiceImpl implements OrderClubService {
|
|
double ableUserMoney = baseMapper.getAbleUserMoney(order.getUserId());
|
|
double ableUserMoney = baseMapper.getAbleUserMoney(order.getUserId());
|
|
double updateMoney = MathUtil.add(ableUserMoney, order.getBalancePayFee()).doubleValue();
|
|
double updateMoney = MathUtil.add(ableUserMoney, order.getBalancePayFee()).doubleValue();
|
|
// 退回用户可用余额
|
|
// 退回用户可用余额
|
|
- orderClubMapper.updateUserMoneyByUserId(updateMoney, order.getUserId());
|
|
|
|
|
|
+ orderClubMapper.updateAbleUserMoneyByUserId(updateMoney, order.getUserId());
|
|
log.info(note + ">>>>>>>>>>>可用余额退回原账户(update[user(ableUserMoney)])userId:" + order.getUserId() + ",orderId:" + orderId);
|
|
log.info(note + ">>>>>>>>>>>可用余额退回原账户(update[user(ableUserMoney)])userId:" + order.getUserId() + ",orderId:" + orderId);
|
|
// 取消收支记录
|
|
// 取消收支记录
|
|
BalanceRecordPo balanceRecord = new BalanceRecordPo();
|
|
BalanceRecordPo balanceRecord = new BalanceRecordPo();
|