| @@ -190,7 +190,7 @@ public class WxOrderController extends BaseController { | |||
| WxComposeOrder composeOrder = orderFactory.getOrderAdapterService(EnumComposeOrder.SINGLE.getCode()).createDBMainOrder(coupon, user, 0, EnumPayWay.PAY_WAY_NOT_UNPAY_CREDIT,EnumPayVersion.NO_VERSION); | |||
| order = wxOrderService.saveFreeOrderForCoupon(new Date(),false,composeOrder,user, coupon, 1, | |||
| wxCouponChannel, orderSaveDto.getFormId(), null,null,EnumPayWay.PAY_WAY_NOT_UNPAY_CREDIT,EnumPayVersion.NO_VERSION, | |||
| EnumOrderShopingType.ONLINE_PURCHASE.getCode(),null); | |||
| EnumOrderShopingType.ONLINE_PURCHASE.getCode(),null,false); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -115,7 +115,7 @@ public class WxPressBatchController extends BaseController { | |||
| if (null == record.getId()) { | |||
| return new ResultData(Result.ERROR,"参数错误"); | |||
| } | |||
| String cidstr = record.getCouponChannelIds(); | |||
| String cidstr = record.getCouponIds(); | |||
| if (StringUtils.isBlank(cidstr)) { | |||
| return new ResultData(Result.ERROR,"参数错误"); | |||
| } | |||
| @@ -6,6 +6,7 @@ CREATE TABLE `wx_press_batch` ( | |||
| `status` int(1) NOT NULL DEFAULT '0' COMMENT '状态0-草稿 1-进行中 2-已停止', | |||
| `create_date` datetime DEFAULT NULL, | |||
| `update_date` datetime DEFAULT NULL, | |||
| `promoter_limit_rule` int(1) NOT NULL DEFAULT '1' COMMENT '发起人限制规则', | |||
| `promoter_allow_count` int(3) NOT NULL DEFAULT '0' COMMENT '发起人允许发起次数', | |||
| `bargainer_allow_same` int(1) NOT NULL DEFAULT '0' COMMENT '同一个用户是否可以砍相同商品', | |||
| `bargainer_allow_count` int(3) NOT NULL DEFAULT '0' COMMENT '同一个用户可砍价次数', | |||
| @@ -17,7 +18,7 @@ CREATE TABLE `wx_press_batch_item` ( | |||
| `tenant_id` varchar(5) NOT NULL, | |||
| `parent_tenant_id` varchar(5) DEFAULT NULL, | |||
| `press_batch_id` bigint(20) NOT NULL COMMENT '批次id', | |||
| `coupon_channel_id` bigint(20) NOT NULL COMMENT '砍价券id', | |||
| `coupon_id` bigint(20) NOT NULL COMMENT '砍价券id', | |||
| `press_batch_status` int(1) NOT NULL COMMENT '批次状态', | |||
| `create_date` datetime DEFAULT NULL, | |||
| `update_date` datetime DEFAULT NULL, | |||
| @@ -104,7 +104,7 @@ public class WxCouponPasswordController extends BaseController { | |||
| 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.getId(),null,payWay,payVersion, | |||
| EnumOrderShopingType.ONLINE_PURCHASE.getCode(),null); | |||
| EnumOrderShopingType.ONLINE_PURCHASE.getCode(),null,false); | |||
| } catch (MallinkException e) { | |||
| setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus)); | |||
| logger.error(e.getMessage(),e); | |||
| @@ -13,6 +13,7 @@ import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderPressService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPressBatchService; | |||
| import com.iformall.utils.RedisLock; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| @@ -57,6 +58,9 @@ public class WxPressOrderController extends BaseController { | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| @Autowired | |||
| WxPressBatchService wxPressBatchService; | |||
| // 砍价列表 - /api/wxCouponChannel/list | |||
| // 我的砍价 - /api/order/pressOrderList | |||
| @@ -168,7 +172,11 @@ public class WxPressOrderController extends BaseController { | |||
| logger.error("用户已参与砍价"); | |||
| return new ResultData(ErrorCode.COUPON_PRESS_IS_EXIST); | |||
| } | |||
| //验证砍价批次规则 | |||
| ResultData result = wxPressBatchService.checkBargainerPressBatchRule(order, memberId); | |||
| if (Result.SUCCESS != result.code) { | |||
| return result; | |||
| } | |||
| try { | |||
| WxOrderPress orderPress = wxOrderPressService.pressCouponJoin(order, wxCouponCVo, memberId); | |||
| if (orderPress != null) { | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| @@ -16,6 +17,8 @@ public class WxOrderPress extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="券ID",name="couponId") | |||
| private Long couponId; | |||
| @TableField(exist = false) | |||
| private List<Long> couponIds; | |||
| @io.swagger.annotations.ApiModelProperty(value="订单ID",name="orderId") | |||
| private Long orderId; | |||
| @io.swagger.annotations.ApiModelProperty(value="砍价参与人ID",name="userId") | |||
| @@ -26,6 +26,8 @@ public class WxPressBatch extends TenantEntity { | |||
| private Date createDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||
| private Date updateDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="发起人限制规则EnumCouponUseLimitRule",name="promoterLimitRule") | |||
| private Integer promoterLimitRule; | |||
| @io.swagger.annotations.ApiModelProperty(value="发起人允许发起次数",name="promoterAllowCount") | |||
| private Integer promoterAllowCount; | |||
| @io.swagger.annotations.ApiModelProperty(value="同一个用户是否可以砍相同商品",name="bargainerAllowSame") | |||
| @@ -34,6 +36,8 @@ public class WxPressBatch extends TenantEntity { | |||
| private Integer bargainerAllowCount; | |||
| @TableField(exist = false) | |||
| private String couponChannelIds; | |||
| private String couponIds; | |||
| } | |||
| @@ -19,8 +19,8 @@ public class WxPressBatchItem extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="批次id",name="pressBatchId") | |||
| private Long pressBatchId; | |||
| @io.swagger.annotations.ApiModelProperty(value="砍价券id",name="couponChannelId") | |||
| private Long couponChannelId; | |||
| @io.swagger.annotations.ApiModelProperty(value="砍价券id",name="couponId") | |||
| private Long couponId; | |||
| @io.swagger.annotations.ApiModelProperty(value="EnumPressBatchStatus",name="pressBatchStatus") | |||
| private Integer pressBatchStatus; | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| @@ -0,0 +1,19 @@ | |||
| package com.iformall.domain.vo; | |||
| import java.io.Serializable; | |||
| import java.text.DecimalFormat; | |||
| import java.util.List; | |||
| import com.iformall.domain.po.WxDateAmountRecord; | |||
| import com.iformall.domain.po.WxPressBatch; | |||
| import lombok.Data; | |||
| @Data | |||
| public class CouponPressBatchVo implements Serializable{ | |||
| private static final long serialVersionUID = 4494858079134918638L; | |||
| //核销金额记录 | |||
| private WxPressBatch pressBatch; | |||
| private List<Long> couponIdList; | |||
| } | |||
| @@ -12,6 +12,6 @@ public interface WxOrderPressMapper extends CommonMapper<WxOrderPress, Long> { | |||
| WxOrderPress selectById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| List<WxOrderPress> findList(WxOrderPress wxOrderPress); | |||
| List<WxOrderPressVo> findPressList(Map paramMap); | |||
| List<WxOrderPress> findPressList(Map paramMap); | |||
| } | |||
| @@ -18,4 +18,6 @@ public interface WxPressBatchItemMapper extends CommonMapper<WxPressBatchItem, L | |||
| void deleteItem(WxPressBatchItem record); | |||
| void deleteAllItem(WxPressBatchItem record); | |||
| List<Long> getCouponIds(@Param("pressBatchId")Long pressBatchId,@Param("tenantId")String tenantId,@Param("pressBatchStatus")Integer pressBatchStatus); | |||
| } | |||
| @@ -59,12 +59,5 @@ public interface WxOrderPressService { | |||
| boolean checkCUserHasJoin(WxOrder order, Long cUserId); | |||
| void sendPressComplateMsg(WxOrder orderUpdatePress); | |||
| } | |||
| @@ -216,7 +216,7 @@ public interface WxOrderService { | |||
| // 2. 创建免费订单, 领取 couponOrder | |||
| WxOrder saveFreeOrderForCoupon(Date orderDate,boolean allowUnPayOrder,WxComposeOrder composeOrder, WxCUserBasicInfo user, WxCoupon coupon, int couponNumber, | |||
| WxCouponChannel couponChannel, String formId, Long couponPasswordId,String extParam, EnumPayWay payWay,EnumPayVersion payVersion, | |||
| Integer shippingType, UserBasicInfoAddress address); | |||
| Integer shippingType, UserBasicInfoAddress address,boolean isPressOrder); | |||
| // 3. 创建有价订单 | |||
| WxOrder saveNoFreeOrderForCoupon(Date orderDate,boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber, | |||
| @@ -10,9 +10,11 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.TtCouponChannelPoi; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPressBatch; | |||
| import com.iformall.domain.po.WxPressBatchItem; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.CouponPressBatchVo; | |||
| import com.iformall.domain.vo.TtCouponVo; | |||
| import com.iformall.domain.vo.WxCouponCVo; | |||
| import com.iformall.domain.vo.WxCouponStatisVo; | |||
| @@ -39,10 +41,16 @@ public interface WxPressBatchService { | |||
| List<WxPressBatchItem> getItemList(Long batchId,String tenantId); | |||
| void saveItems(WxPressBatch pressBatch,String[] couponChannelIds); | |||
| void saveItems(WxPressBatch pressBatch,String[] couponIds); | |||
| void deleteBatch(Long id,String tenantId); | |||
| void deleteItemById(Long itemId,String tenantId); | |||
| void deleteItemByBatchId(Long batchId,String tenantId); | |||
| //验证砍价人规则 | |||
| ResultData checkBargainerPressBatchRule(WxOrder order, Long cUserId); | |||
| //验证砍价发起人规则 | |||
| CouponPressBatchVo getCouponPressBatch(WxCoupon coupon, Long cUserId); | |||
| } | |||
| @@ -39,6 +39,8 @@ import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.utils.*; | |||
| import org.apache.commons.beanutils.BeanUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -70,6 +72,8 @@ import com.iformall.mq.MqBaseProducer; | |||
| import static java.util.stream.Collectors.groupingBy; | |||
| import java.lang.reflect.InvocationTargetException; | |||
| @Service | |||
| public class WxOrderServiceImpl implements WxOrderService { | |||
| @@ -229,6 +233,10 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| private OrderSnapshotService orderSnapshotService; | |||
| @Lazy | |||
| @Autowired | |||
| WxPressBatchService wxPressBatchService; | |||
| @Override | |||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.findList(record)); | |||
| @@ -755,23 +763,46 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param counpon | |||
| * @return | |||
| */ | |||
| private int getUserCouponOrderCount(WxCUserBasicInfo user, WxCoupon counpon,int couponNumber) { | |||
| private int getUserCouponOrderCount(WxCUserBasicInfo user, WxCoupon counpon,int couponNumber,boolean isPressOrder) { | |||
| // + couponOrder ---待使用 | |||
| try { | |||
| WxCouponOrder couponOrderQ = new WxCouponOrder(); | |||
| couponOrderQ.updateTenantInfo(counpon); | |||
| couponOrderQ.setCouponId(counpon.getId()); | |||
| couponOrderQ.setCUserId(user.getId()); | |||
| if (counpon.getUseLimitRule().equals(EnumCouponUseLimitRule.TOBEUSED_USELIMIT.getCode())) { | |||
| couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| } | |||
| // if (counpon.getSendType().equals(EnumCouponSendType.PASSIVE.getCode())) { | |||
| // couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| // } | |||
| //如果是砍价,则需要判断批次规则 | |||
| if (isPressOrder) { | |||
| CouponPressBatchVo checkPressResult = wxPressBatchService.getCouponPressBatch(counpon, user.getId()); | |||
| if (null != checkPressResult) { | |||
| WxPressBatch pressBatch = checkPressResult.getPressBatch(); | |||
| List<Long> cids = checkPressResult.getCouponIdList(); | |||
| couponOrderQ.setCouponIds(cids); | |||
| if (pressBatch.getPromoterLimitRule().equals(EnumCouponUseLimitRule.TOBEUSED_USELIMIT.getCode())) { | |||
| couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| } | |||
| int _count = wxCouponOrderMapper.findProductCount(couponOrderQ)+couponNumber; | |||
| if (_count > pressBatch.getPromoterAllowCount()) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(),"当前用户已达砍价["+counpon.getTitle()+"]所在批次活动发起次数上限."); | |||
| } | |||
| return _count; | |||
| }else { | |||
| if (counpon.getUseLimitRule().equals(EnumCouponUseLimitRule.TOBEUSED_USELIMIT.getCode())) { | |||
| couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| } | |||
| couponOrderQ.setCouponId(counpon.getId()); | |||
| } | |||
| }else { | |||
| if (counpon.getUseLimitRule().equals(EnumCouponUseLimitRule.TOBEUSED_USELIMIT.getCode())) { | |||
| couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| } | |||
| couponOrderQ.setCouponId(counpon.getId()); | |||
| } | |||
| return wxCouponOrderMapper.findProductCount(couponOrderQ)+couponNumber; | |||
| } catch (Exception e) { | |||
| logger.error("购买是否超限-DB, couponId: " + counpon.getId() + ", e:" + e.getMessage(),e); | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(),"["+counpon.getTitle()+"]查询待使用订单错误."); | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(),"["+counpon.getTitle()+"]查询待使用订单错误."+e.getMessage()); | |||
| } | |||
| } | |||
| @@ -825,7 +856,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| // } | |||
| // 检查用户已购买数量 | |||
| try { | |||
| count = getUserCouponOrderCount(user, coupon,1); | |||
| count = getUserCouponOrderCount(user, coupon,1,false); | |||
| } catch (Exception e) { | |||
| //解锁 | |||
| redisLock.unlock(couponIdStr, timeStr); | |||
| @@ -926,7 +957,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| * @param | |||
| */ | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public StockReduceResult stockReduce(boolean allowUnPayOrder,WxCUserBasicInfo user, WxCoupon coupon, WxCouponChannel couponChannel,int number) { | |||
| public StockReduceResult stockReduce(boolean allowUnPayOrder,WxCUserBasicInfo user, WxCoupon coupon, WxCouponChannel couponChannel,int number,boolean isPressOrder) { | |||
| StockReduceResult reduceResult = new StockReduceResult(); | |||
| @@ -978,24 +1009,21 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| if (grouponCount >= coupon.getUseLimitQuantity()) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_LIMITED.getCode(),"["+coupon.getTitle()+"]购买超限."); | |||
| } | |||
| // 检查用户已购买数量 | |||
| int paidCount = 0; | |||
| try { | |||
| paidCount = getUserCouponOrderCount(user, coupon,number); | |||
| paidCount = getUserCouponOrderCount(user, coupon,number,isPressOrder); | |||
| } catch (Exception e) { | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(),"["+coupon.getTitle()+"]查询待使用订单错误."); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(),"["+coupon.getTitle()+"]查询待使用订单错误."+e.getMessage()); | |||
| } | |||
| if (paidCount > coupon.getUseLimitQuantity()) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_LIMITED.getCode(),"此券购买数量已超限["+coupon.getTitle()+"], couponId: " + coupon.getId() + ", count: " + paidCount); | |||
| } | |||
| //如果允许未支付的,则未支付的+已支付的不能超过限购 | |||
| if ((unPaidcount+paidCount) > coupon.getUseLimitQuantity()) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_LIMITED.getCode(),"此券[未支付+已支付]购买数量已超限["+coupon.getTitle()+"], couponId: " + coupon.getId()+ ", count: " + paidCount); | |||
| } | |||
| //减库存, | |||
| if (isChannelStockReduce) { | |||
| try { | |||
| @@ -1825,7 +1853,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } else { | |||
| // 减库存操作 | |||
| try { | |||
| stockReduce(false,user, coupon,null,1); | |||
| stockReduce(false,user, coupon,null,1,false); | |||
| }catch(Exception e) { | |||
| throw new MallinkException(ErrorCode.COUPON_STOCK_ERR.getCode(), e.getMessage()); | |||
| } | |||
| @@ -2771,11 +2799,53 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| Map paramMap = new HashMap(); | |||
| paramMap.put("orderId", record.getId()); | |||
| paramMap.put("tenantId", record.getTenantId()); | |||
| paramMap.put("finalTenantId", record.getFinalTenantId()); | |||
| pressVo.setOrderPressList(wxOrderPressMapper.findPressList(paramMap)); | |||
| pressVo.setOrderPressList(toVoList(wxOrderPressMapper.findPressList(paramMap),record)); | |||
| } | |||
| return pressVo; | |||
| } | |||
| private List<WxOrderPressVo> toVoList(List<WxOrderPress> pressList,WxOrder record) { | |||
| if (null == pressList || pressList.size() <= 0 ) { | |||
| return null; | |||
| } | |||
| String finalTenantId = record.getFinalTenantId(); | |||
| List<Long> cIds = new ArrayList<Long>(); | |||
| for (WxOrderPress op : pressList) { | |||
| cIds.add(op.getUserId()); | |||
| } | |||
| Map<Long,WxCUserBasicInfo> userMap = new HashMap<Long,WxCUserBasicInfo>(); | |||
| WxCUserBasicInfo userq = new WxCUserBasicInfo(); | |||
| userq.setFinalTenantId(finalTenantId); | |||
| userq.setIds(cIds); | |||
| List<WxCUserBasicInfo> userList = wxCUserBasicInfoMapper.findList(userq); | |||
| if (null != userList && userList.size() > 0 ) { | |||
| for (WxCUserBasicInfo cbi : userList) { | |||
| userMap.put(cbi.getId(), cbi); | |||
| } | |||
| } | |||
| List<WxOrderPressVo> retList = new ArrayList<WxOrderPressVo>(); | |||
| for (WxOrderPress op : pressList) { | |||
| WxOrderPressVo vo = new WxOrderPressVo(); | |||
| try { | |||
| BeanUtils.copyProperties(vo, op); | |||
| Long userId = op.getUserId(); | |||
| WxCUserBasicInfo basicInfo = userMap.get(userId); | |||
| if (null != basicInfo) { | |||
| vo.setAvatarUrl(basicInfo.getAvatarUrl()); | |||
| vo.setNickName(basicInfo.getNickName()); | |||
| } | |||
| retList.add(vo); | |||
| } catch (IllegalAccessException e) { | |||
| e.printStackTrace(); | |||
| } catch (InvocationTargetException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| if (retList.size()> 0 ) { | |||
| return retList; | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| public void updateStatusByPressCouponId(Long couponId, TenantEntity tenantEntity, int orderStatus) { | |||
| @@ -2925,7 +2995,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| if (checkCouponIsFree(coupon,couponChannel,shippinType)) { | |||
| // 免费券 | |||
| order = proxy.saveFreeOrderForCoupon(orderDate,allowUnPayOrder,composeOrder,user, coupon,perCouponNumber,couponChannel, | |||
| formId,null,extParam,payWay,payVersion,shippinType,address); | |||
| formId,null,extParam,payWay,payVersion,shippinType,address,isPressOrder); | |||
| if (order != null) { | |||
| // 6. 下订单完成,发送内部消息 | |||
| // 下订单完成,发送内部消息 | |||
| @@ -2979,11 +3049,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| public WxOrder saveFreeOrderForCoupon(Date orderDate,boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber, | |||
| WxCouponChannel couponChannel, String formId, Long couponPasswordId,String extParam,EnumPayWay payWay,EnumPayVersion payVersion, | |||
| Integer shippingType, UserBasicInfoAddress address) { | |||
| Integer shippingType, UserBasicInfoAddress address,boolean isPressOrder) { | |||
| WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); | |||
| // 减库存操作 | |||
| StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber); | |||
| StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber,isPressOrder); | |||
| // 当积分券或者积分停车券时 则进行积分支付 | |||
| Integer orderType; | |||
| @@ -3053,7 +3123,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy(); | |||
| // 3. 减库存操作。所有的订单都跟减库存操作时的订单详情保持一致 | |||
| StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon, couponChannel,couponNumber); | |||
| StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon, couponChannel,couponNumber,isPressOrder); | |||
| // 3. 当积分券或者积分停车券时 则进行积分支付 | |||
| Integer orderType; | |||
| @@ -3148,7 +3218,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| } | |||
| // 2. 减库存操作 | |||
| stockReduce(false,user, coupon, wxCouponChannel,1); | |||
| stockReduce(false,user, coupon, wxCouponChannel,1,false); | |||
| // 3. 当积分券或者积分停车券时 则进行积分支付 | |||
| Integer orderType; | |||
| @@ -3829,7 +3899,6 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| } | |||
| } | |||
| couponUserCheck(wxCUserBasicInfo, wxCouponCVo,premsg); | |||
| Long couponId = wxCouponChannel.getCouponId(); | |||
| @@ -1,9 +1,16 @@ | |||
| package com.iformall.service.impl; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.CouponPressBatchVo; | |||
| import com.iformall.enums.EnumPressBatchStatus; | |||
| import com.iformall.enums.EnumYesOrNo; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import org.slf4j.Logger; | |||
| @@ -23,6 +30,10 @@ public class WxPressBatchServiceImpl implements WxPressBatchService { | |||
| WxPressBatchMapper wxPressBatchMapper; | |||
| @Autowired | |||
| WxPressBatchItemMapper wxPressBatchItemMapper; | |||
| @Autowired | |||
| WxOrderPressMapper wxOrderPressMapper; | |||
| @Autowired | |||
| WxOrderMapper wxOrderMapper; | |||
| @Override | |||
| @@ -62,12 +73,12 @@ public class WxPressBatchServiceImpl implements WxPressBatchService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void saveItems(WxPressBatch pressBatch, String[] couponChannelIds) { | |||
| for (String cid : couponChannelIds) { | |||
| public void saveItems(WxPressBatch pressBatch, String[] couponIds) { | |||
| for (String cid : couponIds) { | |||
| WxPressBatchItem iteq = new WxPressBatchItem(); | |||
| iteq.updateTenantInfo(pressBatch); | |||
| iteq.setPressBatchId(pressBatch.getId()); | |||
| iteq.setCouponChannelId(Long.parseLong(cid)); | |||
| iteq.setCouponId(Long.parseLong(cid)); | |||
| iteq.setPressBatchStatus(pressBatch.getStatus()); | |||
| iteq.setCreateDate(new Date()); | |||
| iteq.setUpdateDate(new Date()); | |||
| @@ -98,6 +109,80 @@ public class WxPressBatchServiceImpl implements WxPressBatchService { | |||
| wxPressBatchItemMapper.deleteAllItem(iteq); | |||
| } | |||
| @Override | |||
| public ResultData checkBargainerPressBatchRule(WxOrder order, Long cUserId) { | |||
| WxPressBatchItem query = new WxPressBatchItem(); | |||
| query.updateTenantInfo(order); | |||
| query.setCouponId(order.getProductId()); | |||
| query.setPressBatchStatus(EnumPressBatchStatus.RUNNING.getCode()); | |||
| List<WxPressBatchItem> batchList = wxPressBatchItemMapper.findList(query); | |||
| //一个砍价商品只能存在一个有效的批次 | |||
| if (null != batchList ) { | |||
| if (batchList.size() > 1) { | |||
| return new ResultData(Result.ERROR,"该砍价存在多个有效批次活动,请联系管理员重新设置."); | |||
| }else { | |||
| WxPressBatchItem batchItem = batchList.get(0); | |||
| WxPressBatch pressBatch = wxPressBatchMapper.getById(batchItem.getPressBatchId(), batchItem.getTenantId()); | |||
| //查询该批次下所有的砍价商品, | |||
| List<Long> batchCouponIds = wxPressBatchItemMapper.getCouponIds(batchItem.getPressBatchId(), batchItem.getTenantId(), EnumPressBatchStatus.RUNNING.getCode()); | |||
| if (null == batchCouponIds || batchCouponIds.size() <= 0 ) { | |||
| return new ResultData(Result.ERROR,"未查询到砍价有效批次活动记录,"); | |||
| } | |||
| //如果不允许砍相同商品 | |||
| if (EnumYesOrNo.NO.getCode() == pressBatch.getBargainerAllowSame()) { | |||
| WxOrderPress orderPressQ1 = new WxOrderPress(); | |||
| orderPressQ1.setTenantId(order.getTenantId()); | |||
| orderPressQ1.setUserId(cUserId); | |||
| orderPressQ1.setCouponId(order.getProductId()); | |||
| int count1 = wxOrderPressMapper.selectCount(new QueryWrapper<>(orderPressQ1)); | |||
| if(count1 >= 1) { | |||
| return new ResultData(Result.ERROR,"当前用户砍已砍过相同商品,"); | |||
| } | |||
| } | |||
| //查询当前用户参与这些券的砍价次数 | |||
| WxOrderPress orderPressQ = new WxOrderPress(); | |||
| orderPressQ.setTenantId(order.getTenantId()); | |||
| orderPressQ.setUserId(cUserId); | |||
| orderPressQ.setCouponIds(batchCouponIds); | |||
| int count = wxOrderPressMapper.selectCount(new QueryWrapper<>(orderPressQ)); | |||
| if(count >= pressBatch.getBargainerAllowCount().intValue()) { | |||
| return new ResultData(Result.ERROR,"当前用户砍价次数已达批次活动设定上限,"); | |||
| } else { | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| @Override | |||
| public CouponPressBatchVo getCouponPressBatch(WxCoupon coupon, Long cUserId) { | |||
| WxPressBatchItem query = new WxPressBatchItem(); | |||
| query.updateTenantInfo(coupon); | |||
| query.setCouponId(coupon.getId()); | |||
| query.setPressBatchStatus(EnumPressBatchStatus.RUNNING.getCode()); | |||
| List<WxPressBatchItem> batchList = wxPressBatchItemMapper.findList(query); | |||
| //一个砍价商品只能存在一个有效的批次 | |||
| if (null != batchList ) { | |||
| if (batchList.size() > 1) { | |||
| throw new MallinkException(Result.ERROR,"该砍价["+coupon.getTitle()+"]存在多个有效批次活动,请联系管理员重新设置."); | |||
| }else { | |||
| WxPressBatchItem batchItem = batchList.get(0); | |||
| WxPressBatch pressBatch = wxPressBatchMapper.getById(batchItem.getPressBatchId(), batchItem.getTenantId()); | |||
| //查询该批次下所有的砍价商品, | |||
| List<Long> batchCouponIds = wxPressBatchItemMapper.getCouponIds(batchItem.getPressBatchId(), batchItem.getTenantId(), EnumPressBatchStatus.RUNNING.getCode()); | |||
| if (null == batchCouponIds || batchCouponIds.size() <= 0 ) { | |||
| throw new MallinkException(Result.ERROR,"未查询到砍价["+coupon.getTitle()+"]有效批次活动记录,"); | |||
| } | |||
| CouponPressBatchVo vo = new CouponPressBatchVo(); | |||
| vo.setPressBatch(pressBatch); | |||
| vo.setCouponIdList(batchCouponIds); | |||
| return vo; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| @@ -579,6 +579,12 @@ | |||
| <if test=" null != couponType "> | |||
| and co.coupon_type = #{couponType} | |||
| </if> | |||
| <if test=" null != couponIds"> | |||
| and co.coupon_id in | |||
| <foreach collection="couponIds" index="index" item="couponIdItem" open="(" separator="," close=")"> | |||
| #{couponIdItem} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| <select id="getCouponCount" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="hashmap"> | |||
| @@ -4,6 +4,8 @@ | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxOrderPress"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||
| <result column="order_id" jdbcType="BIGINT" property="orderId" /> | |||
| <result column="user_id" jdbcType="BIGINT" property="userId" /> | |||
| <result column="press_value" jdbcType="INTEGER" property="pressValue" /> | |||
| @@ -12,17 +14,14 @@ | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`order_id`,`user_id`,`press_value`,`create_date`,`first` | |||
| `id`,`tenant_id`,`parent_tenant_id`,`coupon_id`,`order_id`,`user_id`,`press_value`,`create_date`,`first` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| where `tenant_id` = #{tenantId} | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| @@ -37,7 +36,13 @@ | |||
| </if> | |||
| <if test=" null != createDate "> | |||
| and `create_date` = #{createDate} | |||
| </if> | |||
| </if> | |||
| <if test=" null != couponIds "> | |||
| and coupon_id in | |||
| <foreach collection="couponIds" index="index" item="cIdItem" open="(" separator="," close=")"> | |||
| #{cIdItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -56,30 +61,10 @@ | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <resultMap id="VoBaseResultMap" type="com.iformall.domain.vo.WxOrderPressVo"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="order_id" jdbcType="BIGINT" property="orderId" /> | |||
| <result column="user_id" jdbcType="BIGINT" property="userId" /> | |||
| <result column="press_value" jdbcType="INTEGER" property="pressValue" /> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||
| <result column="first" jdbcType="SMALLINT" property="first" /> | |||
| <result column="nick_name" jdbcType="VARCHAR" property="nickName"/> | |||
| <result column="avatar_url" jdbcType="VARCHAR" property="avatarUrl"/> | |||
| </resultMap> | |||
| <sql id="allVoColumns"> | |||
| op.`id`,op.`order_id`,op.`user_id`,op.`press_value`,op.`create_date`,op.`first`, | |||
| cu.`nick_name`, cu.`avatar_url` | |||
| </sql> | |||
| <select id="findPressList" parameterType="com.iformall.domain.vo.WxOrderPressVo" resultMap="VoBaseResultMap"> | |||
| select <include refid="allVoColumns" /> | |||
| from wx_order_press op | |||
| left join wx_c_user_basic_info cu on cu.id = op.user_id | |||
| where op.`order_id` = #{orderId} | |||
| and op.tenant_id = #{tenantId} and cu.final_tenant_id = #{finalTenantId} | |||
| select <include refid="allColumns" /> | |||
| from wx_order_press op | |||
| where op.`order_id` = #{orderId} and op.tenant_id = #{tenantId} | |||
| order by op.`create_date` desc | |||
| </select> | |||
| </mapper> | |||
| @@ -6,7 +6,7 @@ | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
| <result column="press_batch_id" jdbcType="BIGINT" property="pressBatchId" /> | |||
| <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/> | |||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId"/> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
| <result column="press_batch_status" jdbcType="INTEGER" property="pressBatchStatus"/> | |||
| @@ -14,7 +14,7 @@ | |||
| <sql id="allColumns"> | |||
| `id`, `tenant_id`, `parent_tenant_id`, `press_batch_id`, `coupon_channel_id`, `create_date`,`update_date`,`press_batch_status` | |||
| `id`, `tenant_id`, `parent_tenant_id`, `press_batch_id`, `coupon_id`, `create_date`,`update_date`,`press_batch_status` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -32,8 +32,8 @@ | |||
| and `press_batch_id` = #{pressBatchId} | |||
| </if> | |||
| <if test=" null != couponChannelId"> | |||
| and `coupon_channel_id` = #{couponChannelId} | |||
| <if test=" null != couponId"> | |||
| and `coupon_id` = #{couponId} | |||
| </if> | |||
| <if test=" null != pressBatchStatus"> | |||
| @@ -76,5 +76,12 @@ | |||
| <delete id= "deleteAllItem" parameterType="com.iformall.domain.po.WxPressBatchItem" > | |||
| delete from wx_press_batch_item where `press_batch_id` = #{pressBatchId} and tenant_id=#{tenantId} | |||
| </delete> | |||
| <select id="getCouponIds" parameterType="java.util.HashMap" resultType="Long"> | |||
| select coupon_id from wx_press_batch_item where `press_batch_id` = #{pressBatchId} and tenant_id=#{tenantId} | |||
| <if test=" null != pressBatchStatus"> | |||
| and `press_batch_status` = #{pressBatchStatus} | |||
| </if> | |||
| </select> | |||
| </mapper> | |||
| @@ -8,7 +8,8 @@ | |||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||
| <result column="status" jdbcType="INTEGER" property="status"/> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
| <result column="promoter_limit_rule" jdbcType="INTEGER" property="promoterLimitRule"/> | |||
| <result column="promoter_allow_count" jdbcType="INTEGER" property="promoterAllowCount"/> | |||
| <result column="bargainer_allow_same" jdbcType="INTEGER" property="bargainerAllowSame"/> | |||
| <result column="bargainer_allow_count" jdbcType="INTEGER" property="bargainerAllowCount"/> | |||
| @@ -16,7 +17,7 @@ | |||
| <sql id="allColumns"> | |||
| `id`, `tenant_id`, `parent_tenant_id`, `name`, `status`, `create_date`,`update_date`,`promoter_allow_count`, `bargainer_allow_same`, `bargainer_allow_count` | |||
| `id`, `tenant_id`, `parent_tenant_id`, `name`, `status`, `create_date`,`update_date`,`promoter_limit_rule`,`promoter_allow_count`, `bargainer_allow_same`, `bargainer_allow_count` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -33,6 +34,10 @@ | |||
| <if test=" null != status"> | |||
| and `status` = #{status} | |||
| </if> | |||
| <if test=" null != promoterLimitRule"> | |||
| and `promoter_limit_rule` = #{promoterLimitRule} | |||
| </if> | |||
| <if test=" null != bargainerAllowSame"> | |||
| and `bargainer_allow_same` = #{bargainerAllowSame} | |||