zj
2024-06-03 7479d2c5169265cf29e432a30b22c31073106751
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
package com.nq.service.impl;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nq.common.ServerResponse;
import com.nq.dao.SitePayMapper;
import com.nq.dao.UserRechargeMapper;
import com.nq.enums.EStockType;
import com.nq.pojo.SitePay;
import com.nq.pojo.UserRecharge;
import com.nq.service.ISitePayService;
 
import java.util.ArrayList;
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
 
@Service("iSitePayService")
public class SitePayServiceImpl
        implements ISitePayService {
    @Resource
    SitePayMapper sitePayMapper;
 
    @Resource
    UserRechargeMapper userRechargeMapper;
 
    public ServerResponse add(SitePay sitePay) {
        if (sitePay.getExchangeRate() <= 0) {
            return ServerResponse.createByErrorMsg("汇率不能小于0");
        }
 
 
        SitePay dbSitePay = this.sitePayMapper.findByChannelType(sitePay.getChannelType());
        if (dbSitePay != null) {
            return ServerResponse.createByErrorMsg("支付类型已存在");
        }
        sitePay.setAssetsType(EStockType.IN.getCode());
        int insertCount = this.sitePayMapper.insert(sitePay);
        if (insertCount > 0) {
            return ServerResponse.createBySuccessMsg("添加成功");
        }
        return ServerResponse.createByErrorMsg("添加失败");
    }
 
 
    public ServerResponse listByAdmin(String channelType, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
 
        List<SitePay> sitePays = this.sitePayMapper.listByAdmin(channelType);
        PageInfo pageInfo = new PageInfo(sitePays);
 
        return ServerResponse.createBySuccess(pageInfo);
    }
 
 
    public ServerResponse update(SitePay sitePay) {
        if (sitePay.getId() == null) {
            return ServerResponse.createByErrorMsg("修改id不能为空");
        }
        int updateCount = this.sitePayMapper.updateById(sitePay);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("修改成功");
        }
        return ServerResponse.createByErrorMsg("修改失败");
    }
 
 
    public ServerResponse del(Integer cId) {
        if (cId == null) {
            return ServerResponse.createByErrorMsg("id不能为空");
        }
        int delCount = this.sitePayMapper.deleteByPrimaryKey(cId);
        if (delCount > 0) {
            return ServerResponse.createBySuccessMsg("删除成功");
        }
        return ServerResponse.createByErrorMsg("删除失败");
    }
 
 
    public ServerResponse getPayInfo(Integer type) {
        List<SitePay> sitePays = this.sitePayMapper.selectList(new LambdaQueryWrapper<SitePay>().eq(SitePay::getIsShow,0)
                .eq(SitePay::getCType,type));
        return ServerResponse.createBySuccess(sitePays);
    }
 
 
    public ServerResponse getPayInfoById(Integer payId) {
        return ServerResponse.createBySuccess(this.sitePayMapper.selectByPrimaryKey(payId));
    }
 
    @Override
    public ServerResponse listByPayType(Integer id) {
        List<SitePay> payList = new ArrayList<>();
        if (id==null||id<1){
            return ServerResponse.createByErrorMsg("param is null");
        }
        UserRecharge userRecharge = userRechargeMapper.selectById(id);
        Integer payType = userRecharge.getPayType();
        if (payType!=null){
            if (payType==1){
                payList = sitePayMapper.listByPayType(0);
            } else if (payType==2) {
                payList = sitePayMapper.listByPayType(1);
            }
        }else {
            payList = sitePayMapper.listByAdmin(null);
        }
        return ServerResponse.createBySuccess(payList);
    }
}