diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/order/OrderPayRequest.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/order/OrderPayRequest.java index e63c17514..82225c02a 100644 --- a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/order/OrderPayRequest.java +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/order/OrderPayRequest.java @@ -46,4 +46,6 @@ public class OrderPayRequest { @Schema(description = "下单时小程序的场景值") private Integer scene; + @Schema(description = "openid") + private String openid; } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java index c06b5a5cf..1f5b58e37 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java @@ -21,7 +21,7 @@ import java.util.Map; * @version: V1.0.0 */ @Slf4j -@RequestMapping("notify/ali") +@RequestMapping("notify/ali/") @RestController @Tag(name = "支付宝支付回调 - 订单支付") public class AliPayNotifyController { diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/dal/mysql/express/ExpressMapper.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/dal/mysql/express/ExpressMapper.java new file mode 100644 index 000000000..90979affb --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/dal/mysql/express/ExpressMapper.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.module.shop.dal.mysql.express; + +import cn.iocoder.yudao.module.shop.dal.dataobject.express.ExpressDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ExpressMapper extends BaseMapper { + +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/express/ExpressService.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/express/ExpressService.java new file mode 100644 index 000000000..8e579b951 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/express/ExpressService.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.shop.service.express; + +import cn.iocoder.yudao.module.shop.dal.dataobject.express.ExpressDO; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +/** + * ExpressService 接口 + * +---------------------------------------------------------------------- + * | CRMEB [ CRMEB赋能开发者,助力企业发展 ] + * +---------------------------------------------------------------------- + * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 + * +---------------------------------------------------------------------- + * | Author: CRMEB Team + * +---------------------------------------------------------------------- + */ +@Service +@Validated +public interface ExpressService { + + /** + * 查询快递公司 + * @param code 快递公司编号 + * @return ExpressDO + */ + ExpressDO getByCode(String code); + +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/express/impl/ExpressServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/express/impl/ExpressServiceImpl.java new file mode 100644 index 000000000..4d71df0b3 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/express/impl/ExpressServiceImpl.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.shop.service.express.impl; + + +import cn.iocoder.yudao.module.shop.dal.dataobject.express.ExpressDO; +import cn.iocoder.yudao.module.shop.dal.mysql.express.ExpressMapper; +import cn.iocoder.yudao.module.shop.service.express.ExpressService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +public class ExpressServiceImpl implements ExpressService { + + @Resource + private ExpressMapper dao; + /** + * 查询快递公司 + * @param code 快递公司编号 + */ + @Override + public ExpressDO getByCode(String code) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(ExpressDO::getCode, code); + ExpressDO expressDO = dao.selectOne(lqw); + return expressDO; + } +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/OrderPayServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/OrderPayServiceImpl.java index 57571ca00..09a5b7e22 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/OrderPayServiceImpl.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/OrderPayServiceImpl.java @@ -5,6 +5,8 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.Constants; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration; +import cn.iocoder.yudao.framework.pay.properties.WxPayProperties; import cn.iocoder.yudao.module.infra.api.config.ApiConfigApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserBillDTO; @@ -22,12 +24,17 @@ import cn.iocoder.yudao.module.shop.service.product.StoreProductService; import cn.iocoder.yudao.module.shop.utils.OrderUtil; import cn.iocoder.yudao.module.shop.utils.RedisUtil; import cn.iocoder.yudao.module.shop.vo.order.WxPayJsResultVo; +import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request; +import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result; +import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; +import com.github.binarywang.wxpay.service.WxPayService; import lombok.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.support.TransactionTemplate; +import org.springframework.util.Assert; import java.math.BigDecimal; import java.util.HashMap; @@ -86,6 +93,12 @@ public class OrderPayServiceImpl implements OrderPayService { @Autowired private ApiConfigApi apiConfigApi; + @Autowired + private WxPayOneAutoConfiguration wxPayOneAutoConfiguration; + + @Autowired + private WxPayProperties payProperties; + /** * 支付成功处理 @@ -104,7 +117,7 @@ public class OrderPayServiceImpl implements OrderPayService { // billList.add(userBill); // 更新用户下单数量 - // user.setPayCount(user.getPayCount() + 1); + // user.setPayCount(user.getPayCount() + 1); Boolean execute = transactionTemplate.execute(e -> { @@ -135,6 +148,7 @@ public class OrderPayServiceImpl implements OrderPayService { /** * 余额支付 + * * @param storeOrder 订单 * @return Boolean Boolean */ @@ -191,7 +205,7 @@ public class OrderPayServiceImpl implements OrderPayService { storeOrder.setIsChannel(3); } if (orderPayRequest.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) { - switch (orderPayRequest.getPayChannel()){ + switch (orderPayRequest.getPayChannel()) { case PayConstants.PAY_CHANNEL_WE_CHAT_H5:// H5 storeOrder.setIsChannel(2); break; @@ -229,7 +243,7 @@ public class OrderPayServiceImpl implements OrderPayService { // 微信支付,调用微信预下单,返回拉起微信支付需要的信息 if (storeOrder.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) { // 预下单 - Map unifiedorder = unifiedorder(storeOrder, ip); + Map unifiedorder = unifiedorder(storeOrder, ip, orderPayRequest.getOpenid()); response.setStatus(true); WxPayJsResultVo vo = new WxPayJsResultVo(); vo.setAppId(unifiedorder.get("appId")); @@ -266,11 +280,12 @@ public class OrderPayServiceImpl implements OrderPayService { /** * 预下单 + * * @param storeOrder 订单 - * @param ip ip + * @param ip ip * @return 预下单返回对象 */ - private Map unifiedorder(StoreOrder storeOrder, String ip) { + private Map unifiedorder(StoreOrder storeOrder, String ip,String openid) { // 获取用户openId // 根据订单支付类型来判断获取公众号openId还是小程序openId @@ -314,6 +329,25 @@ public class OrderPayServiceImpl implements OrderPayService { // if (storeOrder.getIsChannel() == 2) { // map.put("mweb_url", responseVo.getMWebUrl()); // } + + WxPayService wxPayService = wxPayOneAutoConfiguration.wxPayOneService(); + Assert.notNull(wxPayService, "获取微信支付配置失败!"); + WxPayUnifiedOrderV3Request wxPayRequest = new WxPayUnifiedOrderV3Request(); + int sum = storeOrder.getPayPrice().multiply(new BigDecimal("100")).intValue(); + wxPayRequest.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(sum)); + wxPayRequest.setDescription("会员充值"); + wxPayRequest.setOutTradeNo(storeOrder.getOrderId()); + wxPayRequest.setNotifyUrl(payProperties.getNotifyUrl()); + wxPayRequest.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(openid)); + wxPayRequest.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(ip)); + wxPayRequest.setAppid(payProperties.getAppId()); + wxPayRequest.setMchid(payProperties.getMchId()); + try { + WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = wxPayService.unifiedOrderV3(TradeTypeEnum.JSAPI, wxPayRequest); + map.put("mweb_url",wxPayUnifiedOrderV3Result.getH5Url()); + } catch (Exception e) { + e.getMessage(); + } return map; } } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java index 0aece763b..fa46ed6af 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java @@ -13,8 +13,10 @@ import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.pay.properties.AliPayProperties; import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.infra.api.config.ApiConfigApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.shop.dal.dataobject.express.ExpressDO; import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder; import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.PhoneRecordDO; import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; @@ -31,6 +33,8 @@ import cn.iocoder.yudao.module.shop.request.order.StoreOrderSendRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderUpdatePriceRequest; import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; import cn.iocoder.yudao.module.shop.response.order.*; +import cn.iocoder.yudao.module.shop.service.express.ExpressService; +import cn.iocoder.yudao.module.shop.service.onepass.OnePassService; import cn.iocoder.yudao.module.shop.service.order.StoreOrderInfoService; import cn.iocoder.yudao.module.shop.service.order.StoreOrderRefundService; import cn.iocoder.yudao.module.shop.service.order.StoreOrderService; @@ -43,12 +47,12 @@ import cn.iocoder.yudao.module.shop.utils.RedisUtil; import cn.iocoder.yudao.module.shop.vo.order.LogisticsResultVo; import cn.iocoder.yudao.module.shop.vo.order.StoreDateRangeSqlPram; import cn.iocoder.yudao.module.shop.vo.order.StoreOrderInfoOldVo; +import cn.iocoder.yudao.module.shop.vo.product.MyRecord; import com.alipay.api.AlipayApiException; import com.alipay.api.internal.util.AlipaySignature; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result; @@ -69,7 +73,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -126,6 +129,15 @@ public class StoreOrderServiceImpl extends ServiceImpl { updateById(storeOrder); @@ -1490,6 +1502,56 @@ public class StoreOrderServiceImpl extends ServiceImpl orderIdList = new ArrayList<>(); +// orderIdList.add(storeOrder.getId()); +// HashMap> orderInfoMap = StoreOrderInfoService.getMapInId(orderIdList); +// if (orderInfoMap.isEmpty() || !orderInfoMap.containsKey(storeOrder.getId())) { +// throw new ServiceException("没有找到购买的商品信息"); +// } +// List productNameList = new ArrayList<>(); +// for (StoreOrderInfoOldVo storeOrderInfoVo : orderInfoMap.get(storeOrder.getId())) { +// productNameList.add(storeOrderInfoVo.getInfo().getProductName()); +// } +// +// record.set("cargo", String.join(",", productNameList));// 物品名称 +// if (express.getPartnerId()) { +// record.set("partner_id", express.getAccount());// 电子面单月结账号(部分快递公司必选) +// } +// if (express.getPartnerKey()) { +// record.set("partner_key", express.getPassword());// 电子面单密码(部分快递公司必选) +// } +// if (express.getNet()) { +// record.set("net", express.getNetName());// 收件网点名称(部分快递公司必选) +// } +// +// MyRecord myRecord = onePassService.expressDump(record); +// storeOrder.setDeliveryId(myRecord.getStr("kuaidinum")); +// } /** * 校验快递发货参数 */ @@ -1500,7 +1562,7 @@ public class StoreOrderServiceImpl extends ServiceImpl