package com.ruoyi.other.controller;
|
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.web.page.PageInfo;
|
import com.ruoyi.common.log.annotation.Log;
|
import com.ruoyi.common.log.enums.BusinessType;
|
import com.ruoyi.common.security.service.TokenService;
|
import com.ruoyi.other.api.domain.ServicePay;
|
import com.ruoyi.other.api.domain.TIntegralRule;
|
import com.ruoyi.other.query.IntegralListQuery;
|
import com.ruoyi.other.query.ServiceListQuery;
|
import com.ruoyi.other.service.TIntegralRecordService;
|
import com.ruoyi.other.service.TIntegralRuleService;
|
import com.ruoyi.other.service.TServicePayService;
|
import com.ruoyi.other.util.MyQrCodeUtil;
|
import com.ruoyi.other.util.ObsUploadUtil;
|
import com.ruoyi.other.util.QRCodeUtil;
|
import com.ruoyi.other.util.UUIDUtil;
|
import com.ruoyi.other.util.payment.wx.WechatPayService;
|
import com.ruoyi.other.vo.IntegralListVO;
|
import com.ruoyi.other.vo.IntegralVO;
|
import com.ruoyi.other.vo.ServiceListVO;
|
import com.ruoyi.other.vo.ServiceVO;
|
import com.ruoyi.system.api.domain.SysUser;
|
import com.ruoyi.system.api.feignClient.SysUserClient;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import javax.imageio.ImageIO;
|
import java.awt.image.BufferedImage;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDateTime;
|
import java.util.Date;
|
import java.util.Map;
|
|
/**
|
* <p>
|
* 前端控制器
|
* </p>
|
*
|
* @author 无关风月
|
* @since 2024-08-06
|
*/
|
@RestController
|
@RequestMapping("/integralRule")
|
public class TServiceController {
|
|
@Autowired
|
private TIntegralRuleService integralRuleService;
|
@Autowired
|
private TIntegralRecordService integralRecordService;
|
|
@Autowired
|
private TokenService tokenService;
|
@Resource
|
private SysUserClient sysUserClient;
|
@Resource
|
private WechatPayService wechatPayService;
|
@Resource
|
private TServicePayService servicePayService;
|
@PostMapping("/servicePageList")
|
@ApiOperation(tags = {"2.0-服务费管理"},value = "服务费管理")
|
public R<ServiceVO> integralPageList(@RequestBody ServiceListQuery query) {
|
Long userid = tokenService.getLoginUser().getUserid();
|
R<SysUser> sysUser = sysUserClient.getSysUser(userid);
|
query.setUserId(userid);
|
ServiceVO serviceVO = new ServiceVO();
|
PageInfo<ServiceListVO> serviceListVOPageInfo = servicePayService.servicePageList(query);
|
serviceVO.setServiceList(serviceListVOPageInfo);
|
ServicePay servicePayBefore = servicePayService.lambdaQuery()
|
.eq(ServicePay::getUserId, userid)
|
.eq(ServicePay::getPayStatus,2)
|
.orderByDesc(ServicePay::getCreateTime)
|
.last("limit 1")
|
.one();
|
if (servicePayBefore==null){
|
serviceVO.setStatus(1);
|
} else if (servicePayBefore.getEndTime().isBefore(LocalDateTime.now())) {
|
serviceVO.setStatus(2);
|
}else{
|
serviceVO.setStatus(3);
|
}
|
if (servicePayBefore!=null){
|
serviceVO.setEndTime(servicePayBefore.getEndTime());
|
}
|
return R.ok(serviceVO);
|
}
|
@PostMapping("/queryPayStatus")
|
@ApiOperation(tags = {"2.0-服务费"},value = "查询支付结果 true成功 false失败")
|
public R<Boolean> integralPageList(@RequestParam("code") String code) throws Exception {
|
Map<String, String> resMap = wechatPayService.queryOrder(code);
|
if("SUCCESS".equals(resMap.get("return_code"))){
|
return R.ok(true);
|
}else{
|
return R.ok(false);
|
}
|
}
|
@PostMapping("/nativePay")
|
@ApiOperation(tags = {"2.0-服务费"},value = "获取支付二维码")
|
public R nativePay(@RequestParam("amount") String amount) throws Exception {
|
// todo 查询每个站点的年服务费
|
Long userid = tokenService.getLoginUser().getUserid();
|
R<SysUser> sysUser = sysUserClient.getSysUser(userid);
|
SysUser data = sysUser.getData();
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
|
Map<String,String> res = wechatPayService.unifiedOrder(code, amount, "服务费缴纳", "/other/wx/serviceCallback");
|
ServicePay servicePay = new ServicePay();
|
servicePay.setUserId(data.getUserId());
|
servicePay.setAmount(new BigDecimal( amount));
|
servicePay.setCode(code);
|
servicePay.setPayStatus(1);
|
servicePay.setPayType(1);
|
servicePay.setDelFlag(0);
|
servicePay.setCreateTime(LocalDateTime.now());
|
servicePayService.save(servicePay);
|
String codeUrl = res.get("code_url");
|
MyQrCodeUtil.createCodeToFile(codeUrl);
|
BufferedImage blueImage = QRCodeUtil.createImage(codeUrl);
|
MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG");
|
String s = ObsUploadUtil.obsUpload(blueFile);
|
System.err.println(s);
|
return R.ok(s);
|
}
|
public static MultipartFile convert(BufferedImage bufferedImage, String fileName) throws IOException {
|
// 将 BufferedImage 转换为字节数组
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ImageIO.write(bufferedImage, "png", baos);
|
byte[] bytes = baos.toByteArray();
|
|
// 创建 ByteArrayResource
|
ByteArrayResource resource = new ByteArrayResource(bytes);
|
|
// 创建 MockMultipartFile
|
MockMultipartFile multipartFile = new MockMultipartFile(
|
"file",
|
fileName,
|
"image/png",
|
resource.getInputStream()
|
);
|
|
return multipartFile;
|
}
|
|
}
|