|
@@ -0,0 +1,101 @@
|
|
|
+package com.caimei365.order.service.impl;
|
|
|
+
|
|
|
+import com.caimei365.order.mapper.BaseMapper;
|
|
|
+import com.caimei365.order.mapper.OnlinePayMapper;
|
|
|
+import com.caimei365.order.mapper.OrderCommonMapper;
|
|
|
+import com.caimei365.order.model.ResponseJson;
|
|
|
+import com.caimei365.order.model.vo.DiscernReceiptVo;
|
|
|
+import com.caimei365.order.model.vo.OrderProductVo;
|
|
|
+import com.caimei365.order.model.vo.OrderVo;
|
|
|
+import com.caimei365.order.service.OnlinePayService;
|
|
|
+import com.caimei365.order.utils.MathUtil;
|
|
|
+import com.google.common.util.concurrent.AtomicDouble;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2021/7/29
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OnlinePayServiceImpl implements OnlinePayService {
|
|
|
+ @Resource
|
|
|
+ private BaseMapper baseMapper;
|
|
|
+ @Resource
|
|
|
+ private OnlinePayMapper onlinePayMapper;
|
|
|
+ @Resource
|
|
|
+ private OrderCommonMapper orderCommonMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取线上支付全局开关状态
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Integer> getPayOnLineSwitch() {
|
|
|
+ Integer status = onlinePayMapper.getPayOnLineSwitch();
|
|
|
+ return ResponseJson.success(status);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收银台数据显示
|
|
|
+ *
|
|
|
+ * @param orderId 订单Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Map<String, Object>> getCheckoutCounter(Integer orderId) {
|
|
|
+ // 订单信息
|
|
|
+ OrderVo order = onlinePayMapper.getOrderByOrderId(orderId);
|
|
|
+ if (null == order) {
|
|
|
+ return ResponseJson.error("订单不存在", null);
|
|
|
+ }
|
|
|
+ // 机构信息
|
|
|
+ String userName = baseMapper.getUserNameByUserId(order.getUserId());
|
|
|
+ // 支付记录
|
|
|
+ List<DiscernReceiptVo> discernReceiptList = orderCommonMapper.getDiscernReceipt(order.getOrderId());
|
|
|
+ if (!discernReceiptList.isEmpty()) {
|
|
|
+ AtomicDouble receiptAmount = new AtomicDouble(0d);
|
|
|
+ AtomicReference<Boolean> offlineFlag = new AtomicReference<>(false);
|
|
|
+ discernReceiptList.forEach(discernReceipt -> {
|
|
|
+ if (2 == discernReceipt.getPayWay()) {
|
|
|
+ offlineFlag.set(true);
|
|
|
+ }
|
|
|
+ if (3 == discernReceipt.getReceiptStatus()) {
|
|
|
+ receiptAmount.set(MathUtil.add(receiptAmount.get(), discernReceipt.getAssociateAmount()).doubleValue());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (offlineFlag.get()) {
|
|
|
+ return ResponseJson.error("已经线下支付过,只能支付支付!", null);
|
|
|
+ }
|
|
|
+ order.setReceiptAmount(receiptAmount.get());
|
|
|
+ }
|
|
|
+ // 商品数据
|
|
|
+ List<OrderProductVo> orderProductList = orderCommonMapper.getOrderProductByOrderId(orderId);
|
|
|
+ //过滤运费商品
|
|
|
+ orderProductList.removeIf(product -> product.getShopId() == 998);
|
|
|
+ // 是否有商品发票属性的限制
|
|
|
+ orderProductList.forEach(orderProduct -> {
|
|
|
+ // 商品含税未知 or 订单选择开企业发票,商品不含税不能开票
|
|
|
+ boolean productTaxFlag = (null == orderProduct.getIncludedTax()) || (null == orderProduct.getInvoiceType()) || (2 == orderProduct.getIncludedTax())
|
|
|
+ || (2 == order.getInvoiceFlag() && (0 == orderProduct.getIncludedTax() && 3 == orderProduct.getInvoiceType()));
|
|
|
+ if (productTaxFlag) {
|
|
|
+ order.setInvoiceStatus(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 返回数据
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("userName", userName);
|
|
|
+ map.put("order", order);
|
|
|
+ map.put("discernReceipt", discernReceiptList);
|
|
|
+ map.put("orderProductList", orderProductList);
|
|
|
+
|
|
|
+ return ResponseJson.success(map);
|
|
|
+ }
|
|
|
+}
|