|
@@ -1,20 +1,32 @@
|
|
package com.txz.mall.service.impl;
|
|
package com.txz.mall.service.impl;
|
|
|
|
|
|
-import com.github.pagehelper.PageInfo;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.txz.mall.core.AbstractService;
|
|
import com.txz.mall.core.AbstractService;
|
|
import com.txz.mall.core.ServiceException;
|
|
import com.txz.mall.core.ServiceException;
|
|
import com.txz.mall.dao.StoreCombinationMapper;
|
|
import com.txz.mall.dao.StoreCombinationMapper;
|
|
import com.txz.mall.model.StoreCombination;
|
|
import com.txz.mall.model.StoreCombination;
|
|
import com.txz.mall.model.StoreFlashActivity;
|
|
import com.txz.mall.model.StoreFlashActivity;
|
|
|
|
+import com.txz.mall.model.StoreOrder;
|
|
|
|
+import com.txz.mall.model.StorePink;
|
|
import com.txz.mall.service.StoreCombinationService;
|
|
import com.txz.mall.service.StoreCombinationService;
|
|
import com.txz.mall.service.StoreFlashActivityService;
|
|
import com.txz.mall.service.StoreFlashActivityService;
|
|
|
|
+import com.txz.mall.service.StoreOrderService;
|
|
|
|
+import com.txz.mall.service.StorePinkService;
|
|
|
|
+import org.apache.commons.lang.time.DateUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
|
|
+import vo.FlashActivityVO;
|
|
import vo.GoPinkVO;
|
|
import vo.GoPinkVO;
|
|
-import vo.StorePinkVO;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -29,64 +41,126 @@ public class StoreCombinationServiceImpl extends AbstractService<StoreCombinatio
|
|
@Resource
|
|
@Resource
|
|
private StoreFlashActivityService storeFlashActivityService;
|
|
private StoreFlashActivityService storeFlashActivityService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private StorePinkService storePinkService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private StoreOrderService storeOrderService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void addActivityProduct(List<StoreCombination> list, Long activityId) {
|
|
public void addActivityProduct(List<StoreCombination> list, Long activityId) {
|
|
StoreFlashActivity flashActivity = storeFlashActivityService.findById(activityId);
|
|
StoreFlashActivity flashActivity = storeFlashActivityService.findById(activityId);
|
|
- if (flashActivity == null) {
|
|
|
|
|
|
+ if (flashActivity == null || flashActivity.getIsDelete().equals(1)) {
|
|
throw new ServiceException("找不到对应的活动");
|
|
throw new ServiceException("找不到对应的活动");
|
|
}
|
|
}
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ throw new ServiceException("添加商品不能为空");
|
|
|
|
+ }
|
|
|
|
+ FlashActivityVO activityVO = JSONObject.parseObject(flashActivity.getContent(), FlashActivityVO.class);
|
|
|
|
+ for (StoreCombination storeCombination : list) {
|
|
|
|
+ storeCombination.setStartTime(flashActivity.getStartTime());
|
|
|
|
+ storeCombination.setStopTime(flashActivity.getEndTime());
|
|
|
|
+ storeCombination.setPeople(activityVO.getGroupNumber());
|
|
|
|
+ storeCombination.setEffectiveTime(activityVO.getCountdownTime());
|
|
|
|
+ storeCombination.setStock(activityVO.getInventory());
|
|
|
|
+ }
|
|
|
|
+ List<Long> productCollect = list.stream().map(StoreCombination::getProductId).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+
|
|
save(list);
|
|
save(list);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void goOpen(Long orderId) {
|
|
|
|
+ StoreOrder storeOrder = storeOrderService.findById(orderId);
|
|
|
|
+ StorePink storePink = new StorePink();
|
|
|
|
+// storePink.setUid(user.getUid());
|
|
|
|
+// storePink.setAvatar(user.getAvatar());
|
|
|
|
+// storePink.setNickname(user.getNickname());
|
|
|
|
+ storePink.setOrderId(storeOrder.getOrderId());
|
|
|
|
+ storePink.setOrderIdKey(storeOrder.getId());
|
|
|
|
+ storePink.setTotalNum(storeOrder.getTotalNum());
|
|
|
|
+ storePink.setTotalPrice(storeOrder.getTotalPrice());
|
|
|
|
+ StoreCombination storeCombination = findById(storeOrder.getCombinationId());
|
|
|
|
+ storePink.setCid(storeCombination.getId());
|
|
|
|
+ storePink.setPid(storeCombination.getProductId());
|
|
|
|
+ storePink.setPeople(storeCombination.getPeople());
|
|
|
|
+ storePink.setPrice(storeCombination.getPrice());
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ Integer effectiveTime = storeCombination.getEffectiveTime();
|
|
|
|
+ storePink.setAddTime(date);
|
|
|
|
+ storePink.setStopTime(DateUtils.addMinutes(date, effectiveTime));
|
|
|
|
+ storePink.setKId(0L);
|
|
|
|
+ storePink.setIsTpl(0);
|
|
|
|
+ storePink.setIsRefund(0);
|
|
|
|
+ storePink.setStatus(1);
|
|
|
|
+ storePinkService.save(storePink);
|
|
|
|
+ // 如果是开团,需要更新订单数据
|
|
|
|
+ storeOrder.setPinkId(storePink.getId());
|
|
|
|
+ storeOrderService.update(storeOrder);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public GoPinkVO goPink(Integer pinkId) {
|
|
|
|
- int isOk = 0;//判断拼团是否完成
|
|
|
|
- int userBool = 0;//判断当前用户是否在团内 0未在 1在
|
|
|
|
- int pinkBool = 0;//判断拼团是否成功 0未成功 1成功
|
|
|
|
-//
|
|
|
|
-// StorePink teamPink = storePinkService.getById(pinkId);
|
|
|
|
-// if (ObjectUtil.isNull(teamPink) || teamPink.getIsRefund()) throw new CrmebException("对应的拼团不存在");
|
|
|
|
-// StoreCombination storeCombination = getById(teamPink.getCid());
|
|
|
|
-// if (ObjectUtil.isNull(storeCombination) || storeCombination.getIsDel()) throw new CrmebException("对应拼团商品不存在");
|
|
|
|
-//
|
|
|
|
-// // 判断拼团活动时效
|
|
|
|
-// if (!storeCombination.getIsShow()) {
|
|
|
|
-// throw new ServiceException("拼团活动已结束");
|
|
|
|
-// }
|
|
|
|
-// if (System.currentTimeMillis() > storeCombination.getStopTime()) {
|
|
|
|
-// throw new ServiceException("拼团活动已结束");
|
|
|
|
-// }
|
|
|
|
|
|
+ public GoPinkVO goPink(Long pinkId) {
|
|
|
|
+ //判断拼团是否完成
|
|
|
|
+ int isOk = 0;
|
|
|
|
+ //判断当前用户是否在团内 0未在 1在
|
|
|
|
+ int userBool = 0;
|
|
|
|
+ //判断拼团是否成功 0未成功 1成功
|
|
|
|
+ int pinkBool = 0;
|
|
|
|
+ Date date = new Date();
|
|
|
|
+
|
|
|
|
+ StorePink teamPink = storePinkService.findById(pinkId);
|
|
|
|
+ if (ObjectUtil.isNull(teamPink) || teamPink.getIsRefund().equals(1)) {
|
|
|
|
+ throw new ServiceException("对应的拼团不存在");
|
|
|
|
+ }
|
|
|
|
+ StoreCombination storeCombination = findById(teamPink.getCid());
|
|
|
|
+ if (ObjectUtil.isNull(storeCombination) || storeCombination.getIsDelete().equals(1)) {
|
|
|
|
+ throw new ServiceException("对应拼团商品不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 判断拼团活动时效
|
|
|
|
+ if (storeCombination.getIsShow().equals(0)) {
|
|
|
|
+ throw new ServiceException("拼团活动已结束");
|
|
|
|
+ }
|
|
|
|
+ if (date.after(storeCombination.getStopTime())) {
|
|
|
|
+ throw new ServiceException("拼团活动已结束");
|
|
|
|
+ }
|
|
//
|
|
//
|
|
// User user = userService.getInfo();
|
|
// User user = userService.getInfo();
|
|
//
|
|
//
|
|
// GoPinkResponse goPinkResponse = new GoPinkResponse();
|
|
// GoPinkResponse goPinkResponse = new GoPinkResponse();
|
|
-// List<StorePink> pinkList;
|
|
|
|
-// if (teamPink.getKId().equals(0)) {
|
|
|
|
-// pinkList = storePinkService.getListByCidAndKid(teamPink.getCid(), teamPink.getId());
|
|
|
|
-// pinkList.add(teamPink);
|
|
|
|
-// } else {
|
|
|
|
-// pinkList = storePinkService.getListByCidAndKid(teamPink.getCid(), teamPink.getKId());
|
|
|
|
-// pinkList.add(storePinkService.getById(teamPink.getKId()));
|
|
|
|
-// }
|
|
|
|
-// //拼团剩余人数
|
|
|
|
-// int count = teamPink.getPeople() - ( CollUtil.isEmpty(pinkList) ? 0 : pinkList.size() );
|
|
|
|
-//
|
|
|
|
-// if (teamPink.getStatus() == 2) {//已完成
|
|
|
|
-// isOk = 1;
|
|
|
|
-// pinkBool = 1;
|
|
|
|
-// }
|
|
|
|
-// if (teamPink.getStatus() == 1) {//进行中
|
|
|
|
-// if (count < 1) {// 拼团已完成
|
|
|
|
-// isOk = 1;
|
|
|
|
-// pinkBool = 1;
|
|
|
|
-// // 拼团完成处理
|
|
|
|
-// storePinkService.pinkSuccess(teamPink.getId());
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// List<Integer> uidList = pinkList.stream().map(StorePink::getUid).collect(Collectors.toList());
|
|
|
|
-// uidList.add(teamPink.getUid());
|
|
|
|
|
|
+ List<StorePink> pinkList;
|
|
|
|
+ if (teamPink.getKId().equals(0L)) {
|
|
|
|
+ pinkList = storePinkService.getListByCidAndKid(teamPink.getCid(), teamPink.getId());
|
|
|
|
+ pinkList.add(teamPink);
|
|
|
|
+ } else {
|
|
|
|
+ // 名额占用的问题 (支付成功的才算1个)
|
|
|
|
+ pinkList = storePinkService.getListByCidAndKid(teamPink.getCid(), teamPink.getKId());
|
|
|
|
+ pinkList.add(storePinkService.findById(teamPink.getKId()));
|
|
|
|
+ }
|
|
|
|
+ //拼团剩余人数
|
|
|
|
+ int count = teamPink.getPeople() - (CollUtil.isEmpty(pinkList) ? 0 : pinkList.size());
|
|
|
|
+
|
|
|
|
+ if (teamPink.getStatus() == 2) {
|
|
|
|
+ //已完成
|
|
|
|
+ isOk = 1;
|
|
|
|
+ pinkBool = 1;
|
|
|
|
+ }
|
|
|
|
+ if (teamPink.getStatus() == 1) {
|
|
|
|
+ //进行中
|
|
|
|
+ if (count < 1) {
|
|
|
|
+ // 拼团已完成
|
|
|
|
+ isOk = 1;
|
|
|
|
+ pinkBool = 1;
|
|
|
|
+ // 拼团完成处理
|
|
|
|
+ storePinkService.pinkSuccess(teamPink.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Long> uidList = pinkList.stream().map(StorePink::getUid).collect(Collectors.toList());
|
|
|
|
+ uidList.add(teamPink.getUid());
|
|
// if (uidList.contains(user.getUid())) {
|
|
// if (uidList.contains(user.getUid())) {
|
|
// userBool = 1;
|
|
// userBool = 1;
|
|
// }
|
|
// }
|
|
@@ -174,81 +248,20 @@ public class StoreCombinationServiceImpl extends AbstractService<StoreCombinatio
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public PageInfo<StoreCombination> getMore(Integer page, Integer size, Integer comId) {
|
|
|
|
-// Page<StoreCombination> combinationPage = PageHelper.startPage(page, size);
|
|
|
|
-// LambdaQueryWrapper<StoreCombination> lqw = new LambdaQueryWrapper<>();
|
|
|
|
-// if (ObjectUtil.isNotNull(comId)) {
|
|
|
|
-// lqw.ne(StoreCombination::getId, comId);
|
|
|
|
-// }
|
|
|
|
-// lqw.eq(StoreCombination::getIsDel, false);
|
|
|
|
-// lqw.eq(StoreCombination::getIsShow, true);
|
|
|
|
-// long millis = System.currentTimeMillis();
|
|
|
|
-// lqw.le(StoreCombination::getStartTime, millis);
|
|
|
|
-// lqw.ge(StoreCombination::getStopTime, millis);
|
|
|
|
-// lqw.orderByDesc(StoreCombination::getSort, StoreCombination::getId);
|
|
|
|
-// List<StoreCombination> storeCombinations = dao.selectList(lqw);
|
|
|
|
-// return CommonPage.copyPageInfo(combinationPage, storeCombinations);
|
|
|
|
- return null;
|
|
|
|
|
|
+ public List<StoreCombination> getMore(Integer comId) {
|
|
|
|
+ Condition condition = new Condition(StoreCombination.class);
|
|
|
|
+ Example.Criteria criteria = condition.createCriteria();
|
|
|
|
+ criteria.andEqualTo("isDelete", 0);
|
|
|
|
+ if (comId != null) {
|
|
|
|
+ criteria.andEqualTo("id", comId);
|
|
|
|
+ }
|
|
|
|
+ criteria.andEqualTo("isShow", 1);
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ criteria.andLessThanOrEqualTo("startTime", date);
|
|
|
|
+ criteria.andGreaterThanOrEqualTo("stopTime", date);
|
|
|
|
+ condition.setOrderByClause("sort DESC, id DESC");
|
|
|
|
+ return findByCondition(condition);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 取消拼团
|
|
|
|
- *
|
|
|
|
- * @return 此处只是转为申请退款订单
|
|
|
|
- * 自己是团长,取消后,顺位第一人变为团长
|
|
|
|
- * 自己不是团长,直接取消
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public Boolean removePink(StorePinkVO storePinkRequest) {
|
|
|
|
-// StorePink userPink = storePinkService.getById(storePinkRequest.getId());
|
|
|
|
-// if (ObjectUtil.isNull(userPink)) throw new CrmebException("未查到拼团信息,无法取消");
|
|
|
|
-// if (userPink.getIsRefund()) throw new CrmebException("拼团订单已退款");
|
|
|
|
-// // 获取是否拼团成功
|
|
|
|
-// if (userPink.getStatus() == 2) {
|
|
|
|
-// throw new CrmebException("拼团已完成,无法取消");
|
|
|
|
-// }
|
|
|
|
-// Integer kid = userPink.getKId() > 0 ? userPink.getKId() : userPink.getId();
|
|
|
|
-// Integer count = storePinkService.getCountByKid(kid);
|
|
|
|
-// if (count.equals(userPink.getPeople())) {
|
|
|
|
-// // 拼团完成操作
|
|
|
|
-// storePinkService.pinkSuccess(kid);
|
|
|
|
-// throw new CrmebException("拼团已完成,无法取消");
|
|
|
|
-// }
|
|
|
|
-// if (userPink.getStatus() == 3) {
|
|
|
|
-// throw new CrmebException("拼团已申请取消");
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// StoreOrder order = storeOrderService.getByOderId(userPink.getOrderId());
|
|
|
|
-// if (ObjectUtil.isNull(order) || order.getIsDel()) throw new CrmebException("拼团订单不存在");
|
|
|
|
-// if (order.getStatus() == -1 && order.getRefundStatus() != 0) {
|
|
|
|
-// throw new CrmebException("拼团订单已进入退款流程");
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// // 订单申请退款
|
|
|
|
-// OrderRefundApplyRequest refundRequest = new OrderRefundApplyRequest();
|
|
|
|
-// refundRequest.setId(order.getId());
|
|
|
|
-// refundRequest.setUni(order.getOrderId());
|
|
|
|
-// refundRequest.setText("拼团订单取消,申请退款");
|
|
|
|
-// refundRequest.setExplain("用户取消拼团订单,申请退款");
|
|
|
|
-// boolean apply = orderService.refundApply(refundRequest);
|
|
|
|
-// if (!apply) throw new CrmebException("订单申请退款失败");
|
|
|
|
-//
|
|
|
|
-// // 拼团改为未完成
|
|
|
|
-// userPink.setStatus(3).setStopTime(System.currentTimeMillis());
|
|
|
|
-// storePinkService.updateById(userPink);
|
|
|
|
-// if (userPink.getKId() == 0) {// 是团长
|
|
|
|
-// List<StorePink> pinkList = storePinkService.getListByCidAndKid(userPink.getCid(), userPink.getId());
|
|
|
|
-// if (CollUtil.isNotEmpty(pinkList)) {
|
|
|
|
-// // 团员更换团长
|
|
|
|
-// StorePink newHeadPink = pinkList.get(pinkList.size() - 1);
|
|
|
|
-// newHeadPink.setKId(0);
|
|
|
|
-// pinkList.remove(pinkList.size() - 1);
|
|
|
|
-// pinkList.forEach(i -> i.setKId(newHeadPink.getId()));
|
|
|
|
-// pinkList.add(newHeadPink);
|
|
|
|
-// storePinkService.updateBatchById(pinkList);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|