From 79124e6afdf2a3bd493759c52b8df414a0c37d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LI-CCONG=5C=E6=9D=8E=E8=81=AA=E8=81=AA?= <1441652193@qq.com> Date: Tue, 12 Mar 2024 18:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=B8=9A=E5=8A=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=8F=91v11=20=E8=AE=A2=E5=8D=95=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E5=8A=9F=E8=83=BD=20&=20Bug=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cc/yunxi/domain/po/Client.java | 4 + .../yunxi/domain/po/RecycleOrderProduct.java | 2 +- .../java/cc/yunxi/service/IClientService.java | 5 +- .../yunxi/service/impl/ClientServiceImpl.java | 97 +++++++++++-------- .../service/impl/RecycleOrderServiceImpl.java | 16 ++- .../main/resources/mapper/ProductMapper.xml | 3 +- .../mapper/RecycleOrderProductMapper.xml | 12 +-- .../mapper/RecycleStationPriceMapper.xml | 1 + 8 files changed, 86 insertions(+), 54 deletions(-) diff --git a/nxhs-service/src/main/java/cc/yunxi/domain/po/Client.java b/nxhs-service/src/main/java/cc/yunxi/domain/po/Client.java index 04564b2..b770629 100644 --- a/nxhs-service/src/main/java/cc/yunxi/domain/po/Client.java +++ b/nxhs-service/src/main/java/cc/yunxi/domain/po/Client.java @@ -110,4 +110,8 @@ public class Client { @TableField("f_creator_time") private LocalDateTime creatorTime; + @ApiModelProperty("修改时间") + @TableField("f_last_modify_time") + private LocalDateTime updateTime; + } diff --git a/nxhs-service/src/main/java/cc/yunxi/domain/po/RecycleOrderProduct.java b/nxhs-service/src/main/java/cc/yunxi/domain/po/RecycleOrderProduct.java index bbe9fc9..0787652 100644 --- a/nxhs-service/src/main/java/cc/yunxi/domain/po/RecycleOrderProduct.java +++ b/nxhs-service/src/main/java/cc/yunxi/domain/po/RecycleOrderProduct.java @@ -57,7 +57,7 @@ public class RecycleOrderProduct { @ApiModelProperty("实际回收单价") @TableField("actual_recoveryl_price") - private BigDecimal ActualRecoveryPrice; + private BigDecimal actualRecoveryPrice; @ApiModelProperty("创建时间") @TableField("f_creator_time") diff --git a/nxhs-service/src/main/java/cc/yunxi/service/IClientService.java b/nxhs-service/src/main/java/cc/yunxi/service/IClientService.java index 070be7d..41f5771 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/IClientService.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/IClientService.java @@ -71,12 +71,13 @@ public interface IClientService extends IService { /** - * 通过openId更新散户余额 + * 通过id|openId更新散户余额 + * @param id * @param openId * @param amount * @param changeTypeEnum */ - void changeBalanceByOpenId(String openId, BigDecimal amount, BalanceChangeTypeEnum changeTypeEnum); + void changeBalanceById(String id, String openId, BigDecimal amount, BalanceChangeTypeEnum changeTypeEnum); /** diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientServiceImpl.java index be31edd..b6a9111 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/ClientServiceImpl.java @@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.math.BigDecimal; import java.security.cert.X509Certificate; +import java.time.LocalDateTime; import java.util.Collections; /** @@ -124,21 +125,38 @@ public class ClientServiceImpl extends ServiceImpl impleme } @Override // 金额交易! - public void changeBalanceByOpenId(String openId, BigDecimal amount, BalanceChangeTypeEnum changeTypeEnum) { + public void changeBalanceById(String id, String openId, BigDecimal amount, BalanceChangeTypeEnum changeTypeEnum) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Client::getWxOpenid, openId); + wrapper.eq(Client::getId, id).or().eq(Client::getWxOpenid, openId); wrapper.last("for update"); Client client = this.getOne(wrapper); BigDecimal balance = client.getBanlance(); + String remark; + LocalDateTime now = LocalDateTime.now(); if (changeTypeEnum.equals(BalanceChangeTypeEnum.INCOME)) { // 收入 - client.setBanlance(balance.add(amount)); + balance = balance.add(amount); + remark = "废品回收结算,收入" + amount + "元"; } else { // 支出/提现 if (balance.compareTo(amount) < 0) { throw new BizIllegalException("余额不足"); } - client.setBanlance(balance.subtract(amount)); + balance = balance.subtract(amount); + remark = "微信提现" + amount + "元"; } + // 更新余额 + client.setBanlance(balance); + client.setUpdateTime(now); this.updateById(client); + + // 添加流水记录 + ClientAccountDetail accountDetail = new ClientAccountDetail(); + accountDetail.setClientId(client.getId()); + accountDetail.setAmount(amount); + accountDetail.setChangeType(changeTypeEnum); + accountDetail.setBanlance(balance); + accountDetail.setRemark(remark); + accountDetail.setCreatorTime(now); + accountDetailMapper.insert(accountDetail); } @@ -153,48 +171,49 @@ public class ClientServiceImpl extends ServiceImpl impleme return accountDetailMapper.selectPage(pageDO, wrapperX); } + @Override @Transactional(rollbackFor = Exception.class) public void cashBalance(String openId, Integer amount) throws Exception { -// BatchTransferModel batchTransferModel = new BatchTransferModel() -// .setAppid(wxPayV3Properties.getAppId()) -// .setOut_batch_no(PayKit.generateStr()) -// .setBatch_name("测试商户转账到零钱") -// .setBatch_remark("测试商户转账到零钱") -// .setTotal_amount(amount) -// .setTotal_num(1) -// .setTransfer_detail_list(Collections.singletonList( -// new TransferDetailInput() -// .setOut_detail_no(PayKit.generateStr()) -// .setTransfer_amount(1) -// .setTransfer_remark("测试商户转账到零钱") -// .setOpenid(openId))); -// -// log.info("发起商家转账请求参数 {}", JSONUtil.toJsonStr(batchTransferModel)); -// // 删除 -// IJPayHttpResponse response = WxPayApi.v3( -// RequestMethodEnum.POST, -// WxDomainEnum.CHINA.toString(), -// TransferApiEnum.TRANSFER_BATCHES.toString(), -// wxPayV3Properties.getMchId(), -// getSerialNumber(), -// null, -// wxPayV3Properties.getKeyPath(), -// JSONUtil.toJsonStr(batchTransferModel) -// ); -// log.info("发起商家转账响应 {}", response); - // 根据证书序列号查询对应的证书来验证签名结果 -// boolean verifySignature = WxPayKit.verifySignature(response, wxPayV3Properties.getPlatformCertPath()); + // 模拟提现成功 + this.changeBalanceById(null, openId, new BigDecimal(amount), BalanceChangeTypeEnum.CASH_OUT); + /* BatchTransferModel batchTransferModel = new BatchTransferModel() + .setAppid(wxPayV3Properties.getAppId()) + .setOut_batch_no(PayKit.generateStr()) + .setBatch_name("测试商户转账到零钱") + .setBatch_remark("测试商户转账到零钱") + .setTotal_amount(amount) + .setTotal_num(1) + .setTransfer_detail_list(Collections.singletonList( + new TransferDetailInput() + .setOut_detail_no(PayKit.generateStr()) + .setTransfer_amount(1) + .setTransfer_remark("测试商户转账到零钱") + .setOpenid(openId))); + + log.info("发起商家转账请求参数 {}", JSONUtil.toJsonStr(batchTransferModel)); + // 删除 + IJPayHttpResponse response = WxPayApi.v3( + RequestMethodEnum.POST, + WxDomainEnum.CHINA.toString(), + TransferApiEnum.TRANSFER_BATCHES.toString(), + wxPayV3Properties.getMchId(), + getSerialNumber(), + null, + wxPayV3Properties.getKeyPath(), + JSONUtil.toJsonStr(batchTransferModel) + ); + log.info("发起商家转账响应 {}", response); +// 根据证书序列号查询对应的证书来验证签名结果 + boolean verifySignature = WxPayKit.verifySignature(response, wxPayV3Properties.getPlatformCertPath()); // log.info("verifySignature: {}", verifySignature); // if (response.getStatus() == OK && verifySignature) { // return response.getBody(); // } -// if (response.getStatus() != OK) { -// throw new BizIllegalException("提现失败"); -// } - // 模拟提现成功 - this.changeBalanceByOpenId(openId, new BigDecimal(amount), BalanceChangeTypeEnum.CASH_OUT); -// return response.getBody(); + if (response.getStatus() != OK) { + throw new BizIllegalException("提现失败"); + } +// return response.getBody(); */ } diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/RecycleOrderServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/RecycleOrderServiceImpl.java index 931961f..1d94fe1 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/RecycleOrderServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/RecycleOrderServiceImpl.java @@ -13,10 +13,7 @@ import cc.yunxi.domain.query.RecycleOrderQuery; import cc.yunxi.domain.vo.recycleorder.*; import cc.yunxi.domain.vo.recycleorderdetail.RecycleOrderDetailCreateVO; import cc.yunxi.domain.vo.recycleorderdetail.RecycleOrderDetailUpdateVO; -import cc.yunxi.enums.BusinessCodeEnum; -import cc.yunxi.enums.OrderStatusEnum; -import cc.yunxi.enums.OrderTypeEnum; -import cc.yunxi.enums.UserTypeEnum; +import cc.yunxi.enums.*; import cc.yunxi.mapper.RecycleOrderMapper; import cc.yunxi.service.IClientService; import cc.yunxi.service.IRecycleOrderProductService; @@ -209,6 +206,7 @@ public class RecycleOrderServiceImpl extends ServiceImpl recycleOrderProducts = BeanUtils.copyList(recycleOrderProductVOList, RecycleOrderProduct.class); this.recycleOrderProductService.updateOrderProducts(recycleOrderProducts); - // 给散户加余额 异步? todo + // 订单结算 异步? todo + BigDecimal totalAmount = new BigDecimal("0.00"); + for (RecycleOrderProduct recycleOrderProduct : recycleOrderProducts) { + BigDecimal weight = BigDecimal.valueOf(recycleOrderProduct.getProductActualWeight()); + BigDecimal price = recycleOrderProduct.getActualRecoveryPrice(); + totalAmount = totalAmount.add(weight.multiply(price)); + } + // 增加收入余额 + clientService.changeBalanceById(clientId, null, totalAmount, BalanceChangeTypeEnum.INCOME); } diff --git a/nxhs-service/src/main/resources/mapper/ProductMapper.xml b/nxhs-service/src/main/resources/mapper/ProductMapper.xml index c2ae604..4672fd7 100644 --- a/nxhs-service/src/main/resources/mapper/ProductMapper.xml +++ b/nxhs-service/src/main/resources/mapper/ProductMapper.xml @@ -14,7 +14,8 @@ WHERE a.`code` = #{productCode} ORDER BY - c.f_creator_time ASC; + c.f_creator_time DESC + LIMIT 1; diff --git a/nxhs-service/src/main/resources/mapper/RecycleOrderProductMapper.xml b/nxhs-service/src/main/resources/mapper/RecycleOrderProductMapper.xml index efd15e4..1ee1f7d 100644 --- a/nxhs-service/src/main/resources/mapper/RecycleOrderProductMapper.xml +++ b/nxhs-service/src/main/resources/mapper/RecycleOrderProductMapper.xml @@ -2,8 +2,8 @@ - - SELECT b.id, b.price_id, @@ -12,14 +12,14 @@ b.reward_points, b.f_creator_time FROM - nx_recycle_order_product a - INNER JOIN nx_price_product b ON a.product_id = b.product_id + nx_price_product b INNER JOIN nx_price c ON b.price_id = c.id AND c.`status` = 1 WHERE - a.`product_id` = #{productId} + b.`product_id` = #{productId} ORDER BY - c.f_creator_time ASC; + c.f_creator_time DESC + LIMIT 1; diff --git a/nxhs-service/src/main/resources/mapper/RecycleStationPriceMapper.xml b/nxhs-service/src/main/resources/mapper/RecycleStationPriceMapper.xml index 2193b11..1b1b327 100644 --- a/nxhs-service/src/main/resources/mapper/RecycleStationPriceMapper.xml +++ b/nxhs-service/src/main/resources/mapper/RecycleStationPriceMapper.xml @@ -14,6 +14,7 @@ and ${ew.sqlSegment} ORDER BY a.f_creator_time DESC + LIMIT 1;