Administrator
6 days ago 316a91aee6236f312d53eca6cebbaa00c2803d92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package cc.mrbird.febs.mall.controller;
 
import cc.mrbird.febs.common.annotation.ControllerEndpoint;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
import cc.mrbird.febs.common.utils.AppContants;
import cc.mrbird.febs.mall.dto.*;
import cc.mrbird.febs.mall.entity.DataDictionaryCustom;
import cc.mrbird.febs.mall.entity.MallCountryDelivery;
import cc.mrbird.febs.mall.entity.MallNewsInfo;
import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper;
import cc.mrbird.febs.mall.service.ICommonService;
import cc.mrbird.febs.mall.service.IMallCountryDeliveryService;
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.core.util.StrUtil;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/admin/system")
public class AdminSystemController extends BaseController {
 
    @Autowired
    private ISystemService systemService;
 
    private final ICommonService commonService;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final WxFaPiaoService wxFaPiaoService;
    private final IMallCountryDeliveryService countryDeliveryService;
 
    @PostMapping(value = "/bonusSystemSetting")
    public FebsResponse bonusSystemSetting(@RequestBody Map<String, Object> map) {
        systemService.bonusSystemSetting(map);
        return new FebsResponse().success().message("设置成功");
    }
 
    @PostMapping(value = "/cashOutSetting")
    public FebsResponse cashOutSetting(CashOutSettingDto cashOutSettingDto) {
        commonService.addDataDic(DataDictionaryEnum.CASHOUT_SETTING.getType(), DataDictionaryEnum.CASHOUT_SETTING.getCode(), cashOutSettingDto, "提现设置");
        return new FebsResponse().success();
    }
 
    @PostMapping(value = "/lwPayConfig")
    @ControllerEndpoint(operation = "保存LWPAY配置")
    public FebsResponse lwPayConfig(LwPayConfigDto dto) {
        if (StrUtil.isBlank(dto.getMemberId())) {
            return new FebsResponse().fail().message("商户号不能为空");
        }
        if (StrUtil.isBlank(dto.getSecretKey())) {
            return new FebsResponse().fail().message("签名密钥不能为空");
        }
        if (StrUtil.isBlank(dto.getNotifyUrl())) {
            return new FebsResponse().fail().message("回调地址不能为空");
        }
        if (StrUtil.isBlank(dto.getReturnUrl())) {
            return new FebsResponse().fail().message("跳转地址不能为空");
        }
        commonService.addDataDic("LWPAY_CONFIG", "MEMBER_ID", dto.getMemberId(), "LWPAY商户号", false);
        commonService.addDataDic("LWPAY_CONFIG", "SECRET_KEY", dto.getSecretKey(), "LWPAY签名密钥", false);
        commonService.addDataDic("LWPAY_CONFIG", "NOTIFY_URL", dto.getNotifyUrl(), "LWPAY异步回调地址", false);
        commonService.addDataDic("LWPAY_CONFIG", "RETURN_URL", dto.getReturnUrl(), "LWPAY支付完成跳转地址", false);
        return new FebsResponse().success().message("保存成功");
    }
 
    @PostMapping(value = "/tokenviewConfig")
    @ControllerEndpoint(operation = "保存Tokenview配置")
    public FebsResponse tokenviewConfig(TokenviewConfigDto dto) {
        if (StrUtil.isBlank(dto.getWebhookSecret())) {
            return new FebsResponse().fail().message("签名密钥不能为空");
        }
        if (StrUtil.isBlank(dto.getTrc20UsdtAddress())) {
            return new FebsResponse().fail().message("收款地址不能为空");
        }
        commonService.addDataDic("TOKENVIEW_CONFIG", "WEBHOOK_SECRET", dto.getWebhookSecret(), "Tokenview Webhook签名密钥", false);
        commonService.addDataDic("TOKENVIEW_CONFIG", "TRC20_USDT_ADDRESS", dto.getTrc20UsdtAddress(), "TRC20 USDT收款地址", false);
        commonService.addDataDic("SALES_SERVICE", "TRC_ADDRESS", dto.getTrc20UsdtAddress(), "TRC20 USDT收款地址", false);
        return new FebsResponse().success().message("保存成功");
    }
 
    @PostMapping(value = "/salesService")
    @ControllerEndpoint(operation = "保存售后服务配置")
    public FebsResponse salesService(SalesServiceDto dto) {
        if (StrUtil.isBlank(dto.getWhatsApp())) {
            return new FebsResponse().fail().message("WhatsApp不能为空");
        }
        if (StrUtil.isBlank(dto.getPhone())) {
            return new FebsResponse().fail().message("联系电话不能为空");
        }
        if (StrUtil.isBlank(dto.getEmail())) {
            return new FebsResponse().fail().message("联系邮箱不能为空");
        }
        if (StrUtil.isBlank(dto.getAddress())) {
            return new FebsResponse().fail().message("联系地址不能为空");
        }
        if (StrUtil.isBlank(dto.getWorkingHours())) {
            return new FebsResponse().fail().message("工作时间不能为空");
        }
        commonService.addDataDic("SALES_SERVICE", "WHATSAPP", dto.getWhatsApp(), "WhatsApp号码", false);
        commonService.addDataDic("SALES_SERVICE", "PHONE", dto.getPhone(), "联系电话", false);
        commonService.addDataDic("SALES_SERVICE", "EMAIL", dto.getEmail(), "联系邮箱", false);
        commonService.addDataDic("SALES_SERVICE", "ADDRESS", dto.getAddress(), "联系地址", false);
        commonService.addDataDic("SALES_SERVICE", "WORKINGHOURS", dto.getWorkingHours(), "工作时间", false);
        return new FebsResponse().success().message("保存成功");
    }
 
    @GetMapping("countryDeliveryList")
    public FebsResponse countryDeliveryList(MallCountryDelivery dto, QueryRequest request) {
        Map<String, Object> data = getDataTable(countryDeliveryService.countryDeliveryList(dto, request));
        return new FebsResponse().success().data(data);
    }
 
    @PostMapping(value = "/countryDeliverySave")
    @ControllerEndpoint(operation = "保存国家运费配置")
    public FebsResponse countryDeliverySave(@Validated CountryDeliveryDto dto) {
        return countryDeliveryService.saveOrUpdate(dto);
    }
 
    @GetMapping(value = "/countryDeliveryDelete/{id}")
    @ControllerEndpoint(operation = "删除国家运费配置")
    public FebsResponse countryDeliveryDelete(@PathVariable Long id) {
        return countryDeliveryService.delete(id);
    }
 
    @PostMapping(value = "/agentAmountSetSetting")
    public FebsResponse agentAmountSetSetting(AdminAgentAmountDto adminAgentAmountDto) {
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.PRICE_AMOUNT.getType(), DataDictionaryEnum.PRICE_AMOUNT.getCode()
        );
        if(ObjectUtil.isEmpty(dic)){
            return new FebsResponse().fail().message("请刷新页面重试");
        }
 
        DataDictionaryCustom giveStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.GIVE_STATE.getType(),
                DataDictionaryEnum.GIVE_STATE.getCode());
        if(ObjectUtil.isEmpty(giveStateDic)){
            return new FebsResponse().fail().message("请刷新页面重试");
        }
 
        DataDictionaryCustom activityBulletinDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.ACTIVITY_BULLETIN.getType(),
                DataDictionaryEnum.ACTIVITY_BULLETIN.getCode());
        if(ObjectUtil.isEmpty(activityBulletinDic)){
            return new FebsResponse().fail().message("请刷新页面重试");
        }
 
        DataDictionaryCustom giveAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.GIVE_AMOUNT.getType(),
                DataDictionaryEnum.GIVE_AMOUNT.getCode());
        if(ObjectUtil.isEmpty(giveAmountDic)){
            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())){
                return new FebsResponse().fail().message("活动公告不能为空");
            }
            if(ObjectUtil.isEmpty(adminAgentAmountDto.getGiveAmount())){
                return new FebsResponse().fail().message("请输入正确的赠送金额");
            }
            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("请输入正确的充值金额");
            }
        }
 
        dic.setValue(adminAgentAmountDto.getAgentAmountValue());
        dataDictionaryCustomMapper.updateById(dic);
 
        giveStateDic.setValue(adminAgentAmountDto.getGiveState());
        dataDictionaryCustomMapper.updateById(giveStateDic);
 
        activityBulletinDic.setValue(adminAgentAmountDto.getActivityBulletin());
        dataDictionaryCustomMapper.updateById(activityBulletinDic);
 
        giveAmountDic.setValue(adminAgentAmountDto.getGiveAmount());
        dataDictionaryCustomMapper.updateById(giveAmountDic);
 
        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()
        );
        HeaderDto headerDto = new HeaderDto();
        headerDto.setCallback_url("https://api.blnka.cn/api/xcxPay/fapiaoCallBack");
        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 = null;
        try {
 
            PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3();
            postStr = wxFaPiaoService.createAuthorization(
                    "PATCH",
                    baseUrl+canonicalUrl,
                    parseObj,
                    privateKey
            );
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        String token = AppContants.FP_TOKEN_HEADER_TYPE+postStr;
        System.out.println("WECHATPAY2-SHA256-RSA2048 "+postStr);
        String s = wxFaPiaoService.sendPatch(baseUrl + canonicalUrl, parseObj, token);
        log.info("配置开发选项:"+s);
 
        return new FebsResponse().success().message(s);
    }
 
    @PostMapping(value = "/agentDetail")
    public FebsResponse agentDetail(AdminAgentDetailDto adminAgentDetailDto) {
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.AGENT_DETAILS.getType(), DataDictionaryEnum.AGENT_DETAILS.getCode()
        );
 
        if(ObjectUtil.isEmpty(dic)){
            return new FebsResponse().fail().message("请刷新页面重试");
        }
        dic.setValue(adminAgentDetailDto.getAgentDetail());
        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);
//    }
}