|
@@ -1,30 +1,18 @@
|
|
|
package com.txz.mall.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.txz.mall.core.AbstractService;
|
|
|
-import com.txz.mall.core.ServiceException;
|
|
|
import com.txz.mall.dao.StorePinkMapper;
|
|
|
-import com.txz.mall.model.StoreCombination;
|
|
|
-import com.txz.mall.model.StoreOrder;
|
|
|
import com.txz.mall.model.StorePink;
|
|
|
-import com.txz.mall.service.StoreCombinationService;
|
|
|
-import com.txz.mall.service.StoreOrderService;
|
|
|
import com.txz.mall.service.StorePinkService;
|
|
|
-import com.txz.mall.util.RandomUtil;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
import tk.mybatis.mapper.entity.Example;
|
|
|
-import vo.OrderRefundApplyVO;
|
|
|
-import vo.StorePinkDetailVO;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -35,139 +23,18 @@ import java.util.stream.Collectors;
|
|
|
public class StorePinkServiceImpl extends AbstractService<StorePink> implements StorePinkService {
|
|
|
@Resource
|
|
|
private StorePinkMapper storePinkMapper;
|
|
|
- @Resource
|
|
|
- private StoreOrderService storeOrderService;
|
|
|
- @Resource
|
|
|
- private StoreCombinationService storeCombinationService;
|
|
|
|
|
|
@Override
|
|
|
- public List<StorePinkDetailVO> getAdminList(Integer pinkId) {
|
|
|
+ public List<StorePink> getListByCidAndKid(Long cid, Long kid) {
|
|
|
Condition condition = new Condition(StorePink.class);
|
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
|
criteria.andEqualTo("isDelete", 0);
|
|
|
- criteria.andEqualTo("id", pinkId);
|
|
|
- criteria.andEqualTo("kId", pinkId);
|
|
|
- List<StorePink> pinkList = findByCondition(condition);
|
|
|
- pinkList = pinkList.stream()
|
|
|
- .sorted(Comparator.comparing(StorePink::getId).reversed())
|
|
|
- .collect(Collectors.toList());
|
|
|
- // 将拼团状态提换为订单状态
|
|
|
- return pinkList.stream().map(pink -> {
|
|
|
- StorePinkDetailVO response = new StorePinkDetailVO();
|
|
|
- BeanUtils.copyProperties(pink, response);
|
|
|
- Condition orderCondition = new Condition(StorePink.class);
|
|
|
- Example.Criteria orderCriteria = condition.createCriteria();
|
|
|
- orderCriteria.andEqualTo("isDelete", 0);
|
|
|
- orderCriteria.andEqualTo("id", pinkId);
|
|
|
- orderCriteria.andEqualTo("orderId", pink.getOrderId());
|
|
|
- StoreOrder storeOrder = storeOrderService.findByCondition(orderCondition).get(0);
|
|
|
- if (ObjectUtil.isNotNull(storeOrder)) {
|
|
|
- response.setOrderStatus(storeOrder.getStatus());
|
|
|
- response.setRefundStatus(storeOrder.getRefundStatus());
|
|
|
- }
|
|
|
- return response;
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ criteria.andEqualTo("kId", kid);
|
|
|
+ criteria.andEqualTo("cId", cid);
|
|
|
+ condition.setOrderByClause("id DESC");
|
|
|
+ return findByCondition(condition);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 检查状态,更新数据
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void detectionStatus() {
|
|
|
- // 查找所有结束时间小等于当前的进行中拼团团长
|
|
|
- Condition condition = new Condition(StorePink.class);
|
|
|
- Example.Criteria criteria = condition.createCriteria();
|
|
|
- criteria.andEqualTo("isDelete", 0);
|
|
|
- criteria.andEqualTo("kId", 0);
|
|
|
- criteria.andEqualTo("status", 1);
|
|
|
- criteria.andLessThanOrEqualTo("stopTime", new Date());
|
|
|
- List<StorePink> headList = findByCondition(condition);
|
|
|
- if (CollUtil.isEmpty(headList)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 1.判断是否拼团成功
|
|
|
- * 2.成功的修改状态
|
|
|
- * 3.失败的拼团改为失败,订单申请退款
|
|
|
- */
|
|
|
- List<StorePink> pinkSuccessList = CollUtil.newArrayList();
|
|
|
- List<StorePink> pinkFailList = CollUtil.newArrayList();
|
|
|
- List<OrderRefundApplyVO> applyList = CollUtil.newArrayList();
|
|
|
- for (StorePink headPink : headList) {
|
|
|
- // 查询团员
|
|
|
- List<StorePink> memberList = getListByCidAndKid(headPink.getCid(), headPink.getId());
|
|
|
- memberList.add(headPink);
|
|
|
- if (headPink.getPeople().equals(memberList.size())) {
|
|
|
- memberList.forEach(i -> i.setStatus(2));
|
|
|
- pinkSuccessList.addAll(memberList);
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 计算虚拟比例,判断是否拼团成功
|
|
|
- StoreCombination storeCombination = storeCombinationService.findById(headPink.getCid());
|
|
|
- // 虚拟成团比例
|
|
|
- Integer virtual = storeCombination.getVirtualRation();
|
|
|
- if (headPink.getPeople() <= memberList.size() + virtual) {
|
|
|
- // 可以虚拟成团
|
|
|
- memberList.forEach(i -> {
|
|
|
- i.setStatus(2);
|
|
|
- i.setIsVirtual(1);
|
|
|
- });
|
|
|
- pinkSuccessList.addAll(memberList);
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 失败
|
|
|
- headPink.setStatus(3);
|
|
|
- // 订单申请退款
|
|
|
- OrderRefundApplyVO refundRequest = new OrderRefundApplyVO();
|
|
|
- refundRequest.setId(headPink.getOrderIdKey());
|
|
|
- refundRequest.setText("拼团订单取消,申请退款");
|
|
|
- refundRequest.setExplain("用户取消拼团订单,申请退款");
|
|
|
- pinkFailList.add(headPink);
|
|
|
- applyList.add(refundRequest);
|
|
|
-
|
|
|
- // 团员处理
|
|
|
- if (CollUtil.isNotEmpty(memberList)) {
|
|
|
- memberList.forEach(i -> i.setStatus(3));
|
|
|
- List<OrderRefundApplyVO> tempApplyList = memberList.stream().map(i -> {
|
|
|
- OrderRefundApplyVO tempRefundRequest = new OrderRefundApplyVO();
|
|
|
- tempRefundRequest.setId(headPink.getOrderIdKey());
|
|
|
- tempRefundRequest.setText("拼团订单取消,申请退款");
|
|
|
- tempRefundRequest.setExplain("用户取消拼团订单,申请退款");
|
|
|
- return tempRefundRequest;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- pinkFailList.addAll(memberList);
|
|
|
- applyList.addAll(tempApplyList);
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(pinkFailList) && !pinkFailList.isEmpty()) {
|
|
|
-// boolean failUpdate = updateBatchById(pinkFailList, 100);
|
|
|
-// if (!failUpdate) {
|
|
|
-// throw new ServiceException("批量更新拼团状态,拼团未成功部分,失败");
|
|
|
-// }
|
|
|
- }
|
|
|
- if (!applyList.isEmpty()) {
|
|
|
- boolean task = storeOrderService.refundApplyTask(applyList);
|
|
|
- if (!task) {
|
|
|
- throw new ServiceException("拼团未成功,订单申请退款失败");
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(pinkSuccessList) && !pinkSuccessList.isEmpty()) {
|
|
|
-// boolean successUpdate = updateBatchById(pinkSuccessList, 100);
|
|
|
-// if (!successUpdate) {
|
|
|
-// throw new ServiceException("批量更新拼团状态,拼团成功部分,失败");
|
|
|
-// }
|
|
|
-// SystemNotification notification = systemNotificationService.getByMark(NotifyConstants.GROUP_SUCCESS_MARK);
|
|
|
-// if (notification.getIsRoutine().equals(1) || notification.getIsWechat().equals(1)) {
|
|
|
-// pinkSuccessList.forEach(i -> {
|
|
|
-// StoreOrder storeOrder = storeOrderService.getByOderId(i.getOrderId());
|
|
|
-// StoreCombination storeCombination = storeCombinationService.getById(i.getCid());
|
|
|
-// User tempUser = userService.getById(i.getUid());
|
|
|
-// // 发送微信模板消息
|
|
|
-// });
|
|
|
-// }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public void pinkSuccess(Long id) {
|
|
@@ -183,66 +50,4 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
|
|
|
update(i);
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public void pinkFail(Long id) {
|
|
|
- StorePink userPink = findById(id);
|
|
|
-// // 订单申请退款
|
|
|
-// 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);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void theSelection(Long id) {
|
|
|
- // 假设只有1个用户是天选
|
|
|
- long luckNum = 1;
|
|
|
-
|
|
|
- Condition condition = new Condition(StorePink.class);
|
|
|
- Example.Criteria criteria = condition.createCriteria();
|
|
|
- criteria.andEqualTo("isDelete", 0);
|
|
|
- // 排除团长
|
|
|
- criteria.andEqualTo("kId", 1);
|
|
|
- // 支付成功的
|
|
|
-
|
|
|
- criteria.andEqualTo("status", 1);
|
|
|
- List<StorePink> list = findByCondition(condition);
|
|
|
- if (CollUtil.isEmpty(list)) {
|
|
|
- throw new ServiceException("没有拼团订单");
|
|
|
- }
|
|
|
- long count = list.stream().filter(i -> i.getLId().equals(1)).count();
|
|
|
- if (count >= luckNum) {
|
|
|
- throw new ServiceException("已有天选");
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> idCollect = list.stream().map(StorePink::getId).collect(Collectors.toList());
|
|
|
- List<Long> randomIds = RandomUtil.uniqueRandom(idCollect, (int) luckNum);
|
|
|
-
|
|
|
- randomIds.forEach(i -> {
|
|
|
- StorePink luckPink = new StorePink();
|
|
|
- luckPink.setId(i);
|
|
|
- luckPink.setLId(1);
|
|
|
- update(luckPink);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<StorePink> getListByCidAndKid(Long cid, Long kid) {
|
|
|
- Condition condition = new Condition(StorePink.class);
|
|
|
- Example.Criteria criteria = condition.createCriteria();
|
|
|
- criteria.andEqualTo("isDelete", 0);
|
|
|
- criteria.andEqualTo("kId", kid);
|
|
|
- criteria.andEqualTo("cId", cid);
|
|
|
- condition.setOrderByClause("id DESC");
|
|
|
- return findByCondition(condition);
|
|
|
- }
|
|
|
-
|
|
|
}
|