|
|
|
|
@@ -40,7 +40,6 @@ import javax.annotation.Resource;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
|
|
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.ACCOUNTEIXST;
|
|
|
|
|
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
|
|
|
|
|
@@ -50,43 +49,27 @@ import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
|
|
|
|
|
public class PayService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
@Autowired
|
|
|
|
|
TbOrderInfoMapper tbOrderInfoMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbOrderPaymentMapper tbOrderPaymentMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbShopPayTypeMapper tbShopPayTypeMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbCashierCartMapper tbCashierCartMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbShopUserMapper tbShopUserMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbShopUserFlowMapper tbShopUserFlowMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbOrderDetailMapper tbOrderDetailMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
RestTemplate restTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
RabbitProducer producer;
|
|
|
|
|
@Resource
|
|
|
|
|
private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private TbGroupOrderCouponMapper couponMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbUserInfoMapper tbUserInfoMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
@@ -95,22 +78,24 @@ public class PayService {
|
|
|
|
|
TbShopInfoMapper tbShopInfoMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
TbQuickPayMapper tbQuickPayMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbmerchantAccountMapper tbmerchantAccountMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
TbPlussShopStaffMapper tbPlussShopStaffMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private TbGroupOrderCouponMapper couponMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TbProductSkuMapper productSkuMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TbProductMapper productMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TbShopUnitMapper shopUnitMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TbProductStockDetailMapper productStockDetailMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisUtils redisUtil;
|
|
|
|
|
|
|
|
|
|
@Value("${gateway.url}")
|
|
|
|
|
private String gateWayUrl;
|
|
|
|
|
@Value("${client.backUrl}")
|
|
|
|
|
@@ -121,14 +106,6 @@ public class PayService {
|
|
|
|
|
private String url;
|
|
|
|
|
@Value("${thirdPay.callBack}")
|
|
|
|
|
private String callBack;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbmerchantAccountMapper tbmerchantAccountMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbPlussShopStaffMapper tbPlussShopStaffMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MpShopUserMapper mpShopUserMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
@@ -136,12 +113,13 @@ public class PayService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private MpShopTableMapper mpShopTableMapper;
|
|
|
|
|
|
|
|
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
|
|
|
|
public PayService(RedisTemplate<String, Object> redisTemplate) {
|
|
|
|
|
this.redisTemplate = redisTemplate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
System.out.println(MD5Util.encrypt("123456".concat("13718478323").concat("10")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result queryPayType(String shopId) {
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, tbShopPayTypeMapper.selectByShopId(shopId));
|
|
|
|
|
@@ -305,7 +283,7 @@ public class PayService {
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
//更新子单状态
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("token", token);
|
|
|
|
|
@@ -387,10 +365,10 @@ public class PayService {
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
@@ -509,10 +487,10 @@ public class PayService {
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
|
|
|
|
}
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("token", token);
|
|
|
|
|
@@ -595,7 +573,7 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(memberAccount)) {
|
|
|
|
|
|
|
|
|
|
if (!memberAccount.substring(0, 2).equals("46")) {
|
|
|
|
|
if (!memberAccount.startsWith("46")) {
|
|
|
|
|
return Result.fail(CodeEnum.ERRORQR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -647,10 +625,10 @@ public class PayService {
|
|
|
|
|
//更新购物车状态
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
@@ -671,14 +649,13 @@ public class PayService {
|
|
|
|
|
producer.sendStockSaleMsg(mqData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject baObj=new JSONObject();
|
|
|
|
|
baObj.put("userId",user.getUserId());
|
|
|
|
|
baObj.put("shopId",user.getShopId());
|
|
|
|
|
baObj.put("amount",orderInfo.getPayAmount());
|
|
|
|
|
baObj.put("balance",user.getAmount());
|
|
|
|
|
baObj.put("type","消费");
|
|
|
|
|
baObj.put("time",flow.getCreateTime());
|
|
|
|
|
JSONObject baObj = new JSONObject();
|
|
|
|
|
baObj.put("userId", user.getUserId());
|
|
|
|
|
baObj.put("shopId", user.getShopId());
|
|
|
|
|
baObj.put("amount", orderInfo.getPayAmount());
|
|
|
|
|
baObj.put("balance", user.getAmount());
|
|
|
|
|
baObj.put("type", "消费");
|
|
|
|
|
baObj.put("time", flow.getCreateTime());
|
|
|
|
|
producer.balance(baObj.toString());
|
|
|
|
|
|
|
|
|
|
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
|
|
|
|
@@ -738,7 +715,7 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(), tbUserInfo.getId().toString(),"2").get(0);
|
|
|
|
|
TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(), tbUserInfo.getId().toString(), "2").get(0);
|
|
|
|
|
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
|
|
|
|
|
return Result.fail(CodeEnum.MEMBERNOEXIST);
|
|
|
|
|
}
|
|
|
|
|
@@ -778,11 +755,10 @@ public class PayService {
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -804,14 +780,13 @@ public class PayService {
|
|
|
|
|
producer.sendStockSaleMsg(mqData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject baObj=new JSONObject();
|
|
|
|
|
baObj.put("userId",user.getUserId());
|
|
|
|
|
baObj.put("shopId",user.getShopId());
|
|
|
|
|
baObj.put("amount",orderInfo.getPayAmount());
|
|
|
|
|
baObj.put("balance",user.getAmount());
|
|
|
|
|
baObj.put("type","消费");
|
|
|
|
|
baObj.put("time",flow.getCreateTime());
|
|
|
|
|
JSONObject baObj = new JSONObject();
|
|
|
|
|
baObj.put("userId", user.getUserId());
|
|
|
|
|
baObj.put("shopId", user.getShopId());
|
|
|
|
|
baObj.put("amount", orderInfo.getPayAmount());
|
|
|
|
|
baObj.put("balance", user.getAmount());
|
|
|
|
|
baObj.put("type", "消费");
|
|
|
|
|
baObj.put("time", flow.getCreateTime());
|
|
|
|
|
producer.balance(baObj.toString());
|
|
|
|
|
clearTableInfoCache(orderInfo);
|
|
|
|
|
|
|
|
|
|
@@ -823,7 +798,7 @@ public class PayService {
|
|
|
|
|
return Result.fail(CodeEnum.PARAM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
|
|
|
|
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
|
|
|
|
return Result.fail(CodeEnum.ORDERNOEXIST);
|
|
|
|
|
@@ -859,8 +834,6 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbShopUserFlow userFlow = new TbShopUserFlow();
|
|
|
|
|
userFlow.setAmount((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount());
|
|
|
|
|
userFlow.setBalance(shopUser.getAmount().subtract((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount()));
|
|
|
|
|
@@ -890,10 +863,10 @@ public class PayService {
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(String.valueOf(orderId), "final");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(orderId, "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(orderId, "closed", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
@@ -980,10 +953,10 @@ public class PayService {
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
|
|
|
|
}
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
@@ -1074,10 +1047,10 @@ public class PayService {
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
@@ -1216,7 +1189,7 @@ public class PayService {
|
|
|
|
|
detailPo.setStatus("closed");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
BigDecimal returnAmount = it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId())));;
|
|
|
|
|
BigDecimal returnAmount = it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId())));
|
|
|
|
|
|
|
|
|
|
detailPo.setReturnNum(map1.get(it.getId()));
|
|
|
|
|
detailPos.add(detailPo);
|
|
|
|
|
@@ -1266,7 +1239,7 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId + "");
|
|
|
|
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(String.valueOf(orderId));
|
|
|
|
|
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
@@ -1318,13 +1291,13 @@ public class PayService {
|
|
|
|
|
tbShopUserFlowMapper.insert(flow);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject baObj=new JSONObject();
|
|
|
|
|
baObj.put("userId",user.getUserId());
|
|
|
|
|
baObj.put("shopId",user.getShopId());
|
|
|
|
|
baObj.put("amount",newOrderInfo.getPayAmount());
|
|
|
|
|
baObj.put("balance",user.getAmount());
|
|
|
|
|
baObj.put("type","退款");
|
|
|
|
|
baObj.put("time",flow.getCreateTime());
|
|
|
|
|
JSONObject baObj = new JSONObject();
|
|
|
|
|
baObj.put("userId", user.getUserId());
|
|
|
|
|
baObj.put("shopId", user.getShopId());
|
|
|
|
|
baObj.put("amount", newOrderInfo.getPayAmount());
|
|
|
|
|
baObj.put("balance", user.getAmount());
|
|
|
|
|
baObj.put("type", "退款");
|
|
|
|
|
baObj.put("time", flow.getCreateTime());
|
|
|
|
|
producer.balance(baObj.toString());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1365,13 +1338,9 @@ public class PayService {
|
|
|
|
|
producer.putOrderCollect(jsonObject.toJSONString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
producer.printMechine(newOrderInfo.getId().toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//修改耗材数据
|
|
|
|
|
JSONObject jsonObject1 = new JSONObject();
|
|
|
|
|
jsonObject1.put("orderId", newOrderInfo.getId());
|
|
|
|
|
@@ -1692,7 +1661,6 @@ public class PayService {
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result getOrderDiscount(String staffId, String orderId, String token) {
|
|
|
|
|
if (ObjectUtil.isNull(staffId) || ObjectUtil.isNull(orderId) || ObjectUtil.isEmpty(staffId) || ObjectUtil.isEmpty(orderId)) {
|
|
|
|
|
return Result.fail(CodeEnum.PARAM);
|
|
|
|
|
@@ -1719,7 +1687,7 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("master".equals(staff.getType())) {
|
|
|
|
|
return Result.success(SUCCESS, new BigDecimal(0.1));
|
|
|
|
|
return Result.success(SUCCESS, new BigDecimal("0.1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(staff.getMaxDiscountAmount()) || ObjectUtil.isNull(staff.getMaxDiscountAmount())) {
|
|
|
|
|
@@ -1729,7 +1697,7 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
if ("0".equals(staff.getDiscountType())) {
|
|
|
|
|
if (staff.getMaxDiscountAmount().compareTo(tbOrderInfo.getOrderAmount()) >= 0) {
|
|
|
|
|
staff.setMaxDiscountAmount(new BigDecimal(0.1));
|
|
|
|
|
staff.setMaxDiscountAmount(new BigDecimal("0.1"));
|
|
|
|
|
} else {
|
|
|
|
|
staff.setMaxDiscountAmount(BigDecimal.ONE.subtract(staff.getMaxDiscountAmount().divide(tbOrderInfo.getOrderAmount(), 2, RoundingMode.HALF_DOWN).setScale(2, RoundingMode.HALF_DOWN)));
|
|
|
|
|
}
|
|
|
|
|
@@ -1739,9 +1707,8 @@ public class PayService {
|
|
|
|
|
return Result.success(SUCCESS, staff.getMaxDiscountAmount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result pcscanpay(String orderId,String ip,String userId,String payType) throws JsonProcessingException {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(ip)) {
|
|
|
|
|
public Result pcscanpay(String orderId, String ip, String userId, String payType) throws JsonProcessingException {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(ip)) {
|
|
|
|
|
return Result.fail(CodeEnum.PARAM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1757,7 +1724,6 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, null);
|
|
|
|
|
if (ObjectUtil.isEmpty(cashierCarts) || ObjectUtil.isNull(cashierCarts)) {
|
|
|
|
|
return Result.fail(CodeEnum.CARTEXIST);
|
|
|
|
|
@@ -1778,7 +1744,6 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
|
|
|
|
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
|
|
|
|
payment = new TbOrderPayment();
|
|
|
|
|
@@ -1814,10 +1779,10 @@ public class PayService {
|
|
|
|
|
reqbody = body.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url,thirdApply.getAppId(),thirdApply.getAppToken(),reqbody,reqbody,orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(),payType,"WECHAT".equals(payType)?thirdApply.getSmallAppid():null,userId,ip,DateUtils.getSsdfTimes(),thirdApply.getStoreId(),backUrl,backUrl);
|
|
|
|
|
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url, thirdApply.getAppId(), thirdApply.getAppToken(), reqbody, reqbody, orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(), payType, "WECHAT".equals(payType) ? thirdApply.getSmallAppid() : null, userId, ip, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), backUrl, backUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
if ("000000".equals(publicResp.getCode())) {
|
|
|
|
|
JspayResp scanpayResp = publicResp.getObjData();
|
|
|
|
|
if ("TRADE_SUCCESS".equals(scanpayResp.getState())) {
|
|
|
|
|
@@ -1835,10 +1800,10 @@ public class PayService {
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
|
|
|
|
}else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
|
|
|
|
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
|
|
|
|
} else {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// JSONObject jsonObject = new JSONObject();
|
|
|
|
|
@@ -1854,7 +1819,7 @@ public class PayService {
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
|
|
|
|
|
|
|
|
|
|
}else if("TRADE_AWAIT".equals(scanpayResp.getState())){
|
|
|
|
|
} else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
|
|
|
|
|
orderInfo.setStatus("paying");
|
|
|
|
|
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
|
|
@@ -1864,11 +1829,11 @@ public class PayService {
|
|
|
|
|
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if("WECHAT".equals(scanpayResp.getPayType())){
|
|
|
|
|
if ("WECHAT".equals(scanpayResp.getPayType())) {
|
|
|
|
|
orderInfo.setPayType("WECHAT");
|
|
|
|
|
}else if("ALIPAY".equals(scanpayResp.getPayType())){
|
|
|
|
|
} else if ("ALIPAY".equals(scanpayResp.getPayType())) {
|
|
|
|
|
orderInfo.setPayType("ALIPAY");
|
|
|
|
|
}else if("UNIONPAY".equals(scanpayResp.getPayType())){
|
|
|
|
|
} else if ("UNIONPAY".equals(scanpayResp.getPayType())) {
|
|
|
|
|
orderInfo.setPayType("UNIONPAY");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1877,7 +1842,7 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
return Result.success(CodeEnum.PAYING,mapper.readTree(scanpayResp.getPayInfo()));
|
|
|
|
|
return Result.success(CodeEnum.PAYING, mapper.readTree(scanpayResp.getPayInfo()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1886,7 +1851,6 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String generateOrderNumber() {
|
|
|
|
|
String date = DateUtils.getSdfTimes();
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
@@ -1894,28 +1858,23 @@ public class PayService {
|
|
|
|
|
return "QR" + date + randomNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result createOrder(String ip, String userId, String payType, String shopId, BigDecimal amount) throws JsonProcessingException {
|
|
|
|
|
|
|
|
|
|
public Result createOrder(String ip,String userId,String payType,String shopId,BigDecimal amount) throws JsonProcessingException {
|
|
|
|
|
if (ObjectUtil.isNull(userId) || ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(payType) || ObjectUtil.isNull(payType)
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNull(userId)||ObjectUtil.isEmpty(userId)||ObjectUtil.isEmpty(payType)||ObjectUtil.isNull(payType)
|
|
|
|
|
|
|
|
|
|
||ObjectUtil.isNull(shopId)||ObjectUtil.isEmpty(shopId)||ObjectUtil.isNull(shopId)||ObjectUtil.isNull(amount)||ObjectUtil.isEmpty(amount)
|
|
|
|
|
){
|
|
|
|
|
|| ObjectUtil.isNull(shopId) || ObjectUtil.isEmpty(shopId) || ObjectUtil.isNull(shopId) || ObjectUtil.isNull(amount) || ObjectUtil.isEmpty(amount)
|
|
|
|
|
) {
|
|
|
|
|
return Result.fail(CodeEnum.PARAM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!"WECHAT".equals(payType)||!"ALIPAY".equals(payType)){
|
|
|
|
|
return Result.fail(CodeEnum.PARAM);
|
|
|
|
|
}
|
|
|
|
|
TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
|
|
|
|
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNull(shopInfo)){
|
|
|
|
|
if (ObjectUtil.isNull(shopInfo)) {
|
|
|
|
|
return Result.fail(CodeEnum.SHOPINFONOEXIST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbOrderInfo orderInfo=new TbOrderInfo();
|
|
|
|
|
TbOrderInfo orderInfo = new TbOrderInfo();
|
|
|
|
|
|
|
|
|
|
String orderNo = generateOrderNumber();
|
|
|
|
|
orderInfo.setOrderNo(orderNo);
|
|
|
|
|
@@ -1963,8 +1922,6 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
|
|
|
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
|
|
|
|
return Result.fail(CodeEnum.NOCUSTOMER);
|
|
|
|
|
@@ -1973,7 +1930,7 @@ public class PayService {
|
|
|
|
|
String reqbody = "店铺收款码";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url,thirdApply.getAppId(),thirdApply.getAppToken(),reqbody,reqbody,orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(),payType,"WECHAT".equals(payType)?thirdApply.getSmallAppid():null,userId,ip,DateUtils.getSsdfTimes(),thirdApply.getStoreId(),backUrl,backUrl);
|
|
|
|
|
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url, thirdApply.getAppId(), thirdApply.getAppToken(), reqbody, reqbody, orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(), payType, "WECHAT".equals(payType) ? thirdApply.getSmallAppid() : null, userId, ip, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), backUrl, backUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
@@ -2014,22 +1971,55 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
return Result.success(CodeEnum.PAYING, mapper.readTree(scanpayResp.getPayInfo()));
|
|
|
|
|
|
|
|
|
|
Map<String,Object> map=new HashMap<>();
|
|
|
|
|
|
|
|
|
|
map.put("orderInfo",orderInfo);
|
|
|
|
|
map.put("payInfo",mapper.readTree(scanpayResp.getPayInfo()));
|
|
|
|
|
return Result.success(CodeEnum.PAYING, map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Result.fail(CodeEnum.FAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result queryOrderPay(String orderId) {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId)) {
|
|
|
|
|
return Result.fail(CodeEnum.PARAM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
|
|
|
|
return Result.fail(CodeEnum.ORDERNOEXIST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ("unpaid".equals(orderInfo.getStatus()) || "paying".equals(orderInfo.getStatus())) {
|
|
|
|
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
|
|
|
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
|
|
|
|
return Result.fail(CodeEnum.NOCUSTOMER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbOrderPayment tbOrderPayment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(tbOrderPayment)) {
|
|
|
|
|
|
|
|
|
|
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), tbOrderPayment.getTradeNumber(), null, thirdApply.getAppToken());
|
|
|
|
|
if (ObjectUtil.isNotNull(orderstatus) && ObjectUtil.isNotEmpty(orderstatus)) {
|
|
|
|
|
if ("000000".equals(orderstatus.getCode())) {
|
|
|
|
|
if ("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())) {
|
|
|
|
|
orderInfo.setStatus("closed");
|
|
|
|
|
orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, orderInfo);
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
System.out.println(MD5Util.encrypt("123456".concat("13718478323").concat("10")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|