935090232@qq.com
2021-03-19 81a3369395a7cccceb7cd36f5238cc6fe2aa88e5
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
package com.matrix.system.shopXcx.api.action;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.matrix.biz.bean.BizUser;
import com.matrix.biz.dao.BizUserDao;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.BasePageQueryDto;
import com.matrix.system.fenxiao.dao.ShopRevenueFlowDao;
import com.matrix.system.fenxiao.entity.ShopRevenueFlow;
import com.matrix.system.hive.service.CodeService;
import com.matrix.system.shopXcx.api.dto.RevenueFlowDto;
import com.matrix.system.shopXcx.api.dto.WithdrawalCashDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
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.util.Date;
 
/**
 * @author jyy
 * @date 2021-03-10
 **/
@Api(tags = "提现接口类")
@RestController
@RequestMapping(value = "/wxapi/salesWithdrawal")
public class WxSalesWithdrawalAction {
 
 
    @Autowired
    private RedisUserLoginUtils redisUserLoginUtils;
 
    @Autowired
    private BizUserDao bizUserDao;
 
    @Autowired
    private ShopRevenueFlowDao revenueFlowDao;
 
 
    @Autowired
    private ShopRevenueFlowDao shopRevenueFlowDao;
    @Autowired
    WeixinServiceUtil weixinServiceUtil;
 
    @Autowired
    CodeService codeService;
 
    @ApiOperation(value = "获取收支明细", notes = "")
    @PostMapping(value = "/getRevenueFlow")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = ShopRevenueFlow.class)
    })
    AjaxResult getInvitationuserList(@RequestBody @Validated RevenueFlowDto revenueFlowDto) {
        BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        Page<ShopRevenueFlow> page=new Page<>(revenueFlowDto.getPageNum(),revenueFlowDto.getPageSize());
        revenueFlowDto.setUserId(loginUser.getOpenId());
        IPage<ShopRevenueFlow> shopSalesmanApplyIPage = revenueFlowDao.selectRevenuFlowList(page,  revenueFlowDto);
        AjaxResult result=AjaxResult.buildSuccessInstance(shopSalesmanApplyIPage.getRecords());
        return result;
    }
 
 
    @ApiOperation(value = "提现", notes = "")
    @PostMapping(value = "/withdrawalCash")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = BasePageQueryDto.class)
    })
    @Transactional
    AjaxResult withdrawalCash(@RequestBody @Validated WithdrawalCashDto withdrawalCashDto) {
        BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        loginUser=bizUserDao.selectById(loginUser.getUserId());
        if(withdrawalCashDto.getAmount()<1){
            return AjaxResult.buildFailInstance("最小提现金额为1元");
        }else if(withdrawalCashDto.getAmount()>20000){
            return AjaxResult.buildFailInstance("最大提现金额为2万元");
        }else{
            if(loginUser.getWithdrawalCash()==null || loginUser.getWithdrawalCash()<withdrawalCashDto.getAmount()){
                return AjaxResult.buildFailInstance("余额不足");
            }else{
 
                String txNo = codeService.get32LenNumberCode();
 
             /*调试注释
             weixinServiceUtil.comPay("提现", txNo,Integer.parseInt((withdrawalCashDto.getAmount()*1000)+""),
                        loginUser.getOpenId(),loginUser.getCompanyId());
                    */
                //记录收益流水
                ShopRevenueFlow invitationRevenueFlow=new ShopRevenueFlow();
                invitationRevenueFlow.setCompanyId(loginUser.getCompanyId());
                invitationRevenueFlow.setCreateBy(MatrixConstance.SYSTEM_USER);
                invitationRevenueFlow.setUpdateBy(txNo);
                invitationRevenueFlow.setCreateTime(new Date());
                invitationRevenueFlow.setUpdateTime(new Date());
                invitationRevenueFlow.setAmount(-withdrawalCashDto.getAmount());
                invitationRevenueFlow.setUserId(loginUser.getOpenId());
                invitationRevenueFlow.setRevenueContent("提现");
                shopRevenueFlowDao.insert(invitationRevenueFlow);
                //扣除用户剩余提现金额
                loginUser.setWithdrawalCash(loginUser.getWithdrawalCash()-withdrawalCashDto.getAmount());
                bizUserDao.updateByModel(loginUser);
                redisUserLoginUtils.updateUserInfo(loginUser);
 
 
                return AjaxResult.buildSuccessInstance("提现成功");
            }
        }
 
 
    }
 
 
 
 
 
}