|
|
@@ -1,32 +1,19 @@
|
|
|
package io.renren.modules.qyh.service.impl;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-import org.apache.shiro.SecurityUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.DesensitizedUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import io.renren.common.canstant.QueueConstant;
|
|
|
import io.renren.common.enums.*;
|
|
|
import io.renren.common.exception.RRException;
|
|
|
import io.renren.common.utils.Constant;
|
|
|
@@ -35,10 +22,15 @@ import io.renren.common.utils.R;
|
|
|
import io.renren.common.utils.config.PropertiesParameter;
|
|
|
import io.renren.modules.qmgj.entity.MemberInfoEntity;
|
|
|
import io.renren.modules.qmgj.service.MemberInfoService;
|
|
|
+import io.renren.modules.qmjz.entity.ScoreStu;
|
|
|
import io.renren.modules.qmjz.entity.WxConsumeInfoEntity;
|
|
|
+import io.renren.modules.qmjz.enums.ScoreType;
|
|
|
+import io.renren.modules.qmjz.enums.TaskType;
|
|
|
+import io.renren.modules.qmjz.mapper.ScoreStuMapper;
|
|
|
+import io.renren.modules.qmjz.service.ScoreStuService;
|
|
|
import io.renren.modules.qmjz.service.WxConsumeInfoService;
|
|
|
import io.renren.modules.qmjz.utils.BeanCopyUtils;
|
|
|
-import io.renren.modules.sys.entity.SysUserEntity;
|
|
|
+import io.renren.modules.qmjz.utils.DateForStr;
|
|
|
import io.renren.modules.qyh.entity.*;
|
|
|
import io.renren.modules.qyh.mapper.MeetMapper;
|
|
|
import io.renren.modules.qyh.model.bo.MeetPeopleBO;
|
|
|
@@ -49,7 +41,25 @@ import io.renren.modules.qyh.model.dto.MyAppointmentDTO;
|
|
|
import io.renren.modules.qyh.model.dto.PointsRecordDTO;
|
|
|
import io.renren.modules.qyh.model.vo.*;
|
|
|
import io.renren.modules.qyh.service.*;
|
|
|
+import io.renren.modules.sys.entity.SysUserEntity;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.springframework.amqp.core.MessageProperties;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service("meetService")
|
|
|
@@ -77,6 +87,12 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
private LoginVerificationService loginVerificationService;
|
|
|
@Autowired
|
|
|
private WxConsumeInfoService wxConsumeInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ScoreStuMapper scoreStuMapper;
|
|
|
+ @Autowired
|
|
|
+ private ScoreStuService scoreStuService;
|
|
|
+ @Autowired
|
|
|
+ private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
@Override
|
|
|
public PageUtils myAppointmentPage(Map<String, Object> params) {
|
|
|
@@ -113,11 +129,13 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
|
|
|
ExpertTopicEntity expertTopicEntity = expertTopicService.loadById(topicId, true);
|
|
|
BigDecimal topicPrice = expertTopicEntity.getTopicPrice();
|
|
|
+ BigDecimal topicPoints = expertTopicEntity.getTopicPoints();
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
MeetEntity meetEntity = new MeetEntity();
|
|
|
BeanCopyUtils.copyPropertiesIgnoreNull(dto, meetEntity);
|
|
|
meetEntity.setMeetPrice(topicPrice);
|
|
|
+ meetEntity.setMeetPoints(topicPoints);
|
|
|
meetEntity.setCreateId(userId);
|
|
|
meetEntity.setUpdateId(userId);
|
|
|
meetEntity.setCreateTime(now);
|
|
|
@@ -137,12 +155,15 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
|
|
|
// 实付价格
|
|
|
BigDecimal actualPrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal actualPoints = BigDecimal.ZERO;
|
|
|
|
|
|
// 拼团方式 0 一对一 1拼团
|
|
|
Integer groupWay = dto.getGroupWay();
|
|
|
if (NumberUtil.equals(groupWay, YnEnum.NO.value())) {
|
|
|
actualPrice = topicPrice;
|
|
|
+ actualPoints = topicPoints;
|
|
|
peopleEntity.setPayPrice(topicPrice);
|
|
|
+ peopleEntity.setPointsDeduction(topicPoints);
|
|
|
meetEntity.setProcess(MeetProcessEnum.RESERVE.value());
|
|
|
meetEntity.setMeetType(MeetTypeEnum.RESERVATION.value());
|
|
|
baseMapper.insert(meetEntity);
|
|
|
@@ -155,8 +176,11 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
throw new RRException("拼团人数不能为空");
|
|
|
}
|
|
|
BigDecimal payPrice = NumberUtil.div(topicPrice, groupNumberPeople, 0, RoundingMode.FLOOR);
|
|
|
+ BigDecimal pointsDeduction = NumberUtil.div(topicPoints, groupNumberPeople, 0, RoundingMode.FLOOR);
|
|
|
actualPrice = payPrice;
|
|
|
+ actualPoints = pointsDeduction;
|
|
|
peopleEntity.setPayPrice(payPrice);
|
|
|
+ peopleEntity.setPointsDeduction(pointsDeduction);
|
|
|
LocalDateTime groupWayEndTime = LocalDateTime.now().plusHours(48);
|
|
|
meetEntity.setGroupWayEndTime(groupWayEndTime);
|
|
|
meetEntity.setMeetType(MeetTypeEnum.IN_A_GROUP.value());
|
|
|
@@ -166,7 +190,7 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
Map<String, String> payFor = null;
|
|
|
try {
|
|
|
payFor = getPayFor(memberInfoEntity, userId, meetEntity.getId(), expertTopicEntity, topicPrice, actualPrice,
|
|
|
- now);
|
|
|
+ now, topicPoints, actualPoints);
|
|
|
} catch (Exception e) {
|
|
|
throw new RRException("支付失败", e);
|
|
|
}
|
|
|
@@ -248,13 +272,15 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
}
|
|
|
ExpertTopicEntity expertTopicEntity = expertTopicService.loadById(meetEntity.getTopicId(), true);
|
|
|
BigDecimal topicPrice = expertTopicEntity.getTopicPrice();
|
|
|
+ BigDecimal topicPoints = expertTopicEntity.getTopicPoints();
|
|
|
|
|
|
BigDecimal payPrice = NumberUtil.div(topicPrice, groupNumberPeople, 0, RoundingMode.FLOOR);
|
|
|
+ BigDecimal pointsDeduction = NumberUtil.div(topicPoints, groupNumberPeople, 0, RoundingMode.FLOOR);
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
Map<String, String> payFor = null;
|
|
|
try {
|
|
|
- payFor = getPayFor(memberInfoEntity, userId, meetId, expertTopicEntity, topicPrice, payPrice, now);
|
|
|
+ payFor = getPayFor(memberInfoEntity, userId, meetId, expertTopicEntity, topicPrice, payPrice, now, topicPoints, pointsDeduction);
|
|
|
} catch (Exception e) {
|
|
|
throw new RRException("支付失败", e);
|
|
|
}
|
|
|
@@ -281,7 +307,7 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, String> getPayFor(MemberInfoEntity memberInfoEntity, Long userId, Long meetId,
|
|
|
- ExpertTopicEntity expertTopicEntity, BigDecimal price, BigDecimal actuallyPaid, LocalDateTime payTime)
|
|
|
+ ExpertTopicEntity expertTopicEntity, BigDecimal price, BigDecimal actuallyPaid, LocalDateTime payTime, BigDecimal points, BigDecimal pointsDeduction)
|
|
|
throws Exception {
|
|
|
String openid = memberInfoEntity.getOpenid();
|
|
|
OrderBusinessTypeEnum typeEnum = OrderBusinessTypeEnum.ASK_EXPERTS;
|
|
|
@@ -298,9 +324,112 @@ public class MeetServiceImpl extends ServiceImpl<MeetMapper, MeetEntity> impleme
|
|
|
bo.setPayTime(payTime);
|
|
|
bo.setPrice(price);
|
|
|
bo.setActuallyPaid(actuallyPaid);
|
|
|
- bo.setPointsDeduction(BigDecimal.ZERO);
|
|
|
+ bo.setPoints(points);
|
|
|
+ bo.setPointsDeduction(pointsDeduction);
|
|
|
bo.setCode(TaskConfigEnum.MEET.code());
|
|
|
- return orderService.payFor(bo);
|
|
|
+ Map<String, String> returnMap = orderService.payFor(bo);
|
|
|
+ if (actuallyPaid.compareTo(BigDecimal.ZERO) == 0 && pointsDeduction.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ // 积分抵扣
|
|
|
+ Integer totalPoints = scoreStuMapper.getTotalPointsByMemberId(memberInfoEntity.getId());
|
|
|
+ if (NumberUtil.isGreater(pointsDeduction, BigDecimal.valueOf(totalPoints))) {
|
|
|
+ throw new RRException("积分不足");
|
|
|
+ }
|
|
|
+ ScoreStu add = new ScoreStu();
|
|
|
+ add.setDay(DateForStr.getInfoDateStr(new Date()));
|
|
|
+ add.setStuId(memberInfoEntity.getId());
|
|
|
+ add.setScoreType(ScoreType.STORE_SCORE.getCode());
|
|
|
+ add.setTaskId(TaskType.WORK_APPLY_DEDUCT.getCode());
|
|
|
+ add.setBusinessId(TaskType.WORK_APPLY_DEDUCT.getCode());
|
|
|
+ add.setScoreEvent(TaskType.WORK_APPLY_DEDUCT.getInfo());
|
|
|
+ add.setScoreValue(NumberUtil.sub(BigDecimal.ZERO, pointsDeduction).intValue());
|
|
|
+ add.setCreateTime(new Date());
|
|
|
+ add.setSurplusScore(NumberUtil.sub(BigDecimal.ZERO, pointsDeduction).intValue() + this.scoreStuService.getTotalScore(memberInfoEntity.getId()));
|
|
|
+ scoreStuMapper.insert(add);
|
|
|
+ String orderNo = returnMap.getOrDefault("orderNo", "");
|
|
|
+ if (StringUtils.isEmpty(orderNo)) {
|
|
|
+ throw new RRException("支付失败");
|
|
|
+ }
|
|
|
+ OrderEntity orderEntity = orderService.loadByPayNo(orderNo, false);
|
|
|
+ if (orderEntity == null) {
|
|
|
+ throw new RRException("支付失败");
|
|
|
+ }
|
|
|
+ payCallback(orderEntity);
|
|
|
+ }
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MemberInfoEntity payCallback(OrderEntity orderEntity) {
|
|
|
+ BigDecimal money = orderEntity.getActuallyPaid();
|
|
|
+ // if(!NumberUtil.equals(money, NumberUtil.toBigDecimal(totalFee))) {
|
|
|
+ // // 支付失败
|
|
|
+ // returnData.put("return_code", "FAIL");
|
|
|
+ // returnData.put("return_msg", "订单金额不符合");
|
|
|
+ // return StringUtil.GetMapToXML(returnData);
|
|
|
+ // }
|
|
|
+
|
|
|
+ Long businessId = orderEntity.getBusinessId();
|
|
|
+ BigDecimal pointsDeduction = orderEntity.getPointsDeduction();
|
|
|
+ MemberInfoEntity memberInfoEntity = memberInfoService.getById(orderEntity.getMemberId());
|
|
|
+ Long memberId = memberInfoEntity.getId();
|
|
|
+
|
|
|
+ MeetEntity meetEntity = getById(businessId);
|
|
|
+ Integer groupWay = meetEntity.getGroupWay();
|
|
|
+
|
|
|
+ Long expertId = meetEntity.getExpertId();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ Long meetId = meetEntity.getId();
|
|
|
+ if (NumberUtil.equals(groupWay, YnEnum.YES.value())) {
|
|
|
+ MeetPeopleEntity peopleEntity = new MeetPeopleEntity();
|
|
|
+ peopleEntity.setMeetId(meetId);
|
|
|
+ peopleEntity.setExpertId(expertId);
|
|
|
+ peopleEntity.setMemberId(memberId);
|
|
|
+ peopleEntity.setIsRegimentalCommander(YnEnum.YES.value());
|
|
|
+ peopleEntity.setIsMeetFinish(YnEnum.NO.value());
|
|
|
+ peopleEntity.setPayPrice(money);
|
|
|
+ peopleEntity.setPointsDeduction(pointsDeduction);
|
|
|
+ peopleEntity.setIsCancelMeet(YnEnum.NO.value());
|
|
|
+ peopleEntity.setCreateId(memberId);
|
|
|
+ peopleEntity.setUpdateId(memberId);
|
|
|
+ peopleEntity.setCreateTime(now);
|
|
|
+ peopleEntity.setUpdateTime(now);
|
|
|
+ peopleEntity.setIsDelete(IsDeleteEnum.NORMAL.value());
|
|
|
+ meetPeopleService.save(peopleEntity);
|
|
|
+ meetEntity.setProcess(MeetProcessEnum.RESERVE.value());
|
|
|
+ meetEntity.setMeetType(MeetTypeEnum.IN_A_GROUP.value());
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("meetId", meetId);
|
|
|
+ rabbitTemplate.convertAndSend(QueueConstant.MEET_EXPIRATION_MS_QUEUE, jsonObject.toString(),
|
|
|
+ message -> {
|
|
|
+ MessageProperties messageProperties = message.getMessageProperties();
|
|
|
+ long millis = LocalDateTimeUtil.between(now, now.plusDays(2)).toMillis();
|
|
|
+ messageProperties.setExpiration(String.valueOf(millis));
|
|
|
+ return message;
|
|
|
+ });
|
|
|
+
|
|
|
+ Integer count = meetPeopleService.selectCountByMeetId(businessId);
|
|
|
+ Integer groupNumberPeople = meetEntity.getGroupNumberPeople();
|
|
|
+ if (NumberUtil.equals(groupNumberPeople, count)) {
|
|
|
+ meetEntity.setProcess(MeetProcessEnum.PAYMENT_SUCCESSFUL.value());
|
|
|
+ meetEntity.setMeetType(MeetTypeEnum.RESERVATION.value());
|
|
|
+
|
|
|
+ }
|
|
|
+ } else if (NumberUtil.equals(groupWay, YnEnum.NO.value())) {
|
|
|
+ meetEntity.setProcess(MeetProcessEnum.PAYMENT_SUCCESSFUL.value());
|
|
|
+ meetEntity.setMeetType(MeetTypeEnum.RESERVATION.value());
|
|
|
+ MeetPeopleEntity meetPeopleEntity = meetPeopleService.getBaseMapper()
|
|
|
+ .selectOne(new LambdaQueryWrapper<MeetPeopleEntity>().eq(MeetPeopleEntity::getMeetId, meetId)
|
|
|
+ .orderByDesc(MeetPeopleEntity::getCreateTime).last("limit 1"));
|
|
|
+ if(ObjectUtil.isNotNull(meetPeopleEntity)) {
|
|
|
+ meetPeopleEntity.setIsDelete(IsDeleteEnum.NORMAL.value());
|
|
|
+ meetPeopleService.save(meetPeopleEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ meetEntity.setUpdateTime(now);
|
|
|
+ meetEntity.setIsDelete(IsDeleteEnum.NORMAL.value());
|
|
|
+ updateById(meetEntity);
|
|
|
+ return memberInfoEntity;
|
|
|
}
|
|
|
|
|
|
@Override
|