|
|
|
|
@@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.chaozhanggui.system.cashierservice.dao.*;
|
|
|
|
|
@@ -35,7 +36,6 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
@@ -166,9 +166,28 @@ public class PayService {
|
|
|
|
|
this.shopSongOrderService = shopSongOrderService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result payOrderTest(String openId, String orderId, String payType, String ip) throws Exception {
|
|
|
|
|
//thirdUrl;
|
|
|
|
|
String appId = "66e3dd399a7621f45a6293c1";
|
|
|
|
|
String reqbody = "茉莉蜜茶";
|
|
|
|
|
BigDecimal money = new BigDecimal("0.10");
|
|
|
|
|
long amount = money.setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue();
|
|
|
|
|
payType = "ALIPAY";
|
|
|
|
|
String smallAppid = "2021004145625815";
|
|
|
|
|
openId = "2088812533865205";
|
|
|
|
|
ip = "1.80.208.76";
|
|
|
|
|
String timesSS = DateUtils.getsdfTimesSS();
|
|
|
|
|
String storeId = "S2409148611";
|
|
|
|
|
//callFSTBack
|
|
|
|
|
//null
|
|
|
|
|
String appToken = "jVQs9aBIFOj1mh2ioDp5RLiNBLcQoRnhniH9xlyc3ZKmDcwOpDargyEIYASCePtbA4hyJ5aeH841HfBA4rEKFsxl5AJjGcQa7qT28qU0SPN6v9dNzKYK1eTyvSw6mNBh";
|
|
|
|
|
PublicResp<WxScanPayResp> scanpay = thirdPayService.scanpay(thirdUrl, appId, reqbody, reqbody, amount, payType, smallAppid, openId, ip, timesSS, storeId, callFSTBack, null, appToken);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Result payOrder(String openId, String orderId, String ip) throws Exception {
|
|
|
|
|
public Result payOrder(String openId, String orderId, String payType, String ip) throws Exception {
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
|
|
|
|
|
return Result.fail("付款用户[userId]参数不能为空");
|
|
|
|
|
@@ -205,6 +224,10 @@ public class PayService {
|
|
|
|
|
return Result.fail("支付通道不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("aliPay".equals(payType) && StrUtil.isBlank(thirdApply.getAlipaySmallAppid())) {
|
|
|
|
|
return Result.fail("店铺未配置支付宝小程序appId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
|
|
|
|
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
|
|
|
|
payment = new TbOrderPayment();
|
|
|
|
|
@@ -212,8 +235,12 @@ public class PayService {
|
|
|
|
|
payment.setAmount(orderInfo.getOrderAmount());
|
|
|
|
|
payment.setPaidAmount(orderInfo.getPayAmount());
|
|
|
|
|
payment.setHasRefundAmount(BigDecimal.ZERO);
|
|
|
|
|
if ("wechatPay".equals(payType)) {
|
|
|
|
|
payment.setPayName("微信支付");
|
|
|
|
|
payment.setPayType("wechatPay");
|
|
|
|
|
} else if ("aliPay".equals(payType)) {
|
|
|
|
|
payment.setPayName("支付宝支付");
|
|
|
|
|
}
|
|
|
|
|
payment.setPayType(payType);
|
|
|
|
|
payment.setReceived(payment.getAmount());
|
|
|
|
|
payment.setChangeFee(BigDecimal.ZERO);
|
|
|
|
|
payment.setMemberId(orderInfo.getMemberId());
|
|
|
|
|
@@ -222,6 +249,12 @@ public class PayService {
|
|
|
|
|
payment.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
tbOrderPaymentMapper.insert(payment);
|
|
|
|
|
} else {
|
|
|
|
|
if (payType.equals("wechatPay")) {
|
|
|
|
|
payment.setPayName("微信支付");
|
|
|
|
|
} else if (payType.equals("aliPay")) {
|
|
|
|
|
payment.setPayName("支付宝支付");
|
|
|
|
|
}
|
|
|
|
|
payment.setPayType(payType);
|
|
|
|
|
payment.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
|
|
|
|
}
|
|
|
|
|
@@ -281,10 +314,25 @@ public class PayService {
|
|
|
|
|
reqbody = body.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(thirdUrl, thirdApply.getAppId(),
|
|
|
|
|
reqbody, reqbody,
|
|
|
|
|
String smallAppid = thirdApply.getSmallAppid();
|
|
|
|
|
if ("aliPay".equals(payType)){
|
|
|
|
|
smallAppid = thirdApply.getAlipaySmallAppid();
|
|
|
|
|
}
|
|
|
|
|
String convertPayType = "aliPay".equals(payType) ? "ALIPAY" : "WECHAT";
|
|
|
|
|
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(thirdUrl,
|
|
|
|
|
thirdApply.getAppId(),
|
|
|
|
|
reqbody,
|
|
|
|
|
reqbody,
|
|
|
|
|
payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),
|
|
|
|
|
"WECHAT", thirdApply.getSmallAppid(), openId, ip, DateUtils.getsdfTimesSS(), thirdApply.getStoreId(), callFSTBack, null, thirdApply.getAppToken());
|
|
|
|
|
convertPayType,
|
|
|
|
|
smallAppid,
|
|
|
|
|
openId,
|
|
|
|
|
ip,
|
|
|
|
|
DateUtils.getsdfTimesSS(),
|
|
|
|
|
thirdApply.getStoreId(),
|
|
|
|
|
callFSTBack,
|
|
|
|
|
null,
|
|
|
|
|
thirdApply.getAppToken());
|
|
|
|
|
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
|
|
|
|
if ("000000".equals(publicResp.getCode())) {
|
|
|
|
|
WxScanPayResp wxScanPayResp = publicResp.getObjData();
|
|
|
|
|
@@ -407,7 +455,7 @@ public class PayService {
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed");
|
|
|
|
|
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
|
|
|
|
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(),"closed");
|
|
|
|
|
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(), "closed");
|
|
|
|
|
log.info("更新购物车:{}", cartCount);
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
@@ -427,13 +475,13 @@ public class PayService {
|
|
|
|
|
mQUtils.sendStockSaleMsg(data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject baObj=new JSONObject();
|
|
|
|
|
baObj.put("userId",userInfo.getId());
|
|
|
|
|
baObj.put("shopId",user.getShopId());
|
|
|
|
|
baObj.put("amount",orderInfo.getOrderAmount());
|
|
|
|
|
baObj.put("balance",user.getAmount());
|
|
|
|
|
baObj.put("type","消费");
|
|
|
|
|
baObj.put("time",flow.getCreateTime());
|
|
|
|
|
JSONObject baObj = new JSONObject();
|
|
|
|
|
baObj.put("userId", userInfo.getId());
|
|
|
|
|
baObj.put("shopId", user.getShopId());
|
|
|
|
|
baObj.put("amount", orderInfo.getOrderAmount());
|
|
|
|
|
baObj.put("balance", user.getAmount());
|
|
|
|
|
baObj.put("type", "消费");
|
|
|
|
|
baObj.put("time", flow.getCreateTime());
|
|
|
|
|
producer.balance(baObj.toString());
|
|
|
|
|
|
|
|
|
|
// 为代客下单清楚当前台桌最新订单
|
|
|
|
|
@@ -528,6 +576,11 @@ public class PayService {
|
|
|
|
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
|
|
|
|
return Result.fail("支付通道不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("aliPay".equals(payType) && StrUtil.isBlank(thirdApply.getAlipaySmallAppid())) {
|
|
|
|
|
return Result.fail("店铺未配置支付宝小程序appId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuffer body = new StringBuffer();
|
|
|
|
|
body.append(orderInfo.getProName());
|
|
|
|
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getOrderNo());
|
|
|
|
|
@@ -605,14 +658,19 @@ public class PayService {
|
|
|
|
|
} else {
|
|
|
|
|
reqbody = body.toString();
|
|
|
|
|
}
|
|
|
|
|
String smallAppid = thirdApply.getSmallAppid();
|
|
|
|
|
if ("aliPay".equals(payType)){
|
|
|
|
|
smallAppid = thirdApply.getAlipaySmallAppid();
|
|
|
|
|
}
|
|
|
|
|
String convertPayType = "aliPay".equals(payType) ? "ALIPAY" : "WECHAT";
|
|
|
|
|
PublicResp<WxScanPayResp> publicResp = thirdPayService.scanpay(
|
|
|
|
|
thirdUrl,
|
|
|
|
|
thirdApply.getAppId(),
|
|
|
|
|
reqbody,
|
|
|
|
|
reqbody,
|
|
|
|
|
payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),
|
|
|
|
|
"WECHAT",
|
|
|
|
|
thirdApply.getSmallAppid(),
|
|
|
|
|
convertPayType,
|
|
|
|
|
smallAppid,
|
|
|
|
|
userId,
|
|
|
|
|
ip,
|
|
|
|
|
// orderInfo.getOrderNo(),
|
|
|
|
|
@@ -901,7 +959,7 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
//更新子单状态
|
|
|
|
|
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(orderInfo.getId(), "closed");
|
|
|
|
|
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(),"closed");
|
|
|
|
|
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(), "closed");
|
|
|
|
|
//修改主单状态
|
|
|
|
|
orderInfo.setStatus("closed");
|
|
|
|
|
orderInfo.setPayType("wx_lite");
|
|
|
|
|
@@ -962,7 +1020,7 @@ public class PayService {
|
|
|
|
|
orderInfo.setPayOrderNo(payOrderNO);
|
|
|
|
|
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
|
|
|
|
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(),"closed");
|
|
|
|
|
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(), "closed");
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("token", 0);
|
|
|
|
|
@@ -1133,7 +1191,7 @@ public class PayService {
|
|
|
|
|
flow.setIsReturn("0");
|
|
|
|
|
tbShopUserFlowMapper.insert(flow);
|
|
|
|
|
//会员活动
|
|
|
|
|
giveActivate(tbShopUser,memberIn.getAmount(),flow.getId());
|
|
|
|
|
giveActivate(tbShopUser, memberIn.getAmount(), flow.getId());
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("shopId", memberIn.getShopId());
|
|
|
|
|
@@ -1143,14 +1201,14 @@ public class PayService {
|
|
|
|
|
return "success";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BigDecimal giveActivate(TbShopUser tbShopUser, BigDecimal memAmount,Integer flowId){
|
|
|
|
|
public BigDecimal giveActivate(TbShopUser tbShopUser, BigDecimal memAmount, Integer flowId) {
|
|
|
|
|
TbActivate activate = tbActivateMapper.selectByAmount(tbShopUser.getShopId(), memAmount);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) {
|
|
|
|
|
if (activate.getIsGiftPro() != null && activate.getIsGiftPro() == 1) {
|
|
|
|
|
List<TbActivateProduct> tbActivateProducts = actProductMapper.queryAllByActivateId(activate.getId());
|
|
|
|
|
List<TbActivateInRecord> actGiveRecords = new ArrayList<>();
|
|
|
|
|
for (TbActivateProduct actPro : tbActivateProducts) {
|
|
|
|
|
TbActivateInRecord record = new TbActivateInRecord(Integer.valueOf(tbShopUser.getId()), actPro.getProductId(), actPro.getNum(), Integer.valueOf(tbShopUser.getShopId()), activate.getId(),flowId);
|
|
|
|
|
TbActivateInRecord record = new TbActivateInRecord(Integer.valueOf(tbShopUser.getId()), actPro.getProductId(), actPro.getNum(), Integer.valueOf(tbShopUser.getShopId()), activate.getId(), flowId);
|
|
|
|
|
actGiveRecords.add(record);
|
|
|
|
|
}
|
|
|
|
|
activateInRecordMapper.insertBatch(actGiveRecords);
|
|
|
|
|
@@ -1232,7 +1290,7 @@ public class PayService {
|
|
|
|
|
flow.setIsReturn("0");
|
|
|
|
|
tbShopUserFlowMapper.insert(flow);
|
|
|
|
|
//会员活动
|
|
|
|
|
BigDecimal awardAmount= giveActivate(tbShopUser,memberIn.getAmount(),flow.getId());
|
|
|
|
|
BigDecimal awardAmount = giveActivate(tbShopUser, memberIn.getAmount(), flow.getId());
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("shopId", memberIn.getShopId());
|
|
|
|
|
jsonObject.put("type", "wxMemberIn");
|
|
|
|
|
@@ -1240,14 +1298,13 @@ public class PayService {
|
|
|
|
|
producer.putOrderCollect(jsonObject.toJSONString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject baObj=new JSONObject();
|
|
|
|
|
JSONObject baObj = new JSONObject();
|
|
|
|
|
baObj.put("userId", tbShopUser.getUserId());
|
|
|
|
|
baObj.put("shopId",tbShopUser.getShopId());
|
|
|
|
|
baObj.put("amount",ObjectUtil.isNull(awardAmount)?memberIn.getAmount():memberIn.getAmount().add(awardAmount));
|
|
|
|
|
baObj.put("balance",tbShopUser.getAmount());
|
|
|
|
|
baObj.put("type","充值");
|
|
|
|
|
baObj.put("time",flow.getCreateTime());
|
|
|
|
|
baObj.put("shopId", tbShopUser.getShopId());
|
|
|
|
|
baObj.put("amount", ObjectUtil.isNull(awardAmount) ? memberIn.getAmount() : memberIn.getAmount().add(awardAmount));
|
|
|
|
|
baObj.put("balance", tbShopUser.getAmount());
|
|
|
|
|
baObj.put("type", "充值");
|
|
|
|
|
baObj.put("time", flow.getCreateTime());
|
|
|
|
|
producer.balance(baObj.toString());
|
|
|
|
|
|
|
|
|
|
return "SUCCESS";
|
|
|
|
|
@@ -1282,7 +1339,6 @@ public class PayService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result paySongOrder(String openId, String shopId, Integer orderId, String ip, TbMerchantThirdApply thirdApply) throws JsonProcessingException {
|
|
|
|
|
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
|
|
|
|
|
return Result.fail("付款用户[openId]参数不能为空");
|
|
|
|
|
|