| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
|
| | | import com.yeshi.fanli.dao.mybatis.PidOrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper;
|
| | |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoOrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
|
| | | import com.yeshi.fanli.dto.HongBaoDTO;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBao;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.entity.order.CommonOrderGoods;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.PidOrder;
|
| | | import com.yeshi.fanli.entity.order.ShareGoodsActivityOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | | import com.yeshi.fanli.exception.HongBaoException;
|
| | | import com.yeshi.fanli.exception.order.ShareGoodsActivityOrderException;
|
| | | import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.msg.UserOrderMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.ShareGoodsActivityOrderService;
|
| | | import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
|
| | |
|
| | | @Service
|
| | | public class HongBaoV2ServiceImpl implements HongBaoV2Service {
|
| | |
| | | @Resource
|
| | | private UserShareGoodsGroupService userShareGoodsGroupService;
|
| | |
|
| | |
|
| | | @Resource
|
| | | private PidOrderMapper pidOrderMapper;
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | |
|
| | | @Resource
|
| | | private UserNotificationService userNotificationService;
|
| | |
|
| | | @Resource
|
| | | private UserOrderMsgNotificationService userOrderMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | @Resource
|
| | | private ShareGoodsActivityOrderService shareGoodsActivityOrderService;
|
| | |
|
| | | @Resource
|
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | |
|
| | | @Resource
|
| | | private UserSystemCouponRecordService userSystemCouponRecordService;
|
| | |
|
| | | @Override
|
| | | public int insert(HongBaoV2 record) {
|
| | |
| | | return hongBaoV2Mapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | private HongBaoV2 getHongBaoV2(HongBao hb) {
|
| | | int type = hb.getType().intValue();
|
| | | HongBaoV2 v2 = new HongBaoV2(hb.getId());
|
| | | v2.setCreateTime(new Date(hb.getCreatetime()));
|
| | | if (hb.getGetTime() == null || hb.getGetTime() == 0)
|
| | | v2.setGetTime(null);
|
| | | else
|
| | | v2.setGetTime(new Date(hb.getGetTime()));
|
| | |
|
| | | v2.setMoney(hb.getMoney());
|
| | | if (hb.getParent() != null)
|
| | | v2.setParent(new HongBaoV2(hb.getParent().getId()));
|
| | |
|
| | | if (hb.getType() == HongBao.TYPE_SHARE_GOODS) {
|
| | | if (hb.getBalanceTime() != null)
|
| | | v2.setPreGetTime(new Date(hb.getPreGettime()));
|
| | | else
|
| | | v2.setPreGetTime(null);
|
| | | } else {
|
| | | if (hb.getPreGettime() == null || hb.getPreGettime() == 0)
|
| | | v2.setPreGetTime(null);
|
| | | else
|
| | | v2.setPreGetTime(new Date(hb.getPreGettime()));
|
| | | }
|
| | |
|
| | | v2.setState(hb.getState());
|
| | | if (hb.getState() == 1 && hb.getBalanceTime() != null) {
|
| | | v2.setState(HongBaoV2.STATE_KELINGQU);
|
| | | }
|
| | | v2.setType(type);
|
| | | v2.setUpdateTime(new Date(hb.getCreatetime()));
|
| | | v2.setUrank(hb.getUrank());
|
| | | v2.setUserInfo(hb.getUserInfo());
|
| | | v2.setVersion(hb.getVersion());
|
| | | return v2;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void convert(HongBao hb) {
|
| | | if (hb == null || hb.getParent() != null)
|
| | | return;
|
| | |
|
| | | int type = hb.getType().intValue();
|
| | | if (type == HongBao.TYPE_TAOBAO || type == HongBao.TYPE_SHARE_GOODS) {// 自购与分享赚需要查询出所有的订单
|
| | | // 属于返利订单
|
| | | String orderId = "";
|
| | | if (hb.getOrder() != null) {
|
| | | orderId = hb.getOrder().getOrderId();
|
| | | // 查询同一订单号的非子红包
|
| | | } else
|
| | | orderId = hb.getOrderId();
|
| | |
|
| | | int count = commonOrderMapper.countByOrderNOAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO);
|
| | |
|
| | | // 已经插入订单
|
| | | if (count > 0)
|
| | | return;
|
| | |
|
| | | //
|
| | |
|
| | | if (hb.getVersion() == 1) {// 很老版本的处理方式,已hongbao为主
|
| | | if (hongBaoV2Mapper.selectByPrimaryKey(hb.getId()) != null)
|
| | | return;
|
| | | HongBaoV2 hongBaoV2 = getHongBaoV2(hb);
|
| | | hongBaoV2.setBeizhu("订单号:" + orderId);
|
| | | hongBaoV2Mapper.insert(hongBaoV2);
|
| | |
|
| | | if (hb.getHasChild())// 存在子红包
|
| | | {
|
| | | List<HongBao> children = hongBaoMapper.selectChildHongBaoByPid(hb.getId());
|
| | | if (children != null)
|
| | | for (HongBao hongBao : children) {
|
| | | HongBaoV2 child = getHongBaoV2(hongBao);
|
| | | hongBaoV2Mapper.insert(child);
|
| | | }
|
| | | }
|
| | |
|
| | | } else {// 新版本处理方式
|
| | |
|
| | | List<HongBao> list = hongBaoMapper.selectByOrderId(orderId);
|
| | |
|
| | | if (list.size() == 0)
|
| | | list = hongBaoMapper.selectByOid(hb.getOrder().getId());
|
| | | if (list != null)
|
| | | // 删除子红包
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (list.get(i).getParent() != null) {
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | if (list.size() <= 0)
|
| | | return;
|
| | | if (list.get(0).getType() == 20)
|
| | | for (HongBao hb1 : list) {
|
| | | PidOrder pidOrder = pidOrderMapper.getPidOrderByHongBaoId(hb1.getId());
|
| | | if (pidOrder != null)
|
| | | hb1.setAuctionId(pidOrder.getAuctionId());
|
| | |
|
| | | }
|
| | |
|
| | | List<TaoBaoOrder> orderList = taoBaoOrderMapper.selectTaoBaoOrderByOrderId(orderId);
|
| | |
|
| | | if (orderList == null || orderList.size() < list.size()) {
|
| | | System.out.println("红包数与订单数不对应");
|
| | | return;
|
| | | }
|
| | |
|
| | | // 加入排序值
|
| | | for (int i = 0; i < orderList.size(); i++) {
|
| | | orderList.get(i).setOrderBy(i + 1);
|
| | | }
|
| | |
|
| | | // 按照auctionId,payMoney排序
|
| | | Comparator<HongBao> cm = new Comparator<HongBao>() {
|
| | | @Override
|
| | | public int compare(HongBao o1, HongBao o2) {
|
| | | if (o1.getAuctionId().longValue() < o2.getAuctionId().longValue())
|
| | | return -3;
|
| | | else if (o1.getAuctionId().longValue() > o2.getAuctionId().longValue()) {
|
| | | return 3;
|
| | | } else {
|
| | | if (o1.getState() - o2.getState() > 0)
|
| | | return 2;
|
| | | else if (o1.getState() - o2.getState() < 0)
|
| | | return -2;
|
| | | else {
|
| | | if (o1.getPayMoney().compareTo(o2.getPayMoney()) >= 0)
|
| | | return 1;
|
| | | else
|
| | | return -1;
|
| | | }
|
| | | }
|
| | | }
|
| | | };
|
| | |
|
| | | Collections.sort(list, cm);
|
| | |
|
| | | Comparator<TaoBaoOrder> cmOrder = new Comparator<TaoBaoOrder>() {
|
| | |
|
| | | @Override
|
| | | public int compare(TaoBaoOrder o1, TaoBaoOrder o2) {
|
| | |
|
| | | if (o1.getAuctionId().longValue() < o2.getAuctionId().longValue())
|
| | | return -3;
|
| | | else if (o1.getAuctionId().longValue() > o2.getAuctionId().longValue()) {
|
| | | return 3;
|
| | | } else {
|
| | | if (o1.getPayment().compareTo(o2.getPayment()) < 0)
|
| | | return 2;
|
| | | else
|
| | | return -2;
|
| | | }
|
| | | }
|
| | | };
|
| | |
|
| | | Collections.sort(orderList, cmOrder);
|
| | |
|
| | | for (TaoBaoOrder t : orderList)
|
| | | System.out.println(t.getAuctionId());
|
| | |
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | CommonOrder commonOrder = TaoBaoOrderUtil.convert(orderList.get(i));
|
| | | CommonOrderGoods goods = new CommonOrderGoods();
|
| | | goods.setGoodsId(orderList.get(i).getAuctionId() + "");
|
| | | goods.setGoodsType(Constant.SOURCE_TYPE_TAOBAO);
|
| | | // 商品是否已经插入
|
| | | List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper
|
| | | .listByGoodsIdAndGoodsType(goods.getGoodsId(), goods.getGoodsType());
|
| | | if (commonGoodsList.size() <= 0)// 不存在就插入商品
|
| | | commonOrderGoodsMapper.insertSelective(goods);
|
| | | else
|
| | | goods.setId(commonGoodsList.get(commonGoodsList.size() - 1).getId());
|
| | | commonOrder.setCommonOrderGoods(goods);
|
| | |
|
| | | commonOrder.setUserInfo(list.get(i).getUserInfo());
|
| | | commonOrder.setCreateTime(new Date(list.get(i).getCreatetime()));
|
| | |
|
| | | // TODO 维权判断
|
| | | List<TaoBaoWeiQuanOrder> weiQuanList = taoBaoWeiQuanOrderMapper.selectListByOrderIdAndState(orderId,
|
| | | "维权成功");
|
| | | if (weiQuanList != null && weiQuanList.size() > 0)
|
| | | commonOrder.setState(CommonOrder.STATE_WQ);
|
| | |
|
| | | commonOrderMapper.insertSelective(commonOrder);
|
| | |
|
| | | // 插入红包
|
| | | HongBaoV2 hongBaoV2 = getHongBaoV2(list.get(i));
|
| | | hongBaoV2.setId(list.get(i).getId());
|
| | | hongBaoV2Mapper.insert(hongBaoV2);
|
| | |
|
| | | HongBaoOrder ho = new HongBaoOrder();
|
| | | ho.setCommonOrder(commonOrder);
|
| | | ho.setCreateTime(new Date());
|
| | | ho.setHongBaoV2(hongBaoV2);
|
| | | hongBaoOrderMapper.insertSelective(ho);
|
| | |
|
| | | if (list.get(i).getHasChild())// 存在子红包
|
| | | {
|
| | | List<HongBao> children = hongBaoMapper.selectChildHongBaoByPid(list.get(i).getId());
|
| | | if (children != null)
|
| | | for (HongBao hongBao : children) {
|
| | | HongBaoV2 child = getHongBaoV2(hongBao);
|
| | | hongBaoV2Mapper.insert(child);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | } else {// 直接插入
|
| | |
|
| | | if (type != HongBao.TYPE_ERJI && type != HongBao.TYPE_YIJI && type != HongBao.TYPE_SHARE_YIJI
|
| | | && type != HongBao.TYPE_SHARE_ERJI) {
|
| | | if (hongBaoV2Mapper.selectByPrimaryKey(hb.getId()) == null)
|
| | | hongBaoV2Mapper.insert(getHongBaoV2(hb));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | |
|
| | | @Resource
|
| | | private UserNotificationService userNotificationService;
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException {
|
| | |
|
| | | Set<Integer> stateSet = new HashSet<>();// 订单状态Set
|
| | | if (commonOrderList != null && commonOrderList.size() > 0) {
|
| | | Map<Integer, HongBaoV2> notificationMap = new HashMap<>();
|
| | | Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
|
| | | int goodsCount = 0;
|
| | | boolean hasAdd = false;
|
| | | for (CommonOrder commonOrder : commonOrderList) {
|
| | | stateSet.add(commonOrder.getState());
|
| | | goodsCount += commonOrder.getCount();
|
| | | if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null)
|
| | | throw new HongBaoException(1, "订单信息不完整");
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder == null) {
|
| | | saveHongBao(commonOrder, type, notificationMap);
|
| | | hasAdd = true;
|
| | | } else {
|
| | | updateHongBao(hongBaoOrder, commonOrder, type);
|
| | | updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
|
| | | }
|
| | | }
|
| | | /**
|
| | | * 通知用户的返利情况
|
| | | */
|
| | | Iterator<Integer> its = notificationMap.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | | Integer t = its.next();
|
| | | HongBaoV2 notify = notificationMap.get(t);
|
| | | String orderId = commonOrderList.get(0).getOrderNo();
|
| | | Long uid = notify.getUserInfo().getId();
|
| | | BigDecimal money = notify.getMoney();
|
| | | switch (t) {
|
| | | case HongBaoV2.TYPE_ZIGOU:
|
| | | userNotificationService.orderFanliStatisticed(uid, orderId);
|
| | | break;
|
| | | case HongBaoV2.TYPE_SHARE_GOODS:
|
| | | userNotificationService.orderShareStatisticed(uid, orderId, money);
|
| | | break;
|
| | | case HongBaoV2.TYPE_YIJI:
|
| | | userNotificationService.orderInviteStatisticed(uid, orderId, money);
|
| | | break;
|
| | | case HongBaoV2.TYPE_ERJI:
|
| | | userNotificationService.orderInviteStatisticed(uid, orderId, money);
|
| | | break;
|
| | | int state = getOrderState(stateSet);
|
| | | if (hasAdd) {
|
| | | Iterator<Integer> its = notificationMap.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | |
|
| | | Integer t = its.next();
|
| | | HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
|
| | | CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
|
| | | String orderId = commonOrderList.get(0).getOrderNo();
|
| | | Long uid = notify.getUserInfo().getId();
|
| | | BigDecimal money = notify.getMoney();
|
| | | switch (t) {
|
| | | case HongBaoV2.TYPE_ZIGOU:
|
| | | userNotificationService.orderFanliStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK,
|
| | | null, money);
|
| | | userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, commonOrder.getPayment(),
|
| | | money, goodsCount, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_SHARE_GOODS:
|
| | | userNotificationService.orderShareStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK,
|
| | | null, money);
|
| | | userOrderMsgNotificationService.orderShareStatistic(uid, orderId, commonOrder.getPayment(),
|
| | | money, goodsCount, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_YIJI:
|
| | | userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount,
|
| | | MsgOrderDetail.STATE_FK, null, money);
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(),
|
| | | money, goodsCount, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_ERJI:
|
| | | userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount,
|
| | | MsgOrderDetail.STATE_FK, null, money);
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(),
|
| | | money, goodsCount, state);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 添加新版本通知
|
| | |
|
| | | if (!hasAdd) {
|
| | | Iterator<Integer> its = notificationMap.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | | Integer t = its.next();
|
| | | HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
|
| | | CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
|
| | | String orderId = commonOrderList.get(0).getOrderNo();
|
| | | Long uid = notify.getUserInfo().getId();
|
| | | BigDecimal money = notify.getMoney();
|
| | | switch (t) {
|
| | | case HongBaoV2.TYPE_ZIGOU:
|
| | | userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, commonOrder.getPayment(),
|
| | | money, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_SHARE_GOODS:
|
| | | userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, commonOrder.getPayment(),
|
| | | money, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_YIJI:
|
| | | userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(),
|
| | | money, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_ERJI:
|
| | | userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(),
|
| | | money, state);
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | private int getOrderState(Set<Integer> states) {
|
| | | if (states.size() == 1)
|
| | | return states.iterator().next();
|
| | | Iterator<Integer> its = states.iterator();
|
| | | while (its.hasNext()) {
|
| | | int tempState = its.next();
|
| | | if (tempState == CommonOrder.STATE_FK)
|
| | | return CommonOrder.STATE_FK;
|
| | | else if (tempState == CommonOrder.STATE_JS)
|
| | | return CommonOrder.STATE_JS;
|
| | | }
|
| | | return CommonOrder.STATE_SX;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type) throws HongBaoException {
|
| | | private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
|
| | | Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException {
|
| | | System.out.println(commonOrder.getOrderNo());
|
| | | HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
|
| | | if (oldHongBao == null)
|
| | |
| | |
|
| | | if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
|
| | | BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
|
| | | // 免单处理
|
| | | boolean mianDan = false;
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | commonOrder.getOrderNo());
|
| | | if (orderList != null && orderList.size() == 1) {// 只有1个订单才参与免单
|
| | | BigDecimal payMent = commonOrder.getPayment();
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS)
|
| | | payMent = commonOrder.getSettlement();
|
| | |
|
| | | if (payMent.compareTo(new BigDecimal(10)) < 0) {
|
| | | mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo());
|
| | | }
|
| | | }
|
| | |
|
| | | HongBaoV2 hongBao = new HongBaoV2(hongBaoOrder.getHongBaoV2().getId());
|
| | | hongBao.setUpdateTime(new Date());
|
| | | // 更改状态与资金
|
| | |
| | | hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
|
| | | hongBao.setMoney(
|
| | | MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
|
| | | if (mianDan)
|
| | | hongBao.setMoney(commonOrder.getPayment());
|
| | | } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
|
| | | hongBao.setState(HongBaoV2.STATE_KELINGQU);
|
| | | hongBao.setMoney(
|
| | | MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
|
| | | hongBao.setPreGetTime(new Date(commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L));
|
| | | if (mianDan)
|
| | | hongBao.setMoney(commonOrder.getSettlement().compareTo(commonOrder.getPayment()) <= 0
|
| | | ? commonOrder.getSettlement() : commonOrder.getPayment());// 返利结算与付款较小的金额
|
| | | } else if (commonOrder.getState() == CommonOrder.STATE_SX) {
|
| | | hongBao.setState(HongBaoV2.STATE_SHIXIAO);
|
| | | hongBao.setMoney(new BigDecimal(0));
|
| | | if (mianDan) {
|
| | | try {
|
| | | userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | throw new HongBaoException(12, "免单券退款出错");
|
| | | }
|
| | | }
|
| | | }
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
|
| | |
|
| | | // 加入通知
|
| | | if (notificationMap.get(type) == null) {
|
| | | HongBaoV2 tempHongBao = new HongBaoV2(oldHongBao.getId());
|
| | | tempHongBao.setUserInfo(oldHongBao.getUserInfo());
|
| | | tempHongBao.setMoney(hongBao.getMoney());
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
|
| | | } else {
|
| | | // 增加付款金额与资金
|
| | | HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
|
| | | tempHongBaoOrder.getCommonOrder()
|
| | | .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
|
| | | tempHongBaoOrder.getHongBaoV2()
|
| | | .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
|
| | | notificationMap.put(type, tempHongBaoOrder);
|
| | | }
|
| | |
|
| | | // 获取子红包
|
| | | List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
|
| | |
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
|
| | | }
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
|
| | |
|
| | | // 加入通知
|
| | | if (notificationMap.get(child.getType()) == null) {
|
| | | HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
|
| | | tempHongBao.setUserInfo(child.getUserInfo());
|
| | | tempHongBao.setMoney(child.getMoney());
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
|
| | | } else {
|
| | | // 增加付款金额与资金
|
| | | HongBaoOrder tempHongBaoOrder = notificationMap.get(child.getType());
|
| | | tempHongBaoOrder.getCommonOrder().setPayment(
|
| | | tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
|
| | | tempHongBaoOrder.getHongBaoV2()
|
| | | .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney()));
|
| | | notificationMap.put(child.getType(), tempHongBaoOrder);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
|
| | | BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
|
| | | BigDecimal fanliRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
|
| | | List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService
|
| | | .listByOrderIdAndUid(commonOrder.getUserInfo().getId(), commonOrder.getOrderNo());
|
| | | if (list != null && list.size() > 0) {
|
| | | fanliRate = list.get(0).getShareRate();
|
| | | }
|
| | |
|
| | | HongBaoV2 hongBao = new HongBaoV2(hongBaoOrder.getHongBaoV2().getId());
|
| | | hongBao.setUpdateTime(new Date());
|
| | | // 更改状态与资金
|
| | |
| | | hongBao.setMoney(new BigDecimal(0));
|
| | | }
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
|
| | | // 通知
|
| | | if (notificationMap.get(type) == null) {
|
| | | HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
|
| | | tempHongBao.setUserInfo(hongBaoOrder.getHongBaoV2().getUserInfo());
|
| | | tempHongBao.setMoney(hongBao.getMoney());
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
|
| | | } else {
|
| | | // 增加付款金额与资金
|
| | | HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
|
| | | tempHongBaoOrder.getCommonOrder()
|
| | | .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
|
| | | tempHongBaoOrder.getHongBaoV2()
|
| | | .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
|
| | | notificationMap.put(type, tempHongBaoOrder);
|
| | | }
|
| | |
|
| | | // 获取子红包
|
| | | List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
|
| | |
| | | }
|
| | |
|
| | | @Transactional
|
| | | private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoV2> notificationMap)
|
| | | private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
|
| | | throws HongBaoException {
|
| | | if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
|
| | | BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
|
| | | // 查询是否有免单计划
|
| | | BigDecimal mianDanMoney = null;
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | commonOrder.getOrderNo());
|
| | | if (orderList != null && orderList.size() == 1) {// 只有1个订单才参与免单
|
| | | BigDecimal payMent = commonOrder.getPayment();
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS)
|
| | | payMent = commonOrder.getSettlement();
|
| | |
|
| | | CommonOrderGoods goods = commonOrderGoodsMapper
|
| | | .selectByPrimaryKey(commonOrder.getCommonOrderGoods().getId());
|
| | | if (goods != null) {
|
| | |
|
| | | try {
|
| | | if (userSystemCouponService.updateCouponRecordUsed(commonOrder.getUserInfo().getId(),
|
| | | commonOrder.getOrderNo(), payMent, Long.parseLong(goods.getGoodsId())))
|
| | | mianDanMoney = payMent;
|
| | | } catch (NumberFormatException e) {
|
| | | throw new HongBaoException(10, "免单商品处理出错");
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | throw new HongBaoException(11, "免单商品处理出错");
|
| | | }
|
| | | }
|
| | | }
|
| | | } else if (commonOrder.getState() == CommonOrder.STATE_SX) {// 设置免单券失效
|
| | | try {
|
| | | userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | HongBaoV2 hongBao = new HongBaoV2();
|
| | | hongBao.setUserInfo(commonOrder.getUserInfo());
|
| | | hongBao.setCreateTime(new Date());
|
| | |
| | | } else {
|
| | | throw new HongBaoException(3, "维权订单不能创建红包");
|
| | | }
|
| | |
|
| | | if (mianDanMoney != null)
|
| | | hongBao.setMoney(mianDanMoney);
|
| | |
|
| | | UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
|
| | | hongBao.setUrank(user.getRank());
|
| | | hongBaoV2Mapper.insertSelective(hongBao);
|
| | |
| | | hongBaoOrder.setHongBaoV2(hongBao);
|
| | | hongBaoOrderMapper.insertSelective(hongBaoOrder);
|
| | | // 加入通知
|
| | | if (notificationMap.get(type) == null)
|
| | | notificationMap.put(type, hongBao);
|
| | | else {
|
| | | notificationMap.get(type).setMoney(notificationMap.get(type).getMoney().add(hongBao.getMoney()));
|
| | | if (notificationMap.get(type) == null) {
|
| | | HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
|
| | | tempHongBao.setUserInfo(hongBao.getUserInfo());
|
| | | tempHongBao.setMoney(hongBao.getMoney());
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
|
| | | } else {
|
| | | // 增加付款金额与资金
|
| | | HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
|
| | | tempHongBaoOrder.getCommonOrder()
|
| | | .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
|
| | | tempHongBaoOrder.getHongBaoV2()
|
| | | .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
|
| | | notificationMap.put(type, tempHongBaoOrder);
|
| | | }
|
| | |
|
| | | UserInfo boss = threeSaleSerivce.getBoss(user.getId());
|
| | | if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO) {// 1级BOSS存在且红包未失效
|
| | | if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1级BOSS存在且红包未失效,免单不支持多级分销
|
| | |
|
| | | // 插入一级子红包
|
| | | BigDecimal firstRate = hongBaoManageService
|
| | |
| | | }
|
| | | hongBaoV2Mapper.insertSelective(firstHongbao);
|
| | | // 用户通知
|
| | | if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null)
|
| | | notificationMap.put(HongBaoV2.TYPE_YIJI, firstHongbao);
|
| | | else {
|
| | | notificationMap.get(HongBaoV2.TYPE_YIJI)
|
| | | .setMoney(notificationMap.get(HongBaoV2.TYPE_YIJI).getMoney().add(firstHongbao.getMoney()));
|
| | | if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) {
|
| | | HongBaoV2 tempHongBao = new HongBaoV2(firstHongbao.getId());
|
| | | tempHongBao.setUserInfo(firstHongbao.getUserInfo());
|
| | | tempHongBao.setMoney(firstHongbao.getMoney());
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(HongBaoV2.TYPE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao));
|
| | | } else {
|
| | | // 增加付款金额与资金
|
| | | HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_YIJI);
|
| | | tempHongBaoOrder.getCommonOrder()
|
| | | .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
|
| | | tempHongBaoOrder.getHongBaoV2()
|
| | | .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(firstHongbao.getMoney()));
|
| | | notificationMap.put(HongBaoV2.TYPE_YIJI, tempHongBaoOrder);
|
| | | }
|
| | |
|
| | | // 插入二级子红包
|
| | |
| | | hongBaoV2Mapper.insertSelective(secondHongbao);
|
| | |
|
| | | // 用户通知
|
| | | if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null)
|
| | | notificationMap.put(HongBaoV2.TYPE_ERJI, secondHongbao);
|
| | | else {
|
| | | notificationMap.get(HongBaoV2.TYPE_ERJI).setMoney(
|
| | | notificationMap.get(HongBaoV2.TYPE_ERJI).getMoney().add(secondHongbao.getMoney()));
|
| | | if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) {
|
| | | HongBaoV2 tempHongBao = new HongBaoV2(secondHongbao.getId());
|
| | | tempHongBao.setUserInfo(secondHongbao.getUserInfo());
|
| | | tempHongBao.setMoney(secondHongbao.getMoney());
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(HongBaoV2.TYPE_ERJI, new HongBaoOrder(tempCommonOrder, tempHongBao));
|
| | | } else {
|
| | | // 增加付款金额与资金
|
| | | HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_ERJI);
|
| | | tempHongBaoOrder.getCommonOrder().setPayment(
|
| | | tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
|
| | | tempHongBaoOrder.getHongBaoV2()
|
| | | .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(secondHongbao.getMoney()));
|
| | | notificationMap.put(HongBaoV2.TYPE_ERJI, tempHongBaoOrder);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | return;
|
| | | // 分享赚
|
| | | BigDecimal shareRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
|
| | |
|
| | | // 判断订单分享活动是否开启
|
| | | if ("1".equalsIgnoreCase(configService.get("share_goods_activity_open"))) {
|
| | | // 没有订单,并且是渠道ID来的,并且
|
| | | UserExtraTaoBaoInfo taoBaoExtraInfo = userExtraTaoBaoInfoService
|
| | | .getByUid(commonOrder.getUserInfo().getId());
|
| | | if (taoBaoExtraInfo != null && ((!StringUtil.isNullOrEmpty(taoBaoExtraInfo.getTaoBaoOrderEnd6Num())
|
| | | && !commonOrder.getOrderNo().endsWith(taoBaoExtraInfo.getTaoBaoOrderEnd6Num().trim()))
|
| | | || StringUtil.isNullOrEmpty(taoBaoExtraInfo.getTaoBaoOrderEnd6Num()))) {
|
| | | List<TaoBaoOrder> taoBaoOrderList = taoBaoOrderMapper
|
| | | .selectTaoBaoOrderByOrderId(commonOrder.getOrderNo());
|
| | | if (taoBaoOrderList != null && taoBaoOrderList.size() > 0
|
| | | && !StringUtil.isNullOrEmpty(taoBaoOrderList.get(0).getRelationId())) {
|
| | | if (shareGoodsActivityOrderService.listByUid(commonOrder.getUserInfo().getId()).size() < 1) {
|
| | | shareRate = new BigDecimal(hongBaoManageService.get("share_activity_proportion"));
|
| | | try {
|
| | | shareGoodsActivityOrderService.addShareGoodsActivityOrder(
|
| | | commonOrder.getUserInfo().getId(), shareRate, commonOrder.getOrderNo());
|
| | | } catch (ShareGoodsActivityOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | HongBaoV2 hongBao = new HongBaoV2();
|
| | | hongBao.setCreateTime(new Date());
|
| | | hongBao.setType(HongBaoV2.TYPE_SHARE_GOODS);
|
| | |
| | | hongBaoOrder.setHongBaoV2(hongBao);
|
| | | hongBaoOrderMapper.insertSelective(hongBaoOrder);
|
| | |
|
| | | if (notificationMap.get(type) == null)
|
| | | notificationMap.put(type, hongBao);
|
| | | else {
|
| | | notificationMap.get(type).setMoney(notificationMap.get(type).getMoney().add(hongBao.getMoney()));
|
| | | if (notificationMap.get(type) == null) {
|
| | | HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
|
| | | tempHongBao.setUserInfo(hongBao.getUserInfo());
|
| | | tempHongBao.setMoney(hongBao.getMoney());
|
| | | CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | tempCommonOrder.setPayment(commonOrder.getPayment());
|
| | | notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
|
| | | } else {
|
| | | // 增加付款金额与资金
|
| | | HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
|
| | | tempHongBaoOrder.getCommonOrder()
|
| | | .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
|
| | | tempHongBaoOrder.getHongBaoV2()
|
| | | .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
|
| | | notificationMap.put(type, tempHongBaoOrder);
|
| | | }
|
| | |
|
| | | // 修改统计数据
|