|
|
@ -1,6 +1,8 @@ |
|
|
|
package org.jeecg.api.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import lombok.Synchronized; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.jeecg.api.bean.PageBean; |
|
|
@ -28,11 +30,13 @@ import org.jeecg.modules.commonShopClass.service.ICommonShopClassService; |
|
|
|
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; |
|
|
|
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService; |
|
|
|
import org.jeecg.modules.pay.MpWxPayService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.actuate.integration.IntegrationGraphEndpoint; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.transaction.Transactional; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
@ -286,6 +290,8 @@ public class AppletIndexServiceImpl implements AppletIndexService { |
|
|
|
|
|
|
|
|
|
|
|
//立即支付 |
|
|
|
@Synchronized |
|
|
|
@Transactional |
|
|
|
@Override |
|
|
|
public Result<?> payOrder(String token,Integer type,String orderId){ |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
@ -315,24 +321,78 @@ public class AppletIndexServiceImpl implements AppletIndexService { |
|
|
|
|
|
|
|
} |
|
|
|
}else { |
|
|
|
CommonOrder commonOrder = commonOrderService.getById(orderId); |
|
|
|
if (commonOrder.getStatus().equals("0")){ |
|
|
|
BigDecimal payPrice = commonOrder.getPrice(); |
|
|
|
log.info("开始处理订单,订单ID: {}", orderId); |
|
|
|
|
|
|
|
// 获取原始订单 |
|
|
|
CommonOrder originalOrder = commonOrderService.getById(orderId); |
|
|
|
if (originalOrder == null) { |
|
|
|
log.error("订单不存在,订单ID: {}", orderId); |
|
|
|
return Result.error("订单不存在"); |
|
|
|
} |
|
|
|
log.info("获取到原始订单: {}", originalOrder); |
|
|
|
|
|
|
|
// 生成新订单ID |
|
|
|
String newOrderId = IdUtil.simpleUUID(); |
|
|
|
log.info("生成的新订单ID: {}", newOrderId); |
|
|
|
|
|
|
|
// 复制订单属性到新订单 |
|
|
|
CommonOrder newOrder = new CommonOrder(); |
|
|
|
BeanUtils.copyProperties(originalOrder, newOrder); |
|
|
|
newOrder.setId(newOrderId); |
|
|
|
// newOrder.setPid(newOrderId); // 确保新订单的pid指向自己 |
|
|
|
log.info("创建的新订单: {}", newOrder); |
|
|
|
|
|
|
|
// 保存新订单 |
|
|
|
commonOrderService.save(newOrder); |
|
|
|
CommonOrder savedOrder = commonOrderService.getById(newOrderId); |
|
|
|
log.info("保存后查询的新订单: {}", savedOrder); |
|
|
|
|
|
|
|
// 处理子订单 |
|
|
|
List<CommonOrder> children = commonOrderService.lambdaQuery() |
|
|
|
.eq(CommonOrder::getPid, orderId) |
|
|
|
.list(); |
|
|
|
log.info("查询到的子订单数量: {}", children.size()); |
|
|
|
|
|
|
|
if (!children.isEmpty()) { |
|
|
|
for (CommonOrder child : children) { |
|
|
|
log.info("处理子订单: {}", child); |
|
|
|
CommonOrder newChild = new CommonOrder(); |
|
|
|
BeanUtils.copyProperties(child, newChild); |
|
|
|
newChild.setId(IdUtil.simpleUUID()); // 为子订单生成新ID |
|
|
|
newChild.setPid(newOrderId); // 指向新父订单 |
|
|
|
commonOrderService.save(newChild); |
|
|
|
log.info("保存的新子订单: {}", newChild); |
|
|
|
|
|
|
|
// 删除旧子订单 |
|
|
|
commonOrderService.removeById(child.getId()); |
|
|
|
log.info("已删除旧子订单,ID: {}", child.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 删除旧订单 |
|
|
|
commonOrderService.removeById(orderId); |
|
|
|
log.info("已删除旧订单,ID: {}", orderId); |
|
|
|
|
|
|
|
// 处理支付 |
|
|
|
if ("0".equals(originalOrder.getStatus())) { |
|
|
|
BigDecimal payPrice = originalOrder.getPrice(); |
|
|
|
int amountCents = payPrice.multiply(new BigDecimal(100)).intValue(); |
|
|
|
log.info("支付金额(分): {}", amountCents); |
|
|
|
|
|
|
|
//吊起微信支付 |
|
|
|
String s = payPrice.multiply(new BigDecimal(100)).toString(); |
|
|
|
int i1 = Double.valueOf(s).intValue(); |
|
|
|
Object appOrder = mpWxPayService.createOrder( |
|
|
|
"购买"+commonOrder.getTitle(), |
|
|
|
"购买" + originalOrder.getTitle(), |
|
|
|
"127.0.0.1", |
|
|
|
commonOrder.getId(), |
|
|
|
i1, |
|
|
|
commonOrder.getId(), |
|
|
|
newOrderId, |
|
|
|
amountCents, |
|
|
|
newOrderId, |
|
|
|
hanHaiMember.getAppletOpenid(), |
|
|
|
commonOrder.toString()); |
|
|
|
originalOrder.toString()); |
|
|
|
|
|
|
|
return Result.OK("支付成功",appOrder); |
|
|
|
log.info("支付结果: {}", appOrder); |
|
|
|
return Result.OK("支付成功", appOrder); |
|
|
|
} |
|
|
|
|
|
|
|
return Result.OK("订单处理成功"); |
|
|
|
} |
|
|
|
return Result.error("订单已支付"); |
|
|
|
} |
|
|
|