feat:额外收费
This commit is contained in:
1 parent
54a431891a
commit
33ff7edc2e
46 files changed
+955
-26
No files matched your search
+2
@@ -121,6 +121,8 @@ public interface HardOrderService extends IService<HardOrderEntity> {
|
||||
|
||||
Integer computeExtraPrice(Integer price, MchManageVo mch, SysUser sysUser);
|
||||
|
||||
Integer computeExtraPriceV2(Integer totalPrice, Long mchId, String hourType, Long userId, Long userDeptId);
|
||||
|
||||
/**
|
||||
* 核销二维码
|
||||
*/
|
||||
|
||||
+22
-2
@@ -34,6 +34,7 @@ import com.bsd.pjcloud.hard.api.dto.order.*;
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.WechatRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.*;
|
||||
import com.bsd.pjcloud.hard.api.utils.HardUtil;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardManagerVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
@@ -46,6 +47,8 @@ import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.*;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundDto;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargeService;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletSettingService;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletXfjDiscounts;
|
||||
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -74,14 +77,16 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
private final HardOrderService hardOrderService;
|
||||
private final WechatPayService wechatPayService;
|
||||
private final AlipayService alipayService;
|
||||
private final HardCarService hardCarService;
|
||||
private final HardAfterSaleCarService hardAfterSaleCarService;
|
||||
private final HardManagerService hardManagerService;
|
||||
|
||||
private final HardOrderMapper hardOrderMapper;
|
||||
|
||||
private final RemoteUserService userService;
|
||||
private final RemoteDeptService deptService;
|
||||
private final RemoteWalletRechargeService walletRechargeService;
|
||||
private final HardCarService hardCarService;
|
||||
private final HardAfterSaleCarService hardAfterSaleCarService;
|
||||
private final RemoteWalletSettingService walletSettingService;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -411,6 +416,11 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
if (totalPrice > order.getPayPrice()) {
|
||||
throw new RuntimeException("退款总金额大于支付总金额");
|
||||
}
|
||||
// 查询设备信息
|
||||
HardManagerVo hardDetail = hardManagerService.getByHardId(order.getHardId());
|
||||
if (ObjectUtil.isNotEmpty(hardDetail)) {
|
||||
orderVo.setHardType(hardDetail.getType());
|
||||
}
|
||||
return orderVo;
|
||||
}
|
||||
|
||||
@@ -559,6 +569,16 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
return entity;
|
||||
}).toList();
|
||||
refundPrice = hardCarService.computerCarTotalPrice(HardTypeEnum.valueOfByType(order.getSysType()), HardOrderTypeEnum.valueOfByType(order.getOrderType()), computerCarList);
|
||||
// TODO 特殊如果是食堂会有额外收费记得退款
|
||||
if (ObjectUtil.equals(order.getHardType(), HardTypeEnum.CANTEEN.getType()) && ObjectUtil.isNotEmpty(order.getExtraPrice()) && order.getExtraPrice() > 0) {
|
||||
int noRefundPrice = order.getPayPrice() - order.getExtraPrice() - refundPrice;
|
||||
if (noRefundPrice >= 0) {
|
||||
Integer noRefundExtraPrice = hardOrderService.computeExtraPriceV2(noRefundPrice, order.getMerchantId(), order.getHourType(), order.getUserId(), order.getUserDeptId());
|
||||
if (noRefundExtraPrice == 0) {
|
||||
refundPrice += order.getExtraPrice();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saveObj.setType(HardSaleTypeEnum.AFTER_SALE.getType());
|
||||
|
||||
+17
-1
@@ -94,6 +94,7 @@ import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletXfjDiscounts;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActCancelItemVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActComItemVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.mch.MchPickUpVo;
|
||||
@@ -301,7 +302,9 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
}
|
||||
int totalPrice = 0, extraPrice = 0, payPrice = 0;
|
||||
totalPrice = hardCarService.computerCarTotalPrice(dto.getSysType(), dto.getOrderType(), dto.getList());
|
||||
if (isExtraPrice) extraPrice = computeExtraPrice(totalPrice, mch, sysUser);
|
||||
if (isExtraPrice) {
|
||||
extraPrice = computeExtraPriceV2(totalPrice, mch.getId(), String.valueOf(dto.getHourType()), sysUser.getUserId(), sysUser.getDeptId());
|
||||
}
|
||||
payPrice = totalPrice + extraPrice;
|
||||
if (isWalletPay) {
|
||||
// 如果是支付的话,不能小于等于0
|
||||
@@ -1132,6 +1135,19 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
return extraPrice;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer computeExtraPriceV2(Integer totalPrice, Long mchId, String hourType, Long userId, Long userDeptId) {
|
||||
List<WalletXfjDiscounts> discountsList = walletSettingService.remoteGetDiscountsList(String.valueOf(mchId), userId, userDeptId).getData();
|
||||
if (ObjectUtil.isEmpty(discountsList)) {
|
||||
return 0;
|
||||
}
|
||||
return discountsList.stream()
|
||||
.filter(item -> ObjectUtil.equals(item.getHourType(), String.valueOf(hourType)))
|
||||
.map(item -> item.computedDiscountsExtraPrice(totalPrice))
|
||||
.reduce(Integer::sum).orElse(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean handCancelCode(HandCancelCodeDto dto) {
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.bsd.pjcloud.thirdparty.constant.pay;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 第三方支付业务类型
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ThirdPayOrderBizTypeEnum {
|
||||
|
||||
MINI_APP_WALLET_RECHARGE("10", "小程序用户钱包充值"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
private final String description;
|
||||
|
||||
public static ThirdPayOrderBizTypeEnum valueOfByType(String type) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.bsd.pjcloud.thirdparty.constant.pay;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 第三方支付订单状态
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ThirdPayOrderStatusEnum {
|
||||
PAY_UNPAID("10", "未支付"),
|
||||
PAY_SUCCESS("20", "支付成功"),
|
||||
PAY_FAILED("30", "已经支付"),
|
||||
|
||||
REFUNDING("100", "退款中"),
|
||||
REFUND_SUCCESS("200", "退款成功"),
|
||||
REFUND_FAILED("300", "退款失败"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
private final String description;
|
||||
|
||||
public static ThirdPayOrderStatusEnum valueOfByType(String type) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
|
||||
}
|
||||
|
||||
}
|
||||
+14
-1
@@ -1,6 +1,7 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.oathmini;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@@ -8,6 +9,19 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ThirdMiniAppPayDto {
|
||||
|
||||
/**
|
||||
* 充值业务类型
|
||||
*/
|
||||
@NotNull(message = "充值业务类型不能为空")
|
||||
private ThirdPayOrderBizTypeEnum bizType;
|
||||
|
||||
/**
|
||||
* 充值业务id
|
||||
*/
|
||||
@NotEmpty(message = "充值业务id不能为空")
|
||||
private String bizId;
|
||||
|
||||
|
||||
/**
|
||||
* 小程序平台
|
||||
*/
|
||||
@@ -17,7 +31,6 @@ public class ThirdMiniAppPayDto {
|
||||
/**
|
||||
* 金额(分)
|
||||
*/
|
||||
@NotNull(message = "金额(分)不能为空")
|
||||
private Integer amount;
|
||||
|
||||
/**
|
||||
|
||||
+16
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -8,11 +9,26 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ThirdMiniJsapiPayDto {
|
||||
|
||||
/**
|
||||
* 充值业务类型
|
||||
*/
|
||||
private ThirdPayOrderBizTypeEnum bizType;
|
||||
|
||||
/**
|
||||
* 充值业务id
|
||||
*/
|
||||
private String bizId;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.pay;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThirdPayOrderDto extends ThirdPayOrderEntity {
|
||||
|
||||
}
|
||||
Vendored
Executable
+155
@@ -0,0 +1,155 @@
|
||||
package com.bsd.pjcloud.thirdparty.entity.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.bsd.pjcloud.common.core.util.TenantTable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 第三方支付订单
|
||||
*/
|
||||
@Data
|
||||
@TenantTable
|
||||
@TableName("third_pay_order")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description = "第三方支付订单")
|
||||
public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 支付平台类型
|
||||
*/
|
||||
@Schema(description = "支付平台类型")
|
||||
private String payPlatformType;
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
@Schema(description = "支付类型")
|
||||
private String bizType;
|
||||
|
||||
/**
|
||||
* 支付相关id
|
||||
*/
|
||||
@Schema(description = "支付相关id")
|
||||
private String bizId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户code
|
||||
*/
|
||||
@Schema(description = "用户code")
|
||||
private String userCode;
|
||||
|
||||
/**
|
||||
* 支付金额(分)
|
||||
*/
|
||||
@Schema(description = "支付金额(分)")
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 支付订单号
|
||||
*/
|
||||
@Schema(description = "支付订单号")
|
||||
private String payNo;
|
||||
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
@Schema(description = "支付时间")
|
||||
private LocalDateTime payTime;
|
||||
|
||||
/**
|
||||
* 支付返回
|
||||
*/
|
||||
@Schema(description = "支付返回")
|
||||
private String payRes;
|
||||
|
||||
/**
|
||||
* 退款订单号
|
||||
*/
|
||||
@Schema(description = "退款订单号")
|
||||
private String refundNo;
|
||||
|
||||
/**
|
||||
* 退款时间
|
||||
*/
|
||||
@Schema(description = "退款时间")
|
||||
private LocalDateTime refundTime;
|
||||
|
||||
/**
|
||||
* 退款返回
|
||||
*/
|
||||
@Schema(description = "退款返回")
|
||||
private String refundRes;
|
||||
|
||||
/**
|
||||
* 订单过期时间
|
||||
*/
|
||||
@Schema(description = "订单过期时间")
|
||||
private LocalDateTime expireTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 删除时间
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除时间")
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* tenantId
|
||||
*/
|
||||
@Schema(description = "tenantId")
|
||||
private Long tenantId;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.bsd.pjcloud.thirdparty.vo.oathmini.pay;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Data
|
||||
public class ThirdMiniAppPayVo {
|
||||
|
||||
private HashMap<String, Object> miniAppPayParams;
|
||||
|
||||
}
|
||||
+4
@@ -3,6 +3,8 @@ package com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* JSAPI/小程序下单
|
||||
*/
|
||||
@@ -37,6 +39,8 @@ public class ThirdMiniJsapiPayVo {
|
||||
|
||||
private String code_url;
|
||||
|
||||
private HashMap<String, Object> miniAppPayParams;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(ThirdMiniWechatQueryVo.SUCCESS, return_code);
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.bsd.pjcloud.thirdparty.vo.pay;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThirdPayOrderVo extends ThirdPayOrderEntity {
|
||||
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+5
@@ -46,6 +46,11 @@ public class MiniAppConfig {
|
||||
*/
|
||||
private String apiV2Key;
|
||||
|
||||
/**
|
||||
* 支付成功的回调
|
||||
*/
|
||||
private String payCallbackUrl;
|
||||
|
||||
/**
|
||||
* 退款回调地址
|
||||
*/
|
||||
|
||||
+23
-6
@@ -7,15 +7,17 @@ import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -28,10 +30,25 @@ public class ThirdMinAppPayCotroller {
|
||||
|
||||
@Operation(summary = "小程序支付")
|
||||
@PostMapping("/app/pay")
|
||||
@Inner(value = false)
|
||||
public R<String> miniPay(@RequestBody ThirdMiniAppPayDto dto) {
|
||||
public R<ThirdMiniAppPayVo> miniPay(@Validated @RequestBody ThirdMiniAppPayDto dto) {
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
return R.ok(thirdMiniAppService.miniPay(user.getId(), dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "小程序支付回调")
|
||||
@PostMapping("/app/pay-callback")
|
||||
@Inner(value = false)
|
||||
public R<String> miniPayCallback(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers) {
|
||||
String body = httpEntity.getBody();
|
||||
return R.ok(thirdMiniAppService.miniPayCallback(body, headers));
|
||||
}
|
||||
|
||||
@Operation(summary = "小程序退款回调")
|
||||
@PostMapping("/app/refund-callback")
|
||||
@Inner(value = false)
|
||||
public R<String> miniRefundCallback(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers) {
|
||||
String body = httpEntity.getBody();
|
||||
return R.ok(thirdMiniAppService.miniRefundCallback(body, headers));
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
Executable
+100
@@ -0,0 +1,100 @@
|
||||
package com.bsd.pjcloud.thirdparty.controller.pay;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方支付订单
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/third-pay-order")
|
||||
@Tag(description = "third-pay-order", name = "第三方支付订单管理")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class ThirdPayOrderController {
|
||||
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_view')")
|
||||
public R<Page<ThirdPayOrderVo>> getThirdPayOrderPage(@ParameterObject Page page, @ParameterObject ThirdPayOrderDto dto) {
|
||||
return R.ok(thirdPayOrderService.scopePage(page, dto, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_view')")
|
||||
public R getById(@PathVariable("id") Long id) {
|
||||
return R.ok(thirdPayOrderService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "新增第三方支付订单", description = "新增第三方支付订单")
|
||||
@SysLog("新增第三方支付订单")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_add')")
|
||||
public R save(@RequestBody ThirdPayOrderEntity thirdPayOrder) {
|
||||
return R.ok(thirdPayOrderService.save(thirdPayOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "修改第三方支付订单", description = "修改第三方支付订单")
|
||||
@SysLog("修改第三方支付订单")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_edit')")
|
||||
public R updateById(@RequestBody ThirdPayOrderEntity thirdPayOrder) {
|
||||
return R.ok(thirdPayOrderService.updateById(thirdPayOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "通过id删除第三方支付订单", description = "通过id删除第三方支付订单")
|
||||
@SysLog("通过id删除第三方支付订单")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_del')")
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
return R.ok(thirdPayOrderService.removeBatchByIds(CollUtil.toList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_export')")
|
||||
public List<ThirdPayOrderEntity> export(ThirdPayOrderEntity thirdPayOrder, Long[] ids) {
|
||||
return thirdPayOrderService.list(Wrappers.lambdaQuery(thirdPayOrder).in(ArrayUtil.isNotEmpty(ids), ThirdPayOrderEntity::getId, ids));
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
Executable
+17
@@ -0,0 +1,17 @@
|
||||
package com.bsd.pjcloud.thirdparty.mapper.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface ThirdPayOrderMapper extends PjcloudBaseMapper<ThirdPayOrderEntity> {
|
||||
|
||||
Page<ThirdPayOrderVo> scopePage(Page page, @Param("dto") ThirdPayOrderDto dto, DataScope dataScope);
|
||||
|
||||
}
|
||||
+14
-1
@@ -4,6 +4,9 @@ import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ThirdMiniAppService {
|
||||
|
||||
@@ -20,5 +23,15 @@ public interface ThirdMiniAppService {
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
String miniPay(Long userId, ThirdMiniAppPayDto dto);
|
||||
ThirdMiniAppPayVo miniPay(Long userId, ThirdMiniAppPayDto dto);
|
||||
|
||||
/**
|
||||
* 小程序支付回调
|
||||
*/
|
||||
String miniPayCallback(String body, Map<String, String> headers);
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
String miniRefundCallback(String body, Map<String, String> headers);
|
||||
}
|
||||
Vendored
Executable
+14
@@ -0,0 +1,14 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
|
||||
public interface ThirdPayOrderService extends IService<ThirdPayOrderEntity> {
|
||||
|
||||
Page<ThirdPayOrderVo> scopePage(Page page, ThirdPayOrderDto dto, DataScope dataScope);
|
||||
|
||||
}
|
||||
+65
-5
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.thirdparty.service.impl.miniapp;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserTokenDTO;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteTokenService;
|
||||
@@ -12,6 +13,7 @@ import com.bsd.pjcloud.app.api.dto.AppUserInfo;
|
||||
import com.bsd.pjcloud.app.api.feign.RemoteAppUserService;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformLoginErrorEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
@@ -22,13 +24,19 @@ import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppWechatService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayLogService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniJsapiPayVo;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargePackageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -47,6 +55,7 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final RemoteTokenService remoteTokenService;
|
||||
private final RemoteAppUserService remoteAppUserService;
|
||||
private final RemoteWalletRechargePackageService remoteWalletRechargePackageService;
|
||||
|
||||
/**
|
||||
* 小程序登录
|
||||
@@ -122,26 +131,77 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
* 小程序支付
|
||||
*/
|
||||
@Override
|
||||
public String miniPay(Long userId, ThirdMiniAppPayDto dto) {
|
||||
ThirdPayLogEntity log = new ThirdPayLogEntity();
|
||||
public ThirdMiniAppPayVo miniPay(Long userId, ThirdMiniAppPayDto dto) {
|
||||
ThirdMiniAppPayVo result = new ThirdMiniAppPayVo();
|
||||
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_WALLET_RECHARGE)) {
|
||||
Long bizId = null;
|
||||
try {
|
||||
bizId = Long.valueOf(dto.getBizId());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("充值业务id解析错误");
|
||||
}
|
||||
// 查询充值配置
|
||||
WalletRechargePackageEntity walletPackage = remoteWalletRechargePackageService.remoteGetById(bizId).getData();
|
||||
if (ObjectUtil.isEmpty(walletPackage)) {
|
||||
throw new RuntimeException("错误的充值配置");
|
||||
}
|
||||
int price = walletPackage.getPayPrice() + walletPackage.getBonusPrice();
|
||||
if (price <= 0) {
|
||||
throw new RuntimeException("错误的充值配置");
|
||||
}
|
||||
dto.setAmount(price);
|
||||
}
|
||||
// 不支持的类型
|
||||
else {
|
||||
throw new RuntimeException("不支持的支付类型");
|
||||
}
|
||||
try {
|
||||
// 微信小程序
|
||||
if (ObjectUtil.equals(dto.getMiniPlatformType().getType(), MiniPlatformTypeEnum.WECHAT.getType())) {
|
||||
ThirdMiniJsapiPayDto wechatPayDto = new ThirdMiniJsapiPayDto();
|
||||
wechatPayDto.setOutTradeNo("");
|
||||
// 当前时间戳+10位随机字符串
|
||||
String outTradeNo = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + RandomUtil.randomString(10);
|
||||
wechatPayDto.setOutTradeNo(outTradeNo);
|
||||
wechatPayDto.setBizId(dto.getBizId());
|
||||
wechatPayDto.setBizType(dto.getBizType());
|
||||
wechatPayDto.setUserId(userId);
|
||||
wechatPayDto.setOpenid(dto.getOpenId());
|
||||
wechatPayDto.setAmount(dto.getAmount());
|
||||
ThirdMiniJsapiPayVo thirdMiniJsapiPayVo = thirdMiniAppWechatService.jsapiPay(wechatPayDto);
|
||||
if (ObjectUtil.isEmpty(thirdMiniJsapiPayVo)) {
|
||||
throw new RuntimeException("创建微信支付错误");
|
||||
}
|
||||
result.setMiniAppPayParams(thirdMiniJsapiPayVo.getMiniAppPayParams());
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(dto.getMiniPlatformType().getType(), MiniPlatformTypeEnum.ALI_PAY.getType())) {
|
||||
|
||||
}
|
||||
// 不支持的支付类型
|
||||
else {
|
||||
throw new RuntimeException("不支持的支付类型");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
thirdPayLogService.save(log);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序支付回调
|
||||
*/
|
||||
@Override
|
||||
public String miniPayCallback(String body, Map<String, String> headers) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
@Override
|
||||
public String miniRefundCallback(String body, Map<String, String> headers) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
+40
@@ -9,8 +9,12 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.thirdparty.config.MiniAppConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.*;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppWechatService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.utils.miniapp.pay.wechat.ThirdMiniWechantPayConstant;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -27,6 +31,7 @@ import java.io.FileInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -45,6 +50,7 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
private final MiniAppConfig miniAppConfig;
|
||||
|
||||
private final WxMaService wxMaService;
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,6 +59,15 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
@Override
|
||||
public ThirdMiniJsapiPayVo jsapiPay(ThirdMiniJsapiPayDto dto) {
|
||||
MiniAppConfig.WechatConfig wechatConfig = miniAppConfig.getWechatConfig();
|
||||
|
||||
ThirdPayOrderEntity payOrder = new ThirdPayOrderEntity();
|
||||
payOrder.setPayPlatformType(MiniPlatformTypeEnum.WECHAT.getType());
|
||||
payOrder.setBizId(dto.getBizId());
|
||||
payOrder.setBizType(dto.getBizType().getType());
|
||||
payOrder.setUserId(dto.getUserId());
|
||||
payOrder.setUserCode(dto.getOpenid());
|
||||
payOrder.setPrice(dto.getAmount());
|
||||
payOrder.setStatus(ThirdPayOrderStatusEnum.PAY_UNPAID.getType());
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
@@ -93,10 +108,35 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
payOrder.setPayTime(LocalDateTime.now());
|
||||
payOrder.setPayRes(res);
|
||||
// 生成小程序 paySign
|
||||
String nonceStr = RandomUtil.randomString(32);
|
||||
long timeStamp = System.currentTimeMillis() / 1000;
|
||||
String payPackage = "prepay_id=" + vo.getPrepay_id();
|
||||
String signType = "MD5";
|
||||
|
||||
String payStr = "appId=" + wechatConfig.getAppId() + "&";
|
||||
payStr += "nonceStr=" + nonceStr + "&";
|
||||
payStr += "package=" + payPackage + "&";
|
||||
payStr += "signType=" + signType + "&";
|
||||
payStr += "timeStamp=" + timeStamp + "&";
|
||||
payStr += "key=" + wechatConfig.getApiV2Key();
|
||||
String paySign = DigestUtils.md5Hex(payStr);
|
||||
|
||||
HashMap<String, Object> miniAppPayParams = new HashMap<>();
|
||||
miniAppPayParams.put("timeStamp", timeStamp);
|
||||
miniAppPayParams.put("nonceStr", nonceStr);
|
||||
miniAppPayParams.put("package", payPackage);
|
||||
miniAppPayParams.put("signType", signType);
|
||||
miniAppPayParams.put("paySign", paySign);
|
||||
vo.setMiniAppPayParams(miniAppPayParams);
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|JSAPI/小程序下单,异常", TAG, e);
|
||||
return null;
|
||||
} finally {
|
||||
thirdPayOrderService.save(payOrder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
Executable
+24
@@ -0,0 +1,24 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.pay.ThirdPayOrderMapper;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 第三方支付订单
|
||||
*/
|
||||
@Service
|
||||
public class ThirdPayOrderServiceImpl extends ServiceImpl<ThirdPayOrderMapper, ThirdPayOrderEntity> implements ThirdPayOrderService {
|
||||
|
||||
@Override
|
||||
public Page<ThirdPayOrderVo> scopePage(Page page, ThirdPayOrderDto dto, DataScope dataScope) {
|
||||
return baseMapper.scopePage(page, dto, dataScope);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -181,8 +181,9 @@ mini-platform:
|
||||
app-secret: a6b0d036b229117595687a7c1705d332
|
||||
merchant-id: 1106210589
|
||||
api-v2-key: qr0w9WkAu6GG3uuxPjDT7bcdIVoBr0rw
|
||||
merchant-serial-path: /Users/dengzhangchen/Desktop/backups/pay/cert/apiclient_cert.p12
|
||||
refund-callback-url: https://rj4jv5rwqs.by.takin.cc/hard/hard-wechant-pay/callback/refund
|
||||
merchant-serial-path: /Users/dengzhangchen/Desktop/backups/pay/third_cert/apiclient_cert.p12
|
||||
pay-callback-url: https://rj4jv5rwqs.by.takin.cc/third/third-mini-app-pay/app/pay-callback
|
||||
refund-callback-url: https://rj4jv5rwqs.by.takin.cc/hard/hard-wechant-pay/app/refund-callback
|
||||
spbill-create-ip: 59.202.170.152
|
||||
base-url: https://api.mch.weixin.qq.com
|
||||
ali-pay-config:
|
||||
|
||||
Vendored
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.bsd.pjcloud.thirdparty.mapper.pay.ThirdPayOrderMapper">
|
||||
|
||||
<sql id="selectA">
|
||||
select a.id,
|
||||
a.pay_platform_type,
|
||||
a.biz_type,
|
||||
a.biz_id,
|
||||
a.user_id,
|
||||
a.user_code,
|
||||
a.price,
|
||||
a.status,
|
||||
a.pay_no,
|
||||
a.pay_time,
|
||||
a.pay_res,
|
||||
a.refund_no,
|
||||
a.refund_time,
|
||||
a.refund_res,
|
||||
a.expire_time,
|
||||
a.create_time,
|
||||
a.update_time,
|
||||
a.create_by,
|
||||
a.update_by,
|
||||
a.del_flag,
|
||||
a.tenant_id
|
||||
</sql>
|
||||
|
||||
<sql id="whereA">
|
||||
a.del_flag = '0'
|
||||
<if test="dto.id != null">
|
||||
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="scopePage" resultType="com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo">
|
||||
<include refid="selectA"/>
|
||||
from third_pay_order a
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
</where>
|
||||
order by a.create_time desc, a.id desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.bsd.pjcloud.wallet.api.constant;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 钱包的unique code
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum WalletXfjDiscountsEnum {
|
||||
|
||||
JZ_DISCOUNT("1", "9折优惠"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String desc;
|
||||
|
||||
public static WalletXfjDiscountsEnum valueOfByCode(String code) {
|
||||
if (ObjectUtil.isEmpty(code)) return null;
|
||||
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(code, v.getCode())).findFirst().get();
|
||||
}
|
||||
|
||||
public static WalletXfjDiscountsEnum descOf(String description) {
|
||||
return Arrays.stream(WalletXfjDiscountsEnum.values())
|
||||
.filter(v -> ObjectUtil.equal(v.getDesc(), description))
|
||||
.findFirst().get();
|
||||
}
|
||||
|
||||
}
|
||||
+69
-3
@@ -4,8 +4,7 @@ import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.*;
|
||||
import com.bsd.pjcloud.common.core.util.TenantTable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -20,7 +19,7 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
@TenantTable
|
||||
@TableName("wallet_setting")
|
||||
@TableName(value = "wallet_setting", autoResultMap = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description = "支付设置")
|
||||
public class WalletSettingEntity extends Model<WalletSettingEntity> {
|
||||
@@ -91,6 +90,36 @@ public class WalletSettingEntity extends Model<WalletSettingEntity> {
|
||||
*/
|
||||
private Long topupUserId;
|
||||
|
||||
/**
|
||||
* 在编消默认费机优惠规则
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<WalletXfjDiscounts> zbDefaultXfjDiscounts;
|
||||
|
||||
/**
|
||||
* 在编消特殊费机优惠规则
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<WalletXfjDiscounts> zbSpecialXfjDiscounts;
|
||||
|
||||
/**
|
||||
* 非在编消默认费机优惠规则
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<WalletXfjDiscounts> fzbDefaultXfjDiscounts;
|
||||
|
||||
/**
|
||||
* 非在编消特殊费机优惠规则
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<WalletXfjDiscounts> fzbSpecialXfjDiscounts;
|
||||
|
||||
/**
|
||||
* 特殊消费机列表
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<String> specialXfjIdList;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@@ -132,4 +161,41 @@ public class WalletSettingEntity extends Model<WalletSettingEntity> {
|
||||
*/
|
||||
@Schema(description = "租户ID")
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 消费机优惠规则
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class WalletXfjDiscounts {
|
||||
|
||||
/**
|
||||
* 时间类型
|
||||
*/
|
||||
private String hourType;
|
||||
|
||||
/**
|
||||
* 基础金额(分),超过了这个基数`extraPer`就生效
|
||||
*/
|
||||
private int basePrice;
|
||||
|
||||
/**
|
||||
* 额外多收的百分比(1.5,10块就是15块)
|
||||
*/
|
||||
private double extraPer;
|
||||
|
||||
/**
|
||||
* 特色菜是否额外收费
|
||||
*/
|
||||
private String specialDishEnable;
|
||||
|
||||
/**
|
||||
* 是否开启
|
||||
*/
|
||||
private String enable;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.bsd.pjcloud.wallet.api.feign;
|
||||
|
||||
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
@FeignClient(contextId = "remoteWalletRechargePackageService", value = ServiceNameConstants.WALLET_SERVICE)
|
||||
public interface RemoteWalletRechargePackageService {
|
||||
|
||||
@GetMapping("/wallet-recharge-package/remote/{id}")
|
||||
R<WalletRechargePackageEntity> remoteGetById(@PathVariable("id") Long id);
|
||||
|
||||
}
|
||||
+8
-2
@@ -4,17 +4,23 @@ import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletXfjDiscounts;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(contextId = "remoteWalletSettingService", value = ServiceNameConstants.WALLET_SERVICE)
|
||||
public interface RemoteWalletSettingService {
|
||||
/**
|
||||
* 获取支付配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/wallet-setting/get-setting")
|
||||
R<WalletSettingVo> get();
|
||||
|
||||
@NoToken
|
||||
@GetMapping("/wallet-setting/remote/get-discounts-list")
|
||||
R<List<WalletXfjDiscounts>> remoteGetDiscountsList(@RequestParam String hardId, @RequestParam Long userId, @RequestParam(required = false) Long userDeptId);
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.bsd.pjcloud.wallet.api.vo;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletXfjDiscountsEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 消费机优惠
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class WalletXfjDiscounts {
|
||||
|
||||
/**
|
||||
* 消费机优惠活动名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 用餐时间段类型
|
||||
*/
|
||||
private String hourType;
|
||||
|
||||
/**
|
||||
* 消费机优惠活动名称
|
||||
*
|
||||
* @see WalletXfjDiscountsEnum
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 基础金额(分),超过了这个基数`extraPer`就生效
|
||||
*/
|
||||
private int basePrice;
|
||||
|
||||
/**
|
||||
* 消费机优惠活动名称
|
||||
*/
|
||||
private Double extraPer;
|
||||
|
||||
public int computedDiscountsExtraPrice(int totalPrice) {
|
||||
if (totalPrice <= basePrice) return 0;
|
||||
double rate = ObjectUtil.isEmpty(extraPer) ? 1.0 : extraPer;
|
||||
if (rate == 1.0) return 0;
|
||||
return (int) Math.round(totalPrice * (rate - 1));
|
||||
}
|
||||
}
|
||||
+1
@@ -6,6 +6,7 @@ com.bsd.pjcloud.wallet.api.feign.RemoteCodeUseService
|
||||
com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargeService
|
||||
com.bsd.pjcloud.wallet.api.feign.RemoteWalletRuleTransactionService
|
||||
com.bsd.pjcloud.wallet.api.feign.RemoteMchService
|
||||
com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargePackageService
|
||||
com.bsd.pjcloud.wallet.api.feign.RemoteWalletSettingService
|
||||
com.bsd.pjcloud.wallet.api.feign.RemoteWalletThirdZyService
|
||||
com.bsd.pjcloud.wallet.api.feign.RemoteWalletTransactionService
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+16
@@ -5,6 +5,7 @@ import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletSettingDto;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletXfjDiscounts;
|
||||
import com.bsd.pjcloud.wallet.service.WalletSettingService;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -14,6 +15,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付设置
|
||||
*
|
||||
@@ -30,11 +33,19 @@ public class WalletSettingController {
|
||||
private final WalletSettingService walletSettingService;
|
||||
|
||||
/* ************************************* start 远程调用 start ************************************* */
|
||||
|
||||
@Inner
|
||||
@GetMapping("/get-setting")
|
||||
public R<WalletSettingVo> get() {
|
||||
return R.ok(walletSettingService.getSetting());
|
||||
}
|
||||
|
||||
@Inner
|
||||
@GetMapping("/remote/get-discounts-list")
|
||||
public R<List<WalletXfjDiscounts>> remoteGetDiscountsList(@RequestParam String hardId, @RequestParam Long userId) {
|
||||
return R.ok(walletSettingService.androidGetDiscountsList(hardId, userId));
|
||||
}
|
||||
|
||||
/* ************************************* end 远程调用 end ************************************* */
|
||||
|
||||
/* ************************************* start app start ************************************* */
|
||||
@@ -45,6 +56,11 @@ public class WalletSettingController {
|
||||
/* ************************************* end app end ************************************* */
|
||||
|
||||
/* ************************************* start android start ************************************* */
|
||||
@GetMapping("/ad/get-discounts-list")
|
||||
public R<List<WalletXfjDiscounts>> androidGetDiscountsList(@RequestParam String hardId, @RequestParam Long userId) {
|
||||
return R.ok(walletSettingService.androidGetDiscountsList(hardId, userId));
|
||||
}
|
||||
|
||||
@GetMapping("/ad/get-setting")
|
||||
public R<WalletSettingVo> androidGet() {
|
||||
return R.ok(walletSettingService.getSetting());
|
||||
|
||||
+8
@@ -37,6 +37,14 @@ public class WalletRechargePackageController {
|
||||
|
||||
private final WalletRechargePackageService walletRechargePackageService;
|
||||
|
||||
/* ************************************* start remote start ************************************* */
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/remote/{id}")
|
||||
public R<WalletRechargePackageEntity> remoteGetById(@PathVariable("id") Long id) {
|
||||
return R.ok(walletRechargePackageService.getById(id));
|
||||
}
|
||||
/* ************************************* end remote end ************************************* */
|
||||
|
||||
/* ************************************* start app start ************************************* */
|
||||
@Operation(summary = "查询全部", description = "查询全部")
|
||||
@GetMapping("/app/list")
|
||||
|
||||
+8
@@ -4,9 +4,17 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletSettingDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletSettingEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletXfjDiscounts;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface WalletSettingService extends IService<WalletSettingEntity> {
|
||||
|
||||
/**
|
||||
* 获取消费机优惠列表
|
||||
*/
|
||||
List<WalletXfjDiscounts> androidGetDiscountsList(String hardId, Long userId);
|
||||
|
||||
WalletSettingVo getSetting();
|
||||
|
||||
void edit(WalletSettingDto dto);
|
||||
|
||||
+73
-3
@@ -3,12 +3,20 @@ package com.bsd.pjcloud.wallet.service.impl;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.admin.api.entity.SysUser;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletXfjDiscountsEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletSettingDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletSettingEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletXfjDiscounts;
|
||||
import com.bsd.pjcloud.wallet.mapper.WalletSettingMapper;
|
||||
import com.bsd.pjcloud.wallet.service.MchManageService;
|
||||
import com.bsd.pjcloud.wallet.service.MchRuleJoinService;
|
||||
import com.bsd.pjcloud.wallet.service.WalletRuleJoinService;
|
||||
import com.bsd.pjcloud.wallet.service.WalletSettingService;
|
||||
@@ -19,12 +27,11 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付设置
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-01-06 10:52:31
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
@@ -32,6 +39,69 @@ import java.math.BigDecimal;
|
||||
@Service
|
||||
public class WalletSettingServiceImpl extends ServiceImpl<WalletSettingMapper, WalletSettingEntity> implements WalletSettingService {
|
||||
|
||||
private final MchManageService mchManageService;
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
/**
|
||||
* 获取消费机优惠列表
|
||||
*/
|
||||
@Override
|
||||
public List<WalletXfjDiscounts> androidGetDiscountsList(String hardId, Long userId) {
|
||||
List<WalletXfjDiscounts> discountsList = new ArrayList<>();
|
||||
UserInfo userInfo = remoteUserService.getInnerByUserId(userId).getData();
|
||||
if (ObjectUtil.isEmpty(userInfo) || ObjectUtil.isEmpty(userInfo.getSysUser())) {
|
||||
return List.of();
|
||||
}
|
||||
WalletSettingVo setting = getSetting();
|
||||
if (ObjectUtil.isEmpty(setting)) {
|
||||
return List.of();
|
||||
}
|
||||
SysUser sysUser = userInfo.getSysUser();
|
||||
|
||||
// 在自营食堂
|
||||
MchManageVo userMch = mchManageService.getFirstMchByDeptId(sysUser.getDeptId(), List.of(MerchantTypeEnum.CANTEEN));
|
||||
boolean isSelfCatering = ObjectUtil.isNotEmpty(userMch);
|
||||
|
||||
List<WalletSettingEntity.WalletXfjDiscounts> list = new ArrayList<>();
|
||||
// 特殊食堂(二楼食堂)
|
||||
if (ObjectUtil.isNotEmpty(setting.getSpecialXfjIdList()) && setting.getSpecialXfjIdList().contains(hardId)) {
|
||||
// 自营食堂下用户
|
||||
if (isSelfCatering) {
|
||||
list = setting.getZbSpecialXfjDiscounts();
|
||||
}
|
||||
// 不在自营食堂下用户
|
||||
else {
|
||||
list = setting.getFzbSpecialXfjDiscounts();
|
||||
}
|
||||
}
|
||||
// 默认食堂
|
||||
else {
|
||||
// 自营食堂下用户
|
||||
if (isSelfCatering) {
|
||||
list = setting.getZbDefaultXfjDiscounts();
|
||||
}
|
||||
// 不在自营食堂下用户
|
||||
else {
|
||||
list = setting.getFzbDefaultXfjDiscounts();
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(list)) {
|
||||
discountsList.addAll(
|
||||
list.stream().map(item -> {
|
||||
WalletXfjDiscounts entity = new WalletXfjDiscounts();
|
||||
entity.setName("食堂差异化就餐收费管理办法");
|
||||
entity.setHourType(item.getHourType());
|
||||
entity.setType(WalletXfjDiscountsEnum.JZ_DISCOUNT.getCode());
|
||||
entity.setExtraPer(item.getExtraPer());
|
||||
entity.setBasePrice(item.getBasePrice());
|
||||
return entity;
|
||||
}).toList()
|
||||
);
|
||||
}
|
||||
return discountsList;
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Cacheable(value = CacheConstants.WALLET_SETTING_DETAIL)
|
||||
public WalletSettingVo getSetting() {
|
||||
|
||||
Reference in new issue
Block a user