| @@ -244,6 +244,7 @@ public class WxCardInfoController extends BaseController { | |||
| @SystemControllerLog(description = "启用/停用") | |||
| public ResultData startOrStop(@RequestBody WxCardInfo WxCardInfo) { | |||
| try { | |||
| WxCardInfo.updateTenantInfo(getTenantInfo()); | |||
| wxCardInfoService.startOrStop(WxCardInfo); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -218,6 +218,7 @@ public class WxCouponController extends BaseController { | |||
| wxCouponService.deleteById(wxCoupon.getId(),wxCoupon.getTenantId()); | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeCouponMerchantCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCoupon.getId()); | |||
| return new ResultData(); | |||
| } | |||
| @@ -277,6 +278,7 @@ public class WxCouponController extends BaseController { | |||
| ResultData result = wxCouponService.updateTtProduct(coupon); | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeCouponMerchantCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCoupon.getId()); | |||
| return result; | |||
| } | |||
| @@ -421,6 +423,7 @@ public class WxCouponController extends BaseController { | |||
| return wxCouponService.updateCouponStockAndEndTime(wxCoupon); | |||
| } | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCoupon.getId()); | |||
| return new ResultData(); | |||
| } | |||
| @@ -442,13 +445,13 @@ public class WxCouponController extends BaseController { | |||
| } | |||
| if (EnumCouponSubsidyType.WECHAT_COUPON.getCode().equals(coupon.getSubsidyType())) { | |||
| // 微信 立减 | |||
| if (coupon.getSubsidyNum() > coupon.getSalePrice()) { | |||
| if (wxCoupon.getSubsidyNum() > coupon.getSalePrice()) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价"); | |||
| } | |||
| } else if (EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode().equals(coupon.getSubsidyType())) { | |||
| // 线下补贴 | |||
| int subsidy_num = wxCoupon.getPrice() - coupon.getSalePrice(); | |||
| if (coupon.getSubsidyNum() > subsidy_num) { | |||
| if (wxCoupon.getSubsidyNum() > subsidy_num) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值"); | |||
| } | |||
| } | |||
| @@ -466,6 +469,7 @@ public class WxCouponController extends BaseController { | |||
| wxCouponService.deleteById(id,getTenantInfo().getTenantId()); | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, id); | |||
| CouponCacheUtils.removeCouponMerchantCache(redisTemplate, id); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @@ -714,6 +718,7 @@ public class WxCouponController extends BaseController { | |||
| couponPasswordService.exportData(request, response, wxCouponPassword); | |||
| if (null != wxCouponPassword.getCouponId()) { | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCouponPassword.getCouponId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCouponPassword.getCouponId()); | |||
| } | |||
| } | |||
| @@ -739,6 +744,7 @@ public class WxCouponController extends BaseController { | |||
| ResultData result = wxCouponService.cardDefer(wxCoupon.getId(),getTenantInfo().getTenantId(),wxCoupon.getValidEndDate()); | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCoupon.getId()); | |||
| return result; | |||
| } | |||
| @@ -9,6 +9,7 @@ import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.WxCouponPassword; | |||
| import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; | |||
| import com.iformall.domain.vo.WxCouponPasswordVo; | |||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||
| import com.iformall.service.WxCouponPasswordService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| @@ -88,6 +89,12 @@ public class WxCouponPasswordController extends BaseController { | |||
| public ResultData batchList(@ModelAttribute WxCouponPassword wxCouponPassword, Integer pageNum, Integer pageSize) { | |||
| wxCouponPassword.updateTenantInfo(getTenantInfo()); | |||
| wxCouponPassword.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||
| StringBuffer statussb = new StringBuffer(); | |||
| statussb.append(EnumCouponPasswordStatus.MSG_SENDED.getCode()).append(",") | |||
| .append(EnumCouponPasswordStatus.MSG_SENDING.getCode()).append(",") | |||
| .append(EnumCouponPasswordStatus.USED.getCode()).append(",") | |||
| .append(EnumCouponPasswordStatus.CANCEL.getCode()); | |||
| wxCouponPassword.setStatusStr(statussb.toString()); | |||
| final PageInfo<WxCouponPasswordVo> page = wxCouponPasswordService.listVoAsPage(wxCouponPassword, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @@ -97,6 +104,7 @@ public class WxCouponPasswordController extends BaseController { | |||
| @SystemControllerLog(description = "启用/停用") | |||
| public ResultData startOrStop(@RequestBody WxCouponPassword wxCouponPassword) { | |||
| try { | |||
| wxCouponPassword.updateTenantInfo(getTenantInfo()); | |||
| wxCouponPasswordService.startOrStop(wxCouponPassword); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -13,6 +13,12 @@ alter table wx_card_info add column status int(1) not null default 0 comment ' | |||
| #update wx_card_info ci left join wx_coupon_order_89 co on ci.id = co.id | |||
| #set ci.c_user_id = co.c_user_id, ci.owner_user_id = co.owner_id | |||
| #update wx_card_info ci left join wx_coupon_password cp on ci.id = cp.card_id | |||
| #set ci.coupon_password_id = cp.id where cp.card_id is not null | |||
| update wx_card_info ci left join wx_coupon_password cp on ci.id = cp.card_id | |||
| set ci.coupon_password = cp.password where ci.coupon_password is null | |||
| alter table wx_coupon_password add column is_stop int(1) not null default 0 comment '是否已停止1-是,0-否'; | |||
| @@ -3,13 +3,18 @@ package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCardInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponPassword; | |||
| import com.iformall.domain.po.WxMerchantBUser; | |||
| import com.iformall.domain.vo.WxCardSpendVo; | |||
| import com.iformall.domain.vo.WxCouponOrderCVo; | |||
| import com.iformall.enums.EnumCardInfoType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.pay.WxPayConstant; | |||
| import com.iformall.service.PosBrunService; | |||
| import com.iformall.service.WxCardInfoService; | |||
| import com.iformall.service.WxCouponPasswordService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| @@ -35,7 +40,13 @@ public class WxCardInfoController extends BaseController { | |||
| @Autowired | |||
| private WxCardInfoService wxCardInfoService; | |||
| @Autowired | |||
| private WxCouponPasswordService couponPasswordService; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @ApiOperation(value = "查询卡信息") | |||
| @GetMapping("detail") | |||
| @ApiImplicitParams({ | |||
| @@ -46,25 +57,49 @@ public class WxCardInfoController extends BaseController { | |||
| } | |||
| String cardIdStr = dynamicId; | |||
| boolean isECard = false; | |||
| WxCardInfo cardInfo = null; | |||
| Map map = new HashMap(); | |||
| String _decodeCouponOrderId = WxCouponOrderCVo.getDecodeExpiredCouponOrderId(dynamicId); | |||
| if (_decodeCouponOrderId.contains(WxCouponOrderCVo.arg)) { | |||
| String[] decodeids = _decodeCouponOrderId.split(WxCouponOrderCVo.arg); | |||
| cardIdStr = decodeids[0]; | |||
| isECard = true; | |||
| } | |||
| WxCardInfo cardInfo = wxCardInfoService.getById(Long.parseLong(cardIdStr)); | |||
| if (null == cardInfo) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "未查询到卡:"+cardIdStr); | |||
| } | |||
| Map map = new HashMap(); | |||
| if (isECard) { | |||
| cardInfo = wxCardInfoService.getById(Long.parseLong(cardIdStr)); | |||
| if (null == cardInfo) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "未查询到卡:"+cardIdStr); | |||
| } | |||
| map.put("cardId", cardInfo.getId()); | |||
| map.put("amount", cardInfo.getAmount()); | |||
| map.put("remainAmount", cardInfo.getRemainingAmount()); | |||
| map.put("cardType", cardInfo.getType()); | |||
| }else { | |||
| map.put("cardId", cardInfo.getCouponPasswordId()); | |||
| Long couponPasswordId = Long.parseLong(cardIdStr); | |||
| //实体卡 | |||
| WxCouponPassword password = couponPasswordService.getById(couponPasswordId); | |||
| if (null == password) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "未查询到卡:"+cardIdStr); | |||
| } | |||
| cardInfo = wxCardInfoService.getByCouponPasswordId(couponPasswordId, password); | |||
| if (null != cardInfo) { | |||
| map.put("cardId", cardInfo.getId()); | |||
| map.put("amount", cardInfo.getAmount()); | |||
| map.put("remainAmount", cardInfo.getRemainingAmount()); | |||
| map.put("cardType", cardInfo.getType()); | |||
| }else { | |||
| //第一次刷卡的时候没有cardInfo | |||
| WxCoupon cq = new WxCoupon(); | |||
| cq.updateTenantInfo(password); | |||
| cq.setId(password.getCouponId()); | |||
| WxCoupon coupon = wxCouponService.findById(cq); | |||
| if (null == coupon) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "卡未查询到券:"+cardIdStr); | |||
| } | |||
| map.put("cardId", couponPasswordId); | |||
| map.put("amount", coupon.getPrice()); | |||
| map.put("remainAmount", coupon.getPrice()); | |||
| map.put("cardType", EnumCardInfoType.CARD.getCode()); | |||
| } | |||
| } | |||
| map.put("amount", cardInfo.getAmount()); | |||
| map.put("remainAmount", cardInfo.getRemainingAmount()); | |||
| map.put("cardType", cardInfo.getType()); | |||
| return new ResultData(map); | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| @@ -116,6 +117,8 @@ public class WxCardPayController extends BaseController { | |||
| @ApiOperation(value = "微信B端扫储值卡码支付订单", notes = "params:{\"dynamicId\":\"String\",\"totalFee\":\"String(元)\"}") | |||
| @PostMapping("scanCard") | |||
| public ResultData scanCard(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | |||
| logger.info("scanCard:"+JSON.toJSONString(paramMap)); | |||
| String cardIdStr = paramMap.get("dynamicId"); | |||
| String totalFeeStr = paramMap.get("totalFee"); | |||
| @@ -168,9 +171,9 @@ public class WxCardPayController extends BaseController { | |||
| logger.error("卡不存在: " + cardIdStr); | |||
| return new ResultData(ErrorCode.CARD_IS_NOT_FOUND); | |||
| } | |||
| return saveCardPayOrder(cUserId,cardInfo,merchantBUser,totalFeeStr,EnumPayWay.PAY_WAY_WECHAT); | |||
| return saveCardPayOrder(false,cUserId,cardInfo,merchantBUser,totalFeeStr,EnumPayWay.PAY_WAY_WECHAT); | |||
| } | |||
| public ResultData savePasswordCardPayOrder(String cardIdStr,String totalFeeStr) { | |||
| Long cardId = null; | |||
| try { | |||
| @@ -200,10 +203,10 @@ public class WxCardPayController extends BaseController { | |||
| } | |||
| WxCardInfo carInfo = wxCardInfoService.cardCreateByOffline(couponPassword, coupon); | |||
| return saveCardPayOrder(Constant.defaultCUserId,carInfo,merchantBUser,totalFeeStr,EnumPayWay.PAY_WAY_WECHAT); | |||
| return saveCardPayOrder(true,Constant.defaultCUserId,carInfo,merchantBUser,totalFeeStr,EnumPayWay.PAY_WAY_WECHAT); | |||
| } | |||
| private ResultData saveCardPayOrder(Long cUserId,WxCardInfo cardInfo,WxMerchantBUser merchantBUser,String totalFeeStr,EnumPayWay payWay) { | |||
| private ResultData saveCardPayOrder(boolean reduceStock,Long cUserId,WxCardInfo cardInfo,WxMerchantBUser merchantBUser,String totalFeeStr,EnumPayWay payWay) { | |||
| if (EnumCardInfoStatus.STOP.getCode().intValue() == cardInfo.getStatus().intValue()) { | |||
| return new ResultData(ErrorCode.CARD_IS_NOT_FOUND.getCode(),"卡已被禁用."); | |||
| @@ -218,14 +221,12 @@ public class WxCardPayController extends BaseController { | |||
| } | |||
| } | |||
| if (StringUtils.isBlank(totalFeeStr) || totalFeeStr.equalsIgnoreCase(Constant.UNDEFINED)) { | |||
| logger.error("totalFee不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "totalFee不能为空"); | |||
| } | |||
| BigDecimal totalFee = new BigDecimal(totalFeeStr); | |||
| totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||
| Integer payment = totalFee.multiply(new BigDecimal(100)).intValue(); | |||
| Long merchantId = merchantBUser.getMerchantId(); | |||
| if(payment > cardInfo.getRemainingAmount()) { | |||
| @@ -276,9 +277,14 @@ public class WxCardPayController extends BaseController { | |||
| record.setIp(ipStr); | |||
| record.setDeductionAmount(payment); | |||
| record.setRemark("操作于["+payWay.getMessage()+"("+payWay.getCode()+")]"); | |||
| Integer couponNumber = null; | |||
| if (reduceStock) { | |||
| couponNumber = 1; | |||
| } | |||
| try { | |||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant,payWay); | |||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant,couponNumber,payWay); | |||
| } catch (MallinkException e) { | |||
| logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -247,6 +247,7 @@ public class WxCouponController extends BaseController { | |||
| wxCouponService.deleteById(wxCoupon.getId(),wxCoupon.getTenantId()); | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeCouponMerchantCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCoupon.getId()); | |||
| return new ResultData(); | |||
| } | |||
| @@ -361,6 +362,7 @@ public class WxCouponController extends BaseController { | |||
| redisLock.setCouponStock(wxCoupon.getId(), wxCoupon.getRemainInventory()); | |||
| ResultData result = wxCouponService.updateCouponStockAndEndTime(wxCoupon); | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCoupon.getId()); | |||
| return result; | |||
| } | |||
| @@ -375,6 +377,7 @@ public class WxCouponController extends BaseController { | |||
| wxCouponService.deleteById(id,getTenantInfo().getTenantId()); | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, id); | |||
| CouponCacheUtils.removeCouponMerchantCache(redisTemplate, id); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @@ -476,6 +479,7 @@ public class WxCouponController extends BaseController { | |||
| couponPasswordService.exportData(request, response, wxCouponPassword); | |||
| if (null != wxCouponPassword.getCouponId()) { | |||
| CouponCacheUtils.removeCouponCache(redisTemplate, wxCouponPassword.getCouponId()); | |||
| CouponCacheUtils.removeOnlyCouponCache(redisTemplate, wxCouponPassword.getCouponId()); | |||
| } | |||
| } | |||
| @@ -188,7 +188,7 @@ public class WxCardPayController extends BaseController { | |||
| record.setRemark("操作于["+payWay.getMessage()+"("+payWay.getCode()+")]"); | |||
| try { | |||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant,payWay); | |||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant,null,payWay); | |||
| } catch (MallinkException e) { | |||
| logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -76,7 +76,43 @@ public class WxCouponController extends BaseController { | |||
| @Autowired | |||
| private SysConfigService sysConfigService; | |||
| @ApiOperation("查询优惠券详情(系统发放卡没有couponChannel)") | |||
| @GetMapping("/couponInfo") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "mallTenantId", value = "mallTenantId", dataType = "String", paramType = "query", required = false)}) | |||
| public ResultData couponInfo(Long couponId,String mallTenantId) { | |||
| if (null == couponId || (StringUtils.isBlank(mallTenantId) || mallTenantId.equalsIgnoreCase(Constant.UNDEFINED)) | |||
| ) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId/mallTenantId为空"); | |||
| } | |||
| if(couponId <= 0){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponIdId为空"); | |||
| } | |||
| WxCoupon coupon = CouponCacheUtils.getOnlyCouponCache(redisTemplate, couponId); | |||
| if (null == coupon) { | |||
| coupon = couponService.getById(couponId,mallTenantId); | |||
| if (null == coupon) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "找不到coupon" + couponId); | |||
| } | |||
| WxCoupon attrsById = couponService.getAttrsById(couponId, mallTenantId); | |||
| coupon.setProductAttrs(attrsById.getProductAttrs()); | |||
| coupon.setSkuAttrs(attrsById.getSkuAttrs()); | |||
| if(EnumCouponType.COUPON_GIFT.getCode().equals(coupon.getType())){ | |||
| WxCoupon couponQ = new WxCoupon(); | |||
| couponQ.updateTenantInfo(coupon); | |||
| List<Long> longs = JSON.parseArray(coupon.getGiftList(), Long.class); | |||
| if(longs != null && longs.size() > 0){ | |||
| couponQ.setIds(longs); | |||
| coupon.setGiftCouponList(couponService.list(couponQ)); | |||
| } | |||
| } | |||
| coupon.setCouponId(coupon.getId()); | |||
| CouponCacheUtils.setOnlyCouponCache(redisTemplate, couponId, coupon); | |||
| } | |||
| return new ResultData(coupon); | |||
| } | |||
| @ApiOperation("根据id(couponChannel)查询详情接口") | |||
| @GetMapping("/couponDetail") | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.RedisCache; | |||
| import com.iformall.common.ErrorCode; | |||
| @@ -421,12 +422,8 @@ public class WxCouponOrderController extends BaseController { | |||
| @ApiOperation(value = "查询转赠卡状态") | |||
| @GetMapping("queryCardStatus") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "id", value = "coupon_order_id", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "cUserId", value = "转赠者", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryCardStatus(@ModelAttribute WxCouponOrder wxCouponOrder) { | |||
| //coupon_order_id判断 | |||
| //coupon_order_id判断 | |||
| Long id = wxCouponOrder.getId(); | |||
| if (id == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| @@ -77,10 +77,11 @@ public class WxCouponPasswordController extends BaseController { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(500, e.getMessage()); | |||
| } | |||
| if (couponPassword.getIsStop().intValue() == EnumYesOrNo.YES.getCode().intValue()) { | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"卡密已经停用"); | |||
| } | |||
| WxCUserBasicInfo member = userService.getById(memberId,getFinalTenantId()); | |||
| if(member == null) { | |||
| logger.error("会员用户未找到: " + memberId); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "会员用户未找到" + memberId); | |||
| } | |||
| @@ -89,9 +90,11 @@ public class WxCouponPasswordController extends BaseController { | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { | |||
| logger.error("此券已作废:" + coupon.getId()); | |||
| 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(); | |||
| @@ -9,6 +9,7 @@ import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @TableName(value = "wx_coupon_password") | |||
| @Data | |||
| @@ -31,6 +32,8 @@ public class WxCouponPassword extends TenantEntity { | |||
| @Excel(name = "状态", width = 20, replace = {"初始_0", "发送中_1", "已发出_2", "已使用_3", "不可用_4"}, orderNum = "4") | |||
| @io.swagger.annotations.ApiModelProperty(value="卡密状态: 0初始1信息发出中2信息已发出3已使用4已过期",name="status") | |||
| private Integer status; | |||
| @TableField(exist = false) | |||
| private List<Integer> statusList; | |||
| @Excel(name = "发送手机", width = 20, orderNum = "5") | |||
| @io.swagger.annotations.ApiModelProperty(value="卡密发送到手机",name="sendedPhone") | |||
| private String sendedPhone; | |||
| @@ -59,7 +59,7 @@ public class WxCouponPasswordVo extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value = "余额(元)", name = "remainPrice") | |||
| private Double remainPrice; | |||
| @Excel(name = "电子卡状态", width = 20, orderNum = "13",replace = {"正常_0", "已禁用_1"}, prefix = "`") | |||
| @io.swagger.annotations.ApiModelProperty(value = "电子卡状态EnumYesOrNo", name = "used") | |||
| @io.swagger.annotations.ApiModelProperty(value = "电子卡状态EnumYesOrNo", name = "cardStatus") | |||
| private Integer cardStatus; | |||
| } | |||
| @@ -42,7 +42,7 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> { | |||
| void deleteById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| Integer setPrice(@Param("id")Long id,@Param("tenantId")String tenantId,@Param("price")Integer price); | |||
| Integer setPrice(@Param("id")Long id,@Param("tenantId")String tenantId,@Param("price")Integer price,@Param("subsidyNum")Integer subsidyNum); | |||
| Integer reduceInventory(@Param("id")Long id,@Param("tenantId")String tenantId,@Param("number")Integer number); | |||
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxCardInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponPassword; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxCardVo; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| @@ -29,6 +30,8 @@ public interface WxCardInfoService { | |||
| */ | |||
| WxCardInfo getById(Long id); | |||
| WxCardInfo getByCouponPasswordId(Long couponPasswordId,TenantEntity tenantEntity); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| @@ -28,7 +28,7 @@ public interface WxCardSpendService { | |||
| * @param order | |||
| * @return | |||
| */ | |||
| ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,EnumPayWay payWay); | |||
| ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,Integer reduceCouponNumber,EnumPayWay payWay); | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| @@ -284,7 +284,7 @@ public class WxCardInfoServiceImpl implements WxCardInfoService { | |||
| @Override | |||
| public WxCardInfo cardCreateByOffline(WxCouponPassword couponPassword,WxCoupon coupon) { | |||
| //如果没有卡,则直接创建一个 | |||
| WxCardInfo cardInfo = this.getById(couponPassword.getId()); | |||
| WxCardInfo cardInfo = this.getByCouponPasswordId(couponPassword.getId(),couponPassword); | |||
| if (null == cardInfo) { | |||
| long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | |||
| String timeStr = String.valueOf(time); | |||
| @@ -309,6 +309,8 @@ public class WxCardInfoServiceImpl implements WxCardInfoService { | |||
| updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||
| couponPasswordMapper.updateById(updateCPwd); | |||
| } | |||
| cardInfo.setCouponPasswordId(couponPassword.getId()); | |||
| cardInfo.setCouponPassword(couponPassword.getPassword()); | |||
| cardInfo.setCUserId(Constant.defaultCUserId); | |||
| cardInfo.setOwnerUserId(Constant.defaultCUserId); | |||
| cardInfo.setServiceFeeAmount(0); | |||
| @@ -327,4 +329,16 @@ public class WxCardInfoServiceImpl implements WxCardInfoService { | |||
| wxCardInfoMapper.updateStatus(cardInfo); | |||
| } | |||
| @Override | |||
| public WxCardInfo getByCouponPasswordId(Long couponPasswordId, TenantEntity tenantEntity) { | |||
| WxCardInfo cardQ = new WxCardInfo(); | |||
| cardQ.updateTenantInfo(tenantEntity); | |||
| cardQ.setCouponPasswordId(couponPasswordId); | |||
| List<WxCardInfo> infoList = wxCardInfoMapper.findList(cardQ); | |||
| if (null != infoList && infoList.size() > 0 ) { | |||
| return infoList.get(0); | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| @@ -18,9 +18,12 @@ import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.PayUtils; | |||
| import com.iformall.utils.RedisLock; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| @@ -54,9 +57,11 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| @Autowired | |||
| WxCouponMerchantMapper wxCouponMerchantMapper; | |||
| @Lazy | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Lazy | |||
| @Autowired | |||
| WxPayAccountService wxPayAccountService; | |||
| @@ -66,23 +71,34 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| @Autowired | |||
| WxCouponOrderMapper wxCouponOrderMapper; | |||
| @Lazy | |||
| @Autowired | |||
| WxProfitSharingOrderService profitSharingOrderService; | |||
| @Autowired | |||
| ExcelService excelService; | |||
| @Lazy | |||
| @Autowired | |||
| WxCreditHistoryService wxCreditHistoryService; | |||
| @Lazy | |||
| @Autowired | |||
| WxScoreRulesService wxScoreRulesService; | |||
| @Lazy | |||
| @Autowired | |||
| WxCashOutService wxCashOutService; | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Lazy | |||
| @Autowired | |||
| WxCouponService wxCouponService; | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| @Override | |||
| public WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId) { | |||
| @@ -102,7 +118,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,EnumPayWay payWay) { | |||
| public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,Integer reduceCouponNumber,EnumPayWay payWay) { | |||
| Date curDate = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| // 1. get card info | |||
| @@ -132,6 +148,15 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| if(payAccount == null){ | |||
| return new ResultData(ErrorCode.API_KEY_NOT_FOUND); | |||
| } | |||
| //扣减库存 | |||
| if (null != reduceCouponNumber && reduceCouponNumber > 0) { | |||
| wxCouponService.reduceRemainInventory(coupon,coupon.getId(),reduceCouponNumber); | |||
| long stock = redisLock.decrease(EnumCacheKey.COUPON_STOCK.getMessage()+coupon.getId(), reduceCouponNumber); | |||
| if (stock < 0 ) { | |||
| return new ResultData(ErrorCode.API_KEY_NOT_FOUND.getCode(),"库存不足"); | |||
| } | |||
| } | |||
| // 4. 扣减计算 | |||
| Double paymentD = 1.0 * cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); | |||
| @@ -2529,6 +2529,10 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL.getCode(),"cardInfo未查询到"); | |||
| } | |||
| if (EnumCardInfoStatus.STOP.getCode().intValue() == cardInfo.getStatus().intValue()) { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL.getCode(),"卡已被停用"); | |||
| } | |||
| //转赠人是否存在 | |||
| Long cUserId = record.getCUserId(); | |||
| @@ -133,7 +133,7 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||
| if (null != cardInfo) { | |||
| co.setUsed(EnumYesOrNo.YES.getCode()); | |||
| co.setPrice(new BigDecimal(cardInfo.getAmount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); | |||
| co.setRemainPrice(new BigDecimal(cardInfo.getRateAmount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); | |||
| co.setRemainPrice(new BigDecimal(cardInfo.getRemainingAmount()).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); | |||
| co.setActiveDate(cardInfo.getCreateDate()); | |||
| WxCUserBasicInfo basicInfo = cUserMap.get(cardInfo.getCUserId()); | |||
| if (null != basicInfo) { | |||
| @@ -1022,7 +1022,7 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| @Override | |||
| @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public ResultData setPrice(WxCoupon record) { | |||
| Integer count = wxCouponMapper.setPrice(record.getId(), record.getTenantId(), record.getPrice()); | |||
| Integer count = wxCouponMapper.setPrice(record.getId(), record.getTenantId(), record.getPrice(),record.getSubsidyNum()); | |||
| if (null == count || count <= 0 ) { | |||
| return new ResultData(Result.ERROR,"设置失败"); | |||
| } | |||
| @@ -1455,9 +1455,12 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| cardInfo.setCouponId(order.getProductId()); | |||
| cardInfo.setAmount(coupon.getPrice()); | |||
| cardInfo.setSaleAmount(coupon.getSalePrice()); | |||
| cardInfo.setCouponPasswordId(couponPassWord.getId()); | |||
| cardInfo.setCouponPassword(couponPassWord.getPassword()); | |||
| cardInfo.setCUserId(user.getId()); | |||
| 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是否已经存在,如果存在,则不添加 | |||
| @@ -31,6 +31,20 @@ public class CouponCacheUtils { | |||
| return RedisCacheUtils.getCacheObject(template, key,WxCouponChannel.class); | |||
| } | |||
| public static void removeOnlyCouponCache(RedisTemplate<String, Object> template,Long couponId) { | |||
| String key = "onlyCouponDetail:"+couponId; | |||
| RedisCacheUtils.removeCache(template, key); | |||
| } | |||
| public static void setOnlyCouponCache(RedisTemplate<String, Object> template,Long couponId,WxCoupon coupon) { | |||
| String key = "onlyCouponDetail:"+couponId; | |||
| RedisCacheUtils.cache(template, key, coupon, 24*3600); | |||
| } | |||
| public static WxCoupon getOnlyCouponCache(RedisTemplate<String, Object> template,Long couponId) { | |||
| String key = "onlyCouponDetail:"+couponId; | |||
| return RedisCacheUtils.getCacheObject(template, key,WxCoupon.class); | |||
| } | |||
| public static void removeCouponCache(RedisTemplate<String, Object> template,Long couponId) { | |||
| String key = "couponDetail:"+couponId; | |||
| @@ -1525,7 +1525,7 @@ | |||
| </update> | |||
| <update id="setPrice" parameterType="HashMap"> | |||
| update wx_coupon set price = #{price} where id = #{id} and tenant_id = #{tenantId} and price = 0 | |||
| update wx_coupon set price = #{price},subsidy_num={subsidyNum} where id = #{id} and tenant_id = #{tenantId} and price = 0 | |||
| </update> | |||
| </mapper> | |||