From 40b8198c7e75ff07e732b97cd2fa808fe51a3272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Thu, 29 Aug 2024 16:37:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/MemberService.java | 166 ++++++++---------- 1 file changed, 74 insertions(+), 92 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java index bc8dd89..ffdc71a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java @@ -3,8 +3,6 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.chaozhanggui.system.cashierservice.bean.TableStateEnum; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.exception.MsgException; @@ -20,8 +18,6 @@ import com.chaozhanggui.system.cashierservice.thirdpay.resp.OrderStatusQueryResp import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp; import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService; import com.chaozhanggui.system.cashierservice.util.*; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -87,6 +83,7 @@ public class MemberService { @Qualifier("tbOrderInfoMapper") @Autowired private TbOrderInfoMapper tbOrderInfoMapper; + private MpShopTableMapper mpShopTableMapper; public Result queryMember(String shopId, String phone, int page, int pageSize) { @@ -316,7 +313,6 @@ public class MemberService { producer.putOrderCollect(jsonObject.toJSONString()); - return Result.success(CodeEnum.SUCCESS, memberIn); } else { String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null; @@ -362,7 +358,7 @@ public class MemberService { flow.setIsReturn("0"); tbShopUserFlowMapper.insert(flow); - BigDecimal fl=null; + BigDecimal fl = null; TbActivate activate = tbActivateMapper.selectByAmount(shopInfo.getId().toString(), memberIn.getAmount()); if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) { BigDecimal awardAmount = BigDecimal.ZERO; @@ -389,7 +385,7 @@ public class MemberService { flow.setCreateTime(new Date()); flow.setIsReturn("0"); tbShopUserFlowMapper.insert(flow); - fl=awardAmount; + fl = awardAmount; } JSONObject jsonObject = new JSONObject(); @@ -399,19 +395,16 @@ public class MemberService { producer.putOrderCollect(jsonObject.toJSONString()); - - JSONObject baObj=new JSONObject(); - baObj.put("userId",shopUser.getUserId()); - baObj.put("shopId",shopInfo.getId()); - baObj.put("amount",ObjectUtil.isNull(fl)?amount:amount.add(fl)); - baObj.put("balance",shopUser.getAmount()); - baObj.put("type","扫码充值"); - baObj.put("time",flow.getCreateTime()); + JSONObject baObj = new JSONObject(); + baObj.put("userId", shopUser.getUserId()); + baObj.put("shopId", shopInfo.getId()); + baObj.put("amount", ObjectUtil.isNull(fl) ? amount : amount.add(fl)); + baObj.put("balance", shopUser.getAmount()); + baObj.put("type", "扫码充值"); + baObj.put("time", flow.getCreateTime()); producer.balance(baObj.toString()); - - return Result.success(CodeEnum.SUCCESS, memberIn); } else if ("TRADE_AWAIT".equals(mainScanResp.getState())) { @@ -432,7 +425,6 @@ public class MemberService { } - public Result queryScanPay(String flowId, String token) { if (ObjectUtil.isEmpty(flowId)) { return Result.fail(CodeEnum.PARAM); @@ -556,13 +548,13 @@ public class MemberService { producer.putOrderCollect(jsonObject.toJSONString()); - JSONObject baObj=new JSONObject(); - baObj.put("userId",shopUser.getUserId()); - baObj.put("shopId",shopUser.getShopId()); - baObj.put("amount",memberIn.getAmount().add(awardAmount)); - baObj.put("balance",shopUser.getAmount()); - baObj.put("type","充值"); - baObj.put("time",flow.getCreateTime()); + JSONObject baObj = new JSONObject(); + baObj.put("userId", shopUser.getUserId()); + baObj.put("shopId", shopUser.getShopId()); + baObj.put("amount", memberIn.getAmount().add(awardAmount)); + baObj.put("balance", shopUser.getAmount()); + baObj.put("type", "充值"); + baObj.put("time", flow.getCreateTime()); producer.balance(baObj.toString()); tbShopUserFlowMapper.insert(flow); @@ -579,7 +571,6 @@ public class MemberService { return Result.success(CodeEnum.SUCCESS, memberIn); } - @Transactional(rollbackFor = Exception.class) public Result memberAccountPay(Map map, String token) throws Exception { if (ObjectUtil.isEmpty(map) || map.size() <= 0 @@ -592,7 +583,6 @@ public class MemberService { } - String memberId = String.valueOf(map.get("memberId")); String shopId = String.valueOf(map.get("shopId")); @@ -604,7 +594,7 @@ public class MemberService { } - if("1".equals(shopInfo.getIsMemberIn())){ + if ("1".equals(shopInfo.getIsMemberIn())) { String accountId = TokenUtil.parseParamFromToken(token).getString("accountId"); TbmerchantAccount account = tbmerchantAccountMapper.selectByPrimaryKey(Integer.valueOf(accountId)); @@ -667,7 +657,7 @@ public class MemberService { flow.setCreateTime(new Date()); flow.setIsReturn("0"); tbShopUserFlowMapper.insert(flow); - BigDecimal fl=null; + BigDecimal fl = null; TbActivate activate = tbActivateMapper.selectByAmount(shopInfo.getId().toString(), memberIn.getAmount()); if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) { @@ -696,7 +686,7 @@ public class MemberService { flow.setIsReturn("0"); tbShopUserFlowMapper.insert(flow); - fl=awardAmount; + fl = awardAmount; } @@ -709,25 +699,19 @@ public class MemberService { producer.putOrderCollect(jsonObject.toJSONString()); - - JSONObject baObj=new JSONObject(); - baObj.put("userId",shopUser.getUserId()); - baObj.put("shopId",shopInfo.getId()); - baObj.put("amount",ObjectUtil.isNull(fl)?amount:amount.add(fl)); - baObj.put("balance",shopUser.getAmount()); - baObj.put("type","充值"); - baObj.put("time",flow.getCreateTime()); + JSONObject baObj = new JSONObject(); + baObj.put("userId", shopUser.getUserId()); + baObj.put("shopId", shopInfo.getId()); + baObj.put("amount", ObjectUtil.isNull(fl) ? amount : amount.add(fl)); + baObj.put("balance", shopUser.getAmount()); + baObj.put("type", "充值"); + baObj.put("time", flow.getCreateTime()); producer.balance(baObj.toString()); - return Result.success(CodeEnum.SUCCESS); } - private MpShopTableMapper mpShopTableMapper; - - - public Result queryMemberAccount(String memberId, int page, int pageSize) { if (ObjectUtil.isEmpty(memberId)) { return Result.fail(CodeEnum.PARAM); @@ -740,47 +724,59 @@ public class MemberService { } - public Result returnAccount(String flowId,String remark){ - if(ObjectUtil.isEmpty(flowId)||ObjectUtil.isNull(flowId)){ + public Result returnAccount(String flowId, String remark) { + if (ObjectUtil.isEmpty(flowId) || ObjectUtil.isNull(flowId)) { return Result.fail(CodeEnum.PARAM); } - TbShopUserFlow flow= tbShopUserFlowMapper.selectByPrimaryKey(Integer.valueOf(flowId)); - if(ObjectUtil.isNull(flow)||ObjectUtil.isEmpty(flow)){ + TbShopUserFlow flow = tbShopUserFlowMapper.selectByPrimaryKey(Integer.valueOf(flowId)); + if (ObjectUtil.isNull(flow) || ObjectUtil.isEmpty(flow)) { return Result.fail(CodeEnum.USERSHOPFLOWNOEXIST); } - if(!"0".equals(flow.getIsReturn())){ + if (!"0".equals(flow.getIsReturn())) { return Result.fail(CodeEnum.ORDERRETURN); } - TbShopUser user=tbShopUserMapper.selectByPrimaryKey(flow.getShopUserId()); + TbShopUser user = tbShopUserMapper.selectByPrimaryKey(flow.getShopUserId()); - if(ObjectUtil.isEmpty(user)||ObjectUtil.isNull(user)){ + if (ObjectUtil.isEmpty(user) || ObjectUtil.isNull(user)) { return Result.fail(CodeEnum.ACCOUNTEIXST); } + + BigDecimal amount=BigDecimal.ZERO; + /** + * + */ if(N.gt(flow.getAmount(),user.getAmount())){ - return Result.fail(CodeEnum.ACCOUNTAMOUNT); + amount=user.getAmount(); + }else { + amount=flow.getAmount(); } - TbShopInfo shopInfo=tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(user.getShopId())); - if(ObjectUtil.isEmpty(shopInfo)||ObjectUtil.isNull(shopInfo)){ + + + + + TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(user.getShopId())); + if (ObjectUtil.isEmpty(shopInfo) || ObjectUtil.isNull(shopInfo)) { return Result.fail(CodeEnum.MERCHANTEIXST); } - TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId())); - if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { - return Result.fail(CodeEnum.NOCUSTOMER); - } - if("scanMemberIn".equals(flow.getBizCode())) { - String no=DateUtils.getSsdfTimes(); + if ("scanMemberIn".equals(flow.getBizCode())) { + TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId())); + if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { + return Result.fail(CodeEnum.NOCUSTOMER); + } - PublicResp publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(),no , null, flow.getRemark(), "充值退款", flow.getAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken()); + String no = DateUtils.getSsdfTimes(); + + PublicResp publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), no, null, flow.getRemark(), "充值退款",amount.setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken()); if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) { if ("000000".equals(publicResp.getCode())) { if (!"SUCCESS".equals(publicResp.getObjData().getState()) && !publicResp.getObjData().getState().equals("ING")) { @@ -794,44 +790,30 @@ public class MemberService { } else if ("cashMemberIn".equals(flow.getBizCode())) { - } else { - return Result.fail(CodeEnum.OPARETIONERROR); - } - user.setAmount(user.getAmount().subtract(flow.getAmount())); - user.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKey(user); + } else { + return Result.fail(CodeEnum.OPARETIONERROR); + } + user.setAmount(user.getAmount().subtract(amount)); + user.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(user); - flow.setIsReturn("1"); - flow.setRemark(remark); - tbShopUserFlowMapper.updateByPrimaryKey(flow); + flow.setIsReturn("1"); + flow.setRemark(remark); + tbShopUserFlowMapper.updateByPrimaryKey(flow); - - JSONObject baObj=new JSONObject(); - baObj.put("userId",user.getUserId()); - baObj.put("shopId",user.getId()); - baObj.put("amount",flow.getAmount()); - baObj.put("balance",user.getAmount()); - baObj.put("type","退款"); - baObj.put("time",new Date()); - producer.balance(baObj.toString()); - return Result.success(CodeEnum.SUCCESS); + JSONObject baObj = new JSONObject(); + baObj.put("userId", user.getUserId()); + baObj.put("shopId", user.getId()); + baObj.put("amount", amount); + baObj.put("balance", user.getAmount()); + baObj.put("type", "退款"); + baObj.put("time", new Date()); + producer.balance(baObj.toString()); + return Result.success(CodeEnum.SUCCESS); } - - - - - - - - - - - - - }