| @@ -11,6 +11,8 @@ import com.iformall.service.order.OrderFactory; | |||||
| import com.iformall.service.order.entity.WxComposeOrder; | import com.iformall.service.order.entity.WxComposeOrder; | ||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -19,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.HashMap; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -29,6 +32,9 @@ public class WxCouponPasswordController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCouponPasswordService couponPasswordService; | private WxCouponPasswordService couponPasswordService; | ||||
| @Autowired | |||||
| private WxCardInfoService wxCardInfoService; | |||||
| @Autowired | @Autowired | ||||
| private WxCouponService couponService; | private WxCouponService couponService; | ||||
| @@ -42,47 +48,110 @@ public class WxCouponPasswordController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| OrderFactory orderFactory; | OrderFactory orderFactory; | ||||
| @ApiOperation(value = "根据卡密领卡", notes = "{\"password\":\"String\",\"formId\":\"String\"}") | |||||
| @ApiOperation(value = "根据卡密领卡", notes = "{\"password\":\"String\",\"formId\":\"String\",\"payCheck\":\"String\",\"payPassword\":\"String\"}") | |||||
| @PostMapping("getCouponOrderByPassword") | @PostMapping("getCouponOrderByPassword") | ||||
| public ResultData getCouponOrderByPassword(@RequestBody Map<String, String> params) { | public ResultData getCouponOrderByPassword(@RequestBody Map<String, String> params) { | ||||
| logger.info("getCouponOrderByPassword: " + getIpAddr() + params.toString()); | logger.info("getCouponOrderByPassword: " + getIpAddr() + params.toString()); | ||||
| String password = params.get("password"); | String password = params.get("password"); | ||||
| String formId = params.get("formId"); | String formId = params.get("formId"); | ||||
| String payCheck = params.get("payCheck"); | |||||
| String payPassword = params.get("payPassword"); | |||||
| Long memberId; | Long memberId; | ||||
| try { | try { | ||||
| memberId = getMemberId(); | memberId = getMemberId(); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| return new ResultData(Result.ERROR,e.getMessage()); | return new ResultData(Result.ERROR,e.getMessage()); | ||||
| } | } | ||||
| return getCouponOrderByPassword(password, formId, 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,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)) { | 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)) { | |||||
| 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(), "支付校验方式非法"); | |||||
| } | |||||
| if (null == payCheckEnum) { | |||||
| 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) { | |||||
| isCardId = true; | |||||
| } | |||||
| // 1. 根据password获取领取的couponId | // 1. 根据password获取领取的couponId | ||||
| WxCouponPassword couponPasswordQ = new WxCouponPassword(); | WxCouponPassword couponPasswordQ = new WxCouponPassword(); | ||||
| couponPasswordQ.updateTenantInfo(getTenantInfo()); | couponPasswordQ.updateTenantInfo(getTenantInfo()); | ||||
| couponPasswordQ.setPassword(password); | |||||
| if (isCardId) { | |||||
| try { | |||||
| Long cardId = Long.parseLong(password); | |||||
| couponPasswordQ.setId(cardId); | |||||
| }catch (Exception e) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "password参数非法"); | |||||
| } | |||||
| }else { | |||||
| couponPasswordQ.setPassword(password); | |||||
| } | |||||
| couponPasswordQ.setExpireDate(new Date()); | 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(), "卡未查询到"); | |||||
| } | } | ||||
| couponPassword.setDefaultUser(false); | |||||
| 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; | |||||
| couponPassword.setDefaultUser(true); | |||||
| couponPassword.setWxCardInfo(cardInfo); | |||||
| }else { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "当前卡已经绑定激活,不能进行此操作"); | |||||
| } | |||||
| } | |||||
| 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()) { | 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) { | 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()); | WxCUserBasicInfo member = userService.getById(memberId,getFinalTenantId()); | ||||
| if(member == null) { | if(member == null) { | ||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "会员用户未找到" + memberId); | throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "会员用户未找到" + memberId); | ||||
| @@ -92,41 +161,105 @@ public class WxCouponPasswordController extends BaseController { | |||||
| if (coupon == null) { | if (coupon == null) { | ||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | 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 (coupon.getPrice() <= 0) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"卡面值未设置,请联系管理员."); | |||||
| //如果是线下已经使用的卡,券作废了,卡仍然可以进行绑定 | |||||
| if (!isDefaultUser) { | |||||
| if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | |||||
| } | } | ||||
| // 卡密领取卡券 | // 卡密领取卡券 | ||||
| Integer pwdStatus = couponPassword.getStatus(); | Integer pwdStatus = couponPassword.getStatus(); | ||||
| setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.USED); | |||||
| setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.USED,payCheckEnum,payPassword); | |||||
| couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode()); | couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode()); | ||||
| // 3. 领取free coupon | // 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 || couponPassword.isDefaultUser()) { | |||||
| 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()); | |||||
| } | |||||
| } | } | ||||
| return new ResultData(); | 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(); | WxCouponPassword updateCouponPwd = new WxCouponPassword(); | ||||
| updateCouponPwd.setId(couponPassword.getId()); | updateCouponPwd.setId(couponPassword.getId()); | ||||
| updateCouponPwd.setStatus(pwdStatus.getCode()); | updateCouponPwd.setStatus(pwdStatus.getCode()); | ||||
| if (null != payCheckEnum && payCheckEnum.getCode().intValue() == EnumCouponPasswordPayCheck.PASSWORD.getCode().intValue()) { | |||||
| updateCouponPwd.setPayPassword(payPassword); | |||||
| } | |||||
| couponPasswordService.saveOrUpdate(updateCouponPwd); | couponPasswordService.saveOrUpdate(updateCouponPwd); | ||||
| } | } | ||||
| @ApiOperation(value = "查询卡详情") | |||||
| @GetMapping("getCardDetail") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "cardId", value = "券ID", dataType = "String", paramType = "query", required = true) | |||||
| }) | |||||
| public ResultData getCardDetail(String cardId) { | |||||
| if (StringUtils.isBlank(cardId) || cardId.equalsIgnoreCase(Constant.UNDEFINED)) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"参数错误."); | |||||
| } | |||||
| cardId = StringUtils.trimToNull(cardId); | |||||
| WxCouponPassword password = null; | |||||
| try { | |||||
| password = couponPasswordService.getById(Long.parseLong(cardId)); | |||||
| if (null == password) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"参数错误."); | |||||
| } | |||||
| }catch(Exception e) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(),"参数错误."); | |||||
| } | |||||
| WxCoupon coupon = couponService.getById(password.getCouponId(),password.getTenantId()); | |||||
| if (coupon == null) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| Map retMap = new HashMap(); | |||||
| retMap.put("title", coupon.getTitle()); | |||||
| retMap.put("couponPasswordId", password.getId()); | |||||
| if (null != password.getCardId()) { | |||||
| WxCardInfo cardInfo = wxCardInfoService.getById(password.getCardId()); | |||||
| if (null != cardInfo) { | |||||
| Long owner = cardInfo.getOwnerUserId(); | |||||
| if (!owner.equals(Constant.defaultCUserId)) { | |||||
| WxCUserBasicInfo user = userService.getById(owner, password.getFinalTenantId()); | |||||
| if (null != user) { | |||||
| retMap.put("owner", user.getPhone()); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| return new ResultData(retMap); | |||||
| } | |||||
| @ApiOperation(value = "实体卡转赠", notes = "{\"cardId\":\"String\",\"formId\":\"String\",\"payCheck\":\"String\",\"payPassword\":\"String\"}") | |||||
| @PostMapping("transfer") | |||||
| public ResultData transfer(@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,payPassword, memberId,EnumPayWay.PAY_WAY_NOT_UNPAY_PASSWD,EnumPayVersion.NO_VERSION); | |||||
| } | |||||
| } | } | ||||
| @@ -121,7 +121,7 @@ public class CouponOrderNoticeSchedule { | |||||
| public void couponOrderExpiringSchedule() { | public void couponOrderExpiringSchedule() { | ||||
| List<WxMall> malls = getMalls(); | List<WxMall> malls = getMalls(); | ||||
| for (WxMall mall: malls) { | for (WxMall mall: malls) { | ||||
| Date oneDayBefore = DateUtils.getTimeAfterDays(-1, new Date()); | |||||
| Date oneDayBefore = DateUtils.getTimeAfterDays(1, new Date()); | |||||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(mall.getTenantId(),oneDayBefore); | List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(mall.getTenantId(),oneDayBefore); | ||||
| if (null != list && list.size() > 0 ) { | if (null != list && list.size() > 0 ) { | ||||
| list.stream().forEach(co -> { | list.stream().forEach(co -> { | ||||
| @@ -143,7 +143,7 @@ public class CouponOrderNoticeSchedule { | |||||
| public void couponOrderRefundSchedule() { | public void couponOrderRefundSchedule() { | ||||
| List<WxMall> malls = getMalls(); | List<WxMall> malls = getMalls(); | ||||
| for (WxMall mall: malls) { | for (WxMall mall: malls) { | ||||
| Date oneDayBefore = DateUtils.getTimeAfterDays(-1, new Date()); | |||||
| Date oneDayBefore = DateUtils.getTimeAfterDays(1, new Date()); | |||||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId(),oneDayBefore); | List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId(),oneDayBefore); | ||||
| if (null != list && list.size() > 0 ) { | if (null != list && list.size() > 0 ) { | ||||
| list.stream().forEach(co -> { | list.stream().forEach(co -> { | ||||
| @@ -61,5 +61,10 @@ public class WxCouponPassword extends TenantEntity { | |||||
| @TableField(exist = false) | @TableField(exist = false) | ||||
| private String statusStr; | private String statusStr; | ||||
| @TableField(exist = false) | |||||
| private boolean isDefaultUser; | |||||
| @TableField(exist = false) | |||||
| private WxCardInfo wxCardInfo; | |||||
| } | } | ||||
| @@ -14,11 +14,11 @@ public class WxCardPriceTemplate implements Serializable { | |||||
| private static final long serialVersionUID = -2321650008236516884L; | private static final long serialVersionUID = -2321650008236516884L; | ||||
| @NotNull | @NotNull | ||||
| @Excel(name="卡ID",width = 20,orderNum = "1") | |||||
| @Excel(name="*卡ID",width = 20,orderNum = "1") | |||||
| @io.swagger.annotations.ApiModelProperty(value="ID",name="couponPasswordId") | @io.swagger.annotations.ApiModelProperty(value="ID",name="couponPasswordId") | ||||
| private String couponPasswordId; | private String couponPasswordId; | ||||
| @NotNull | @NotNull | ||||
| @Excel(name="面额(元)",width = 20,orderNum = "2") | |||||
| @Excel(name="*面额(元)",width = 20,orderNum = "2") | |||||
| @io.swagger.annotations.ApiModelProperty(value="面额(元)",name="price") | @io.swagger.annotations.ApiModelProperty(value="面额(元)",name="price") | ||||
| private String price; | private String price; | ||||
| } | } | ||||
| @@ -0,0 +1,36 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponPasswordPayCheck { | |||||
| NO_CHECK(0, "无验证"), | |||||
| PASSWORD(1, "密码"), | |||||
| ZHIWEN(2, "指纹识别"); | |||||
| public static EnumCouponPasswordPayCheck getEnum(Integer code) { | |||||
| for (EnumCouponPasswordPayCheck value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponPasswordPayCheck(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -2482,10 +2482,10 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| //判断卡是否已消费 | //判断卡是否已消费 | ||||
| //面额与余额是否相同 | //面额与余额是否相同 | ||||
| if (!cardCVo.getAmount().equals(cardCVo.getRemainingAmount())) { | |||||
| logger.info("面额与余额不相同"); | |||||
| return new ResultData(ErrorCode.CARD_TRANSFER_INVALID); | |||||
| } | |||||
| // if (!cardCVo.getAmount().equals(cardCVo.getRemainingAmount())) { | |||||
| // logger.info("面额与余额不相同"); | |||||
| // return new ResultData(ErrorCode.CARD_TRANSFER_INVALID); | |||||
| // } | |||||
| //保存到转赠表中 id,coupon_order_id,tenant_id,title,amount,remain_amount,from_user,to_user,status,create_date,update_date | //保存到转赠表中 id,coupon_order_id,tenant_id,title,amount,remain_amount,from_user,to_user,status,create_date,update_date | ||||
| try { | try { | ||||
| saveCardTransfer(record, cardCVo); | saveCardTransfer(record, cardCVo); | ||||
| @@ -2538,10 +2538,10 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| //判断卡是否已消费 | //判断卡是否已消费 | ||||
| //面额与余额是否相同 | //面额与余额是否相同 | ||||
| if (!cardCVo.getAmount().equals(cardCVo.getRemainingAmount())) { | |||||
| logger.info("面额与余额不相同"); | |||||
| return new ResultData(ErrorCode.CARD_TRANSFER_INVALID); | |||||
| } | |||||
| // if (!cardCVo.getAmount().equals(cardCVo.getRemainingAmount())) { | |||||
| // logger.info("面额与余额不相同"); | |||||
| // return new ResultData(ErrorCode.CARD_TRANSFER_INVALID); | |||||
| // } | |||||
| return new ResultData(Result.SUCCESS, "查询成功"); | return new ResultData(Result.SUCCESS, "查询成功"); | ||||
| } | } | ||||
| @@ -198,34 +198,11 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| @Override | @Override | ||||
| public WxCouponPassword getByObj(WxCouponPassword obj) { | public WxCouponPassword getByObj(WxCouponPassword obj) { | ||||
| String errMsg = "兑换码已失效"; | |||||
| List<WxCouponPassword> pwdList = wxCouponPasswordMapper.findList(obj); | List<WxCouponPassword> pwdList = wxCouponPasswordMapper.findList(obj); | ||||
| if (pwdList.size() <= 0) { | |||||
| logger.error(ErrorCode.COUPON_PASSWORD_NOT_FOUND.getMessage()); | |||||
| throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND.getCode(), errMsg); | |||||
| } | |||||
| WxCouponPassword password = null; | |||||
| Integer errCode = EnumCouponPasswordStatus.INIT.getCode(); | |||||
| for( WxCouponPassword pwd: pwdList) { | |||||
| if (pwd.getStatus().equals(EnumCouponPasswordStatus.USED.getCode())) { | |||||
| errCode = EnumCouponPasswordStatus.USED.getCode(); | |||||
| continue; | |||||
| } | |||||
| if (!pwd.getStatus().equals(EnumCouponPasswordStatus.USED.getCode()) && | |||||
| !pwd.getStatus().equals(EnumCouponPasswordStatus.CANCEL.getCode())) { | |||||
| password = pwd; | |||||
| } | |||||
| } | |||||
| if (password == null) { | |||||
| if (errCode.equals(EnumCouponPasswordStatus.USED.getCode())) { | |||||
| logger.error(ErrorCode.COUPON_PASSWORD_HAD_USED.getMessage()); | |||||
| throw new MallinkException(ErrorCode.COUPON_PASSWORD_HAD_USED.getCode(), errMsg); | |||||
| } else { | |||||
| logger.error(ErrorCode.COUPON_PASSWORD_IS_CANCELED.getMessage()); | |||||
| throw new MallinkException(ErrorCode.COUPON_PASSWORD_IS_CANCELED.getCode(), errMsg); | |||||
| } | |||||
| if (null == pwdList || pwdList.size() != 1 ) { | |||||
| return null; | |||||
| } | } | ||||
| WxCouponPassword password = pwdList.get(0); | |||||
| return password; | return password; | ||||
| } | } | ||||
| @@ -353,10 +330,20 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| public void exportTemplate(HttpServletRequest request, HttpServletResponse response) { | public void exportTemplate(HttpServletRequest request, HttpServletResponse response) { | ||||
| List<WxCardPriceTemplate> list = new ArrayList<>(); | List<WxCardPriceTemplate> list = new ArrayList<>(); | ||||
| WxCardPriceTemplate u1 = new WxCardPriceTemplate(); | WxCardPriceTemplate u1 = new WxCardPriceTemplate(); | ||||
| u1.setCouponPasswordId("输入卡号ID"); | |||||
| u1.setPrice("输入面额"); | |||||
| u1.setCouponPasswordId("336482251798482944"); | |||||
| u1.setPrice("500"); | |||||
| WxCardPriceTemplate u2 = new WxCardPriceTemplate(); | |||||
| u2.setCouponPasswordId("336482251802677248"); | |||||
| u2.setPrice("500.5"); | |||||
| WxCardPriceTemplate u3 = new WxCardPriceTemplate(); | |||||
| u3.setCouponPasswordId("336482251802677249"); | |||||
| u3.setPrice("500.53"); | |||||
| list.add(u1); | list.add(u1); | ||||
| list.add(u2); | |||||
| list.add(u3); | |||||
| excelService.exportExcel(list, null, "卡设置面额模板", WxCardPriceTemplate.class, "卡设置面额模板.xlsx", response, true); | excelService.exportExcel(list, null, "卡设置面额模板", WxCardPriceTemplate.class, "卡设置面额模板.xlsx", response, true); | ||||
| } | } | ||||
| @@ -1498,68 +1498,80 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| /// 储值卡信息添加 | /// 储值卡信息添加 | ||||
| if (isCard) { | if (isCard) { | ||||
| Integer fee = 0; | Integer fee = 0; | ||||
| WxCardInfo cardInfo = new WxCardInfo(); | |||||
| cardInfo.setId(couponOrder.getId()); | |||||
| cardInfo.updateTenantInfo(order); | |||||
| cardInfo.setCouponId(order.getProductId()); | |||||
| cardInfo.setAmount(coupon.getPrice()); | |||||
| cardInfo.setSaleAmount(coupon.getSalePrice()); | |||||
| if (null != couponPassWord) { | |||||
| cardInfo.setCouponPasswordId(couponPassWord.getId()); | |||||
| cardInfo.setCouponPassword(couponPassWord.getPassword()); | |||||
| } | |||||
| cardInfo.setCUserId(user.getId()); | |||||
| cardInfo.setOwnerUserId(user.getId()); | |||||
| cardInfo.setRemainingAmount(coupon.getPrice()); | |||||
| if (!coupon.checkIsFree()) { | |||||
| //判断该transctionId是否已经存在,如果存在,则不添加 | |||||
| WxCardInfo cardInfoq = new WxCardInfo(); | |||||
| cardInfoq.setTransactionId(payOrder.getTransactionId()); | |||||
| List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq); | |||||
| if (null != cardInfoList && cardInfoList.size() > 0) { | |||||
| //do nothing | |||||
| }else { | |||||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); | |||||
| if(cAppInfo == null){ | |||||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||||
| if(payAccount == null){ | |||||
| throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); | |||||
| } | |||||
| // 有价卡 | |||||
| cardInfo.setTransactionId(payOrder.getTransactionId()); | |||||
| WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); | |||||
| fee = OrderHelper.getRealRateAmount(share.getRealPayMent(), payAccount); | |||||
| Integer shareAmount = share.getRealPayMent() - fee; | |||||
| cardInfo.setShareFeeAmount(shareAmount); | |||||
| cardInfo.setRemainingShareFeeAmount(shareAmount); | |||||
| cardInfo.setRateAmount(0); | |||||
| } | |||||
| } else { | |||||
| // 免费卡 | |||||
| cardInfo.setShareFeeAmount(0); | |||||
| cardInfo.setRemainingShareFeeAmount(0); | |||||
| cardInfo.setRateAmount(0); | |||||
| if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||||
| WxCouponPassword updateCPwd = new WxCouponPassword(); | |||||
| updateCPwd.setId(couponPassWord.getId()); | |||||
| updateCPwd.setCardId(cardInfo.getId()); | |||||
| updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||||
| couponPasswordMapper.updateById(updateCPwd); | |||||
| } | |||||
| } | |||||
| cardInfo.setServiceFeeAmount(fee); | |||||
| cardInfo.setCreateDate(curr); | |||||
| cardInfo.setUpdateDate(curr); | |||||
| cardInfo.setSupportTransfer(coupon.getSupportTransfer()); | |||||
| //检查卡是否下架,如果是,不可转赠 | |||||
| WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId()); | |||||
| if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) { | |||||
| cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); | |||||
| } | |||||
| wxCardInfoMapper.insert(cardInfo); | |||||
| WxCardInfo cardInfo = null; | |||||
| if (null != couponPassWord && couponPassWord.isDefaultUser()) { | |||||
| cardInfo = couponPassWord.getWxCardInfo(); | |||||
| cardInfo.setUpdateDate(curr); | |||||
| cardInfo.setOwnerUserId(user.getId()); | |||||
| cardInfo.setCUserId(user.getId()); | |||||
| wxCardInfoMapper.updateById(cardInfo); | |||||
| }else { | |||||
| cardInfo = new WxCardInfo(); | |||||
| cardInfo.setId(couponOrder.getId()); | |||||
| cardInfo.updateTenantInfo(order); | |||||
| cardInfo.setCouponId(order.getProductId()); | |||||
| cardInfo.setAmount(coupon.getPrice()); | |||||
| cardInfo.setRemainingAmount(coupon.getPrice()); | |||||
| cardInfo.setSaleAmount(coupon.getSalePrice()); | |||||
| if (null != couponPassWord) { | |||||
| cardInfo.setCouponPasswordId(couponPassWord.getId()); | |||||
| cardInfo.setCouponPassword(couponPassWord.getPassword()); | |||||
| //后置卡券可能没有面额 | |||||
| cardInfo.setAmount(couponPassWord.getPrice()); | |||||
| cardInfo.setRemainingAmount(couponPassWord.getPrice()); | |||||
| } | |||||
| cardInfo.setCUserId(user.getId()); | |||||
| cardInfo.setOwnerUserId(user.getId()); | |||||
| if (!coupon.checkIsFree()) { | |||||
| //判断该transctionId是否已经存在,如果存在,则不添加 | |||||
| WxCardInfo cardInfoq = new WxCardInfo(); | |||||
| cardInfoq.setTransactionId(payOrder.getTransactionId()); | |||||
| List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq); | |||||
| if (null != cardInfoList && cardInfoList.size() > 0) { | |||||
| //do nothing | |||||
| }else { | |||||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); | |||||
| if(cAppInfo == null){ | |||||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||||
| if(payAccount == null){ | |||||
| throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); | |||||
| } | |||||
| // 有价卡 | |||||
| cardInfo.setTransactionId(payOrder.getTransactionId()); | |||||
| WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); | |||||
| fee = OrderHelper.getRealRateAmount(share.getRealPayMent(), payAccount); | |||||
| Integer shareAmount = share.getRealPayMent() - fee; | |||||
| cardInfo.setShareFeeAmount(shareAmount); | |||||
| cardInfo.setRemainingShareFeeAmount(shareAmount); | |||||
| cardInfo.setRateAmount(0); | |||||
| } | |||||
| } else { | |||||
| // 免费卡 | |||||
| cardInfo.setShareFeeAmount(0); | |||||
| cardInfo.setRemainingShareFeeAmount(0); | |||||
| cardInfo.setRateAmount(0); | |||||
| if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||||
| WxCouponPassword updateCPwd = new WxCouponPassword(); | |||||
| updateCPwd.setId(couponPassWord.getId()); | |||||
| updateCPwd.setCardId(cardInfo.getId()); | |||||
| updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||||
| couponPasswordMapper.updateById(updateCPwd); | |||||
| } | |||||
| } | |||||
| cardInfo.setServiceFeeAmount(fee); | |||||
| cardInfo.setCreateDate(curr); | |||||
| cardInfo.setUpdateDate(curr); | |||||
| cardInfo.setSupportTransfer(coupon.getSupportTransfer()); | |||||
| //检查卡是否下架,如果是,不可转赠 | |||||
| WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId()); | |||||
| if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) { | |||||
| cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); | |||||
| } | |||||
| wxCardInfoMapper.insert(cardInfo); | |||||
| } | |||||
| } | } | ||||
| try{ | try{ | ||||
| @@ -3058,8 +3070,25 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| Integer shippingType, UserBasicInfoAddress address,boolean isPressOrder) { | Integer shippingType, UserBasicInfoAddress address,boolean isPressOrder) { | ||||
| WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); | WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); | ||||
| // 减库存操作 | |||||
| StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber,isPressOrder); | |||||
| //实体卡未激活的,已经消费了,不用再扣库存 | |||||
| if (null != wxCouponPassword && wxCouponPassword.isDefaultUser()) { | |||||
| //do nothing | |||||
| }else { | |||||
| // 减库存操作 | |||||
| StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber,isPressOrder); | |||||
| //渠道的库存和价格可以随时修改。这里需要校验一下 | |||||
| if (stockReduceResult.isChannelStockReduce()) { | |||||
| //再查询一下,此时有可能价格已经修改 | |||||
| WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannel.getId(),coupon.getTenantId()); | |||||
| //如果这个时候渠道价格已经清空了 | |||||
| if (null == wxCouponChannel.getChannelPrice()) { | |||||
| throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已变动[清空],请刷新后重新下单."); | |||||
| } | |||||
| if (wxCouponChannel.getChannelPrice().intValue() > 0 ) { | |||||
| throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已非免费,请刷新后重新下单."); | |||||
| } | |||||
| } | |||||
| } | |||||
| // 当积分券或者积分停车券时 则进行积分支付 | // 当积分券或者积分停车券时 则进行积分支付 | ||||
| Integer orderType; | Integer orderType; | ||||
| @@ -3070,18 +3099,6 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| orderType = EnumOrderType.COUPON.getCode(); | orderType = EnumOrderType.COUPON.getCode(); | ||||
| } | } | ||||
| //渠道的库存和价格可以随时修改。这里需要校验一下 | |||||
| if (stockReduceResult.isChannelStockReduce()) { | |||||
| //再查询一下,此时有可能价格已经修改 | |||||
| WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannel.getId(),coupon.getTenantId()); | |||||
| //如果这个时候渠道价格已经清空了 | |||||
| if (null == wxCouponChannel.getChannelPrice()) { | |||||
| throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已变动[清空],请刷新后重新下单."); | |||||
| } | |||||
| if (wxCouponChannel.getChannelPrice().intValue() > 0 ) { | |||||
| throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已非免费,请刷新后重新下单."); | |||||
| } | |||||
| } | |||||
| // 4. 保存Order | // 4. 保存Order | ||||
| WxOrder record = new WxOrder(); | WxOrder record = new WxOrder(); | ||||