| @@ -32,6 +32,16 @@ public class AppTest { | |||
| * 注册并查询用户详细信息 参数 | |||
| */ | |||
| // paramMap.put("phone","18872592633"); | |||
| // paramMap.put("nickName","周小菇凉"); | |||
| // paramMap.put("sex","1"); | |||
| // paramMap.put("avatarUrl",""); | |||
| /** | |||
| * 查询用户详细信息 参数 | |||
| */ | |||
| // paramMap.put("phone","18872592633"); | |||
| paramMap.put("openId","opvcM5A41kbQF_NY8k3LMDqxCDUM"); | |||
| /** | |||
| * 创建交易信息 参数 | |||
| @@ -59,15 +69,15 @@ public class AppTest { | |||
| /** | |||
| * 积分抵扣 参数 | |||
| */ | |||
| IdWorker idWorker = IdWorker.get(); | |||
| paramMap.put("transactionId",String.valueOf(idWorker.nextId()));//***订单Id | |||
| paramMap.put("shopNumber","1001");//***门店唯一标识 对应双方平台门店 | |||
| paramMap.put("shopName","百丽");//门店名称 | |||
| paramMap.put("userNumber","546907706202185728");//***会员Id546907706202185728 | |||
| paramMap.put("userPhone","18872592633");//会员手机号 | |||
| paramMap.put("timeEnd","2021-04-26 11:43:00");//***积分抵扣时间 | |||
| paramMap.put("amount","100");//***付款金额(分) | |||
| paramMap.put("summary","我要换东西");//付款摘要 | |||
| // IdWorker idWorker = IdWorker.get(); | |||
| // paramMap.put("transactionId",String.valueOf(idWorker.nextId()));//***订单Id | |||
| // paramMap.put("shopNumber","1001");//***门店唯一标识 对应双方平台门店 | |||
| // paramMap.put("shopName","百丽");//门店名称 | |||
| // paramMap.put("userNumber","546907706202185728");//***会员Id546907706202185728 | |||
| // paramMap.put("userPhone","18872592633");//会员手机号 | |||
| // paramMap.put("timeEnd","2021-04-26 11:43:00");//***积分抵扣时间 | |||
| // paramMap.put("amount","100");//***付款金额(分) | |||
| // paramMap.put("summary","我要换东西");//付款摘要 | |||
| /** | |||
| @@ -83,6 +93,12 @@ public class AppTest { | |||
| */ | |||
| // String s = HttpUtil.doPost("https://openapitest.malls.iformall.com/api/userInfo/register", headMap, JSON.toJSONString(paramMap)); | |||
| /** | |||
| * 注册并查询用户详细信息 接口 | |||
| */ | |||
| String s = HttpUtil.doPost("https://openapitest.malls.iformall.com/api/userInfo/get", headMap, JSON.toJSONString(paramMap)); | |||
| /** | |||
| * 创建交易信息 接口 | |||
| */ | |||
| @@ -96,7 +112,7 @@ public class AppTest { | |||
| /** | |||
| * 交易退款 接口 | |||
| */ | |||
| String s = HttpUtil.doPost("https://openapitest.malls.iformall.com/api/thirdCircle/pointDeduction", headMap, JSON.toJSONString(paramMap)); | |||
| // String s = HttpUtil.doPost("https://openapitest.malls.iformall.com/api/thirdCircle/pointDeduction", headMap, JSON.toJSONString(paramMap)); | |||
| System.out.println(s); | |||
| @@ -0,0 +1,42 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumTtOrderStatus { | |||
| ORDER_STATUS_PENDING_PAYMENT(0, "待付款"), | |||
| ORDER_STATUS_PAYMENT_ING(1,"支付中"), | |||
| ORDER_STATUS_PAYMENT_SUCCESS(1, "已支付"), | |||
| ORDER_STATUS_OVERTIME_CANCEL(2, "已取消"), | |||
| ORDER_STATUS_PENDING_REFUND(3, "待退款"), | |||
| ORDER_STATUS_REFUND_SUCCESS(4,"已退款"), | |||
| ORDER_STATUS_REFUND_FAILD(5, "退款失败"), | |||
| ; | |||
| public static EnumTtOrderStatus getEnum(Integer code) { | |||
| for (EnumTtOrderStatus value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumTtOrderStatus(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -3,6 +3,7 @@ package com.iformall.service.tt; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.OrderSaveDto; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.tt.TtOrder; | |||
| import com.iformall.enums.EnumPayWay; | |||
| @@ -24,4 +25,8 @@ public interface TtOrderService { | |||
| ResultData cancelOrder(Long orderId, Long memberId); | |||
| TtOrder detail(Long orderId, Long memberId); | |||
| ResultData createPay(TenantEntity tenantEntity,Long orderId, Long memberId, WxAppinfo appinfo); | |||
| ResultData updateOrderStatus(TenantEntity tenantInfo, Long orderId, Long memberId, WxAppinfo cAppInfo); | |||
| } | |||
| @@ -9,9 +9,14 @@ import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.tt.TtCoupon; | |||
| import com.iformall.domain.po.tt.TtOrder; | |||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||
| import com.iformall.douyin.pay.orderQuery.OrderQueryResult; | |||
| import com.iformall.douyin.pay.preOrder.CreatePreOrderResult; | |||
| import com.iformall.douyin.pay.preOrder.DouYinCreatePreOrder; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.tt.TtCouponService; | |||
| import com.iformall.service.tt.TtOrderService; | |||
| @@ -28,6 +33,8 @@ public class TtOrderServiceImpl implements TtOrderService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| private final Integer time_out = 30*60; | |||
| @Autowired | |||
| private TtOrderMapper ttOrderMapper; | |||
| @@ -37,6 +44,9 @@ public class TtOrderServiceImpl implements TtOrderService { | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @Autowired | |||
| private WxAppinfoService wxAppinfoService; | |||
| @Override | |||
| public PageInfo<TtOrder> listAsPage(TtOrder record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> ttOrderMapper.findList(record)); | |||
| @@ -53,8 +63,8 @@ public class TtOrderServiceImpl implements TtOrderService { | |||
| orderQ.setCUserId(cUserId); | |||
| orderQ.setProductId(couponId); | |||
| List<Integer> statuss = new ArrayList<>(); | |||
| statuss.add(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
| statuss.add(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| statuss.add(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
| statuss.add(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| orderQ.setStatusS(statuss); | |||
| Integer listCount = ttOrderMapper.findListCount(orderQ); | |||
| if(listCount.intValue() > 0){ | |||
| @@ -72,6 +82,9 @@ public class TtOrderServiceImpl implements TtOrderService { | |||
| if (!coupon.getStatus().equals(EnumTtCouponStatus.TTCOUPON_STATUS_SHELFING.getCode())) { | |||
| return new ResultData(ErrorCode.TTCOUPON_IS_TAKE_OFF); | |||
| } | |||
| if(coupon.getSalePrice() == null || coupon.getSalePrice().intValue() == 0){ | |||
| return new ResultData(ErrorCode.TTCOUPON_IS_TAKE_OFF); | |||
| } | |||
| try { | |||
| // 4.2 保存订单 | |||
| @@ -86,10 +99,10 @@ public class TtOrderServiceImpl implements TtOrderService { | |||
| order.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||
| order.setPayment(coupon.getSalePrice()); | |||
| if(order.getPayment() == null || order.getPayment().intValue() == 0){ | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| order.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| order.setPaymentTime(now); | |||
| }else{ | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
| order.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
| } | |||
| order.setCreateDate(now); | |||
| order.setUpdateDate(now); | |||
| @@ -113,27 +126,27 @@ public class TtOrderServiceImpl implements TtOrderService { | |||
| if(memberId != null && !ttOrder.getCUserId().equals(memberId)){ | |||
| return new ResultData(ErrorCode.ORDER_USER_NOT_MATCH); | |||
| } | |||
| if(ttOrder.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode())){//订单待付款 | |||
| if(ttOrder.getOrderStatus().equals(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode())){//订单待付款 | |||
| TtOrder record = new TtOrder(); | |||
| record.setId(ttOrder.getId()); | |||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
| record.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
| record.setUpdateDate(new Date()); | |||
| ttOrderMapper.updateById(record); | |||
| return new ResultData(); | |||
| }else | |||
| if(ttOrder.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode())){//订单已支付 | |||
| if(ttOrder.getOrderStatus().equals(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode())){//订单已支付 | |||
| return new ResultData(ErrorCode.ORDER_HAD_PAY); | |||
| }else | |||
| if(ttOrder.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode())){//订单已取消 | |||
| if(ttOrder.getOrderStatus().equals(EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode())){//订单已取消 | |||
| return new ResultData(ErrorCode.ORDER_HAD_CANCEL); | |||
| }else | |||
| if(ttOrder.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_PENDING_REFUND.getCode())){//订单待退款 | |||
| if(ttOrder.getOrderStatus().equals(EnumTtOrderStatus.ORDER_STATUS_PENDING_REFUND.getCode())){//订单待退款 | |||
| return new ResultData(ErrorCode.ORDER_PAY_IN_REFUND); | |||
| }else | |||
| if(ttOrder.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode())){//订单已退款 | |||
| if(ttOrder.getOrderStatus().equals(EnumTtOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode())){//订单已退款 | |||
| return new ResultData(ErrorCode.ORDER_PAY_REFUND); | |||
| }else | |||
| if(ttOrder.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_REFUND_FAILD.getCode())){//订单退款失败 | |||
| if(ttOrder.getOrderStatus().equals(EnumTtOrderStatus.ORDER_STATUS_REFUND_FAILD.getCode())){//订单退款失败 | |||
| return new ResultData(ErrorCode.ORDER_PAY_REFUND_FAIL); | |||
| } | |||
| return new ResultData(ErrorCode.ORDER_IS_FAIL); | |||
| @@ -153,4 +166,138 @@ public class TtOrderServiceImpl implements TtOrderService { | |||
| return ttOrder; | |||
| } | |||
| @Override | |||
| public ResultData createPay(TenantEntity tenantEntity,Long orderId, Long memberId, WxAppinfo appInfo) { | |||
| TtOrder order = ttOrderMapper.selectById(orderId); | |||
| if (null == order) { | |||
| logger.error("pay order, order not allow, orderId: " + orderId); | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| } | |||
| if(!order.getCUserId().equals(memberId)){ | |||
| return new ResultData(ErrorCode.ORDER_USER_NOT_MATCH); | |||
| } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(memberId,tenantEntity.getFinalTenantId()); | |||
| if ( null == wxCUserBasicInfo) { | |||
| logger.error("会员用户不存在."+memberId); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(),"会员用户不存在."+memberId); | |||
| } | |||
| if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| // WxAppinfo appInfo = wxAppinfoService.getByAppId(appId); | |||
| if(appInfo == null) { | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| TtCoupon coupon = ttCouponService.getById(order.getProductId()); | |||
| if (!coupon.getStatus().equals(EnumTtCouponStatus.TTCOUPON_STATUS_SHELFING.getCode())) { | |||
| logger.error("券已经下架了>>>" + order.getProductId()); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | |||
| } | |||
| if (order.getPaymentType() != EnumPayType.PAY_PAYMENT.getCode()) { | |||
| return new ResultData(ErrorCode.PAY_ORDER_IS_NOT_PAYMENT); | |||
| } | |||
| if (order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()) { | |||
| logger.error("订单已支付: " + order.toString()); | |||
| return new ResultData(ErrorCode.ORDER_HAD_PAY); | |||
| } else if (order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()) { | |||
| logger.error("订单已取消: " + order.toString()); | |||
| return new ResultData(ErrorCode.ORDER_HAD_CANCEL); | |||
| } else if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PAYMENT_ING.getCode()){ | |||
| logger.info("订单支付中: " + order.toString()); | |||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), appInfo.getSecret(), order.getId().toString(), null); | |||
| String trade_state = orderQueryResult.getOrderStatus(); | |||
| if ("PROCESSING".equals(trade_state)) {//处理中 | |||
| return new ResultData(ErrorCode.PAY_ORDER_PAYING); | |||
| }else if ("SUCCESS".equals(trade_state)) {//成功 | |||
| TtOrder orderSuc = new TtOrder(); | |||
| orderSuc.setId(order.getId()); | |||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| orderSuc.setUpdateDate(new Date()); | |||
| ttOrderMapper.updateById(orderSuc); | |||
| return new ResultData(ErrorCode.PAY_ORDER_EXIST,"该订单已经支付,请勿重复支付!"); | |||
| }else if ("FAIL".equals(trade_state)) {//失败 | |||
| }else if ("TIMEOUT".equals(trade_state)) {//超时 | |||
| } | |||
| } else{ | |||
| if (order.getOrderStatus() != EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()) { | |||
| logger.error("订单已支付: " + order.toString()); | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_PAY); | |||
| } | |||
| } | |||
| DouYinCreatePreOrder preOrder = new DouYinCreatePreOrder(); | |||
| preOrder.setAppId(appInfo.getAppId()); | |||
| preOrder.setOutOrderNo(order.getId().toString()); | |||
| preOrder.setTotalAmount(order.getPayment()); | |||
| preOrder.setSubject(coupon.getTitle()); | |||
| preOrder.setBody(coupon.getTitle()); | |||
| preOrder.setValidTime(time_out); | |||
| // preOrder.setNotifyUrl();//回调地址 | |||
| CreatePreOrderResult preOrderResult = DouYinPayHelper.createPreOrder(preOrder); | |||
| if(preOrderResult.isSuccess()){ | |||
| TtOrder orderSuc = new TtOrder(); | |||
| orderSuc.setId(order.getId()); | |||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_ING.getCode()); | |||
| orderSuc.setUpdateDate(new Date()); | |||
| ttOrderMapper.updateById(orderSuc); | |||
| } | |||
| return new ResultData(preOrderResult); | |||
| } | |||
| @Override | |||
| public ResultData updateOrderStatus(TenantEntity tenantEntity, Long orderId, Long memberId, WxAppinfo appInfo) { | |||
| TtOrder order = ttOrderMapper.selectById(orderId); | |||
| if (null == order) { | |||
| logger.error("pay order, order not allow, orderId: " + orderId); | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| } | |||
| if(!order.getCUserId().equals(memberId)){ | |||
| return new ResultData(ErrorCode.ORDER_USER_NOT_MATCH); | |||
| } | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(memberId,tenantEntity.getFinalTenantId()); | |||
| if ( null == wxCUserBasicInfo) { | |||
| logger.error("会员用户不存在."+memberId); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(),"会员用户不存在."+memberId); | |||
| } | |||
| if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| // WxAppinfo appInfo = wxAppinfoService.getByAppId(appId); | |||
| if(appInfo == null) { | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PAYMENT_ING.getCode()){ | |||
| logger.info("订单支付中: " + order.toString()); | |||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), appInfo.getSecret(), order.getId().toString(), null); | |||
| String trade_state = orderQueryResult.getOrderStatus(); | |||
| if ("PROCESSING".equals(trade_state)) {//处理中 | |||
| return new ResultData(ErrorCode.PAY_ORDER_PAYING); | |||
| }else if ("SUCCESS".equals(trade_state)) {//成功 | |||
| TtOrder orderSuc = new TtOrder(); | |||
| orderSuc.setId(order.getId()); | |||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| orderSuc.setUpdateDate(new Date()); | |||
| ttOrderMapper.updateById(orderSuc); | |||
| return new ResultData(ErrorCode.PAY_ORDER_EXIST,"该订单已经支付,请勿重复支付!"); | |||
| }else if ("FAIL".equals(trade_state)) {//失败 | |||
| TtOrder orderSuc = new TtOrder(); | |||
| orderSuc.setId(order.getId()); | |||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
| orderSuc.setUpdateDate(new Date()); | |||
| ttOrderMapper.updateById(orderSuc); | |||
| }else if ("TIMEOUT".equals(trade_state)) {//超时 | |||
| TtOrder orderSuc = new TtOrder(); | |||
| orderSuc.setId(order.getId()); | |||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
| orderSuc.setUpdateDate(new Date()); | |||
| ttOrderMapper.updateById(orderSuc); | |||
| } | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -1,27 +1,14 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.OrderSaveDto; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.tt.TtOrder; | |||
| import com.iformall.domain.vo.WxCouponCVo; | |||
| import com.iformall.domain.vo.WxOrderCouponPressVo; | |||
| import com.iformall.domain.vo.WxOrderCouponVo; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.tt.TtOrderService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.RedisLock; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| @@ -30,11 +17,9 @@ import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Qualifier; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.Date; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.Map; | |||
| @RestController | |||
| @@ -47,24 +32,12 @@ public class TtOrderController extends BaseController { | |||
| @Autowired | |||
| private TtOrderService ttOrderService; | |||
| WxOrderService wxOrderService; | |||
| @Autowired | |||
| private WxCouponChannelService wxCouponChannelService; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| private WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @Autowired | |||
| @Qualifier("couponDetailRedisTemplate") | |||
| RedisTemplate<String, WxCouponCVo> cdRedisTemplate; | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| @ApiOperation("分页订单列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -164,4 +137,90 @@ public class TtOrderController extends BaseController { | |||
| return new ResultData(order); | |||
| } | |||
| /** | |||
| * tt支付 | |||
| * @param paramMap | |||
| * @param request | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| //@ApiOperation(value = "发起小程序支付订单", notes = "{\"orderId\":\"string\"}") | |||
| @RequestMapping(value = "/createPay", method = RequestMethod.POST) | |||
| public ResultData _create(@RequestBody Map<String, String> paramMap, HttpServletRequest request) throws Exception { | |||
| logger.info("/api/pay/create" + paramMap.toString()); | |||
| String orderIdStr = paramMap.get("orderId"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.info("orderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| Long orderId; | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "orderId: " + orderIdStr + ", e: " + e.getMessage()); | |||
| } | |||
| Long memberId; | |||
| try { | |||
| memberId = getMemberId(); | |||
| } catch (MallinkException e) { | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumPayWay.PAY_WAY_TT); | |||
| if(cAppInfo == null){ | |||
| return new ResultData(ErrorCode.APP_ID_NOT_ENABLE); | |||
| } | |||
| return ttOrderService.createPay(getTenantInfo(),orderId,memberId,cAppInfo); | |||
| } | |||
| @ApiOperation(value = "更新支付订单状态", notes = "{\"payOrderId\":\"string\",\"orderId\":\"string\",\"status\":integer,\"reason\":\"string\"}") | |||
| @PostMapping("/updateOrderStatus") | |||
| public ResultData updateOrderStatus(@RequestBody Map<String, Object> paramMap) { | |||
| logger.info("/api/pay/updateOrderStatus" + paramMap.toString()); | |||
| String orderIdStr = (String) paramMap.get("orderId"); | |||
| String codeStr = (String) paramMap.get("code"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.info("orderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(codeStr)) { | |||
| logger.info("code不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "code不能为空"); | |||
| } | |||
| Long orderId; | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "orderId: " + orderIdStr + ", e: " + e.getMessage()); | |||
| } | |||
| Integer code; | |||
| try { | |||
| code = Integer.valueOf(codeStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "code: " + codeStr + ", e: " + e.getMessage()); | |||
| } | |||
| Long memberId; | |||
| try { | |||
| memberId = getMemberId(); | |||
| } catch (MallinkException e) { | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumPayWay.PAY_WAY_TT); | |||
| if (cAppInfo == null) { | |||
| return new ResultData(ErrorCode.APP_ID_NOT_ENABLE); | |||
| } | |||
| if(code.intValue() == 0){ | |||
| return ttOrderService.updateOrderStatus(getTenantInfo(),orderId,memberId,cAppInfo); | |||
| }else{ | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,223 +0,0 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.tt.TtCUser; | |||
| import com.iformall.enums.EnumCreditLockedStatus; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.utils.IPUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/pay") | |||
| @Api(description = "支付相关接口") | |||
| public class TtPayOrderController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @Autowired | |||
| private WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @Autowired | |||
| private WxAppinfoService wxAppinfoService; | |||
| /** | |||
| * 微信支付 | |||
| * @param paramMap | |||
| * @param request | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| //@ApiOperation(value = "发起微信小程序支付订单", notes = "{\"orderId\":\"string\"}") | |||
| @RequestMapping(value = "/create", method = RequestMethod.POST) | |||
| public ResultData _create(@RequestBody Map<String, String> paramMap, HttpServletRequest request) throws Exception { | |||
| logger.info("/api/pay/create" + paramMap.toString()); | |||
| String orderIdStr = paramMap.get("orderId"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.info("orderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| TtCUser user = getTtCUser(); | |||
| if (!user.basicInfoIs()) { | |||
| logger.error("暂未成为会员,请授权手机号"); | |||
| return new ResultData(ErrorCode.USER_IS_NOT_MEMBER.getCode(), "暂未成为会员,请授权手机号"); | |||
| } | |||
| return _create(orderIdStr,user.getUserId(),EnumPayWay.PAY_WAY_TT,user.getAppId(),new PayExtraParam("openId",user.getOpenId()),request); | |||
| } | |||
| private ResultData _create(String orderIdStr,Long userId, EnumPayWay payWay,String appId,PayExtraParam parm,HttpServletRequest request) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(userId,getTenantInfo().getFinalTenantId()); | |||
| if ( null == wxCUserBasicInfo) { | |||
| logger.error("会员用户不存在."+userId); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(),"会员用户不存在."+userId); | |||
| } | |||
| if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||
| } | |||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(appId); | |||
| if(appInfo == null) { | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| Long orderId = 0L; | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | |||
| } | |||
| WxPayOrder record = new WxPayOrder(); | |||
| record.setOrderId(orderId); | |||
| try { | |||
| record.setIp(IPUtil.getIpAddr(request)); | |||
| return wxPayOrderService.createPayOrder(appInfo, wxCUserBasicInfo, record, payWay,parm); | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error("payment wechat, order create error, req 3: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation(value = "更新支付订单状态", notes = "{\"payOrderId\":\"string\",\"orderId\":\"string\",\"status\":integer,\"reason\":\"string\"}") | |||
| @PostMapping("/updatePayOrder") | |||
| public ResultData updatePayOrder(@RequestBody Map<String, Object> paramMap) { | |||
| logger.info("/api/pay/updatePayOrder" + paramMap.toString()); | |||
| String payOrderIdStr = (String) paramMap.get("payOrderId"); | |||
| String orderIdStr = (String) paramMap.get("orderId"); | |||
| String reasonStr = (String) paramMap.get("reason"); | |||
| Integer status = (Integer) paramMap.get("status"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.info("orderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| Long payOrderId = 0L, orderId = 0L; | |||
| try { | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error("orderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | |||
| } | |||
| if (!StringUtils.isBlank(payOrderIdStr)) { | |||
| try { | |||
| payOrderId = Long.valueOf(payOrderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error("payOrderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payOrderId参数不正确"); | |||
| } | |||
| } | |||
| if(payOrderIdStr.equalsIgnoreCase("0")) { | |||
| // 免费券直接返回成功 | |||
| return new ResultData(Result.SUCCESS, "免费券支付状态更新成功"); | |||
| } | |||
| WxPayOrder payOrder = new WxPayOrder(); | |||
| payOrder.setId(payOrderId); | |||
| payOrder.setPayOrderNo(String.valueOf(payOrderId)); | |||
| payOrder.setOrderId(orderId); | |||
| payOrder.setPayOrderStatus(status); | |||
| payOrder.setFailReason(reasonStr); | |||
| payOrder.updateTenantInfo(getTenantInfo()); | |||
| payOrder.setPayVendor(EnumPayWay.PAY_WAY_WECHAT.getCode()); | |||
| try { | |||
| //有价券支付成功 | |||
| if (status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { | |||
| // 前端提示支付成功, 不作为支付成功标志,只检查支付订单状态 | |||
| // 有价券不走update, callback更新 | |||
| if (payOrderId<=0) { | |||
| logger.error("/api/pay/updatePayOrder error : payOrderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payOrderId非法"+payOrderId+"[payOrderIdStr:"+payOrderIdStr+"]"); | |||
| } | |||
| payOrder = wxPayOrderService.getById(payOrderId,payOrder.getTenantId()); | |||
| if (null == payOrder) { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "未查询到payOrder."); | |||
| } | |||
| WxOrder order = wxOrderService.getById(orderId,payOrder.getTenantId()); | |||
| if (null == order) { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "未查询到Order["+orderId+"]."); | |||
| } | |||
| WxCoupon wxCoupon = wxCouponService.getById(order.getProductId(),order.getTenantId()); | |||
| if (null == wxCoupon) { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "未查询到优惠券[orderId:"+orderId+"]."); | |||
| } | |||
| //拼团的订单,如果查询到是拼团待付款的,则重新查询是否已经真的支付,其他的直接返回订单信息 | |||
| if (wxPayOrderService.isOrderGroupCoupon(payOrder, wxCoupon)) { | |||
| if (!order.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode())) { | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", order); | |||
| } | |||
| }else { | |||
| //非拼团的订单,支付成功,关闭订单,撤销支付订单,支付转退款的,直接返回订单信息,其他需要查询真实支付状态 | |||
| if (payOrder.getPayOrderStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())|| | |||
| payOrder.getPayOrderStatus().equals(EnumPayStatus.PAY_STATUS_CLOSE.getCode())|| | |||
| payOrder.getPayOrderStatus().equals(EnumPayStatus.PAY_STATUS_REVERSE.getCode())|| | |||
| payOrder.getPayOrderStatus().equals(EnumPayStatus.PAY_STATUS_REFUND.getCode())) { | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", order); | |||
| } | |||
| } | |||
| //查询微信订单状态并更新 | |||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(payOrder, EnumPayWay.getEnum(payOrder.getPayVendor())); | |||
| //WxCUser user = getUser(); | |||
| //WxAppinfo appInfo = getAppInfo(user.getAppId()); | |||
| if (null == appInfo) { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "当前支付类型["+payOrder.getPayVendor()+"]找不到C端appInfo"); | |||
| } | |||
| WxPayAccount payAccount = wxPayAccountService.getById(appInfo.getPayId()); | |||
| try { | |||
| WxPayOrder wo = wxPayOrderService.handleWxOrderQuery(payOrder, order, appInfo, payAccount, IdWorker.get(),false); | |||
| if (null != wo) { | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", order); | |||
| } | |||
| }catch(MallinkException e) { | |||
| //已经同步了微信的支付状态,表示已经更新 | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", order); | |||
| } | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "查询微信订单支付状态失败,请稍后!"); | |||
| } else if (status.equals(EnumPayStatus.PAY_STATUS_FAIL.getCode())) { | |||
| // 有价券支付失败 | |||
| wxPayOrderService.handlePayOrderFail(payOrder, EnumPayStatus.PAY_STATUS_FAIL.getCode()); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功"); | |||
| } catch (MallinkException e) { | |||
| logger.error("支付状态更新失败2: " + payOrder.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error("支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | |||
| } | |||
| } | |||
| } | |||