| | |
| | | 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.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.*; |
| | | 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.IntegralListVO; |
| | | import com.ruoyi.other.vo.IntegralVO; |
| | | import com.ruoyi.other.vo.ServiceListVO; |
| | | import com.ruoyi.other.vo.ServiceVO; |
| | | 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 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; |
| | | |
| | | /** |
| | |
| | | private WechatPayService wechatPayService; |
| | | @Resource |
| | | private TServicePayService servicePayService; |
| | | @Resource |
| | | private SiteClient siteClient; |
| | | // 查询服务费缴纳情况 |
| | | @GetMapping("/getServiceStatus/{userId}") |
| | | public R<String> getServiceStatus(@PathVariable("userId") Integer userId) { |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | 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 = "服务费管理") |
| | | @ApiOperation(tags = {"2.0-服务费"},value = "服务费管理") |
| | | public R<ServiceVO> integralPageList(@RequestBody ServiceListQuery query) { |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | R<SysUser> sysUser = sysUserClient.getSysUser(userid); |
| | |
| | | ServicePay servicePayBefore = servicePayService.lambdaQuery() |
| | | .eq(ServicePay::getUserId, userid) |
| | | .eq(ServicePay::getPayStatus,2) |
| | | .eq(ServicePay::getDelFlag,0) |
| | | .orderByDesc(ServicePay::getCreateTime) |
| | | .last("limit 1") |
| | | .one(); |
| | |
| | | } |
| | | @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"))){ |
| | | 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 nativePay(@RequestParam("amount") String amount) throws Exception { |
| | | @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, amount, "服务费缴纳", "/other/wx/serviceCallback"); |
| | | Map<String,String> res = wechatPayService.unifiedOrder(code, site.getAnnualServiceFee()+"", "服务费缴纳", "/other/wx/serviceCallback"); |
| | | ServicePay servicePay = new ServicePay(); |
| | | servicePay.setUserId(data.getUserId()); |
| | | servicePay.setAmount(new BigDecimal( amount)); |
| | | servicePay.setAmount(site.getAnnualServiceFee()); |
| | | servicePay.setCode(code); |
| | | servicePay.setPayStatus(1); |
| | | servicePay.setPayType(1); |
| | |
| | | MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG"); |
| | | String s = ObsUploadUtil.obsUpload(blueFile); |
| | | System.err.println(s); |
| | | return R.ok(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()+"", "服务费缴纳",data.getOpenId(), "/other/wx/serviceCallback"); |
| | | } |
| | | public static MultipartFile convert(BufferedImage bufferedImage, String fileName) throws IOException { |
| | | // 将 BufferedImage 转换为字节数组 |