package com.ruoyi.other.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.ruoyi.chargingPile.api.feignClient.SiteClient;
|
import com.ruoyi.chargingPile.api.model.Site;
|
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.IntegralPay;
|
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.*;
|
import com.ruoyi.other.util.pay.CreateLinkStringByGet1;
|
import com.ruoyi.other.util.pay.HttpRequester;
|
import com.ruoyi.other.util.pay.HttpRespons;
|
import com.ruoyi.other.util.pay.Md5_Sign;
|
import com.ruoyi.other.util.payment.wx.WechatPayService;
|
import com.ruoyi.other.vo.*;
|
import com.ruoyi.system.api.domain.SysUser;
|
import com.ruoyi.system.api.feignClient.SysUserClient;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.models.auth.In;
|
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.math.RoundingMode;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDateTime;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
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;
|
@Resource
|
private SiteClient siteClient;
|
// 查询服务费缴纳情况
|
@GetMapping("/getServiceStatus/{userId}")
|
public R<String> getServiceStatus(@PathVariable("userId") Integer userId) {
|
ServicePay servicePayBefore = servicePayService.lambdaQuery()
|
.eq(ServicePay::getUserId, userId)
|
.eq(ServicePay::getPayStatus,2)
|
.eq(ServicePay::getDelFlag,0)
|
.orderByDesc(ServicePay::getCreateTime)
|
.last("limit 1")
|
.one();
|
if (servicePayBefore==null){
|
return R.ok("1");
|
}
|
else if (servicePayBefore.getEndTime().isBefore(LocalDateTime.now())) {
|
return R.ok("2");
|
}
|
else{
|
return R.ok("3");
|
}
|
|
}
|
@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)
|
.eq(ServicePay::getDelFlag,0)
|
.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("id") Integer id) throws Exception {
|
ServicePay servicePay = servicePayService.getById(id);
|
if (servicePay.getPayStatus()==2){
|
return R.ok(true);
|
}else{
|
return R.ok(false);
|
}
|
}
|
@PostMapping("/nativePay")
|
@ApiOperation(tags = {"2.0-服务费"},value = "管理后台缴纳服务费获取支付二维码")
|
public R<PayDto> nativePay() throws Exception {
|
Long userid = tokenService.getLoginUser().getUserid();
|
R<SysUser> sysUser = sysUserClient.getSysUser(userid);
|
SysUser data = sysUser.getData();
|
List<Site> sites = siteClient.getSiteAll().getData();
|
Site site = sites.stream().filter(e -> e.getId().equals(data.getSiteId())).findFirst().orElse(null);
|
if (site==null){
|
return R.fail("当前登录用户未绑定站点");
|
}
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
|
Map<String,String> res = wechatPayService.unifiedOrder(code, site.getAnnualServiceFee()+"", site.getCode()+"服务费缴纳", "/other/wx/serviceCallback");
|
ServicePay servicePay = new ServicePay();
|
servicePay.setUserId(data.getUserId());
|
servicePay.setAmount(site.getAnnualServiceFee());
|
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);
|
PayDto payDto = new PayDto();
|
payDto.setId(servicePay.getId());
|
payDto.setQrCode(s);
|
payDto.setServiceMoney(site.getAnnualServiceFee());
|
return R.ok(payDto);
|
}
|
@Resource
|
private WeChatUtil weChatUtil;
|
@PostMapping("/bindOpenId")
|
@ApiOperation(tags = {"2.0-服务费"},value = "小程序绑定openId")
|
public R bindOpenId(@RequestParam("jscode") String jscode) throws Exception {
|
//使用jscode获取微信openid
|
Map<String, Object> map = weChatUtil.code2Session(jscode);
|
Integer errcode = Integer.valueOf(map.get("errcode").toString());
|
if(0 != errcode){
|
return R.fail(map.get("msg").toString());
|
}
|
String openid = map.get("openid").toString();
|
Long userid = tokenService.getLoginUser().getUserid();
|
R<SysUser> sysUser = sysUserClient.getSysUser(userid);
|
SysUser data = sysUser.getData();
|
data.setOpenId(openid);
|
sysUserClient.updateSysUser(data);
|
return R.ok();
|
}
|
@PostMapping("/servicePayApplet")
|
@ApiOperation(tags = {"2.0-服务费"},value = "小程序缴纳服务费")
|
public R servicePayApplet() throws Exception {
|
|
Long userid = tokenService.getLoginUser().getUserid();
|
R<SysUser> sysUser = sysUserClient.getSysUser(userid);
|
SysUser data = sysUser.getData();
|
List<Site> sites = siteClient.getSiteAll().getData();
|
Site site = sites.stream().filter(e -> e.getId().equals(data.getSiteId())).findFirst().orElse(null);
|
if (site==null){
|
return R.fail("当前登录用户未绑定站点");
|
}
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
|
ServicePay servicePay = new ServicePay();
|
servicePay.setUserId(data.getUserId());
|
servicePay.setAmount(site.getAnnualServiceFee());
|
servicePay.setCode(code);
|
servicePay.setPayStatus(1);
|
servicePay.setPayType(1);
|
servicePay.setDelFlag(0);
|
servicePay.setCreateTime(LocalDateTime.now());
|
servicePayService.save(servicePay);
|
|
|
return wechatPayService.unifiedOrderApplet(servicePay.getId()+"",code, site.getAnnualServiceFee()+"", site.getCode()+"服务费缴纳",data.getOpenId(), "/other/wx/serviceCallback");
|
}
|
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;
|
}
|
|
}
|