jyy
2021-04-09 1443f8eb9f3b001e84f101852aa5f6ec7f49f4c9
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
package com.matrix.system.shopXcx.api.action;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.component.wechat.externalInterface.protocol.paramProtocol.BrandWCPayRequestData;
import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.BasePageQueryDto;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.system.hive.bean.MoneyCardUse;
import com.matrix.system.hive.bean.MoneyCardUseFlow;
import com.matrix.system.hive.bean.SysVipInfo;
import com.matrix.system.hive.dao.MoneyCardUseFlowDao;
import com.matrix.system.hive.dao.MoneyCardUseV2Dao;
import com.matrix.system.hive.service.CodeService;
import com.matrix.system.shopXcx.api.vo.WxMoneyCardUseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @author jyy
 * @date 2021-04-09
 **/
@Api(tags = "会员储值卡")
@RestController
@RequestMapping(value = "/wxapi/moneyCardUse")
public class WxMoneyCardUseAction {
 
    @Autowired
    WeixinServiceUtil weixinServiceUtil;
 
 
    @Autowired
    private MoneyCardUseV2Dao moneyCardUseV2Dao;
 
    @Autowired
    private RedisUserLoginUtils redisUserLoginUtils;
 
    @Autowired
    MoneyCardUseFlowDao moneyCardUseFlowDao;
 
    @Autowired
    CodeService codeService;
 
    @ApiOperation(value = "查询会员储值卡", notes = "")
    @GetMapping(value = "/getUserMoneyCardUseList")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = WxMoneyCardUseVO.class)
    })
    public AjaxResult getUserMoneyCardUseList(@RequestBody @Validated BasePageQueryDto pageDto) {
        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("vip_id", sysVipInfo.getId());
        IPage<MoneyCardUse> page = new Page<>(pageDto.getPageNum(), pageDto.getPageSize());
        IPage pageList = moneyCardUseV2Dao.selectPage(page, queryWrapper);
        List<WxMoneyCardUseVO> rows = (List<WxMoneyCardUseVO>) pageList.getRecords().stream().map(item -> {
            WxMoneyCardUseVO vo = new WxMoneyCardUseVO();
            BeanUtils.copyProperties(item, vo);
            return vo;
        }).collect(Collectors.toList());
        return AjaxResult.buildSuccessInstance(rows);
    }
 
    @ApiOperation(value = "创建储值卡充值预付单", notes = "传入参数 {rechargeAmount:10} 最少充值1元,最多2位小数 ")
    @PostMapping(value = "/createRechargeOrder")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = AjaxResult.class)
    })
    public AjaxResult createRechargeOrder(@RequestBody Map<String, String> param) throws Exception {
 
        String rechargeAmount = param.get("rechargeAmount");
        if (StringUtils.isBlank(rechargeAmount)) {
            return AjaxResult.buildFailInstance("去输入充值金额");
        }
        double total = new BigDecimal(rechargeAmount).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
        if (total < 0.02) {
            return AjaxResult.buildFailInstance("充值金额最底1元");
        }
        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow();
        moneyCardUseFlow.setVipId(sysVipInfo.getId());
        moneyCardUseFlow.setPayNo(codeService.get32LenNumberCode());
        moneyCardUseFlow.setTotal(total);
        moneyCardUseFlow.setCreateTime(new Date());
        moneyCardUseFlow.setType(MoneyCardUseFlow.USE_TYPE_CZ);
        moneyCardUseFlowDao.insert(moneyCardUseFlow);
        moneyCardUseFlow.setContent("微信充值");
        BrandWCPayRequestData payData = weixinServiceUtil.createRechargeOrder("储值卡充值", moneyCardUseFlow.getPayNo(),
                (int) (moneyCardUseFlow.getTotal() * 100), sysVipInfo.getOpenId(), String.valueOf(moneyCardUseFlow.getId()));
        AjaxResult result = AjaxResult.buildSuccessInstance(payData);
        result.putInMap("orderId", moneyCardUseFlow.getId());
        return result;
    }
 
    @ApiOperation(value = "查询充值结果", notes = " ")
    @GetMapping(value = "/getRechargePayStatus/{orderId}")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = AjaxResult.class)
    })
    public AjaxResult getRechargePayStatus(@PathVariable Long orderId) {
        AjaxResult result =AjaxResult.buildSuccessInstance("查询成功");
        MoneyCardUseFlow moneyCardUseFlow = moneyCardUseFlowDao.selectById(orderId);
        if (moneyCardUseFlow.getCarUseId() != null) {
            result.putInMap("status", "success");
            result.putInMap("msg", "支付成功");
        } else {
            LogUtil.debug("充值等待支付中={}。。。", orderId);
            PayThreadPool.waitThread(orderId.intValue(), new Object());
            result = PayThreadPool.getThreadResult(orderId.intValue());
            LogUtil.debug("充值订单支付完成={}。。。", orderId);
        }
        return result;
    }
 
 
 
    @ApiOperation(value = "查询会员储值卡充值使用记录", notes = "keywords 传入会员卡ID")
    @GetMapping(value = "/getRechargeList")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = MoneyCardUseFlow.class)
    })
    public AjaxResult getRechargeList(@RequestBody @Validated BasePageQueryDto pageDto) {
        if(StringUtils.isBlank(pageDto.getKeywords())){
            return AjaxResult.buildFailInstance("keywords参数是必须的");
        }
        PaginationVO pageVo = new PaginationVO();
        pageVo.setOffset((pageDto.getPageNum() - 1) * pageDto.getPageSize());
        pageVo.setLimit(pageDto.getPageSize());
        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        MoneyCardUseFlow moneyCardUseFlow=new MoneyCardUseFlow();
        moneyCardUseFlow.setVipId(sysVipInfo.getId());
        moneyCardUseFlow.setCarUseId(Long.parseLong(pageDto.getKeywords()));
        List<MoneyCardUseFlow> dataList = moneyCardUseFlowDao.selectInPage(moneyCardUseFlow, pageVo);
        return AjaxResult.buildSuccessInstance(dataList, moneyCardUseFlowDao.selectTotalRecord(moneyCardUseFlow));
    }
 
 
 
}