Merge branch 'tkk' into test
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
|
||||
import com.chaozhanggui.system.cashierservice.service.PayService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
@@ -40,8 +41,17 @@ public class PayController {
|
||||
return Result.fail("订单号不允许为空");
|
||||
}
|
||||
|
||||
if (!map.containsKey("payType")) {
|
||||
return Result.fail("支付类型不允许为空");
|
||||
}
|
||||
|
||||
String payType = map.get("payType");
|
||||
if (StrUtil.isEmpty(payType)) {
|
||||
return Result.fail("支付类型不允许为空");
|
||||
}
|
||||
|
||||
try {
|
||||
return payService.payOrder(openId, map.get("orderId"), IpUtil.getIpAddr(request));
|
||||
return payService.payOrderTest(openId, map.get("orderId"), payType, IpUtil.getIpAddr(request));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public class TbMerchantThirdApply implements Serializable {
|
||||
|
||||
private String smallAppid;
|
||||
|
||||
private String alipaySmallAppid;
|
||||
|
||||
private String storeId;
|
||||
|
||||
|
||||
@@ -117,4 +119,12 @@ public class TbMerchantThirdApply implements Serializable {
|
||||
public void setStoreId(String storeId) {
|
||||
this.storeId = storeId;
|
||||
}
|
||||
|
||||
public String getAlipaySmallAppid() {
|
||||
return alipaySmallAppid;
|
||||
}
|
||||
|
||||
public void setAlipaySmallAppid(String alipaySmallAppid) {
|
||||
this.alipaySmallAppid = alipaySmallAppid;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -167,9 +167,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]参数不能为空");
|
||||
@@ -206,6 +225,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();
|
||||
@@ -213,8 +236,12 @@ public class PayService {
|
||||
payment.setAmount(orderInfo.getOrderAmount());
|
||||
payment.setPaidAmount(orderInfo.getPayAmount());
|
||||
payment.setHasRefundAmount(BigDecimal.ZERO);
|
||||
payment.setPayName("微信支付");
|
||||
payment.setPayType("wechatPay");
|
||||
if ("wechatPay".equals(payType)) {
|
||||
payment.setPayName("微信支付");
|
||||
} else if ("aliPay".equals(payType)) {
|
||||
payment.setPayName("支付宝支付");
|
||||
}
|
||||
payment.setPayType(payType);
|
||||
payment.setReceived(payment.getAmount());
|
||||
payment.setChangeFee(BigDecimal.ZERO);
|
||||
payment.setMemberId(orderInfo.getMemberId());
|
||||
@@ -223,6 +250,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();
|
||||
@@ -406,7 +454,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();
|
||||
@@ -426,13 +474,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());
|
||||
|
||||
// 为代客下单清楚当前台桌最新订单
|
||||
@@ -527,6 +575,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());
|
||||
@@ -604,14 +657,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(),
|
||||
@@ -900,7 +958,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");
|
||||
@@ -961,7 +1019,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);
|
||||
@@ -1233,7 +1291,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");
|
||||
@@ -1241,14 +1299,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";
|
||||
@@ -1283,7 +1340,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]参数不能为空");
|
||||
|
||||
Reference in New Issue
Block a user