| @@ -164,7 +164,7 @@ public class WxOrderController extends BaseController { | |||
| if (!wxOrderService.checkCouponIsFree(coupon)) | |||
| return new ResultData(ErrorCode.COUPON_IS_NOT_FREE); | |||
| // 免费券 | |||
| order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); | |||
| order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -0,0 +1,80 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.Constant; | |||
| 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 java.util.Date; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/couponPassword") | |||
| @Api(description = "卡密相关接口") | |||
| public class WxCouponPasswordController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxCouponPasswordService couponPasswordService; | |||
| @Autowired | |||
| private WxCouponService couponService; | |||
| @Autowired | |||
| private WxOrderService orderService; | |||
| @ApiOperation(value = "根据卡密领卡", notes = "{\"password\":\"String\",\"formId\":\"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"); | |||
| if (StringUtils.isBlank(password) || password.equalsIgnoreCase(Constant.UNDEFINED)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "password不能为空"); | |||
| } | |||
| // 1. 根据password获取领取的couponId | |||
| WxCouponPassword couponPasswordQ = new WxCouponPassword(); | |||
| couponPasswordQ.setTenantId(getTenantId()); | |||
| 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()); | |||
| } | |||
| // 2. 设置已使用 | |||
| try { | |||
| WxCouponPassword updateCouponPwd = new WxCouponPassword(); | |||
| updateCouponPwd.setId(couponPassword.getId()); | |||
| updateCouponPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||
| couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||
| couponPasswordService.saveOrUpdate(updateCouponPwd); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.DB_FAIL); | |||
| } | |||
| // 3. 领取free coupon | |||
| WxCUser cuUser = getUser(); | |||
| WxCoupon coupon = couponService.getById(couponPassword.getId()); | |||
| // TODO ? check 卡券状态 | |||
| orderService.saveFreeOrderForCoupon(cuUser, coupon, null, formId, couponPassword.getId()); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -219,8 +219,12 @@ public enum ErrorCode{ | |||
| COUPON_PRESS_IS_OVERTIME(9071, "砍价已超时"), | |||
| COUPON_PRESS_IS_EXIST(9072, "此人已参与此次砍价"), | |||
| /** | |||
| * 卡密 | |||
| */ | |||
| CARD_PASSWORD_NOT_FOUND(9501, "卡密未找到"), | |||
| CARD_PASSWORD_HAD_USED(9502, "卡密已使用"), | |||
| CARD_PASSWORD_IS_CANCELED(9503, "卡密已过期或者已下架"), | |||
| /** | |||
| * 微信 | |||
| @@ -25,6 +25,14 @@ public interface WxCouponPasswordService { | |||
| * @return | |||
| */ | |||
| WxCouponPassword getById(Long id); | |||
| /** | |||
| * 根据密码获取卡密信息 | |||
| * | |||
| * @param obj | |||
| * @return | |||
| */ | |||
| WxCouponPassword getByObj(WxCouponPassword obj); | |||
| /** | |||
| * 保存或更新实体 | |||
| @@ -176,7 +176,7 @@ public interface WxOrderService { | |||
| boolean checkCouponIsFree(WxCoupon coupon); | |||
| // 2. 创建免费订单, 领取 couponOrder | |||
| WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId); | |||
| WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId); | |||
| // 3. 创建有价订单 | |||
| WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId); | |||
| @@ -6,6 +6,8 @@ import com.iformall.common.IdWorker; | |||
| import com.iformall.domain.po.WxCouponPassword; | |||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||
| import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCouponPasswordMapper; | |||
| import com.iformall.service.WxCouponPasswordService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -33,6 +35,34 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||
| return wxCouponPasswordMapper.selectByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public WxCouponPassword getByObj(WxCouponPassword obj) { | |||
| List<WxCouponPassword> pwdList = wxCouponPasswordMapper.findList(obj); | |||
| if (pwdList.size() <= 0) { | |||
| throw new MallinkException(ErrorCode.CARD_PASSWORD_NOT_FOUND); | |||
| } | |||
| 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())) { | |||
| throw new MallinkException(ErrorCode.CARD_PASSWORD_HAD_USED); | |||
| } else { | |||
| throw new MallinkException(ErrorCode.CARD_PASSWORD_IS_CANCELED); | |||
| } | |||
| } | |||
| return password; | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxCouponPassword record) { | |||
| if (record.getId() == null) { | |||
| @@ -34,7 +34,7 @@ import java.util.stream.Collectors; | |||
| @Service | |||
| public class WxCouponServiceImpl implements WxCouponService { | |||
| public class WxCouponServiceImpl implements WxCouponService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| @@ -118,6 +118,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| private WxMsgLimitService wxMsgLimitService; | |||
| @Autowired | |||
| private WxCouponPasswordMapper couponPasswordMapper; | |||
| @Override | |||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | |||
| @@ -636,7 +639,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param order | |||
| * @param coupon | |||
| */ | |||
| private WxCouponOrder createCouponOrder(WxOrder order, WxCUser user, WxCoupon coupon) { | |||
| private WxCouponOrder createCouponOrder(WxOrder order, WxCUser user, WxCoupon coupon, Long couponPasswordId) { | |||
| Date curr = new Date(); | |||
| Date valid_date = null; | |||
| int limit_days = Constant.WX_LIMIT_DAYS; | |||
| @@ -720,6 +723,12 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| cardInfo.setShareFeeAmount(0); | |||
| cardInfo.setRemainingShareFeeAmount(0); | |||
| cardInfo.setRateAmount(0); | |||
| if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||
| WxCouponPassword updateCPwd = new WxCouponPassword(); | |||
| updateCPwd.setId(couponPasswordId); | |||
| updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||
| couponPasswordMapper.updateByPrimaryKeySelective(updateCPwd); | |||
| } | |||
| } | |||
| cardInfo.setServiceFeeAmount(fee); | |||
| @@ -812,7 +821,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // 创建couponOrder | |||
| WxCouponOrder couponOrder = null; | |||
| try { | |||
| couponOrder = createCouponOrder(record, user, coupon); | |||
| couponOrder = createCouponOrder(record, user, coupon, null); | |||
| } catch (Exception e) { | |||
| logger.error("保存订单:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR.getCode(), coupon.getTitle() + ErrorCode.COUPON_ORDER_SAVE_ERR.getMessage()); | |||
| @@ -859,7 +868,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // 创建couponOrder | |||
| try { | |||
| createCouponOrder(updateOrder, user, coupon); | |||
| createCouponOrder(updateOrder, user, coupon, null); | |||
| } catch (Exception e) { | |||
| logger.error("创建券包:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| @@ -1360,7 +1369,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| WxOrder order = null; | |||
| if (checkCouponIsFree(coupon)) { | |||
| // 免费券 | |||
| order = saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); | |||
| order = saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null); | |||
| if(order != null) { | |||
| // 6. 下订单完成,发送内部消息 | |||
| // 下订单完成,发送内部消息 | |||
| @@ -1394,7 +1403,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId) { | |||
| public WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId) { | |||
| // 1. check user info and coupon info | |||
| userCouponMerchantCheck(user, coupon); | |||
| if (coupon.checkIsCreditCoupon()) { | |||
| @@ -1434,7 +1443,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // 5. 创建couponOrder | |||
| try { | |||
| createCouponOrder(record, user, coupon); | |||
| createCouponOrder(record, user, coupon, couponPasswordId); | |||
| } catch (Exception e) { | |||
| logger.error("couponOrder失败:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| @@ -34,13 +34,13 @@ | |||
| and `coupon_short` = #{couponShort} | |||
| </if> | |||
| <if test=" null != password "> | |||
| and `password` like concat('%', #{password},'%') | |||
| and `password` = #{password} | |||
| </if> | |||
| <if test=" null != status "> | |||
| and `status` = #{status} | |||
| </if> | |||
| <if test=" null != sendedPhone "> | |||
| and `sended_phone` like concat('%', #{sendedPhone},'%') | |||
| and `sended_phone` = #{sendedPhone} | |||
| </if> | |||
| <if test=" null != cardId "> | |||
| and `card_id` = #{cardId} | |||
| @@ -52,7 +52,7 @@ | |||
| and `update_date` = #{updateDate} | |||
| </if> | |||
| <if test=" null != expireDate "> | |||
| and `expire_date` = #{expireDate} | |||
| and `expire_date` > #{expireDate} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| @@ -69,7 +69,8 @@ | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_coupon_password | |||
| select <include refid="allColumns" /> | |||
| from wx_coupon_password | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||