Browse Source

tt

release_toaliyun_real
xhxu 5 years ago
parent
commit
d287777cdf
7 changed files with 276 additions and 2449 deletions
  1. +3
    -0
      mallinkService/src/main/java/com/iformall/domain/po/tt/TtCoupon.java
  2. +3
    -0
      mallinkService/src/main/java/com/iformall/domain/po/tt/TtOrder.java
  3. +38
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumTtCouponType.java
  4. +5
    -0
      mallinkService/src/main/java/com/iformall/service/tt/impl/TtCouponServiceImpl.java
  5. +4
    -2318
      mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java
  6. +0
    -131
      mallinkTTCApi/src/main/java/com/iformall/controller/TtOrderController.java
  7. +223
    -0
      mallinkTTCApi/src/main/java/com/iformall/controller/TtPayOrderController.java

+ 3
- 0
mallinkService/src/main/java/com/iformall/domain/po/tt/TtCoupon.java View File

@@ -129,6 +129,9 @@ public class TtCoupon extends TenantEntity {
@TableField(exist = false)
private WxMerchant author;

@TableField(exist = false)
private TtCoupon couponCoumn;

@TableField(exist = false)
@io.swagger.annotations.ApiModelProperty(value = "审批流参数", name = "columnCoupons")
private List<TtCoupon> columnCoupons;


+ 3
- 0
mallinkService/src/main/java/com/iformall/domain/po/tt/TtOrder.java View File

@@ -67,6 +67,9 @@ public class TtOrder extends TenantEntity {
@TableField(exist = false)
private String paymentStr;

@TableField(exist = false)
protected TtCoupon ttCoupon;

@TableField(exist = false)
protected List<Integer> statusS;



+ 38
- 0
mallinkService/src/main/java/com/iformall/enums/EnumTtCouponType.java View File

@@ -0,0 +1,38 @@
package com.iformall.enums;

/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumTtCouponType {


COUPON_COLUMN(1, "专栏"),
COUPON_SINGLE(2, "单课程"),
COUPON_MORE(3, "子课程"),
;

public static EnumTtCouponType getEnum(Integer code) {
for (EnumTtCouponType value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}

private Integer code;
private String message;

EnumTtCouponType(Integer code, String message) {
this.code = code;
this.message = message;
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}
}

+ 5
- 0
mallinkService/src/main/java/com/iformall/service/tt/impl/TtCouponServiceImpl.java View File

@@ -7,6 +7,7 @@ import com.iformall.common.IdWorker;
import com.iformall.common.ResultData;
import com.iformall.domain.po.tt.TtCoupon;
import com.iformall.mapper.*;
import com.iformall.service.WxMerchantService;
import com.iformall.service.tt.TtCouponService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -26,6 +27,9 @@ public class TtCouponServiceImpl implements TtCouponService {
@Autowired
TtCouponMapper ttCouponMapper;

@Autowired
WxMerchantService wxMerchantService;


@Override
public PageInfo<TtCoupon> listAsPage(TtCoupon record, Integer pageIndex, Integer pageSize) {
@@ -81,6 +85,7 @@ public class TtCouponServiceImpl implements TtCouponService {
@Override
public TtCoupon detail(Long productId) {
TtCoupon byId = this.getById(productId);
byId.setAuthor(wxMerchantService.getById(byId.getMerchantId()));
return byId;
}
}

+ 4
- 2318
mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java
File diff suppressed because it is too large
View File


+ 0
- 131
mallinkTTCApi/src/main/java/com/iformall/controller/TtOrderController.java View File

@@ -164,135 +164,4 @@ public class TtOrderController extends BaseController {
return new ResultData(order);
}

@ApiOperation(value = "根据orderId查询接口", notes = "{\"orderId\":\"string\"}")
@GetMapping("/findById")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderId", value = "订单id", dataType = "String", paramType = "query", required = true)
})
public ResultData findById(String orderId) {
if (orderId == null || orderId.equalsIgnoreCase(Constant.UNDEFINED)) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
Long id = 0L;
try {
id = Long.valueOf(orderId);
} catch (NumberFormatException e) {
logger.error("parse orderId failed");
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID转换异常");
}
WxOrder order = null;
try {
order = wxOrderService.getById(id,getTenantInfo().getTenantId());
if (order != null) {
return new ResultData(Result.SUCCESS, "查询成功", order);
} else {
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
}
} catch (Exception e) {
logger.error("parse orderId failed");
return new ResultData(ErrorCode.DB_FAIL.getCode(), "订单查询未成功,e:" + e.getMessage());
}
}

@ApiOperation(value = "获取未支付订单", notes = "{\"couponId\":\"string\"}")
@GetMapping("getUnPaidOrder")
@ApiImplicitParams({
@ApiImplicitParam(name = "couponId", value = "券id", dataType = "String", paramType = "query", required = true)
})
public ResultData getUnPaidOrder(String couponId) {
if (couponId == null || couponId.equalsIgnoreCase(Constant.UNDEFINED)) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
Long id = 0L;
try {
id = Long.valueOf(couponId);
} catch (NumberFormatException e) {
logger.error("parse couponId failed");
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "券ID转换异常");
}
WxCoupon wxCoupon = null;
try {
wxCoupon = wxCouponService.getById(id,getTenantInfo().getTenantId());
} catch (Exception e) {
logger.error("券ID获取券信息失败, couponId: " + couponId);
return new ResultData(ErrorCode.COUPON_IS_EMPTY);
}
if(wxCoupon == null) {
logger.error("券ID获取券信息失败, couponId: " + couponId);
return new ResultData(ErrorCode.COUPON_IS_EMPTY);
}

WxOrder order = null;
try {
WxCUserBasicInfo member = wxCUserBasicInfoService.getById(getMemberId(),getTenantInfo().getFinalTenantId());
if(member == null) {
logger.error("会员用户未找到: " + getMemberId());
throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "会员用户未找到" + getMemberId());
}
order = wxOrderService.getUnPaidOrder(member, wxCoupon);
if (order != null) {
return new ResultData(Result.SUCCESS, "查询成功", order);
} else {
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
}
} catch (Exception e) {
logger.error("parse orderId failed");
return new ResultData(ErrorCode.DB_FAIL.getCode(), "订单查询未成功,e:" + e.getMessage());
}
}

@ApiOperation("我的砍价-分页列表接口")
@GetMapping("pressOrderList")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
public ResultData pressOrderList(@ModelAttribute WxOrder wxOrder, Integer pageNum, Integer pageSize) {
// c端用户应该只能看到自己的订单
if (wxOrder == null) wxOrder = new WxOrder();
Long memberId;
try {
memberId = getMemberId();
} catch (Exception e) {
return new ResultData(Result.ERROR,e.getMessage());
}
wxOrder.setCUserId(memberId);
wxOrder.setSortColumns(BaseEntity.SortField.CreateDate_DESC);
final PageInfo<WxOrderCouponPressVo> page = wxOrderService.listPressVoAsPage(wxOrder, pageNum, pageSize);
return new ResultData(page);
}

@ApiOperation("砍价订单-详情接口")
@GetMapping("pressOrderDetail")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderId", value = "订单id", dataType = "String", paramType = "query", required = true)
})
public ResultData pressOrderDetail(String orderId) {
// c端用户应该只能看到自己的订单细节
WxOrder wxOrder = new WxOrder();
if(StringUtils.isBlank(orderId)) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID不能为空");
}
Long id = 0L;
try {
id = Long.valueOf(orderId);
} catch (NumberFormatException e) {
logger.error("parse orderId failed");
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID转换异常");
}
wxOrder.setId(id);
wxOrder.updateTenantInfo(getTenantInfo());
try {
final WxOrderCouponPressVo orderCouponPressVo = wxOrderService.detailPressVo(wxOrder);
if (orderCouponPressVo == null) {
logger.error("orderCouponPressVo is null: " + orderId);
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
}
return new ResultData(orderCouponPressVo);
} catch (Exception e) {
logger.error("SQL: " + e.getMessage());
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
}
}


}

+ 223
- 0
mallinkTTCApi/src/main/java/com/iformall/controller/TtPayOrderController.java View File

@@ -0,0 +1,223 @@
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());
}
}
}

Loading…
Cancel
Save