peternameyakj
2024-07-15 63c70bfc6add5979445f93201c410c44b5305f6c
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
package com.nq.service.impl;
 
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.nq.common.ServerResponse;
import com.nq.dao.*;
import com.nq.enums.EConfigKey;
import com.nq.pojo.*;
import com.nq.service.*;
import com.nq.utils.KeyUtils;
import com.nq.utils.PropertiesUtil;
import com.nq.utils.SymmetricCryptoUtil;
import com.nq.utils.redis.CookieUtils;
import com.nq.utils.redis.JsonUtil;
import com.nq.utils.redis.RedisShardedPoolUtils;
import com.nq.vo.admin.AdminCountVO;
import com.nq.vo.agent.AgentInfoVO;
import com.nq.vo.agent.AgentSecondInfoVO;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
 
@Service("iAgentUserService")
public class AgentUserServiceImpl implements IAgentUserService {
    private static final Logger log = LoggerFactory.getLogger(AgentUserServiceImpl.class);
 
 
    @Resource
    AgentUserMapper agentUserMapper;
 
    @Resource
    SiteTaskLogMapper siteTaskLogMapper;
 
 
    @Autowired
    ISiteInfoService iSiteInfoService;
 
    @Autowired
    IAgentDistributionUserService iAgentDistributionUserService;
 
    @Autowired
    IAgentAgencyFeeService iAgentAgencyFeeService;
 
 
    @Resource
    UserRechargeMapper userRechargeMapper;
 
    @Resource
    UserWithdrawMapper userWithdrawMapper;
 
    @Resource
    UserMapper userMapper;
 
    @Autowired
    IStockConfigServices iStockConfigServices;
 
 
    public AgentUser getCurrentAgent(HttpServletRequest request) {
//        String loginToken = CookieUtils.readLoginToken(request, PropertiesUtil.getProperty("agent.cookie.name"));
        String loginToken = request.getHeader(PropertiesUtil.getProperty("agent.cookie.name"));
        if (StringUtils.isEmpty(loginToken)) {
            return null;
        }
        String agentJson = RedisShardedPoolUtils.get(loginToken);
        AgentUser agentUser = (AgentUser) JsonUtil.string2Obj(agentJson, AgentUser.class);
        if (agentUser ==null){
            return null;
        }
 
        return this.agentUserMapper.selectByPrimaryKey(agentUser.getId());
    }
 
 
    public AgentUser findByCode(String agentCode) {
        return this.agentUserMapper.findByCode(agentCode);
    }
 
 
    public ServerResponse login(String agentPhone, String agentPwd, String verifyCode, HttpServletRequest request) {
//        if (StringUtils.isBlank(verifyCode)) {
//            return ServerResponse.createByErrorMsg("验证码不能为空");
//        }
        String original = (String) request.getSession().getAttribute("KAPTCHA_SESSION_KEY");
 
//        if (!verifyCode.equalsIgnoreCase(original)) {
//            return ServerResponse.createByErrorMsg("验证码错误");
//        }
 
        if (StringUtils.isBlank(agentPhone) || StringUtils.isBlank(agentPwd)) {
            return ServerResponse.createByErrorMsg("参数不能为空");
        }
        agentPwd = SymmetricCryptoUtil.encryptPassword(agentPwd);
        AgentUser agentUser = this.agentUserMapper.login(agentPhone, agentPwd);
        if (agentUser == null) {
            return ServerResponse.createByErrorMsg("用户密码不正确");
        }
 
        if (agentUser.getIsLock().intValue() == 1) {
            return ServerResponse.createByErrorMsg("登陆失败,您的账号已被锁定!");
        }
 
        return ServerResponse.createBySuccess(agentUser);
    }
 
 
    public ServerResponse getAgentInfo(HttpServletRequest request) {
        String host = "";
        ServerResponse serverResponse = this.iSiteInfoService.getInfo(request);
        if (serverResponse.isSuccess()) {
            SiteInfo siteInfo = (SiteInfo) serverResponse.getData();
            if (StringUtils.isBlank(siteInfo.getSiteHost())) {
                return ServerResponse.createByErrorMsg("info host未设置");
            }
            host = siteInfo.getSiteHost();
        }
        String loginToken = CookieUtils.readLoginToken(request, PropertiesUtil.getProperty("agent.cookie.name"));
        String agentJson = RedisShardedPoolUtils.get(loginToken);
        AgentUser agentUser = (AgentUser) JsonUtil.string2Obj(agentJson, AgentUser.class);
        if (agentUser ==null){
          return   ServerResponse.createByError("請先登錄",null);
        }
        AgentUser dbuser = this.agentUserMapper.selectByPrimaryKey(agentUser.getId());
        AgentInfoVO agentInfoVO = assembleAgentInfoVO(dbuser, host);
        return ServerResponse.createBySuccess(agentInfoVO);
    }
 
 
    public ServerResponse updatePwd(String oldPwd, String newPwd, HttpServletRequest request) {
        if (StringUtils.isBlank(oldPwd) || StringUtils.isBlank(newPwd)) {
            return ServerResponse.createByErrorMsg("参数不能为空");
        }
 
        AgentUser agentUser = getCurrentAgent(request);
            if (agentUser ==null){
             return    ServerResponse.createByError("請先登錄",null);
            }
        oldPwd = SymmetricCryptoUtil.encryptPassword(oldPwd);
        if (!oldPwd.equals(agentUser.getAgentPwd())) {
            return ServerResponse.createByErrorMsg("密码错误");
        }
 
        agentUser.setAgentPwd(SymmetricCryptoUtil.encryptPassword(newPwd));
        int updateCount = this.agentUserMapper.updateByPrimaryKeySelective(agentUser);
 
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("修改成功");
        }
        return ServerResponse.createByErrorMsg("修改失败");
    }
 
 
    public ServerResponse addAgentUser(String agentName, String agentPwd, String agentRealName, String agentPhone, Integer parentId, String poundageScale,  String deferredFeesScale, String receiveDividendsScale, HttpServletRequest request) {
        if (StringUtils.isBlank(agentName) ||
                StringUtils.isBlank(agentPwd) ||
                StringUtils.isBlank(agentRealName) ||
                StringUtils.isBlank(agentPhone)) {
            return ServerResponse.createByErrorMsg("添加失败,参数不能为空");
        }
 
        AgentUser dbuser = this.agentUserMapper.findByName(agentName);
        if (dbuser != null) {
            return ServerResponse.createByErrorMsg("添加失败,代理名已存在");
        }
 
        AgentUser dbuser2 = this.agentUserMapper.findByPhone(agentPhone);
        if (dbuser2 != null) {
            return ServerResponse.createByErrorMsg("添加失败,手机号已存在");
        }
 
        AgentUser agentUser = new AgentUser();
        agentUser.setAgentName(agentName);
        agentUser.setAgentPwd(SymmetricCryptoUtil.encryptPassword(agentPwd));
        agentUser.setAgentCode(KeyUtils.getAgentUniqueKey());
        agentUser.setAgentRealName(agentRealName);
        agentUser.setAgentPhone(agentPhone);
        agentUser.setAddTime(new Date());
        agentUser.setIsLock(Integer.valueOf(0));
        agentUser.setPoundageScale(new BigDecimal(poundageScale));
        agentUser.setDeferredFeesScale(new BigDecimal(deferredFeesScale));
        agentUser.setReceiveDividendsScale(new BigDecimal(receiveDividendsScale));
        agentUser.setTotalMoney(new BigDecimal(0));
        /*AgentUser currentAgent = getCurrentAgent(request);
        agentUser.setParentId(currentAgent.getId());
        agentUser.setParentName(currentAgent.getAgentName());*/
        AgentUser parentAgent = this.agentUserMapper.selectByPrimaryKey(parentId);
        if (parentId != null && parentId>0) {
            if (parentAgent != null) {
                if(parentAgent.getAgentLevel()>=6){
                    return ServerResponse.createByErrorMsg("六级代理不能添加下级");
                }
                agentUser.setParentId(parentAgent.getId());
                agentUser.setParentName(parentAgent.getAgentName());
                agentUser.setAgentLevel(parentAgent.getAgentLevel()+1);
            } else {
                //总代理默认0级
                agentUser.setAgentLevel(Integer.valueOf(0));
                agentUser.setParentId(Integer.valueOf(0));
            }
        } else {
            //总代理默认0级
            agentUser.setAgentLevel(Integer.valueOf(0));
            agentUser.setParentId(Integer.valueOf(0));
        }
 
        int insertCount = 0;
        try {
            this.agentUserMapper.insert(agentUser);
            insertCount = agentUser.getId();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (insertCount > 0) {
            if (parentAgent != null) {
                //分销用户数据处理
                recursiveSaveAgentDistributionUser(insertCount,parentId,parentAgent.getAgentLevel());
            }
            return ServerResponse.createBySuccessMsg("保存代理用户成功");
        }
        return ServerResponse.createByErrorMsg("添加失败,请重试");
    }
 
    //分销代理数据:循环添加
    public int recursiveSaveAgentDistributionUser(int agentId, int parentId,int level){
        int k = 0;
        int pId = parentId;
        for (int i = level; i >= 0; i--){
            AgentUser parentAgent = this.agentUserMapper.selectByPrimaryKey(pId);
            System.out.print("分销代理数据level="+i+"===parentid="+parentAgent.getParentId());
            //分销用户数据处理
            AgentDistributionUser agentDistributionUser = new AgentDistributionUser();
            agentDistributionUser.setAgentId(agentId);
            agentDistributionUser.setParentId(parentAgent.getId());
            agentDistributionUser.setParentLevel(parentAgent.getAgentLevel());
            iAgentDistributionUserService.insert(agentDistributionUser);
 
            if (parentAgent.getParentId()==null){
                pId = 0;
            }else{
                pId = parentAgent.getParentId();
 
            }
            k++;
        }
        return k;
    }
 
 
    public ServerResponse<PageInfo> getSecondAgent(int pageNum, int pageSize, HttpServletRequest request) {
        Page<AgentSecondInfoVO> page = PageHelper.startPage(pageNum, pageSize);
        AgentUser agentUser = getCurrentAgent(request);
        if (agentUser ==null){
        return     ServerResponse.createByError("請先登錄",null);
        }
        //log.info("======test=======" + agentUser.getId().toString());
        List<AgentUser> agentUsers = this.agentUserMapper.getSecondAgent(agentUser.getId());
        /*
        List<AgentSecondInfoVO> agentSecondInfoVOS = Lists.newArrayList();
        for (AgentUser agentUser1 : agentUsers) {
            AgentSecondInfoVO agentSecondInfoVO = assembleAgentSecondInfoVO(agentUser1);
            agentSecondInfoVOS.add(agentSecondInfoVO);
        }*/
        PageInfo pageInfo = new PageInfo(page);
        pageInfo.setList(agentUsers);
        return ServerResponse.createBySuccess(pageInfo);
    }
 
    /*查询代理所有上级*/
    @Override
    public  List<AgentUser> getAgentSuperiorList(int agentId){
        return  this.agentUserMapper.getAgentSuperiorList(agentId);
    }
 
    public ServerResponse<PageInfo> listByAdmin(String realName, String phone, int pageNum, int pageSize, int id, HttpServletRequest request) {
        Page<AgentUser> page = PageHelper.startPage(pageNum, pageSize);
 
        this.agentUserMapper.listByAdmin(realName, phone, id);
        PageInfo pageInfo = new PageInfo(page);
 
        return ServerResponse.createBySuccess(pageInfo);
    }
 
    public ServerResponse add(AgentUser agentUser, HttpServletRequest request) {
        if (StringUtils.isBlank(agentUser.getAgentName()) ||
                StringUtils.isBlank(agentUser.getAgentPhone()) ||
                StringUtils.isBlank(agentUser.getAgentRealName()) ||
                StringUtils.isBlank(agentUser.getAgentPwd())) {
            return ServerResponse.createByErrorMsg("参数不能为空");
        }
 
        log.info("添加代理商的参数 {}",new Gson().toJson(agentUser));
 
        AgentUser pAgent = this.agentUserMapper.findByPhone(agentUser.getAgentPhone());
        if (pAgent != null) {
            return ServerResponse.createByErrorMsg("手机号已存在");
        }
        AgentUser cAgent = this.agentUserMapper.findByCode(agentUser.getAgentCode());
        if (cAgent != null) {
            return ServerResponse.createByErrorMsg("代理编码已存在");
        }
        AgentUser nameAgent = this.agentUserMapper.findByName(agentUser.getAgentName());
        if (nameAgent != null) {
            return ServerResponse.createByErrorMsg("代理名已存在");
        }
 
        AgentUser dbAgent = new AgentUser();
        dbAgent.setAgentName(agentUser.getAgentName());
        dbAgent.setAgentPwd(SymmetricCryptoUtil.encryptPassword(agentUser.getAgentPwd()));
        dbAgent.setAgentPhone(agentUser.getAgentPhone());
        dbAgent.setAgentRealName(agentUser.getAgentRealName());
        dbAgent.setAddTime(new Date());
        dbAgent.setIsLock(Integer.valueOf(0));
//        dbAgent.setAgentCode(KeyUtils.getAgentUniqueKey());
        dbAgent.setAgentCode(agentUser.getAgentCode());
        dbAgent.setOnLineServices(agentUser.getOnLineServices());
 
        if (agentUser.getParentId() != null) {
            AgentUser parentAgent = this.agentUserMapper.selectByPrimaryKey(agentUser.getParentId());
            if (parentAgent != null) {
                dbAgent.setParentId(parentAgent.getId());
                dbAgent.setParentName(parentAgent.getAgentName());
                //判断代理等级
                StockConfig stockConfig = iStockConfigServices.queryByKey(EConfigKey.AGENT_MAX_GRADE.getCode());
                if(null != agentUser.getAgentLevel() && agentUser.getAgentLevel() > Integer.parseInt(stockConfig.getCValue())){
                    return ServerResponse.createByErrorMsg("代理最大等级为"+stockConfig.getCValue());
                }
                dbAgent.setAgentLevel(parentAgent.getAgentLevel()+1);
            } else {
                //总代理默认0级
                dbAgent.setAgentLevel(Integer.valueOf(0));
                dbAgent.setParentId(Integer.valueOf(0));
            }
        }
        log.info("添加代理商的参数  数据库{}",new Gson().toJson(dbAgent));
        int insertCount = this.agentUserMapper.insert(dbAgent);
        if (insertCount > 0) {
            return ServerResponse.createBySuccessMsg("添加代理成功");
        }
        return ServerResponse.createByErrorMsg("添加代理失败");
    }
 
 
    public ServerResponse update(AgentUser agentUser) {
        AgentUser dbAgent = new AgentUser();
 
        if (StringUtils.isNotBlank(agentUser.getAgentName())) {
            return ServerResponse.createByErrorMsg("代理名不能变更");
        }
 
        AgentUser cAgent = this.agentUserMapper.findByCodeAndNeid(agentUser.getAgentCode(),agentUser.getId());
        if (cAgent != null) {
            return ServerResponse.createByErrorMsg("代理编码已存在");
        }
 
        dbAgent.setId(agentUser.getId());
        dbAgent.setAgentCode(agentUser.getAgentCode());
        if (StringUtils.isNotBlank(agentUser.getAgentPwd())) {
            dbAgent.setAgentPwd(SymmetricCryptoUtil.encryptPassword(agentUser.getAgentPwd()));
        }
        dbAgent.setOnLineServices(agentUser.getOnLineServices());
        if (StringUtils.isNotBlank(agentUser.getAgentRealName())) {
            dbAgent.setAgentRealName(agentUser.getAgentRealName());
        }
        if (StringUtils.isNotBlank(agentUser.getSiteLever())) {
            dbAgent.setSiteLever(agentUser.getSiteLever());
        }
        if (StringUtils.isNotBlank(agentUser.getAgentPhone())) {
            AgentUser phoneAgent = this.agentUserMapper.findByPhone(agentUser.getAgentPhone());
 
            if (phoneAgent == null || phoneAgent.getId() == agentUser.getId()) {
                dbAgent.setAgentPhone(agentUser.getAgentPhone());
            } else {
                return ServerResponse.createByErrorMsg("手机号已存在,请更换手机");
            }
        }
        if (agentUser.getIsLock() != null) {
            dbAgent.setIsLock(agentUser.getIsLock());
        }
 
        if (agentUser.getParentId() != null) {
 
            AgentUser parentAgent = this.agentUserMapper.selectByPrimaryKey(agentUser.getParentId());
            if (parentAgent != null) {
                dbAgent.setParentId(parentAgent.getId());
                dbAgent.setParentName(parentAgent.getAgentName());
            }
        }
 
        int updateCount = this.agentUserMapper.updateByPrimaryKeySelective(dbAgent);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("修改代理成功");
        }
        return ServerResponse.createByErrorMsg("修改代理失败");
    }
 
    @Override
    public ServerResponse updateOnlineServices(String paramAgentUser,int agentId) {
        int updateCount = this.agentUserMapper.updateOnlineServices(paramAgentUser,agentId);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("修改代理成功");
        }
        return ServerResponse.createByErrorMsg("修改代理失败");
 
    }
 
    @Override
    public ServerResponse<List<AgentUser>> getParensAgent() {
        return ServerResponse.createBySuccess(agentUserMapper.getParensAgent());
    }
 
    public int CountAgentNum() {
        return this.agentUserMapper.CountAgentNum();
    }
 
 
    private AgentSecondInfoVO assembleAgentSecondInfoVO(AgentUser agentUser) {
        AgentSecondInfoVO agentSecondInfoVO = new AgentSecondInfoVO();
        agentSecondInfoVO.setId(agentUser.getId());
        agentSecondInfoVO.setAgentCode(agentUser.getAgentCode());
        agentSecondInfoVO.setAgentName(agentUser.getAgentName());
        agentSecondInfoVO.setAgentPhone(agentUser.getAgentPhone());
        agentSecondInfoVO.setAgentRealName(agentUser.getAgentRealName());
        return agentSecondInfoVO;
    }
 
    private AgentInfoVO assembleAgentInfoVO(AgentUser agentUser, String host) {
        AgentInfoVO agentInfoVO = new AgentInfoVO();
        agentInfoVO.setId(agentUser.getId());
        agentInfoVO.setAgentName(agentUser.getAgentName());
        agentInfoVO.setAgentRealName(agentUser.getAgentRealName());
        agentInfoVO.setAgentPhone(agentUser.getAgentPhone());
        agentInfoVO.setAgentCode(agentUser.getAgentCode());
        agentInfoVO.setAddTime(agentUser.getAddTime());
        agentInfoVO.setIsLock(agentUser.getIsLock());
        agentInfoVO.setParentId(agentUser.getParentId());
        agentInfoVO.setParentName(agentUser.getParentName());
        agentInfoVO.setTotalMoney(agentUser.getTotalMoney());
        agentInfoVO.setOnLineServices(agentUser.getOnLineServices());
 
        String pcUrl = host + PropertiesUtil.getProperty("site.pc.reg.url") + agentUser.getAgentCode();
        agentInfoVO.setPcUrl(pcUrl);
        String mUrl = host + PropertiesUtil.getProperty("site.m.reg.url") + agentUser.getAgentCode();
        agentInfoVO.setMUrl(mUrl);
        return agentInfoVO;
    }
 
    /*代理账户扣款*/
    @Transactional
    public ServerResponse updateAgentAmt(Integer agentId, Integer amt, Integer direction) {
        if (agentId == null || amt == null || direction == null) {
            return ServerResponse.createByErrorMsg("参数不能为空");
        }
 
        AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId);
        if (agentUser == null) {
            return ServerResponse.createByErrorMsg("代理不存在");
        }
 
        BigDecimal totalMoney = agentUser.getTotalMoney();//扣除前金额
        BigDecimal back_amt = agentUser.getTotalMoney();//扣除后余额
        BigDecimal deduct_amt = new BigDecimal(amt);//扣除金额
        if (totalMoney==null){
            totalMoney = new BigDecimal(0);
        }
        if (direction.intValue() == 0) {
 
        } else if (direction.intValue() == 1) {
            if (totalMoney.compareTo(new BigDecimal(amt)) < 0) {
                return ServerResponse.createByErrorMsg("扣款失败, 总资金不足");
            }
            deduct_amt = deduct_amt.multiply(new BigDecimal(-1));
            back_amt = back_amt.subtract(new BigDecimal(amt));
        } else {
            return ServerResponse.createByErrorMsg("不存在此操作");
        }
 
        //修改代理账户余额
        AgentUser user = new AgentUser();
        user.setId(agentUser.getId());
        user.setTotalMoney(deduct_amt);
        agentUserMapper.updateTotalMoney(user);
        //利润明细增加
        AgentAgencyFee agentAgencyFee = new AgentAgencyFee();
        agentAgencyFee.setAgentId(agentUser.getId());
        agentAgencyFee.setStatus(1);
        agentAgencyFee.setAymentType(2);
        agentAgencyFee.setBusinessId(0);
        agentAgencyFee.setFeeType(0);
        agentAgencyFee.setTotalMoney(deduct_amt);
        agentAgencyFee.setProfitMoney(new BigDecimal(amt.intValue()));
        agentAgencyFee.setRemarks("【提现支出】提现金额:"+amt);
        iAgentAgencyFeeService.insert(agentAgencyFee);
 
 
        SiteTaskLog siteTaskLog = new SiteTaskLog();
        siteTaskLog.setTaskType("管理员修改代理金额");
        StringBuffer cnt = new StringBuffer();
        cnt.append("管理员修改代理金额 - ")
                .append((direction.intValue() == 0) ? "入款" : "扣款")
                .append(amt).append("元");
        siteTaskLog.setTaskCnt(cnt.toString());
 
        StringBuffer target = new StringBuffer();
        target.append("代理id : ").append(agentUser.getId())
                .append("修改前 总资金 = ").append(totalMoney)
                .append("修改后 总资金 = ").append(back_amt);
        siteTaskLog.setTaskTarget(target.toString());
 
        siteTaskLog.setIsSuccess(Integer.valueOf(0));
        siteTaskLog.setAddTime(new Date());
 
        int insertCount = this.siteTaskLogMapper.insert(siteTaskLog);
        if (insertCount > 0) {
            return ServerResponse.createBySuccessMsg("修改资金成功");
        }
        return ServerResponse.createByErrorMsg("修改资金失败");
    }
 
    /*删除代理*/
    public ServerResponse delAgent(Integer agentId) {
        AgentUser dbAgent = this.agentUserMapper.selectByPrimaryKey(agentId);
 
        if (dbAgent == null) {
            return ServerResponse.createByErrorMsg("代理不存在,请正常操作!");
        }
 
        int updateCount = this.agentUserMapper.deleteByPrimaryKey(agentId);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("删除代理成功");
        }
        return ServerResponse.createByErrorMsg("删除代理失败");
    }
 
    @Override
    public ServerResponse count(HttpServletRequest request) {
        String loginToken = CookieUtils.readLoginToken(request, PropertiesUtil.getProperty("agent.cookie.name"));
        String agentJson = RedisShardedPoolUtils.get(loginToken);
        AgentUser agentUser = (AgentUser) JsonUtil.string2Obj(agentJson, AgentUser.class);
        if (agentUser ==null){
            return   ServerResponse.createByError("請先登錄",null);
        }
        AdminCountVO adminCountVO = new AdminCountVO();
 
 
        //累计充值金额
        BigDecimal charge_sum_amt = userRechargeMapper.agentCountChargeSumAmt(Integer.valueOf(1),agentUser.getId());
        //今日充值金额
        BigDecimal charge_today_sum_amt = userRechargeMapper.agentCountTotalRechargeAmountByTime(Integer.valueOf(1),agentUser.getId());
 
        //累计提现金额
        BigDecimal sp_withdraw_sum_amt_success =userWithdrawMapper.agentCountSpWithSumAmtByState(Integer.valueOf(1),agentUser.getId());
 
        //今日提现金额
        BigDecimal sp_withdraw_sum_today_amt_success = userWithdrawMapper.agentCountSpWithSumAmTodaytByState(Integer.valueOf(1),agentUser.getId());
 
        /**
         * 当天注册人数
         * */
        int regDayCount = userMapper.querySumTodayRegCount(agentUser.getId());
        adminCountVO.setToDayRegCount(regDayCount);
        List<UserRecharge>  list  =   userRechargeMapper.queryDayFrist(agentUser.getId());
        adminCountVO.setToDayFristRechargeCount(list.size());
        adminCountVO.setToDayRechargeCount(list.size());
 
        BigDecimal b =  BigDecimal.ZERO;
 
        for (int i = 0; i < list.size(); i++) {
            b.add(list.get(i).getPayAmt());
        }
        adminCountVO.setToDayFristRechargeMoney(b);
        adminCountVO.setCharge_sum_amt(charge_sum_amt);
        adminCountVO.setCharge_today_sum_amt(charge_today_sum_amt);
        adminCountVO.setSp_withdraw_sum_amt_success(sp_withdraw_sum_amt_success);
        adminCountVO.setSp_withdraw_sum_today_amt_success(sp_withdraw_sum_today_amt_success);
 
        return ServerResponse.createBySuccess(adminCountVO);
    }
}