diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/entity/RepairOrderInfo.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/entity/RepairOrderInfo.java index f72928e0..84c1e02d 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/entity/RepairOrderInfo.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/entity/RepairOrderInfo.java @@ -162,4 +162,4 @@ public class RepairOrderInfo extends TenantBaseDO { private String activeId; -} \ No newline at end of file +} diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java index d28d0cec..2c895981 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java @@ -112,4 +112,6 @@ public interface RepairOrderInfoService extends IService { * @return */ Map payTransactions(String orderId); + + } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java index 8ade533c..42562e9c 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java @@ -25,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; @@ -196,7 +197,7 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl amountMap = new HashMap<>(4); // 金额单位为分 - amountMap.put("total", orderInfo.getPayMoney()); + amountMap.put("total", orderInfo.getPayMoney().multiply(BigDecimal.valueOf(100L)).intValue()); //人民币 amountMap.put("currency", "CNY"); params.put("amount", amountMap); diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/ClientOrderApi.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/ClientOrderApi.java new file mode 100644 index 00000000..b50f0e8d --- /dev/null +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/ClientOrderApi.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.app.apy; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; +import cn.iocoder.yudao.module.order.entity.RepairOrderInfo; +import cn.iocoder.yudao.module.order.service.RepairOrderInfoService; +import cn.iocoder.yudao.module.order.vo.RepairOrderInfoRespVO; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户端 - 维修模块 订单模块") +@RestController +@RequestMapping("/userClient/order") +@Validated +public class ClientOrderApi { + @Resource + private RepairOrderInfoService repairOrderInfoService; + @GetMapping("/page") + @Operation(summary = "订单分页查询") + @TenantIgnore + public CommonResult getOrderPage(RepairOrderInfoRespVO respVO, + @RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){ + // 当前登录用户的id + Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); + respVO.setUserId(loginUserId); + Page page = new Page<>(pageNo, pageSize); + return success(repairOrderInfoService.getOrderPageByStatus(respVO, page)); + } +} diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java index dbdde9bc..92de6798 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java @@ -1,15 +1,21 @@ package cn.iocoder.yudao.module.app.apy; +import cn.hutool.json.JSONUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; import cn.iocoder.yudao.module.order.service.RepairOrderInfoService; +import cn.iocoder.yudao.util.WechatPayConfig; +import com.alibaba.fastjson.JSONObject; +import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -20,16 +26,50 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; public class RepairPayApi { @Resource private RepairOrderInfoService repairOrderInfoService; - + @Resource + private WechatPayConfig wechatPayConfig; /** * 支付吊起接口 * @param orderId 订单主键 * @return */ @GetMapping("/toPay") + @TenantIgnore public CommonResult> payTransactions(String orderId){ Map res = repairOrderInfoService.payTransactions(orderId); return success(res); } + private final ReentrantLock lock = new ReentrantLock(); + @PostMapping("/payNotify") + public Map payNotify(@RequestBody JSONObject jsonObject) { + try { + String key = wechatPayConfig.getApiV3Key(); + String json = jsonObject.toString(); + String associated_data = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.associated_data"); + String ciphertext = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.ciphertext"); + String nonce = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.nonce"); + String decryptData = new AesUtil(key.getBytes(StandardCharsets.UTF_8)).decryptToString(associated_data.getBytes(StandardCharsets.UTF_8), nonce.getBytes(StandardCharsets.UTF_8), ciphertext); + //验签成功 + JSONObject decryptDataObj = JSONObject.parseObject(decryptData, JSONObject.class); + if(lock.tryLock()) { + try { + String orderNo = decryptDataObj.get("out_trade_no").toString(); + repairOrderInfoService.rechargeCallback(orderNo); + } catch (Exception ignored){ + + } finally{ + //要主动释放锁 + lock.unlock(); + } + } + }catch (Exception ignored){ + + } + + Map res = new HashMap<>(); + res.put("code", "SUCCESS"); + res.put("message", "成功"); + return res; + } }