feat:下单bug
This commit is contained in:
1 parent
a932190426
commit
2b25aafc15
13 files changed
+120
-22
No files matched your search
+3
@@ -6,6 +6,9 @@ import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum HardOrderStatusEnum {
|
||||
|
||||
+6
@@ -28,8 +28,14 @@ public enum HardOrderTypeEnum {
|
||||
|
||||
public static final List<HardOrderTypeEnum> refundList = List.of(BELOW, RESERVE);
|
||||
|
||||
public static final List<HardOrderTypeEnum> payList = List.of(BELOW, RESERVE);
|
||||
|
||||
public static boolean isRefund(HardOrderTypeEnum type) {
|
||||
return refundList.contains(type);
|
||||
}
|
||||
|
||||
public static boolean isPay(HardOrderTypeEnum type) {
|
||||
return refundList.contains(type);
|
||||
}
|
||||
|
||||
}
|
||||
+3
@@ -5,4 +5,7 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HardCarDto extends HardCarEntity {
|
||||
|
||||
private Long orderId;
|
||||
|
||||
}
|
||||
+8
@@ -3,6 +3,14 @@ package com.bsd.pjcloud.hard.api.dto.order;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class HardOrderDto extends HardOrderEntity {
|
||||
|
||||
/**
|
||||
* 用户相关
|
||||
*/
|
||||
private List<Long> userIds;
|
||||
|
||||
}
|
||||
+11
-1
@@ -3,10 +3,11 @@ package com.bsd.pjcloud.hard.api.vo.order;
|
||||
import com.bsd.pjcloud.admin.api.vo.base.BaseDeptInterface;
|
||||
import com.bsd.pjcloud.admin.api.vo.base.BaseUserInterface;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.base.BaseMchInterface;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HardOrderVo extends HardOrderEntity implements BaseUserInterface, BaseDeptInterface {
|
||||
public class HardOrderVo extends HardOrderEntity implements BaseUserInterface, BaseDeptInterface, BaseMchInterface {
|
||||
/**
|
||||
* 用户相关
|
||||
*/
|
||||
@@ -20,4 +21,13 @@ public class HardOrderVo extends HardOrderEntity implements BaseUserInterface, B
|
||||
* 部门相关
|
||||
*/
|
||||
private String deptName;
|
||||
|
||||
private String merchantName;
|
||||
|
||||
/**
|
||||
* 设备相关
|
||||
*/
|
||||
private String hardName;
|
||||
|
||||
private String hardType;
|
||||
}
|
||||
@@ -13,6 +13,11 @@
|
||||
<artifactId>pjcloud-hardware-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!--引入分布式事务-->
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-common-seata</artifactId>
|
||||
</dependency>
|
||||
<!--必备: 注册中心客户端-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
||||
+17
-1
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.controller.order;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -13,8 +14,12 @@ import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.app.HardCarSaveOrUpdateDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardCarDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardParentCarEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
|
||||
import com.bsd.pjcloud.hard.service.HardCarService;
|
||||
import com.bsd.pjcloud.hard.service.HardOrderService;
|
||||
import com.bsd.pjcloud.hard.service.HardParentCarService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
@@ -41,6 +46,7 @@ import java.util.List;
|
||||
public class HardCarController {
|
||||
|
||||
private final HardCarService hardCarService;
|
||||
private final HardOrderService hardOrderService;
|
||||
|
||||
/* ************************************* start app start ************************************* */
|
||||
@GetMapping("/app/mch-detail")
|
||||
@@ -51,7 +57,7 @@ public class HardCarController {
|
||||
}
|
||||
|
||||
@GetMapping("/app/order-id")
|
||||
@Operation(summary = "根据订单id查询当前用户购物车")
|
||||
@Operation(summary = "根据订单id查询购物车")
|
||||
public R<List<HardCarVo>> appOrderId(@RequestParam Long orderId) {
|
||||
return R.ok(hardCarService.getByOrderId(orderId));
|
||||
}
|
||||
@@ -67,6 +73,16 @@ public class HardCarController {
|
||||
}
|
||||
/* ************************************* end app end ************************************* */
|
||||
|
||||
@GetMapping("/order-id")
|
||||
@Operation(summary = "根据订单id查询购物车")
|
||||
public R<Page<HardCarVo>> orderId(@ParameterObject Page page, @RequestParam Long orderId) {
|
||||
HardOrderEntity order = hardOrderService.getById(orderId);
|
||||
if (ObjectUtil.isEmpty(order)) return null;
|
||||
HardCarDto dto = new HardCarDto();
|
||||
dto.setParentCarId(order.getParentCarId());
|
||||
return R.ok(hardCarService.pageJoin(page, dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('hard_hardCar_view')")
|
||||
|
||||
+2
-1
@@ -13,7 +13,8 @@ public interface HardCarMapper extends PjcloudBaseMapper<HardCarEntity> {
|
||||
|
||||
default Page<HardCarVo> pageJoin(Page page, HardCarDto dto) {
|
||||
MPJLambdaWrapper<HardCarEntity> wrapper = new MPJLambdaWrapper<HardCarEntity>()
|
||||
.selectAll(HardCarEntity.class);
|
||||
.selectAll(HardCarEntity.class)
|
||||
.eqIfExists(HardCarEntity::getParentCarId, dto.getParentCarId());
|
||||
return selectJoinPage(page, HardCarVo.class, wrapper);
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -1,10 +1,13 @@
|
||||
package com.bsd.pjcloud.hard.mapper.order;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardManagerEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -12,7 +15,14 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface HardOrderMapper extends PjcloudBaseMapper<HardOrderEntity> {
|
||||
default Page<HardOrderVo> pageJoin(Page page, HardOrderDto dto) {
|
||||
MPJLambdaWrapper<HardOrderEntity> wrapper = new MPJLambdaWrapper<HardOrderEntity>()
|
||||
.selectAll(HardOrderEntity.class);
|
||||
.selectAll(HardOrderEntity.class)
|
||||
.selectAs(HardManagerEntity::getName, HardOrderVo::getHardName)
|
||||
.selectAs(HardManagerEntity::getType, HardOrderVo::getHardType)
|
||||
.leftJoin(HardManagerEntity.class, HardManagerEntity::getId, HardOrderEntity::getHardId)
|
||||
.eqIfExists(HardOrderEntity::getOrderType, dto.getOrderType())
|
||||
.eqIfExists(HardOrderEntity::getPayType, dto.getPayType())
|
||||
.eqIfExists(HardOrderEntity::getOrderStatus, dto.getOrderStatus())
|
||||
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), HardOrderEntity::getUserId, dto.getUserIds());
|
||||
return selectJoinPage(page, HardOrderVo.class, wrapper);
|
||||
}
|
||||
|
||||
|
||||
+41
-12
@@ -25,6 +25,7 @@ import com.bsd.pjcloud.hard.api.entity.HardManagerEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardParentCarEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.HardManagerVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardCarService;
|
||||
@@ -36,6 +37,7 @@ import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
|
||||
import com.bsd.pjcloud.wallet.api.feign.*;
|
||||
import com.bsd.pjcloud.wallet.api.utils.MchDataUtil;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyVo;
|
||||
@@ -79,6 +81,7 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
private final RemoteWalletSettingService walletSettingService;
|
||||
private final RemoteUserService userService;
|
||||
private final RemoteDeptService deptService;
|
||||
private final HardParentCarServiceImpl hardParentCarServiceImpl;
|
||||
|
||||
@Override
|
||||
public Page<HardOrderVo> pageJoin(Page page, HardOrderDto dto) {
|
||||
@@ -86,15 +89,27 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
if (ObjectUtil.isNotEmpty(list.getRecords())) {
|
||||
// 用户
|
||||
List<Long> userIds = list.getRecords().stream().map(HardOrderVo::getUserId).distinct().toList();
|
||||
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
|
||||
if (ObjectUtil.isNotEmpty(userList.getData())) {
|
||||
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
|
||||
if (ObjectUtil.isNotEmpty(userIds)) {
|
||||
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
|
||||
if (ObjectUtil.isNotEmpty(userList.getData())) {
|
||||
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
|
||||
}
|
||||
}
|
||||
// 部门
|
||||
List<Long> deptIds = list.getRecords().stream().map(HardOrderVo::getDeptId).distinct().toList();
|
||||
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
|
||||
if (ObjectUtil.isNotEmpty(deptList.getData())) {
|
||||
DataUtil.convertDeptList(list.getRecords(), deptList.getData());
|
||||
if (ObjectUtil.isNotEmpty(deptIds)) {
|
||||
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
|
||||
if (ObjectUtil.isNotEmpty(deptList.getData())) {
|
||||
DataUtil.convertDeptList(list.getRecords(), deptList.getData());
|
||||
}
|
||||
}
|
||||
// 商户
|
||||
List<Long> mchIds = list.getRecords().stream().map(HardOrderVo::getMerchantId).distinct().toList();
|
||||
if (ObjectUtil.isNotEmpty(mchIds)) {
|
||||
R<List<MchManageVo>> mchList = remoteMchService.getByIds(mchIds);
|
||||
if (ObjectUtil.isNotEmpty(mchList.getData())) {
|
||||
MchDataUtil.convertMchList(list.getRecords(), CollectionUtils.convertMap(mchList.getData(), MchManageVo::getId));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
@@ -151,7 +166,7 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
.orderSourceTypeId(dto.getOrderSourceTypeId())
|
||||
.totalPrice(totalPrice)
|
||||
.extraPrice(extraPrice)
|
||||
.payPrice(0)
|
||||
.payPrice(totalPrice + extraPrice)
|
||||
.isOfflineOrder(YesNoEnum.NO.getCode())
|
||||
.productDesc(subject)
|
||||
.build();
|
||||
@@ -163,7 +178,6 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional(rollbackFor = Exception.class)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long appCreateOrder(@Valid HardAppCreateOrderDto dto) {
|
||||
// 钱包
|
||||
@@ -204,6 +218,7 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
.orderSourceTypeId(dto.getOrderSourceTypeId())
|
||||
.totalPrice(totalPrice)
|
||||
.extraPrice(0)
|
||||
.payPrice(totalPrice)
|
||||
.isOfflineOrder(YesNoEnum.NO.getCode())
|
||||
.productDesc(subject)
|
||||
.build();
|
||||
@@ -215,16 +230,24 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void fastReduceBalance(HardOrderEntity order) {
|
||||
boolean isPay = isPay(HardOrderTypeEnum.valueOfByType(order.getOrderType()), HardPayTypeEnum.valueOfByType(order.getPayType()));
|
||||
WalletBalanceTransactionDto reduceBuild = WalletBalanceTransactionDto.builder().walletId(order.getWalletId()).price(order.getPayPrice()).bizId(String.valueOf(order.getId())).bizType(WalletBizEnum.PAYMENT).build();
|
||||
WalletBalanceTransactionDto reduceBuild = new WalletBalanceTransactionDto();
|
||||
reduceBuild.setWalletId(order.getWalletId());
|
||||
reduceBuild.setPrice(order.getPayPrice());
|
||||
reduceBuild.setBizId(String.valueOf(order.getId()));
|
||||
reduceBuild.setBizType(WalletBizEnum.PAYMENT);
|
||||
WalletTransactionEntity walletTransaction = walletTransactionService.reduceWalletBalance(reduceBuild).getData();
|
||||
if (ObjectUtil.isNotEmpty(walletTransaction)) {
|
||||
// 订单表订单状态
|
||||
Integer payPrice = isPay ? order.getTotalPrice() + order.getExtraPrice() : 0;
|
||||
HardOrderEntity update = HardOrderEntity.builder().id(order.getId()).payTime(LocalDateTime.now()).orderStatus(HardOrderStatusEnum.PAY.getType()).payPrice(payPrice).build();
|
||||
baseMapper.updateById(update);
|
||||
// 父购物车订单表订单状态
|
||||
HardParentCarEntity updateParentCar = HardParentCarEntity.builder().id(order.getParentCarId()).orderStatus(HardOrderStatusEnum.PAY.getType()).build();
|
||||
hardParentCarServiceImpl.updateById(updateParentCar);
|
||||
// 核销二维码
|
||||
cancelCode(order);
|
||||
}
|
||||
@@ -299,9 +322,15 @@ public class HardwareOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardO
|
||||
return flag;
|
||||
}
|
||||
|
||||
// 是否需要支付(目前只有线下的现金是不走平台扣款)
|
||||
// 是否需要支付
|
||||
private boolean isPay(HardOrderTypeEnum type, HardPayTypeEnum payType) {
|
||||
return ObjectUtil.equals(type, HardOrderTypeEnum.BELOW) && !ObjectUtil.equals(payType, HardPayTypeEnum.CASH);
|
||||
if (ObjectUtil.equals(type, HardOrderTypeEnum.BELOW) && ObjectUtil.equals(payType, HardPayTypeEnum.CASH)) {
|
||||
return false;
|
||||
}
|
||||
if (!HardOrderTypeEnum.isPay(type)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 是否需要额外支付(目前只有食堂需要)
|
||||
|
||||
+5
-3
@@ -1,6 +1,7 @@
|
||||
package com.bsd.pjcloud.wallet.api.dto;
|
||||
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -9,22 +10,23 @@ import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NotEmpty
|
||||
@Data
|
||||
public class WalletBalanceTransactionDto {
|
||||
|
||||
@NotNull(message = "钱包id不能为空")
|
||||
@JsonProperty("walletId")
|
||||
private Long walletId;
|
||||
|
||||
@NotNull(message = "操作金额不能为空")
|
||||
@JsonProperty("price")
|
||||
private Integer price;
|
||||
|
||||
@NotEmpty(message = "业务类型关联id不能为空")
|
||||
@JsonProperty("bizId")
|
||||
private String bizId;
|
||||
|
||||
@NotNull(message = "业务类型不能为空")
|
||||
@JsonProperty("bizType")
|
||||
private WalletBizEnum bizType;
|
||||
|
||||
}
|
||||
+3
-3
@@ -6,18 +6,18 @@ import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(contextId = "remoteWalletTransactionService", value = ServiceNameConstants.WALLET_SERVICE)
|
||||
public interface RemoteWalletTransactionService {
|
||||
|
||||
@NoToken
|
||||
@GetMapping("/wallet-transaction/add-balance")
|
||||
@PostMapping("/wallet-transaction/add-balance")
|
||||
R<WalletTransactionEntity> addWalletBalance(@RequestBody WalletBalanceTransactionDto dto);
|
||||
|
||||
@NoToken
|
||||
@GetMapping("/wallet-transaction/reduce-balance")
|
||||
@PostMapping("/wallet-transaction/reduce-balance")
|
||||
R<WalletTransactionEntity> reduceWalletBalance(@RequestBody WalletBalanceTransactionDto dto);
|
||||
|
||||
}
|
||||
@@ -13,6 +13,11 @@
|
||||
<artifactId>pjcloud-wallet-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!--引入分布式事务-->
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-common-seata</artifactId>
|
||||
</dependency>
|
||||
<!--必备: undertow容器-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Reference in new issue
Block a user