Selaa lähdekoodia

1是 码商的投诉 转发入库后 不自动给码商群加账 显示的对应商户的加减
2是 这个投诉入库后 不拉黑相对应单号的uid

LiYi 1 viikko sitten
vanhempi
säilyke
78ecc91014

+ 4 - 4
src/main/java/org/jebot/handler/HandlerManager.java

@@ -18,10 +18,7 @@ import org.jebot.handler.impl.complaint.ComplaintHandler;
 import org.jebot.handler.impl.merchant.*;
 import org.jebot.handler.impl.price.PriceQueryHandler;
 import org.jebot.repository.jebot.*;
-import org.jebot.repository.xxpay.MchAccountRepository;
-import org.jebot.repository.xxpay.PayOrderRepository;
-import org.jebot.repository.xxpay.PayPassageRepository;
-import org.jebot.repository.xxpay.PayProductRepository;
+import org.jebot.repository.xxpay.*;
 import org.jebot.service.IAccountBookService;
 import org.jebot.service.IMchService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -63,6 +60,9 @@ public class HandlerManager {
     @Resource
     PayOrderRepository payOrderRepository;
 
+    @Resource
+    BlackUserRepository blackUserRepository;
+
     @Resource
     PayPassageRepository passageRepository;
 

+ 59 - 13
src/main/java/org/jebot/handler/impl/complaint/ComplaintHandler.java

@@ -16,6 +16,7 @@ import org.jebot.handler.dto.BotMessage;
 import org.jebot.models.jebot.BotAccountBook;
 import org.jebot.models.jebot.BotComplaint;
 import org.jebot.models.jebot.BotGroup;
+import org.jebot.models.xxpay.BlackUser;
 import org.jebot.models.xxpay.PayOrder;
 import org.jebot.repository.jebot.BotAccountBookRepository;
 import org.jebot.service.dto.UpdateBalance;
@@ -124,21 +125,39 @@ public class ComplaintHandler extends AbstractHandler {
             BotAccountBook channelAccountBook = accountBookRepository.findByBelongIdAndType(channelGroup.getDataId(), Constant.DATA_TYPE_CHANNEL);
             if (channelAccountBook == null) {
                 channelAccountBook = new BotAccountBook();
-                channelAccountBook.setBelongId(merchantGroup.getDataId());
-                channelAccountBook.setBelongName(merchantGroup.getDataName());
-                channelAccountBook.setType(Constant.DATA_TYPE_MERCHANT);
+                channelAccountBook.setBelongId(channelGroup.getDataId());      // ✅ 通道ID
+                channelAccountBook.setBelongName(channelGroup.getDataName());  // ✅ 通道名称
+                channelAccountBook.setType(Constant.DATA_TYPE_CHANNEL);        // ✅ 通道类型
                 channelAccountBook.setPaymentBalance(0);
                 channelAccountBook.setAgentBalance(0);
-                channelAccountBook = accountBookRepository.save(merchantAccountBook);
+                channelAccountBook = accountBookRepository.save(channelAccountBook); // ✅ 保存通道账本
             }
 
+
+            //更新总通道余额
+            BotAccountBook channelAllAccountBook = accountBookRepository.findByBelongIdAndType(channelGroup.getGroupId(), Constant.DATA_TYPE_CHANNEL);
+            if (channelAllAccountBook == null) {
+                channelAllAccountBook = new BotAccountBook();
+                channelAllAccountBook.setBelongId(channelGroup.getDataId());      // ✅ 通道ID
+                channelAllAccountBook.setBelongName(channelGroup.getDataName());  // ✅ 通道名称
+                channelAllAccountBook.setType(Constant.DATA_TYPE_CHANNEL);        // ✅ 通道类型
+                channelAllAccountBook.setPaymentBalance(0);
+                channelAllAccountBook.setAgentBalance(0);
+                channelAllAccountBook = accountBookRepository.save(channelAllAccountBook); // ✅ 保存通道账本
+            }
+
+
+
             double oldMerchantPaymentBalance = merchantAccountBook.getPaymentBalance();
             double oldChannelPaymentBalance = channelAccountBook.getPaymentBalance();
+            double oldChannelAllPaymentBalance = channelAllAccountBook.getPaymentBalance();
             double amount = payOrder.getAmount().movePointLeft(Constant.AMOUNT_MOVE_POINT).doubleValue();
             double newMerchantPaymentBalance = BigDecimal.valueOf(oldMerchantPaymentBalance).movePointRight(Constant.AMOUNT_MOVE_POINT).
                     add(payOrder.getAmount()).movePointLeft(Constant.AMOUNT_MOVE_POINT).doubleValue();
             double newChannelPaymentBalance = BigDecimal.valueOf(oldChannelPaymentBalance).movePointRight(Constant.AMOUNT_MOVE_POINT).
                     add(payOrder.getAmount()).movePointLeft(Constant.AMOUNT_MOVE_POINT).doubleValue();
+            double newChannelAllPaymentBalance = BigDecimal.valueOf(oldChannelAllPaymentBalance).movePointRight(Constant.AMOUNT_MOVE_POINT).
+                    add(payOrder.getAmount()).movePointLeft(Constant.AMOUNT_MOVE_POINT).doubleValue();
 
             //转发消息到商户群组
             CopyMessage sendMerchantCopyMessage = new CopyMessage(merchantGroup.getGroupId(), update.message().chat().id(), update.message().messageId());
@@ -165,6 +184,17 @@ public class ComplaintHandler extends AbstractHandler {
             channelMessage.setBotGroup(channelGroup);
             channelMessage.setBotUser(botMessage.getBotUser());
             updateChannelPaymentBalance.setMessage(channelMessage);
+
+            //更新通道总余额
+            UpdateBalance updateChannelAllPaymentBalance = new UpdateBalance();
+            updateChannelAllPaymentBalance.setId(channelAllAccountBook.getId());
+            updateChannelAllPaymentBalance.setOldBalance(oldChannelAllPaymentBalance);
+            updateChannelAllPaymentBalance.setNewBalance(newChannelAllPaymentBalance);
+            updateChannelAllPaymentBalance.setAmount(amount);
+            BotMessage channelAllMessage = new BotMessage();
+            channelAllMessage.setBotGroup(channelGroup);
+            channelAllMessage.setBotUser(botMessage.getBotUser());
+            updateChannelAllPaymentBalance.setMessage(channelAllMessage);
             //构建发出投诉单号到上游群组的消息
             StringBuilder stringBuilderChannel = new StringBuilder();
             stringBuilderChannel.append("投诉订单: ").append("\n");
@@ -194,11 +224,11 @@ public class ComplaintHandler extends AbstractHandler {
                 Thread.sleep(300);
                 merchantMessageResponse = botMessage.getTelegramBot().execute(sendMerchantMessage);
                 Thread.sleep(300);
-                channelMessageResponse =   botMessage.getTelegramBot().execute(sendChannelMessage);
+                channelMessageResponse = botMessage.getTelegramBot().execute(sendChannelMessage);
                 Thread.sleep(300);
-                channelOrderMessageResponse =   botMessage.getTelegramBot().execute(sendChannelMessageOrder);
+                channelOrderMessageResponse = botMessage.getTelegramBot().execute(sendChannelMessageOrder);
                 Thread.sleep(300);
-                if (!merchantCopyResponse.isOk() || !merchantMessageResponse.isOk() || !channelMessageResponse.isOk()){
+                if (!merchantCopyResponse.isOk() || !merchantMessageResponse.isOk() || !channelMessageResponse.isOk()) {
                     log.error("消息发送失败: {}", merchantCopyResponse);
                     throw new Exception("消息发送失败");
                 }
@@ -211,11 +241,11 @@ public class ComplaintHandler extends AbstractHandler {
                     if (merchantMessageResponse != null && merchantMessageResponse.message().messageId() != null) {
                         botMessage.getTelegramBot().execute(new DeleteMessage(merchantGroup.getGroupId(), merchantMessageResponse.message().messageId()));
                     }
-                    if (channelMessageResponse != null && channelMessageResponse.message().messageId()  != null) {
-                        botMessage.getTelegramBot().execute(new DeleteMessage(channelGroup.getGroupId(), channelMessageResponse.message().messageId() ));
+                    if (channelMessageResponse != null && channelMessageResponse.message().messageId() != null) {
+                        botMessage.getTelegramBot().execute(new DeleteMessage(channelGroup.getGroupId(), channelMessageResponse.message().messageId()));
                     }
-                    if (channelOrderMessageResponse != null && channelOrderMessageResponse.message().messageId()  != null) {
-                        botMessage.getTelegramBot().execute(new DeleteMessage(channelGroup.getGroupId(), channelOrderMessageResponse.message().messageId() ));
+                    if (channelOrderMessageResponse != null && channelOrderMessageResponse.message().messageId() != null) {
+                        botMessage.getTelegramBot().execute(new DeleteMessage(channelGroup.getGroupId(), channelOrderMessageResponse.message().messageId()));
                     }
                 } catch (Exception rollbackException) {
                     log.error("消息撤回失败: {}", rollbackException.getMessage());
@@ -223,7 +253,7 @@ public class ComplaintHandler extends AbstractHandler {
             }
 
             try {
-                handlerManager.getAccountBookService().updateMutiPaymentBalanceByIdAndPaymentBalance(updateMerchantPaymentBalance, updateChannelPaymentBalance);
+                handlerManager.getAccountBookService().updateMutiPaymentBalanceByIdAndPaymentBalance(updateMerchantPaymentBalance, updateChannelPaymentBalance,updateChannelAllPaymentBalance);
             } catch (Exception e) {
                 log.error("更新商户或通道余额失败: {}", e.getMessage());
                 e.printStackTrace();
@@ -240,7 +270,7 @@ public class ComplaintHandler extends AbstractHandler {
                     if (channelMessageResponse != null && channelMessageResponse.message() != null) {
                         botMessage.getTelegramBot().execute(new DeleteMessage(channelGroup.getGroupId(), channelMessageResponse.message().messageId()));
                     }
-                    if (channelOrderMessageResponse != null&& channelOrderMessageResponse.message() !=null) {
+                    if (channelOrderMessageResponse != null && channelOrderMessageResponse.message() != null) {
                         botMessage.getTelegramBot().execute(new DeleteMessage(channelGroup.getGroupId(), channelOrderMessageResponse.message().messageId()));
                     }
                 } catch (Exception rollbackException) {
@@ -276,6 +306,22 @@ public class ComplaintHandler extends AbstractHandler {
             if (!sendResponse.isOk()) {
                 log.error("投诉单号转发结果发送失败: {}", sendResponse);
             }
+
+            //投诉完成,拉黑uid到t_black_user
+            String buyerId = payOrder.getBuyerId();
+            if (buyerId != null) {
+                //查询一下以前拉黑过没
+                BlackUser blackUserOld = handlerManager.getBlackUserRepository().findByUserId(buyerId);
+                if (blackUserOld != null) {
+                    //以前拉黑过 不操作
+                    return true;
+                }
+                BlackUser blackUser = new BlackUser();
+                blackUser.setUserId(buyerId);
+                blackUser.setCreateTime(new Date());
+                blackUser.setType(0);
+                this.handlerManager.getBlackUserRepository().save(blackUser);
+            }
             return true;
         }
         return false;

+ 31 - 0
src/main/java/org/jebot/models/xxpay/BlackUser.java

@@ -0,0 +1,31 @@
+package org.jebot.models.xxpay;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+@Entity(name = "t_black_user")
+@NoArgsConstructor
+@AllArgsConstructor
+public class BlackUser {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "Id")
+    private Long id;
+
+    @Column(name = "UserId")
+    private String userId;
+
+    @Column(name = "type")
+    private int type;
+
+    @Column(name = "CreateTime")
+    private Date createTime;
+
+}

+ 21 - 0
src/main/java/org/jebot/repository/xxpay/BlackUserRepository.java

@@ -0,0 +1,21 @@
+package org.jebot.repository.xxpay;
+
+import org.jebot.models.xxpay.BlackUser;
+import org.jebot.models.xxpay.PayOrder;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Component;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+@Component
+public interface BlackUserRepository extends JpaRepository<BlackUser, String> {
+
+    //通过支付单号查询支付订单
+    @Query("SELECT t FROM t_black_user t WHERE t.userId =:userId")
+    BlackUser findByUserId(@Param("userId") String userId);
+
+}