diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 916337d..d5ed2bd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.controller; import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto; +import com.chaozhanggui.system.cashierservice.model.PaymentReq; import com.chaozhanggui.system.cashierservice.service.PayService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -45,8 +46,6 @@ public class PayController { * @param token * @param loginName * @param clientType - * @param orderId - * @param authCode * @return */ @RequestMapping("scanpay") @@ -55,13 +54,10 @@ public class PayController { @RequestHeader("token") String token, @RequestHeader("loginName") String loginName, @RequestHeader("clientType") String clientType, - @RequestParam("orderId") String orderId, - @RequestParam("payAmount") BigDecimal payAmount, - @RequestParam("discountAmount") BigDecimal discountAmount, - @RequestParam("authCode") String authCode + @RequestBody PaymentReq paymentReq - ) { - return payService.scanPay(orderId,authCode, IpUtil.getIpAddr(request),token,payAmount,discountAmount); + ) { + return payService.scanPay(paymentReq.getOrderId(),paymentReq.getAuthCode(), IpUtil.getIpAddr(request),token,paymentReq.getPayAmount(),paymentReq.getDiscountAmount()); } @@ -70,23 +66,17 @@ public class PayController { * @param token * @param loginName * @param clientType - * @param orderId - * @param memberId * @return */ - @GetMapping("accountPay") + @RequestMapping("accountPay") @LimitSubmit(key = "accountPay:%s") public Result accountPay(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName, @RequestHeader("clientType") String clientType, - @RequestParam("orderId") String orderId, - @RequestParam("memberId") String memberId, - @RequestParam("memberAccount") String memberAccount, - @RequestParam("payAmount") BigDecimal payAmount, - @RequestParam("discountAmount") BigDecimal discountAmount + @RequestBody PaymentReq paymentReq ){ - return payService.accountPay(orderId,memberId,token,memberAccount,payAmount,discountAmount); + return payService.accountPay(paymentReq.getOrderId(),paymentReq.getMemberId(),token,paymentReq.getMemberAccount(),paymentReq.getPayAmount(),paymentReq.getDiscountAmount()); } @@ -159,21 +149,16 @@ public class PayController { * @param token * @param loginName * @param clientType - * @param orderId - * @param memberCode * @return */ - @GetMapping("memberScanPay") + @RequestMapping("memberScanPay") @LimitSubmit(key = "memberScanPay:%s") public Result memberScanPay(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName, @RequestHeader("clientType") String clientType, - @RequestParam("orderId") String orderId, - @RequestParam("memberCode") String memberCode, - @RequestParam("payAmount") BigDecimal payAmount, - @RequestParam("discountAmount") BigDecimal discountAmount + @RequestBody PaymentReq paymentReq ){ - return payService.memberScanPay(orderId,memberCode,token,payAmount,discountAmount); + return payService.memberScanPay(paymentReq.getOrderId(),paymentReq.getMemberCode(),token,paymentReq.getPayAmount(),paymentReq.getDiscountAmount()); } @@ -183,18 +168,15 @@ public class PayController { * @param token * @param loginName * @param clientType - * @param orderId * @return */ - @GetMapping("cashPay") + @RequestMapping("cashPay") @LimitSubmit(key = "cashPay:%s") public Result cashPay(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName, @RequestHeader("clientType") String clientType, - @RequestParam("orderId") String orderId, - @RequestParam("payAmount") BigDecimal payAmount, - @RequestParam("discountAmount") BigDecimal discountAmount){ - return payService.cashPay(orderId,token,payAmount,discountAmount); + @RequestBody PaymentReq paymentReq){ + return payService.cashPay(paymentReq.getOrderId(),token,paymentReq.getPayAmount(),paymentReq.getDiscountAmount()); } @@ -225,18 +207,15 @@ public class PayController { * @param token * @param loginName * @param clientType - * @param orderId * @return */ - @GetMapping("bankPay") + @RequestMapping("bankPay") @LimitSubmit(key = "bankPay:%s") public Result bankPay(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName, @RequestHeader("clientType") String clientType, - @RequestParam("orderId") String orderId, - @RequestParam("payAmount") BigDecimal payAmount, - @RequestParam("discountAmount") BigDecimal discountAmount){ - return payService.bankPay(orderId,token); + @RequestBody PaymentReq paymentReq){ + return payService.bankPay(paymentReq.getOrderId(),token,paymentReq.getPayAmount(),paymentReq.getDiscountAmount()); } @@ -275,4 +254,16 @@ public class PayController { public Result testOrder( @RequestParam("orderId") String orderId){ return Result.success(CodeEnum.SUCCESS); } + + + + @RequestMapping("getOrderDiscount") + public Result getOrderDiscount(@RequestHeader("token") String token, + @RequestHeader("loginName") String loginName, + @RequestHeader("clientType") String clientType, + @RequestParam("orderId") String orderId, + @RequestParam("staffId") String staffId + ){ + return payService.getOrderDiscount(staffId, orderId, token); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/model/PaymentReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/model/PaymentReq.java new file mode 100644 index 0000000..e04a67b --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/model/PaymentReq.java @@ -0,0 +1,26 @@ +package com.chaozhanggui.system.cashierservice.model; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; + +@Data +public class PaymentReq implements Serializable { + + private String orderId; + + private BigDecimal payAmount; + + private BigDecimal discountAmount; + + private String authCode; + + private String memberId; + + private String memberAccount; + + private String memberCode; + + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 020ba31..a3c1587 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -1505,4 +1505,44 @@ public class PayService { tbGroupOrderInfoMapper.update(groupOrderInfo); return Result.success(CodeEnum.SUCCESS); } + + + public Result getOrderDiscount(String staffId,String orderId,String token ){ + if(ObjectUtil.isNull(staffId)||ObjectUtil.isNull(orderId)||ObjectUtil.isEmpty(staffId)||ObjectUtil.isEmpty(orderId)){ + return Result.fail(CodeEnum.PARAM); + } + JSONObject tokeObj= TokenUtil.parseParamFromToken(token); + if(Objects.isNull(tokeObj)){ + return Result.fail(CodeEnum.TOKENTERROR); + } + + if(!tokeObj.getString("staffId").equals(staffId)){ + return Result.fail(CodeEnum.PARAM); + } + + + TbOrderInfo tbOrderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); + if(ObjectUtil.isNull(tokeObj)||ObjectUtil.isEmpty(tbOrderInfo)){ + return Result.fail(CodeEnum.ORDERNOEXIST); + } + + TbPlussShopStaff staff=tbPlussShopStaffMapper.selectByPrimaryKey(Integer.valueOf(staffId)); + + if(ObjectUtil.isEmpty(staff)||ObjectUtil.isNull(staff)){ + return Result.fail(CodeEnum.STAFFNOEXISTERROE); + } + + if(ObjectUtil.isEmpty(staff.getMaxDiscountAmount())||ObjectUtil.isNull(staff.getMaxDiscountAmount())){ + return Result.success(SUCCESS,BigDecimal.ZERO); + } + + if("0".equals(staff.getDiscountType())){ + staff.setMaxDiscountAmount(staff.getMaxDiscountAmount().divide(tbOrderInfo.getOrderAmount()).setScale(2,BigDecimal.ROUND_DOWN)); + } + + return Result.success(SUCCESS,staff.getMaxDiscountAmount()); + + + + } }