| @@ -1,7 +1,18 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.vo.WxOrderQueryVo; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.enums.EnumUserType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCUserService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -17,6 +28,7 @@ import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| @RestController | |||
| @@ -24,9 +36,15 @@ import java.util.Map; | |||
| public class WxOrderController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxCouponChannelService wxCouponChannelService; | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @Autowired | |||
| private WxCUserService wxCUserService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -112,5 +130,110 @@ public class WxOrderController extends BaseController { | |||
| return new ResultData(data); | |||
| } | |||
| @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}") | |||
| @PostMapping("save") | |||
| public ResultData saveOrder(@RequestBody Map<String, String> paramMap) { | |||
| MallUserInfo mallUserInfo = getUser(); | |||
| WxCUser wxCUser = new WxCUser(); | |||
| if (mallUserInfo != null) { | |||
| wxCUser = wxCUserService.getById(mallUserInfo.getId()); | |||
| if (wxCUser == null) { | |||
| throw new MallinkException(ErrorCode.USER_NOT_MEMBER); | |||
| } | |||
| } | |||
| logger.info("OrderSave: " + paramMap.toString()); | |||
| //Assert.notNull(wxOrders.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| String couponChannelIdStr = paramMap.get("couponChannelId"); | |||
| String couponIdStr = paramMap.get("couponId"); | |||
| String pressStr = paramMap.get("press"); | |||
| String orderGroupIdStr = paramMap.get("orderGroupId"); | |||
| String formId = paramMap.get("formId"); | |||
| if (StringUtils.isBlank(couponChannelIdStr)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); | |||
| } | |||
| Long couponChannelId = 0L, couponId = 0L, orderGroupId = null; | |||
| boolean isPress = false; | |||
| if (StringUtils.isNotBlank(couponChannelIdStr)) { | |||
| try { | |||
| couponChannelId = Long.valueOf(couponChannelIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error("couponChannelId convert error, " + couponChannelIdStr + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponChannelId: " + couponChannelIdStr + ", e:" + e.getMessage()); | |||
| } | |||
| WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannelId); | |||
| if (wxCouponChannel == null) { | |||
| logger.error("couponChannelId convert error, " + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||
| } | |||
| if (wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { | |||
| Date now = new Date(); | |||
| if (wxCouponChannel.getBeginTime().getTime() > now.getTime()) { | |||
| logger.error("此券活动未开始:" + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_NOT_STARTED); | |||
| } | |||
| if (wxCouponChannel.getEndTime().getTime() < now.getTime()) { | |||
| logger.error("此券活动已结束:" + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_END); | |||
| } | |||
| } | |||
| if (wxCouponChannel.getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { | |||
| logger.error("此券已下架:" + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | |||
| } | |||
| if (StringUtils.isBlank(couponIdStr)) { | |||
| couponId = wxCouponChannel.getCouponId(); | |||
| } | |||
| } | |||
| if (couponId <= 0 && !StringUtils.isBlank(couponIdStr)) { | |||
| try { | |||
| couponId = Long.valueOf(couponIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error("couponId convert error, " + couponIdStr + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponId: " + couponIdStr + ", e:" + e.getMessage()); | |||
| } | |||
| } | |||
| if (couponId <= 0) { | |||
| logger.error("couponChannelId或者couponId不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId或者couponId不能为空"); | |||
| } | |||
| if(pressStr != null) { | |||
| try{ | |||
| isPress = Boolean.valueOf(pressStr); | |||
| } catch (Exception e) { | |||
| logger.error("press转换失败"); | |||
| } | |||
| } | |||
| if (orderGroupIdStr != null) { | |||
| try { | |||
| orderGroupId = Long.valueOf(orderGroupIdStr); | |||
| } catch (Exception e) { | |||
| logger.error("orderGroupId转换失败"); | |||
| } | |||
| } | |||
| //用于标记当前操作人为A端用户 | |||
| wxCUser.setUserType(EnumUserType.MALLUSER.getCode()); | |||
| try { | |||
| WxOrder order = wxOrderService.saveCouponOrder(wxCUser, couponChannelId, couponId, isPress, orderGroupId, formId); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.ORDER_IS_FAIL, e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,22 +1,26 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxProfitSharingOrderService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| 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 java.util.Map; | |||
| @RestController | |||
| @RequestMapping("wxPayOrder") | |||
| @@ -24,14 +28,10 @@ public class WxPayOrderController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| @Autowired | |||
| private WxProfitSharingOrderService xProfitSharingOrderService; | |||
| private WxOrderService wxOrderService; | |||
| @Autowired | |||
| private WxAppinfoService wxAppinfoService; | |||
| private WxPayOrderService wxPayOrderService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @@ -84,4 +84,70 @@ public class WxPayOrderController extends BaseController { | |||
| logger.debug("[" + getIpAddr() + "] WxPayOrderController::findById"); | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxPayOrderService.getById(id)); | |||
| } | |||
| @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参数不正确"); | |||
| } | |||
| } | |||
| WxPayOrder payOrder = new WxPayOrder(); | |||
| payOrder.setId(payOrderId); | |||
| payOrder.setOrderId(orderId); | |||
| payOrder.setPayOrderStatus(status); | |||
| payOrder.setFailReason(reasonStr); | |||
| WxOrder order = null; | |||
| try { | |||
| if(status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) && !payOrderIdStr.equals("0")) { | |||
| // 前端提示支付成功, 不作为支付成功标志,只检查支付订单状态 | |||
| // 有价券不走update, callback更新 | |||
| payOrder = wxPayOrderService.getById(payOrderId); | |||
| if(payOrder.getPayOrderStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { | |||
| order = wxOrderService.getById(orderId); | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", order); | |||
| } else { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "支付未状态,请等待!!"); | |||
| } | |||
| } else { | |||
| // 1. 免费券,status = 1,成功 | |||
| // 2. 有价券,status = 2,取消支付 | |||
| if(status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { | |||
| wxPayOrderService.handlePayOrderStatusUpdate(payOrder, 1); | |||
| } else if (status.equals(EnumPayStatus.PAY_STATUS_FAIL.getCode())) { | |||
| wxPayOrderService.handlePayOrderStatusUpdate(payOrder, 2); | |||
| } | |||
| } | |||
| 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()); | |||
| } | |||
| } | |||
| } | |||
| @@ -279,6 +279,8 @@ public enum ErrorCode{ | |||
| MEM_SCORE_NOT_ENOUGH(13001, "成长值不够扣减值"), | |||
| CREDIT_ZERO(13100,"本次操作积分为零"), | |||
| CREDIT_NOT_ENOUGH(13101, "积分不够扣减值"), | |||
| USER_NOT_MEMBER(13102, "该用户不是小程序会员"), | |||
| /** | |||
| * 标签 | |||
| @@ -3,13 +3,14 @@ package com.iformall.domain.po; | |||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |||
| import com.iformall.utils.Constant; | |||
| import javax.persistence.*; | |||
| import java.util.*; | |||
| import java.math.*; | |||
| import javax.persistence.Transient; | |||
| import java.util.List; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.math.BigDecimal; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.UUID; | |||
| @Table(name = "wx_c_user") | |||
| @JsonIgnoreProperties(ignoreUnknown = true) | |||
| @@ -178,6 +179,18 @@ public class WxCUser implements Serializable { | |||
| @Transient | |||
| protected Date endDate; | |||
| //用户类型 枚举:EnumUserType | |||
| @Transient | |||
| protected Integer userType; | |||
| public Integer getUserType() { | |||
| return userType; | |||
| } | |||
| public void setUserType(Integer userType) { | |||
| this.userType = userType; | |||
| } | |||
| public Date getStartDate() { | |||
| return startDate; | |||
| } | |||
| @@ -431,7 +431,12 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| //扣减积分操作记录 | |||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| //记录操作人类型 | |||
| if (user.getUserType() == EnumUserType.MALLUSER.getCode()) { | |||
| creditHistory.setOperatorType(EnumUserType.MALLUSER.getCode()); | |||
| } else { | |||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| } | |||
| creditHistory.setOperatorId(user.getId()); | |||
| creditHistory.setCreditNum(coupon.getCreditPrice()); | |||
| creditHistory.setCUserId(user.getId()); | |||