|
|
|
|
@@ -8,13 +8,13 @@ import com.chaozhanggui.system.cashierservice.entity.*;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.entity.po.OrderDetailPo;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.model.ReturnWTZInfo;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.thirdpay.resp.MainScanResp;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.thirdpay.resp.OrderReturnResp;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.thirdpay.resp.OrderStatusQueryResp;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService;
|
|
|
|
|
@@ -30,8 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@@ -74,37 +73,33 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbUserInfoMapper tbUserInfoMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
ThirdPayService thirdPayService;
|
|
|
|
|
@Autowired
|
|
|
|
|
TbShopInfoMapper tbShopInfoMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
TbQuickPayMapper tbQuickPayMapper;
|
|
|
|
|
@Value("${gateway.url}")
|
|
|
|
|
private String gateWayUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${client.backUrl}")
|
|
|
|
|
private String backUrl;
|
|
|
|
|
|
|
|
|
|
@Value("${thirdPay.payType}")
|
|
|
|
|
private String thirdPayType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${thirdPay.url}")
|
|
|
|
|
private String url;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${thirdPay.callBack}")
|
|
|
|
|
private String callBack;
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
ThirdPayService thirdPayService;
|
|
|
|
|
System.out.printf("%.2f%n", new BigDecimal(1).setScale(2, RoundingMode.DOWN));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result queryPayType(String shopId) {
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, tbShopPayTypeMapper.selectByShopId(shopId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result scanPay(String orderId, String authCode, String ip, String token) {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(authCode) || ObjectUtil.isEmpty(ip)) {
|
|
|
|
|
@@ -123,12 +118,12 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<TbCashierCart> cashierCarts= tbCashierCartMapper.selectByOrderId(orderId,"create");
|
|
|
|
|
if(ObjectUtil.isEmpty(cashierCarts)||ObjectUtil.isNull(cashierCarts)){
|
|
|
|
|
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "create");
|
|
|
|
|
if (ObjectUtil.isEmpty(cashierCarts) || ObjectUtil.isNull(cashierCarts)) {
|
|
|
|
|
return Result.fail(CodeEnum.CARTEXIST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuffer body=new StringBuffer();
|
|
|
|
|
StringBuffer body = new StringBuffer();
|
|
|
|
|
for (TbCashierCart cashierCart : cashierCarts) {
|
|
|
|
|
body.append(cashierCart.getName());
|
|
|
|
|
}
|
|
|
|
|
@@ -195,14 +190,14 @@ public class PayService {
|
|
|
|
|
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
|
|
|
|
|
|
|
if("ysk".equals(thirdPayType)){
|
|
|
|
|
if ("ysk".equals(thirdPayType)) {
|
|
|
|
|
|
|
|
|
|
ScanPayReq scanPayReq = new ScanPayReq();
|
|
|
|
|
scanPayReq.setAppId(thirdApply.getAppId());
|
|
|
|
|
scanPayReq.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
scanPayReq.setAuthCode(authCode);
|
|
|
|
|
scanPayReq.setNotifyUrl(backUrl);
|
|
|
|
|
scanPayReq.setConsumeFee(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
|
|
|
|
scanPayReq.setConsumeFee(payment.getAmount().setScale(2, RoundingMode.DOWN).toPlainString());
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(scanPayReq);
|
|
|
|
|
scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
@@ -258,21 +253,21 @@ public class PayService {
|
|
|
|
|
return Result.fail(object.getString("msg"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
String reqbody="";
|
|
|
|
|
String reqbody = "";
|
|
|
|
|
|
|
|
|
|
if(body.length()>15){
|
|
|
|
|
reqbody=body.substring(0,6).concat("....").concat(body.substring(body.length()-6,body.length())).toString();
|
|
|
|
|
}else {
|
|
|
|
|
reqbody=body.toString();
|
|
|
|
|
if (body.length() > 15) {
|
|
|
|
|
reqbody = body.substring(0, 6).concat("....").concat(body.substring(body.length() - 6, body.length()));
|
|
|
|
|
} else {
|
|
|
|
|
reqbody = body.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PublicResp<MainScanResp> publicResp= thirdPayService.mainScan(url,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),payType.equals("wechatPay")?"wx212769170d2c6b2a":null,authCode,orderInfo.getOrderNo(),"S2405103298",callBack,thirdApply.getAppToken());
|
|
|
|
|
if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){
|
|
|
|
|
if("000000".equals(publicResp.getCode())){
|
|
|
|
|
MainScanResp mainScanResp= publicResp.getObjData();
|
|
|
|
|
if("TRADE_SUCCESS".equals(mainScanResp.getState())){
|
|
|
|
|
PublicResp<MainScanResp> publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), reqbody, reqbody, payment.getAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null, authCode, orderInfo.getOrderNo(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken());
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
if ("000000".equals(publicResp.getCode())) {
|
|
|
|
|
MainScanResp mainScanResp = publicResp.getObjData();
|
|
|
|
|
if ("TRADE_SUCCESS".equals(mainScanResp.getState())) {
|
|
|
|
|
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
|
|
|
|
payment.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
|
|
|
|
@@ -299,7 +294,7 @@ public class PayService {
|
|
|
|
|
producer.printMechine(orderId);
|
|
|
|
|
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, mainScanResp);
|
|
|
|
|
}else if("TRADE_AWAIT".equals(mainScanResp.getState())){
|
|
|
|
|
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
|
|
|
|
orderInfo.setStatus("paying");
|
|
|
|
|
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
|
|
@@ -318,7 +313,6 @@ public class PayService {
|
|
|
|
|
return Result.fail("失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result queryOrder(String orderId, String token) {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId)) {
|
|
|
|
|
return Result.fail(CodeEnum.PARAM);
|
|
|
|
|
@@ -339,46 +333,46 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
TbOrderPayment tbOrderPayment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(tbOrderPayment)) {
|
|
|
|
|
if("ysk".equals(thirdPayType)){
|
|
|
|
|
TradeQueryReq tradeQueryReq = new TradeQueryReq();
|
|
|
|
|
tradeQueryReq.setAppId(thirdApply.getAppId());
|
|
|
|
|
tradeQueryReq.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
tradeQueryReq.setOrderNumber(tbOrderPayment.getTradeNumber());
|
|
|
|
|
if ("ysk".equals(thirdPayType)) {
|
|
|
|
|
TradeQueryReq tradeQueryReq = new TradeQueryReq();
|
|
|
|
|
tradeQueryReq.setAppId(thirdApply.getAppId());
|
|
|
|
|
tradeQueryReq.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
tradeQueryReq.setOrderNumber(tbOrderPayment.getTradeNumber());
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(tradeQueryReq);
|
|
|
|
|
tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"), tradeQueryReq, String.class);
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (object.get("code").equals("0")) {
|
|
|
|
|
JSONObject data = object.getJSONObject("data");
|
|
|
|
|
if ("1".equals(data.getString("status"))) {
|
|
|
|
|
orderInfo.setStatus("closed");
|
|
|
|
|
orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(tradeQueryReq);
|
|
|
|
|
tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"), tradeQueryReq, String.class);
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (object.get("code").equals("0")) {
|
|
|
|
|
JSONObject data = object.getJSONObject("data");
|
|
|
|
|
if ("1".equals(data.getString("status"))) {
|
|
|
|
|
orderInfo.setStatus("closed");
|
|
|
|
|
orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
|
|
|
|
|
|
|
//更新购物车状态
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
//更新购物车状态
|
|
|
|
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("token", token);
|
|
|
|
|
jsonObject.put("type", "create");
|
|
|
|
|
jsonObject.put("orderId", orderId);
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("token", token);
|
|
|
|
|
jsonObject.put("type", "create");
|
|
|
|
|
jsonObject.put("orderId", orderId);
|
|
|
|
|
|
|
|
|
|
producer.putOrderCollect(jsonObject.toJSONString());
|
|
|
|
|
producer.putOrderCollect(jsonObject.toJSONString());
|
|
|
|
|
|
|
|
|
|
producer.printMechine(orderId);
|
|
|
|
|
producer.printMechine(orderId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
PublicResp<OrderStatusQueryResp> orderstatus=thirdPayService.queryOrder(url,thirdApply.getAppId(),orderInfo.getOrderNo(),null,thirdApply.getAppToken());
|
|
|
|
|
if(ObjectUtil.isNotNull(orderstatus)&&ObjectUtil.isNotEmpty(orderstatus)){
|
|
|
|
|
if("000000".equals(orderstatus.getCode())){
|
|
|
|
|
if("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())){
|
|
|
|
|
} else {
|
|
|
|
|
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), null, orderInfo.getOrderNo(), 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);
|
|
|
|
|
@@ -408,7 +402,6 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result accountPay(String orderId, String memberId, String token) {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(memberId)) {
|
|
|
|
|
@@ -432,7 +425,6 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId));
|
|
|
|
|
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
|
|
|
|
|
return Result.fail(CodeEnum.MEMBERNOEXIST);
|
|
|
|
|
@@ -487,7 +479,6 @@ public class PayService {
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result memberScanPay(String orderId, String memberCode, String token) {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(memberCode)) {
|
|
|
|
|
@@ -512,13 +503,13 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbUserInfo tbUserInfo=tbUserInfoMapper.selectByCardNo(memberCode);
|
|
|
|
|
if(ObjectUtil.isEmpty(tbUserInfo)){
|
|
|
|
|
TbUserInfo tbUserInfo = tbUserInfoMapper.selectByCardNo(memberCode);
|
|
|
|
|
if (ObjectUtil.isEmpty(tbUserInfo)) {
|
|
|
|
|
return Result.fail(CodeEnum.ACCOUNTEIXST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(),tbUserInfo.getId().toString()).get(0);
|
|
|
|
|
TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(), tbUserInfo.getId().toString()).get(0);
|
|
|
|
|
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
|
|
|
|
|
return Result.fail(CodeEnum.MEMBERNOEXIST);
|
|
|
|
|
}
|
|
|
|
|
@@ -545,7 +536,7 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
|
|
|
|
orderInfo.setMemberId(user.getUserId().toString());
|
|
|
|
|
orderInfo.setMemberId(user.getUserId());
|
|
|
|
|
orderInfo.setPayType("deposit");
|
|
|
|
|
orderInfo.setStatus("closed");
|
|
|
|
|
orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo()));
|
|
|
|
|
@@ -572,7 +563,6 @@ public class PayService {
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result cashPay(String orderId, String token) {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId)) {
|
|
|
|
|
@@ -621,7 +611,6 @@ public class PayService {
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result bankPay(String orderId, String token) {
|
|
|
|
|
if (ObjectUtil.isEmpty(orderId)) {
|
|
|
|
|
@@ -669,7 +658,6 @@ public class PayService {
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result returnOrder(List<TbOrderDetail> list, String token) {
|
|
|
|
|
if (ObjectUtil.isEmpty(list) || list.size() <= 0) {
|
|
|
|
|
@@ -738,11 +726,11 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
OrderDetailPo detailPo = new OrderDetailPo();
|
|
|
|
|
// totalAmount = totalAmount.add(it.getPriceAmount());
|
|
|
|
|
totalAmount = totalAmount.add(it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(map1.get(it.getId()))));
|
|
|
|
|
totalAmount = totalAmount.add(it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId()))));
|
|
|
|
|
saleAmount = saleAmount.add(it.getPrice());
|
|
|
|
|
payAmount = payAmount.add(it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(map1.get(it.getId()))));
|
|
|
|
|
payAmount = payAmount.add(it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId()))));
|
|
|
|
|
// payAmount=payAmount.add(it.getPriceAmount());
|
|
|
|
|
packAMount = packAMount.add(it.getPackAmount().divide(new BigDecimal(it.getNum()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(map1.get(it.getId()))));
|
|
|
|
|
packAMount = packAMount.add(it.getPackAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId()))));
|
|
|
|
|
|
|
|
|
|
detailPo.setId(it.getId());
|
|
|
|
|
if (map1.get(it.getId()) + it.getReturnNum() >= it.getNum()) {
|
|
|
|
|
@@ -751,7 +739,7 @@ public class PayService {
|
|
|
|
|
detailPo.setStatus("closed");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
BigDecimal returnAmount = it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, BigDecimal.ROUND_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);
|
|
|
|
|
it.setNum(map1.get(it.getId()));
|
|
|
|
|
@@ -774,26 +762,43 @@ public class PayService {
|
|
|
|
|
if ("scanCode".equals(payType) || "wx_lite".equals(payType)) {
|
|
|
|
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(merchantId));
|
|
|
|
|
MsgException.checkNull(thirdApply, "支付参数配置错误");
|
|
|
|
|
ReturnOrderReq req = new ReturnOrderReq();
|
|
|
|
|
req.setAppId(thirdApply.getAppId());
|
|
|
|
|
req.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
req.setOrderNumber(orderInfo.getPayOrderNo());
|
|
|
|
|
req.setAmount(String.format("%.2f", newOrderInfo.getPayAmount().setScale(2, BigDecimal.ROUND_DOWN)));
|
|
|
|
|
req.setMercRefundNo(orderInfo.getOrderNo());
|
|
|
|
|
req.setRefundReason("退货");
|
|
|
|
|
req.setPayPassword(thirdApply.getPayPassword());
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(req);
|
|
|
|
|
req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
log.info("merchantOrderReturn req:{}", JSONUtil.toJsonStr(req));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/returnOrder"), req, String.class);
|
|
|
|
|
log.info("merchantOrderReturn:{}", response.getBody());
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (!object.get("code").equals("0")) {
|
|
|
|
|
MsgException.check(true, "退款渠道调用失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("ysk".equals(thirdPayType)) {
|
|
|
|
|
ReturnOrderReq req = new ReturnOrderReq();
|
|
|
|
|
req.setAppId(thirdApply.getAppId());
|
|
|
|
|
req.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
req.setOrderNumber(orderInfo.getPayOrderNo());
|
|
|
|
|
req.setAmount(String.format("%.2f", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN)));
|
|
|
|
|
req.setMercRefundNo(orderInfo.getOrderNo());
|
|
|
|
|
req.setRefundReason("退货");
|
|
|
|
|
req.setPayPassword(thirdApply.getPayPassword());
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(req);
|
|
|
|
|
req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
log.info("merchantOrderReturn req:{}", JSONUtil.toJsonStr(req));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/returnOrder"), req, String.class);
|
|
|
|
|
log.info("merchantOrderReturn:{}", response.getBody());
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (!object.get("code").equals("0")) {
|
|
|
|
|
MsgException.check(true, "退款渠道调用失败");
|
|
|
|
|
}
|
|
|
|
|
// newOrderInfo.setPayOrderNo(object.getJSONObject("data").getString("refundOrderNumber"));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), null, orderInfo.getOrderNo(), "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
if ("000000".equals(publicResp.getCode())) {
|
|
|
|
|
if (!publicResp.getObjData().getState().equals("ING") || "SUCCESS".equals(publicResp.getObjData().getState())) {
|
|
|
|
|
MsgException.check(true, "退款渠道调用失败");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MsgException.check(true, "退款渠道调用失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -832,139 +837,145 @@ public class PayService {
|
|
|
|
|
producer.putOrderCollect(jsonObject.toJSONString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
producer.printMechine(newOrderInfo.getId() + "");
|
|
|
|
|
producer.printMechine(String.valueOf(newOrderInfo.getId()));
|
|
|
|
|
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result quickPay(String token, String amount, String authCode, String payType) {
|
|
|
|
|
|
|
|
|
|
JSONObject info = TokenUtil.parseParamFromToken(token);
|
|
|
|
|
MsgException.checkNull(info, "获取信息失败");
|
|
|
|
|
|
|
|
|
|
String shopId = info.getString("shopId");
|
|
|
|
|
String staffId = info.getString("staffId");
|
|
|
|
|
|
|
|
|
|
BigDecimal payAmount = new BigDecimal(amount).setScale(2, RoundingMode.DOWN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbShopInfoMapper tbShopInfoMapper;
|
|
|
|
|
String orderNo = SnowFlakeUtil.generateOrderNo();
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TbQuickPayMapper tbQuickPayMapper;
|
|
|
|
|
TbQuickPay tbQuickPay = new TbQuickPay(null, Integer.valueOf(staffId), Integer.valueOf(shopId), orderNo, payType, payAmount, "1", null, new Date(), null);
|
|
|
|
|
|
|
|
|
|
public Result quickPay(String token,String amount,String authCode,String payType){
|
|
|
|
|
|
|
|
|
|
JSONObject info= TokenUtil.parseParamFromToken(token);
|
|
|
|
|
MsgException.checkNull(info,"获取信息失败");
|
|
|
|
|
|
|
|
|
|
String shopId=info.getString("shopId");
|
|
|
|
|
String staffId=info.getString("staffId");
|
|
|
|
|
|
|
|
|
|
BigDecimal payAmount=new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String orderNo=SnowFlakeUtil.generateOrderNo();
|
|
|
|
|
|
|
|
|
|
TbQuickPay tbQuickPay= new TbQuickPay(null,Integer.valueOf(staffId),Integer.valueOf(shopId),orderNo,payType,payAmount,"1",null,new Date(),null);
|
|
|
|
|
|
|
|
|
|
if("cash".equals(payType)){
|
|
|
|
|
if ("cash".equals(payType)) {
|
|
|
|
|
tbQuickPay.setStatus("0");
|
|
|
|
|
tbQuickPay.setUpdateTime(new Date());
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
TbShopInfo tbShopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
|
|
|
|
MsgException.checkNull(tbShopInfo,"店铺信息不存在");
|
|
|
|
|
} else {
|
|
|
|
|
TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
|
|
|
|
MsgException.checkNull(tbShopInfo, "店铺信息不存在");
|
|
|
|
|
|
|
|
|
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbShopInfo.getMerchantId()));
|
|
|
|
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
|
|
|
|
return Result.fail(CodeEnum.NOCUSTOMER);
|
|
|
|
|
}
|
|
|
|
|
ScanPayReq scanPayReq = new ScanPayReq();
|
|
|
|
|
scanPayReq.setAppId(thirdApply.getAppId());
|
|
|
|
|
scanPayReq.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
scanPayReq.setAuthCode(authCode);
|
|
|
|
|
scanPayReq.setNotifyUrl(backUrl);
|
|
|
|
|
scanPayReq.setConsumeFee(payAmount.toPlainString());
|
|
|
|
|
if ("ysk".equals(thirdPayType)) {
|
|
|
|
|
ScanPayReq scanPayReq = new ScanPayReq();
|
|
|
|
|
scanPayReq.setAppId(thirdApply.getAppId());
|
|
|
|
|
scanPayReq.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
scanPayReq.setAuthCode(authCode);
|
|
|
|
|
scanPayReq.setNotifyUrl(backUrl);
|
|
|
|
|
scanPayReq.setConsumeFee(payAmount.toPlainString());
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(scanPayReq);
|
|
|
|
|
scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class);
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (object.get("code").equals("0")) {
|
|
|
|
|
tbQuickPay.setTradeNo(object.getJSONObject("data").get("orderNumber").toString());
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(scanPayReq);
|
|
|
|
|
scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class);
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (object.get("code").equals("0")) {
|
|
|
|
|
tbQuickPay.setTradeNo(object.getJSONObject("data").get("orderNumber").toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
tbQuickPayMapper.insert(tbQuickPay);
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS,tbQuickPay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result queryQuickPayStatus(Integer id){
|
|
|
|
|
|
|
|
|
|
TbQuickPay tbQuickPay= tbQuickPayMapper.selectByPrimaryKey(id);
|
|
|
|
|
MsgException.checkNull(tbQuickPay,"订单信息不存在");
|
|
|
|
|
if(tbQuickPay.getPayType().equals("scanpay")&&"1".equals(tbQuickPay.getStatus())) {
|
|
|
|
|
|
|
|
|
|
TbShopInfo tbShopInfo= tbShopInfoMapper.selectByPrimaryKey(tbQuickPay.getShopId());
|
|
|
|
|
MsgException.checkNull(tbShopInfo,"店铺信息不存在");
|
|
|
|
|
|
|
|
|
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbShopInfo.getMerchantId()));
|
|
|
|
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
|
|
|
|
return Result.fail(CodeEnum.NOCUSTOMER);
|
|
|
|
|
}
|
|
|
|
|
TradeQueryReq tradeQueryReq = new TradeQueryReq();
|
|
|
|
|
tradeQueryReq.setAppId(thirdApply.getAppId());
|
|
|
|
|
tradeQueryReq.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
tradeQueryReq.setOrderNumber(tbQuickPay.getTradeNo());
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(tradeQueryReq);
|
|
|
|
|
tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"), tradeQueryReq, String.class);
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (object.get("code").equals("0")) {
|
|
|
|
|
JSONObject data = object.getJSONObject("data");
|
|
|
|
|
if ("1".equals(data.getString("status"))) {
|
|
|
|
|
|
|
|
|
|
tbQuickPay.setStatus("0");
|
|
|
|
|
tbQuickPay.setUpdateTime(new Date());
|
|
|
|
|
tbQuickPayMapper.updateByPrimaryKeySelective(tbQuickPay);
|
|
|
|
|
PublicResp<MainScanResp> publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), "快捷收款", "快捷收款", payAmount.setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null, authCode, tbQuickPay.getOrderNo(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken());
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
if ("000000".equals(publicResp.getCode())) {
|
|
|
|
|
MainScanResp mainScanResp = publicResp.getObjData();
|
|
|
|
|
if ("TRADE_SUCCESS".equals(mainScanResp.getState())) {
|
|
|
|
|
tbQuickPay.setTradeNo(mainScanResp.getPayOrderId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS,tbQuickPay);
|
|
|
|
|
|
|
|
|
|
tbQuickPayMapper.insert(tbQuickPay);
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, tbQuickPay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result queryQuickPayStatus(Integer id) {
|
|
|
|
|
|
|
|
|
|
TbQuickPay tbQuickPay = tbQuickPayMapper.selectByPrimaryKey(id);
|
|
|
|
|
MsgException.checkNull(tbQuickPay, "订单信息不存在");
|
|
|
|
|
if (tbQuickPay.getPayType().equals("scanpay") && "1".equals(tbQuickPay.getStatus())) {
|
|
|
|
|
|
|
|
|
|
public Result queryQuickPay(String token,int pageNo,int pageSize){
|
|
|
|
|
JSONObject info= TokenUtil.parseParamFromToken(token);
|
|
|
|
|
MsgException.checkNull(info,"获取信息失败");
|
|
|
|
|
TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(tbQuickPay.getShopId());
|
|
|
|
|
MsgException.checkNull(tbShopInfo, "店铺信息不存在");
|
|
|
|
|
|
|
|
|
|
String shopId=info.getString("shopId");
|
|
|
|
|
String staffId=info.getString("staffId");
|
|
|
|
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbShopInfo.getMerchantId()));
|
|
|
|
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
|
|
|
|
return Result.fail(CodeEnum.NOCUSTOMER);
|
|
|
|
|
}
|
|
|
|
|
if ("ysk".equals(thirdPayType)) {
|
|
|
|
|
TradeQueryReq tradeQueryReq = new TradeQueryReq();
|
|
|
|
|
tradeQueryReq.setAppId(thirdApply.getAppId());
|
|
|
|
|
tradeQueryReq.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
tradeQueryReq.setOrderNumber(tbQuickPay.getTradeNo());
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = BeanUtil.transBean2Map(tradeQueryReq);
|
|
|
|
|
tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"), tradeQueryReq, String.class);
|
|
|
|
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
|
|
|
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
|
|
|
|
if (object.get("code").equals("0")) {
|
|
|
|
|
JSONObject data = object.getJSONObject("data");
|
|
|
|
|
if ("1".equals(data.getString("status"))) {
|
|
|
|
|
|
|
|
|
|
tbQuickPay.setStatus("0");
|
|
|
|
|
tbQuickPay.setUpdateTime(new Date());
|
|
|
|
|
tbQuickPayMapper.updateByPrimaryKeySelective(tbQuickPay);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), null, tbQuickPay.getOrderNo(), thirdApply.getAppToken());
|
|
|
|
|
if (ObjectUtil.isNotNull(orderstatus) && ObjectUtil.isNotEmpty(orderstatus)) {
|
|
|
|
|
if ("000000".equals(orderstatus.getCode())) {
|
|
|
|
|
if ("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())) {
|
|
|
|
|
|
|
|
|
|
tbQuickPay.setStatus("0");
|
|
|
|
|
tbQuickPay.setUpdateTime(new Date());
|
|
|
|
|
tbQuickPayMapper.updateByPrimaryKeySelective(tbQuickPay);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, tbQuickPay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result queryQuickPay(String token, int pageNo, int pageSize) {
|
|
|
|
|
JSONObject info = TokenUtil.parseParamFromToken(token);
|
|
|
|
|
MsgException.checkNull(info, "获取信息失败");
|
|
|
|
|
|
|
|
|
|
String shopId = info.getString("shopId");
|
|
|
|
|
String staffId = info.getString("staffId");
|
|
|
|
|
PageHelper.startPage(pageNo, pageSize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<TbQuickPay> list= tbQuickPayMapper.selectByShopIdAndStaffId(Integer.valueOf(shopId),Integer.valueOf(staffId));
|
|
|
|
|
PageInfo pageInfo=new PageInfo(list);
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS,pageInfo);
|
|
|
|
|
List<TbQuickPay> list = tbQuickPayMapper.selectByShopIdAndStaffId(Integer.valueOf(shopId), Integer.valueOf(staffId));
|
|
|
|
|
PageInfo pageInfo = new PageInfo(list);
|
|
|
|
|
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String generateReturnOrderNumber() {
|
|
|
|
|
String date = DateUtils.getSdfTimes();
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
int randomNum = random.nextInt(900) + 100;
|
|
|
|
|
return "RO" + date + randomNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
System.out.println(String.format("%.2f", new BigDecimal(1).setScale(2, BigDecimal.ROUND_DOWN)));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|