From b76a3ff7ab495640704a7820cd6bf1fe2ba639c4 Mon Sep 17 00:00:00 2001 From: kino <378907426@qq.com> Date: Sat, 16 Jan 2021 11:54:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=BB=9F=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=E5=8D=95=20=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../winery/WineryOrdersController.java | 169 ++++++++++++------ .../winery/domain/winery/WineryOrders.java | 29 +++ 2 files changed, 142 insertions(+), 56 deletions(-) diff --git a/hope-winery/src/main/java/com/ruoyi/winery/controller/winery/WineryOrdersController.java b/hope-winery/src/main/java/com/ruoyi/winery/controller/winery/WineryOrdersController.java index 359d1643c..22f710b02 100644 --- a/hope-winery/src/main/java/com/ruoyi/winery/controller/winery/WineryOrdersController.java +++ b/hope-winery/src/main/java/com/ruoyi/winery/controller/winery/WineryOrdersController.java @@ -2,82 +2,85 @@ package com.ruoyi.winery.controller.winery; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; - -import java.util.List; -import java.util.Arrays; - -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.winery.domain.goods.GoodsSpec; -import lombok.RequiredArgsConstructor; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; +import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; +import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; +import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.WxPayService; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.winery.domain.winery.WineryOrders; import com.ruoyi.winery.service.IWineryOrdersService; -import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.common.core.page.TableDataInfo; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.util.*; + +import static com.ruoyi.common.core.domain.AjaxResult.error; +import static com.ruoyi.common.core.domain.AjaxResult.success; import static com.ruoyi.common.utils.SecurityUtils.*; /** * 客户订单Controller - * + * * @author ruoyi * @date 2020-12-28 */ @RequiredArgsConstructor(onConstructor_ = @Autowired) @RestController -@RequestMapping("/winery/user_orders" ) +@RequestMapping("/winery/user_orders") public class WineryOrdersController extends BaseController { private final IWineryOrdersService iWineryOrdersService; + @Autowired + private WxPayService wxPayService; + /** * 查询客户订单列表 */ @PreAuthorize("@ss.hasPermi('winery:user_orders:list')") @GetMapping("/list") - public TableDataInfo list(WineryOrders wineryOrders) - { + public TableDataInfo list(WineryOrders wineryOrders) { startPage(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(wineryOrders); lqw.eq(!isAdmin(), WineryOrders::getDeptId, getDeptId()); - if (wineryOrders.getGoodsId() != null){ - lqw.eq(WineryOrders::getGoodsId ,wineryOrders.getGoodsId()); + if (wineryOrders.getGoodsId() != null) { + lqw.eq(WineryOrders::getGoodsId, wineryOrders.getGoodsId()); } - if (StringUtils.isNotBlank(wineryOrders.getGoodsName())){ - lqw.like(WineryOrders::getGoodsName ,wineryOrders.getGoodsName()); + if (StringUtils.isNotBlank(wineryOrders.getGoodsName())) { + lqw.like(WineryOrders::getGoodsName, wineryOrders.getGoodsName()); } - if (StringUtils.isNotBlank(wineryOrders.getGoodsType())){ - lqw.eq(WineryOrders::getGoodsType ,wineryOrders.getGoodsType()); + if (StringUtils.isNotBlank(wineryOrders.getGoodsType())) { + lqw.eq(WineryOrders::getGoodsType, wineryOrders.getGoodsType()); } - if (StringUtils.isNotBlank(wineryOrders.getGoodsSpec())){ - lqw.eq(WineryOrders::getGoodsSpec ,wineryOrders.getGoodsSpec()); + if (StringUtils.isNotBlank(wineryOrders.getGoodsSpec())) { + lqw.eq(WineryOrders::getGoodsSpec, wineryOrders.getGoodsSpec()); } - if (StringUtils.isNotBlank(wineryOrders.getGoodsFaceImg())){ - lqw.eq(WineryOrders::getGoodsFaceImg ,wineryOrders.getGoodsFaceImg()); + if (StringUtils.isNotBlank(wineryOrders.getGoodsFaceImg())) { + lqw.eq(WineryOrders::getGoodsFaceImg, wineryOrders.getGoodsFaceImg()); } - if (wineryOrders.getGoodsPrice() != null){ - lqw.eq(WineryOrders::getGoodsPrice ,wineryOrders.getGoodsPrice()); + if (wineryOrders.getGoodsPrice() != null) { + lqw.eq(WineryOrders::getGoodsPrice, wineryOrders.getGoodsPrice()); } - if (wineryOrders.getGoodsCount() != null){ - lqw.eq(WineryOrders::getGoodsCount ,wineryOrders.getGoodsCount()); + if (wineryOrders.getGoodsCount() != null) { + lqw.eq(WineryOrders::getGoodsCount, wineryOrders.getGoodsCount()); } - if (wineryOrders.getOrderStatus() != null){ - lqw.eq(WineryOrders::getOrderStatus ,wineryOrders.getOrderStatus()); + if (wineryOrders.getOrderStatus() != null) { + lqw.eq(WineryOrders::getOrderStatus, wineryOrders.getOrderStatus()); } List list = iWineryOrdersService.list(lqw); return getDataTable(list); @@ -86,42 +89,69 @@ public class WineryOrdersController extends BaseController { /** * 导出客户订单列表 */ - @PreAuthorize("@ss.hasPermi('winery:user_orders:export')" ) - @Log(title = "客户订单" , businessType = BusinessType.EXPORT) - @GetMapping("/export" ) + @PreAuthorize("@ss.hasPermi('winery:user_orders:export')") + @Log(title = "客户订单", businessType = BusinessType.EXPORT) + @GetMapping("/export") public AjaxResult export(WineryOrders wineryOrders) { LambdaQueryWrapper lqw = new LambdaQueryWrapper(wineryOrders); List list = iWineryOrdersService.list(lqw); - ExcelUtil util = new ExcelUtil(WineryOrders. class); - return util.exportExcel(list, "user_orders" ); + ExcelUtil util = new ExcelUtil(WineryOrders.class); + return util.exportExcel(list, "user_orders"); } /** * 获取客户订单详细信息 */ - @PreAuthorize("@ss.hasPermi('winery:user_orders:query')" ) - @GetMapping(value = "/{id}" ) - public AjaxResult getInfo(@PathVariable("id" ) Long id) { + @PreAuthorize("@ss.hasPermi('winery:user_orders:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) { return AjaxResult.success(iWineryOrdersService.getById(id)); } /** * 新增客户订单 */ - @PreAuthorize("@ss.hasPermi('winery:user_orders:add')" ) - @Log(title = "客户订单" , businessType = BusinessType.INSERT) + @PreAuthorize("@ss.hasPermi('winery:user_orders:add')") + @Log(title = "客户订单", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody WineryOrders wineryOrders) { + public AjaxResult add(@RequestBody WineryOrders wineryOrders, HttpServletRequest req) { wineryOrders.setCreateBy(getUsername()); wineryOrders.setDeptId(getDeptId()); - return toAjax(iWineryOrdersService.save(wineryOrders) ? 1 : 0); + + // 统一下单 + WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); + request.setTotalFee(wineryOrders.getGoodsPrice().multiply(new BigDecimal(100)).intValue()); + request.setBody(wineryOrders.getGoodsName()); + String outTradeNo = UUID.randomUUID().toString().replace("-", ""); + request.setOutTradeNo(outTradeNo); + request.setNotifyUrl(""); + request.setTradeType("JSAPI"); + String userName = getLoginUser().getUser().getUserName(); + String openId = ""; + if (userName.contains("mini-")) { + openId = userName.split(",")[1]; + } + request.setOpenid(openId); + + Map map = new HashMap<>(); + try { + map.put("orderId", wineryOrders.getId()); + Objects payMsg = wxPayService.createOrder(request); + map.put("payMsg", payMsg); + wineryOrders.setPayMsg(payMsg.toString()); + iWineryOrdersService.save(wineryOrders); + return success("success", map); + } catch (WxPayException e) { + e.printStackTrace(); + return error(); + } } /** * 修改客户订单 */ - @PreAuthorize("@ss.hasPermi('winery:user_orders:edit')" ) - @Log(title = "客户订单" , businessType = BusinessType.UPDATE) + @PreAuthorize("@ss.hasPermi('winery:user_orders:edit')") + @Log(title = "客户订单", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody WineryOrders wineryOrders) { wineryOrders.setUpdateBy(getUsername()); @@ -131,10 +161,37 @@ public class WineryOrdersController extends BaseController { /** * 删除客户订单 */ - @PreAuthorize("@ss.hasPermi('winery:user_orders:remove')" ) - @Log(title = "客户订单" , businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}" ) + @PreAuthorize("@ss.hasPermi('winery:user_orders:remove')") + @Log(title = "客户订单", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(iWineryOrdersService.removeByIds(Arrays.asList(ids)) ? 1 : 0); } + + @Log(title = "回调", businessType = BusinessType.OTHER) + @PostMapping("/payNotify") + String payNotify(@RequestBody String xmlData) throws WxPayException { + WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData); + // TODO 根据自己业务场景需要构造返回对象 + return WxPayNotifyResponse.success("成功"); + } + + @PreAuthorize("@ss.hasPermi('winery:user_orders:remove')") + @Log(title = "退款", businessType = BusinessType.OTHER) + @PostMapping("/refund") + AjaxResult refund(@PathVariable Long id) { + WineryOrders order = iWineryOrdersService.getById(id); + WxPayRefundRequest request = new WxPayRefundRequest(); + request.setRefundFee(order.getGoodsPrice().intValue()); + request.setTotalFee(order.getGoodsPrice().intValue()); + request.setOutTradeNo(order.getOutTradeNo()); + WxPayRefundResult refund = null; + try { + refund = wxPayService.refund(request); + return AjaxResult.success(refund); + } catch (WxPayException e) { + e.printStackTrace(); + return error(); + } + } } diff --git a/hope-winery/src/main/java/com/ruoyi/winery/domain/winery/WineryOrders.java b/hope-winery/src/main/java/com/ruoyi/winery/domain/winery/WineryOrders.java index 15695dfca..4796ff66e 100644 --- a/hope-winery/src/main/java/com/ruoyi/winery/domain/winery/WineryOrders.java +++ b/hope-winery/src/main/java/com/ruoyi/winery/domain/winery/WineryOrders.java @@ -82,6 +82,35 @@ public class WineryOrders implements Serializable { @Excel(name = "商品基准单价") private BigDecimal goodsPrice; + /** + * 统一订单号 + */ + @Excel(name = "统一订单号") + private String outTradeNo; + + /** + * 统一退款号 + */ + @Excel(name = "统一退款号") + private String outRefundNo; + + /** + * 支付参数 + */ + private String payMsg; + + /** + * 取消时间 + */ + @Excel(name = "取消时间") + private Date cancelTime; + + /** + * 退款时间 + */ + @Excel(name = "退款时间") + private Date refundTime; + /** * 商品数量 */