|
|
|
@@ -29,6 +29,9 @@ public class WxCouponPasswordController extends BaseController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponPasswordService couponPasswordService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCardInfoService wxCardInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponService couponService; |
|
|
|
@@ -42,41 +45,46 @@ public class WxCouponPasswordController extends BaseController { |
|
|
|
@Autowired |
|
|
|
OrderFactory orderFactory; |
|
|
|
|
|
|
|
@ApiOperation(value = "根据卡密领卡", notes = "{\"password\":\"String\",\"formId\":\"String\",\"payCheck\":\"String\"}") |
|
|
|
@ApiOperation(value = "根据卡密领卡", notes = "{\"password\":\"String\",\"formId\":\"String\",\"payCheck\":\"String\",\"payPassword\":\"String\"}") |
|
|
|
@PostMapping("getCouponOrderByPassword") |
|
|
|
public ResultData getCouponOrderByPassword(@RequestBody Map<String, String> params) { |
|
|
|
logger.info("getCouponOrderByPassword: " + getIpAddr() + params.toString()); |
|
|
|
String password = params.get("password"); |
|
|
|
String formId = params.get("formId"); |
|
|
|
String payCheck = params.get("payCheck"); |
|
|
|
String payPassword = params.get("payPassword"); |
|
|
|
Long memberId; |
|
|
|
try { |
|
|
|
memberId = getMemberId(); |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(Result.ERROR,e.getMessage()); |
|
|
|
} |
|
|
|
return getCouponOrderByPassword(password, formId,payCheck, memberId,EnumPayWay.PAY_WAY_NOT_UNPAY_PASSWD,EnumPayVersion.NO_VERSION); |
|
|
|
return getCouponOrderByPassword(password, formId,payCheck,payPassword, memberId,EnumPayWay.PAY_WAY_NOT_UNPAY_PASSWD,EnumPayVersion.NO_VERSION); |
|
|
|
} |
|
|
|
|
|
|
|
private ResultData getCouponOrderByPassword(String password,String formId,String payCheck,Long memberId,EnumPayWay payWay,EnumPayVersion payVersion) { |
|
|
|
private ResultData getCouponOrderByPassword(String password,String formId,String payCheck,String payPassword,Long memberId,EnumPayWay payWay,EnumPayVersion payVersion) { |
|
|
|
password = StringUtils.trimToNull(password); |
|
|
|
payPassword = StringUtils.trimToNull(payPassword); |
|
|
|
if (StringUtils.isBlank(password) || password.equalsIgnoreCase(Constant.UNDEFINED)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "password不能为空"); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "卡号或者卡密不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isBlank(payCheck) || payCheck.equalsIgnoreCase(Constant.UNDEFINED)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payCheck不能为空"); |
|
|
|
payCheck = String.valueOf(EnumCouponPasswordPayCheck.NO_CHECK.getCode()); |
|
|
|
} |
|
|
|
|
|
|
|
EnumCouponPasswordPayCheck payCheckEnum = null; |
|
|
|
try { |
|
|
|
payCheckEnum = EnumCouponPasswordPayCheck.getEnum(Integer.parseInt(payCheck)); |
|
|
|
}catch (Exception e) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payCheck非法"); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "支付校验方式非法"); |
|
|
|
} |
|
|
|
if (null == payCheckEnum) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payCheck非法"); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "支付校验方式非法"); |
|
|
|
} |
|
|
|
if (payCheckEnum.getCode().intValue() == EnumCouponPasswordPayCheck.PASSWORD.getCode().intValue()) { |
|
|
|
if (StringUtils.isBlank(payPassword) || payPassword.equalsIgnoreCase(Constant.UNDEFINED)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "支付密码不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
boolean isCardId = false; |
|
|
|
if (password.length() > 10) { |
|
|
|
@@ -97,22 +105,46 @@ public class WxCouponPasswordController extends BaseController { |
|
|
|
couponPasswordQ.setPassword(password); |
|
|
|
} |
|
|
|
couponPasswordQ.setExpireDate(new Date()); |
|
|
|
WxCouponPassword couponPassword = null; |
|
|
|
try { |
|
|
|
couponPassword = couponPasswordService.getByObj(couponPasswordQ); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
return new ResultData(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
return new ResultData(500, e.getMessage()); |
|
|
|
WxCouponPassword couponPassword = couponPasswordService.getByObj(couponPasswordQ); |
|
|
|
if (null == couponPassword) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "卡未查询到"); |
|
|
|
} |
|
|
|
|
|
|
|
WxCardInfo cardInfo = null; |
|
|
|
Long cardId = couponPassword.getCardId(); |
|
|
|
//如果卡已经被激活,但是绑定的用户是系统默认用户,则是线下卡进行绑定,仍然可以继续 |
|
|
|
boolean isDefaultUser = false; |
|
|
|
if (null != cardId) { |
|
|
|
cardInfo = wxCardInfoService.getById(cardId); |
|
|
|
if (null == cardInfo) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "当前卡已激活电子卡,但是电子卡未查询到,请联系管理员"); |
|
|
|
} |
|
|
|
if (cardInfo.getOwnerUserId().equals(memberId)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "当前卡已经属于您,无需再次激活"); |
|
|
|
} |
|
|
|
if (cardInfo.getOwnerUserId().equals(Constant.defaultCUserId)) { |
|
|
|
isDefaultUser = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!isDefaultUser) { |
|
|
|
if (couponPassword.getStatus().equals(EnumCouponPasswordStatus.USED.getCode())) { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND.getCode(), "卡已经激活过,不允许当前操作"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (couponPassword.getStatus().equals(EnumCouponPasswordStatus.CANCEL.getCode())) { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND.getCode(), "卡已作废,不能激活"); |
|
|
|
} |
|
|
|
|
|
|
|
if (couponPassword.getIsStop().intValue() == EnumYesOrNo.YES.getCode().intValue()) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"卡密已经停用"); |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"卡已经停用"); |
|
|
|
} |
|
|
|
|
|
|
|
if (couponPassword.getPrice() <= 0) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"卡密面值未设置,请联系管理员."); |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"卡面值未设置,请联系管理员."); |
|
|
|
} |
|
|
|
|
|
|
|
WxCUserBasicInfo member = userService.getById(memberId,getFinalTenantId()); |
|
|
|
if(member == null) { |
|
|
|
throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "会员用户未找到" + memberId); |
|
|
|
@@ -122,41 +154,54 @@ public class WxCouponPasswordController extends BaseController { |
|
|
|
if (coupon == null) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY); |
|
|
|
} |
|
|
|
if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); |
|
|
|
//如果是线下已经使用的卡,券作废了,卡仍然可以进行绑定 |
|
|
|
if (!isDefaultUser) { |
|
|
|
if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); |
|
|
|
} |
|
|
|
} |
|
|
|
// if (coupon.getPrice() <= 0) { |
|
|
|
// return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"卡面值未设置,请联系管理员."); |
|
|
|
// } |
|
|
|
|
|
|
|
// 卡密领取卡券 |
|
|
|
Integer pwdStatus = couponPassword.getStatus(); |
|
|
|
setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.USED); |
|
|
|
setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.USED,payCheckEnum,payPassword); |
|
|
|
couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode()); |
|
|
|
|
|
|
|
// 3. 领取free coupon |
|
|
|
try { |
|
|
|
WxComposeOrder composeOrder = orderFactory.getOrderAdapterService(EnumComposeOrder.SINGLE.getCode()).createDBMainOrder(coupon, member, 0, payWay,payVersion); |
|
|
|
WxOrder order = orderService.saveFreeOrderForCoupon(new Date(),false,composeOrder,member, coupon, 1, |
|
|
|
null, formId, couponPassword,null,payWay,payVersion, |
|
|
|
EnumOrderShopingType.ONLINE_PURCHASE.getCode(),null,false); |
|
|
|
} catch (MallinkException e) { |
|
|
|
setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus)); |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
return new ResultData(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus)); |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
return new ResultData(500, e.getMessage()); |
|
|
|
} |
|
|
|
if (null == cardInfo) { |
|
|
|
try { |
|
|
|
WxComposeOrder composeOrder = orderFactory.getOrderAdapterService(EnumComposeOrder.SINGLE.getCode()).createDBMainOrder(coupon, member, 0, payWay,payVersion); |
|
|
|
WxOrder order = orderService.saveFreeOrderForCoupon(new Date(),false,composeOrder,member, coupon, 1, |
|
|
|
null, formId, couponPassword,null,payWay,payVersion, |
|
|
|
EnumOrderShopingType.ONLINE_PURCHASE.getCode(),null,false); |
|
|
|
} catch (MallinkException e) { |
|
|
|
setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus),null,null); |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
return new ResultData(e.getErrorCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus),null,null); |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
return new ResultData(500, e.getMessage()); |
|
|
|
} |
|
|
|
}else { |
|
|
|
try { |
|
|
|
cardInfo.setOwnerUserId(memberId); |
|
|
|
cardInfo.setUpdateDate(new Date()); |
|
|
|
wxCardInfoService.saveOrUpdate(cardInfo); |
|
|
|
}catch(Exception e) { |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
return new ResultData(500, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
private void setCouponPasswordStatus(WxCouponPassword couponPassword, EnumCouponPasswordStatus pwdStatus) { |
|
|
|
private void setCouponPasswordStatus(WxCouponPassword couponPassword, EnumCouponPasswordStatus pwdStatus,EnumCouponPasswordPayCheck payCheckEnum,String payPassword) { |
|
|
|
WxCouponPassword updateCouponPwd = new WxCouponPassword(); |
|
|
|
updateCouponPwd.setId(couponPassword.getId()); |
|
|
|
updateCouponPwd.setStatus(pwdStatus.getCode()); |
|
|
|
if (null != payCheckEnum && payCheckEnum.getCode().intValue() == EnumCouponPasswordPayCheck.PASSWORD.getCode().intValue()) { |
|
|
|
updateCouponPwd.setPayPassword(payPassword); |
|
|
|
} |
|
|
|
couponPasswordService.saveOrUpdate(updateCouponPwd); |
|
|
|
} |
|
|
|
|
|
|
|
} |