New file |
| | |
| | | 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.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.dto.MoneyCardUseFlowDto; |
| | | 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 = "/getUserVipCard") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "ok", response = WxMoneyCardUseVO.class) |
| | | }) |
| | | public AjaxResult getUserVipCard() { |
| | | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("vip_id", sysVipInfo.getId()); |
| | | queryWrapper.eq("is_vip_car","Y"); |
| | | MoneyCardUse moneyCardUse = moneyCardUseV2Dao.selectOne(queryWrapper); |
| | | WxMoneyCardUseVO vo = new WxMoneyCardUseVO(); |
| | | BeanUtils.copyProperties(moneyCardUse, vo); |
| | | return AjaxResult.buildSuccessInstance(vo); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "查询会员储值卡", notes = "") |
| | | @PostMapping(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()); |
| | | System.out.println(rows.get(0).getId()); |
| | | 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") |
| | | @PostMapping(value = "/getRechargeList") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "ok", response = MoneyCardUseFlow.class) |
| | | }) |
| | | public AjaxResult getRechargeList(@RequestBody @Validated MoneyCardUseFlowDto pageDto) { |
| | | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); |
| | | pageDto.setCompanyId(sysVipInfo.getCompanyId()); |
| | | List<MoneyCardUseFlow> dataList = moneyCardUseFlowDao.selectForWxInPage(pageDto); |
| | | return AjaxResult.buildSuccessInstance(dataList); |
| | | } |
| | | |
| | | |
| | | |
| | | } |