From 15d223c549e0d94316db344f2f6337b605fffbae Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 16 Jan 2024 10:56:38 +0800
Subject: [PATCH] fapiao

---
 src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 110 insertions(+), 4 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java b/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java
index b4d8cd2..bef7b04 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/AdminSystemController.java
@@ -3,17 +3,22 @@
 import cc.mrbird.febs.common.annotation.ControllerEndpoint;
 import cc.mrbird.febs.common.entity.FebsResponse;
 import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
-import cc.mrbird.febs.mall.dto.AdminAgentAmountDto;
-import cc.mrbird.febs.mall.dto.AdminAgentDetailDto;
-import cc.mrbird.febs.mall.dto.CashOutSettingDto;
+import cc.mrbird.febs.mall.dto.*;
 import cc.mrbird.febs.mall.entity.DataDictionaryCustom;
 import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper;
 import cc.mrbird.febs.mall.service.ICommonService;
 import cc.mrbird.febs.mall.service.ISystemService;
+import cc.mrbird.febs.pay.model.HeaderDto;
+import cc.mrbird.febs.pay.service.WxFaPiaoService;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -21,7 +26,11 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.io.IOException;
 import java.math.BigDecimal;
+import java.security.KeyPair;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 @Slf4j
@@ -36,6 +45,7 @@
 
     private final ICommonService commonService;
     private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
+    private final WxFaPiaoService wxFaPiaoService;
 
     @PostMapping(value = "/bonusSystemSetting")
     public FebsResponse bonusSystemSetting(@RequestBody Map<String, Object> map) {
@@ -76,6 +86,12 @@
             return new FebsResponse().fail().message("请刷新页面重试");
         }
 
+        DataDictionaryCustom chargeAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.CHARGE_AMOUNT.getType(),
+                DataDictionaryEnum.CHARGE_AMOUNT.getCode());
+        if(ObjectUtil.isEmpty(chargeAmountDic)){
+            return new FebsResponse().fail().message("请刷新页面重试");
+        }
+
         String giveState = adminAgentAmountDto.getGiveState();
         if(1 == Integer.parseInt(giveState)){
             if(ObjectUtil.isEmpty(adminAgentAmountDto.getActivityBulletin())){
@@ -86,6 +102,12 @@
             }
             if(BigDecimal.ZERO.compareTo(new BigDecimal(adminAgentAmountDto.getGiveAmount())) > 0){
                 return new FebsResponse().fail().message("请输入正确的赠送金额");
+            }
+            if(ObjectUtil.isEmpty(adminAgentAmountDto.getChargeAmount())){
+                return new FebsResponse().fail().message("请输入正确的充值金额");
+            }
+            if(BigDecimal.ZERO.compareTo(new BigDecimal(adminAgentAmountDto.getChargeAmount())) > 0){
+                return new FebsResponse().fail().message("请输入正确的充值金额");
             }
         }
 
@@ -101,7 +123,52 @@
         giveAmountDic.setValue(adminAgentAmountDto.getGiveAmount());
         dataDictionaryCustomMapper.updateById(giveAmountDic);
 
-        return new FebsResponse().success();
+        chargeAmountDic.setValue(adminAgentAmountDto.getChargeAmount());
+        dataDictionaryCustomMapper.updateById(chargeAmountDic);
+
+        return new FebsResponse().success().message("操作成功");
+    }
+
+    @PostMapping(value = "/faPiaoSet")
+    public FebsResponse faPiaoSet(FaPiaoDto faPiaoDto) {
+        dataDictionaryCustomMapper.updateDicValueByTypeAndCode(
+                DataDictionaryEnum.FP_CALLBACK_URL.getType(),
+                DataDictionaryEnum.FP_CALLBACK_URL.getCode(),
+                faPiaoDto.getCallbackUrl()
+        );
+        KeyPair privateKey = wxFaPiaoService.getPrivateKey();
+        HeaderDto headerDto = new HeaderDto();
+        headerDto.setCallback_url(faPiaoDto.getCallbackUrl());
+        headerDto.setShow_fapiao_cell(false);
+        String parseObj = JSONUtil.parseObj(headerDto).toString();
+        String baseUrl = "https://api.mch.weixin.qq.com";
+        String canonicalUrl = "/v3/new-tax-control-fapiao/merchant/development-config";
+        String postStr = wxFaPiaoService.createAuthorization(
+                "POST",
+                canonicalUrl,
+                parseObj,
+                privateKey
+        );
+        // 创建httppost
+        try {
+            HttpClient httpClient = new HttpClient();
+            PostMethod post = new PostMethod(baseUrl+canonicalUrl);
+            post.setRequestHeader("Accept", "application/json");
+            post.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36");
+            post.setRequestHeader("Content-Type", "application/json");
+            post.setRequestHeader("Connection", "keep-alive");
+            post.setRequestHeader("Authorization",  "WECHATPAY2-SHA256-RSA2048 "+postStr);
+            RequestEntity entity = new StringRequestEntity(parseObj, "text/html", "utf-8");
+            post.setRequestEntity(entity);
+            httpClient.executeMethod(post);
+            String responseBodyAsString = post.getResponseBodyAsString();
+            cn.hutool.json.JSONObject maps = JSONUtil.parseObj(responseBodyAsString);
+            System.out.println(maps);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return new FebsResponse().success().message("操作成功");
     }
 
     @PostMapping(value = "/agentDetail")
@@ -117,4 +184,43 @@
         dataDictionaryCustomMapper.updateById(dic);
         return new FebsResponse().success();
     }
+
+    @PostMapping(value = "/indexVideoSet")
+    public FebsResponse indexVideoSet(AdminIndexVideoDto adminIndexVideoDto) {
+        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.VIDEO_URL_INDEX.getType(),
+                DataDictionaryEnum.VIDEO_URL_INDEX.getCode()
+        );
+        if(ObjectUtil.isEmpty(dic)){
+            return new FebsResponse().fail().message("请刷新页面重试");
+        }
+        dic.setValue(adminIndexVideoDto.getVideoUrl());
+        dataDictionaryCustomMapper.updateById(dic);
+        return new FebsResponse().success();
+    }
+
+//    public static void main(String[] args) {
+//        List<Integer> lines = Arrays.asList(new Integer[]{1, 1, 0,  1, 1, 0, 0, 1, 0,  1, 1, 0, 1, 0, 1, 0});
+//        //数字连续出现的计数
+//        Integer symbol = 0;
+//        //数字连续出现的次数限制
+//        Integer times = 3;
+//        //出现的数字
+//        Integer symbolNum = 1;
+//        //满足规则的次数
+//        Integer timesOneSign = 0;
+//        for(int i=0;i<lines.size();i++){
+//            if(symbolNum == lines.get(i)){
+//                symbol = symbol + 1;
+//                if(symbol >= times){
+//                    timesOneSign = timesOneSign + 1;
+//                    symbol = 0;
+//                }
+//            }else{
+//                symbol = 0;
+//            }
+//        }
+//
+//        System.out.println(timesOneSign);
+//    }
 }

--
Gitblit v1.9.1