|
|
@@ -11,6 +11,7 @@ import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.*;
|
|
|
@@ -20,8 +21,11 @@ import com.cyksj.model.manage.views.AccountView;
|
|
|
import com.cyksj.model.request.OrderRefundReq;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.mange.AccountCommonService;
|
|
|
+import com.cyksj.service.mange.CmsGroupService;
|
|
|
+import com.cyksj.service.mange.CmsOrderDonService;
|
|
|
import com.cyksj.service.order.OrderCommonService;
|
|
|
import com.cyksj.service.order.OrderRefundService;
|
|
|
+import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.web.util.EasyExcelUtils;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -38,6 +42,7 @@ import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* 项目名: yhlxj
|
|
|
@@ -78,6 +83,8 @@ public class AccountTempController {
|
|
|
|
|
|
private final UserBenefitsService userBenefitsService;
|
|
|
|
|
|
+ private final CmsOrderDonService cmsOrderDonService;
|
|
|
+
|
|
|
/**
|
|
|
* 新增临时账号
|
|
|
*/
|
|
|
@@ -250,6 +257,276 @@ public class AccountTempController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private final GroupRelationClearService relationClearService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 奈飞15天以内的车票自动退款
|
|
|
+ */
|
|
|
+ @PutMapping("/nf/refund/ff")
|
|
|
+ public Result<String> neRefundff(Long skuId) {
|
|
|
+ //先处理奈飞月付
|
|
|
+ List<GroupsRelation> groupsRelations = relationMapper.selectNfFF(skuId);
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(1);
|
|
|
+ groupsRelations.forEach(relation->{
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getRelationId, relation.getId())
|
|
|
+ .eq(OrderDon::getUserId, relation.getUserId())
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (orderDon == null) {
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.refund_balance);
|
|
|
+ log.info("订单不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (orderDon.getMoney() != null && orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ log.info("订单金额为0 先不做处理");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
|
|
|
+ Integer months = sku.getMonths();
|
|
|
+ BigDecimal money = orderDon.getMoney().add(Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO));
|
|
|
+ BigDecimal single = money.divide(BigDecimal.valueOf(months * 30), 2, RoundingMode.DOWN);
|
|
|
+ long betDay = DateUtil.between(DateTime.now(), relation.getExpiryTime(), DateUnit.DAY) + 1;
|
|
|
+ BigDecimal refundMoney = single.multiply(BigDecimal.valueOf(betDay));
|
|
|
+ //退款
|
|
|
+ OrderRefundReq orderRefundReq = new OrderRefundReq();
|
|
|
+ orderRefundReq.setOrderId(orderDon.getId());
|
|
|
+ orderRefundReq.setRefundMoney(refundMoney);
|
|
|
+ orderDon.setRefundDesc("奈飞15天内过期自动退款");
|
|
|
+ String outNo = null;
|
|
|
+ try {
|
|
|
+ orderRefundReq.setRefundType("ALI_PAY");
|
|
|
+ outNo = orderRefundService.centerRefund(orderRefundReq, orderDon);
|
|
|
+ orderDon.setStatus(OrderDon.Status.refund);
|
|
|
+ orderDon.setRefundMoney(orderRefundReq.getRefundMoney());
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+ clearUserLockingRelation(relationMapper.selectById(orderDon.getRelationId()), orderDon);
|
|
|
+ //记录退款
|
|
|
+ orderRefundService.refundRecord(orderDon, orderRefundReq.getRefundMoney(), null, goodsDon, sku, outNo, orderDon.getType().getType(), null);
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.refund_balance);
|
|
|
+ } catch (Exception e) {
|
|
|
+ orderRefundReq.setRefundType("balance");
|
|
|
+ userBenefitsService.addUserBalance(relation.getUserId(), refundMoney, UserBalanceSourceRecord.Source.clear_valid, relation.getYhsId(), orderDon.getId(), goodsDon.getTitle() + UserBalanceSourceRecord.Source.clear_valid.getDesc(), true);
|
|
|
+ //修改订单状态 为退款
|
|
|
+ orderDon.setStatus(OrderDon.Status.refund);
|
|
|
+ orderDon.setRefundBalance(refundMoney);
|
|
|
+ orderDon.setRefundMoney(BigDecimal.ZERO);
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+ orderRefundService.refundRecord(orderDon, orderRefundReq.getRefundMoney(), null, goodsDon, sku, outNo, "balance", null);
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.refund_balance);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 张凯 指定奈飞用户退款
|
|
|
+ */
|
|
|
+ @PutMapping("/nf/refund/ff/userId")
|
|
|
+ public Result<String> neRefundffUid(Long userId, Long skuId) {
|
|
|
+ //先处理奈飞月付
|
|
|
+ List<GroupsRelation> groupsRelations = relationMapper.seelctNeRefundffUid(userId, skuId);
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(1);
|
|
|
+ groupsRelations.forEach(relation -> {
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getRelationId, relation.getId())
|
|
|
+ .eq(OrderDon::getUserId, relation.getUserId())
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (orderDon == null) {
|
|
|
+ log.info("订单不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (orderDon.getMoney() != null && orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ log.info("订单金额为0 先不做处理");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
|
|
|
+ Integer months = sku.getMonths();
|
|
|
+ BigDecimal money = orderDon.getMoney().add(Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO));
|
|
|
+ BigDecimal single = money.divide(BigDecimal.valueOf(months * 30), 0, RoundingMode.DOWN);
|
|
|
+ long betDay = DateUtil.between(DateTime.now(), relation.getExpiryTime(), DateUnit.DAY) + 1;
|
|
|
+ BigDecimal refundMoney = single.multiply(BigDecimal.valueOf(betDay));
|
|
|
+ //退款
|
|
|
+ OrderRefundReq orderRefundReq = new OrderRefundReq();
|
|
|
+ orderRefundReq.setOrderId(orderDon.getId());
|
|
|
+ orderRefundReq.setRefundMoney(refundMoney);
|
|
|
+ orderDon.setRefundDesc("异常账号奈飞车票自动退款");
|
|
|
+ String outNo = null;
|
|
|
+ try {
|
|
|
+ orderRefundReq.setRefundType("ALI_PAY");
|
|
|
+ outNo = orderRefundService.centerRefund(orderRefundReq, orderDon);
|
|
|
+ orderDon.setStatus(OrderDon.Status.refund);
|
|
|
+ orderDon.setRefundMoney(orderRefundReq.getRefundMoney());
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+ clearUserLockingRelation(relationMapper.selectById(orderDon.getRelationId()), orderDon);
|
|
|
+ //记录退款
|
|
|
+ orderRefundService.refundRecord(orderDon, orderRefundReq.getRefundMoney(), null, goodsDon, sku, outNo, orderDon.getType().getType(), null);
|
|
|
+ try {
|
|
|
+ if (orderDon.getIsFixedDistribute()) {
|
|
|
+ log.info("退款分销订单:{}", orderDon.getId());
|
|
|
+ cmsOrderDonService.deductDsPoints(orderDon);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.refund_balance);
|
|
|
+ } catch (Exception e) {
|
|
|
+ orderRefundReq.setRefundType("balance");
|
|
|
+ userBenefitsService.addUserBalance(relation.getUserId(), refundMoney, UserBalanceSourceRecord.Source.clear_valid, relation.getYhsId(), orderDon.getId(), goodsDon.getTitle() + UserBalanceSourceRecord.Source.clear_valid.getDesc(), true);
|
|
|
+ //修改订单状态 为退款
|
|
|
+ orderDon.setStatus(OrderDon.Status.refund);
|
|
|
+ orderDon.setRefundBalance(refundMoney);
|
|
|
+ orderDon.setRefundMoney(BigDecimal.ZERO);
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+ orderRefundService.refundRecord(orderDon, orderRefundReq.getRefundMoney(), null, goodsDon, sku, outNo, "balance", null);
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.refund_balance);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常账号奈飞月付 清除
|
|
|
+ */
|
|
|
+ @PutMapping("/clear")
|
|
|
+ public void test() {
|
|
|
+ List<GroupsRelation> groupsRelations = relationMapper.getNfMonthError();
|
|
|
+
|
|
|
+ groupsRelations.forEach(relation->{
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.manual);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 备用账号已设置车队 修改类型
|
|
|
+ * */
|
|
|
+ @PutMapping("/sync/account/type")
|
|
|
+ public void tyope() {
|
|
|
+ List<Account> accounts = accountMapper.selectList(Wrappers.lambdaQuery(Account.class)
|
|
|
+ .eq(Account::getType, 2));
|
|
|
+ accounts.forEach(account->{
|
|
|
+ GroupsTrips groupsTrips = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
+ .eq(GroupsTrips::getAccountId, account.getId())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (groupsTrips != null) {
|
|
|
+ account.setType(1);
|
|
|
+ accountMapper.updateById(account);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private final CmsGroupService groupService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将空车位合并
|
|
|
+ */
|
|
|
+ @PutMapping("/sync/num")
|
|
|
+ public void syncNfNum() {
|
|
|
+ //70537 uid:655884
|
|
|
+ //gid :69951
|
|
|
+ Long skuId = 4l;
|
|
|
+ List<GroupsTrips> groupsTrips = groupsMapper.selectList(Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
+ .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
|
|
|
+ .eq(GroupsTrips::getSkuId, skuId)
|
|
|
+ .eq(GroupsTrips::getAvailableNum, 3)
|
|
|
+ .orderByDesc(GroupsTrips::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+
|
|
|
+ groupsTrips.forEach(data->{
|
|
|
+ Long groupsId = data.getId();
|
|
|
+ List<GroupsRelation> groupsRelations = relationMapper.selectList(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .ne(GroupsRelation::getUserId, 0)
|
|
|
+ .eq(GroupsRelation::getGroupsId, groupsId));
|
|
|
+
|
|
|
+ groupsRelations.forEach(relation->{
|
|
|
+ relationMapper.updateNum();
|
|
|
+ GroupsTrips replace = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
+ .gt(GroupsTrips::getAvailableNum, 0)
|
|
|
+ .eq(GroupsTrips::getSkuId, skuId)
|
|
|
+ .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
|
|
|
+ .orderByAsc(GroupsTrips::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (replace != null) {
|
|
|
+ GroupsRelation replaceRelation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getGroupsId, replace.getId())
|
|
|
+ .eq(GroupsRelation::getUserId, 0)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (replaceRelation != null) {
|
|
|
+ replaceRelation.setUserId(relation.getUserId());
|
|
|
+ replaceRelation.setStartTime(relation.getStartTime());
|
|
|
+ replaceRelation.setExpiryTime(relation.getExpiryTime());
|
|
|
+ replaceRelation.setStatus(relation.getStatus());
|
|
|
+ replaceRelation.setYhsId(relation.getYhsId());
|
|
|
+ relationMapper.updateById(replaceRelation);
|
|
|
+
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getUserId, relation.getUserId())
|
|
|
+ .eq(OrderDon::getRelationId, relation.getId())
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (orderDon != null) {
|
|
|
+ orderDon.setRelationId(replaceRelation.getId());
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+ }
|
|
|
+ log.info("userId:{}", relation.getUserId());
|
|
|
+ relation.setNewRelationId(replaceRelation.getId());
|
|
|
+ relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.change_ticket);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ List<GroupsTrips> emptys = groupsMapper.selectList(Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
+ .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
|
|
|
+ .eq(GroupsTrips::getSkuId, skuId)
|
|
|
+ .eq(GroupsTrips::getAvailableNum, 5));
|
|
|
+ emptys.forEach(e->{
|
|
|
+ try {
|
|
|
+ log.info("开始删除空白车队id:{}", e.getId());
|
|
|
+ groupService.close(e.getId());
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error(StringUtil.getErrorMsg(ex));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private final UserTicketClearedRecordMapper userTicketClearedRecordMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拉黑用户 车票
|
|
|
+ */
|
|
|
+ @GetMapping("/return")
|
|
|
+ public void return1(Long userId) {
|
|
|
+ List<UserTicketClearedRecord> blacks = userTicketClearedRecordMapper.selectList(Wrappers.lambdaQuery(UserTicketClearedRecord.class)
|
|
|
+ .eq(UserTicketClearedRecord::getUserId, userId)
|
|
|
+ .eq(UserTicketClearedRecord::getSource, "black")
|
|
|
+ .gt(UserTicketClearedRecord::getCreatedTime, DateUtil.parse("2024-10-30 12:00:39")));
|
|
|
+
|
|
|
+ for (UserTicketClearedRecord black : blacks) {
|
|
|
+
|
|
|
+ Long relationId = black.getRelationId();
|
|
|
+
|
|
|
+ Long toUserId = black.getUserId();
|
|
|
+
|
|
|
+ GroupsRelation relation = relationMapper.selectById(relationId);
|
|
|
+ if (relation.getUserId() == 0) {
|
|
|
+ relation.setUserId(toUserId);
|
|
|
+ relation.setStartTime(black.getStartTime());
|
|
|
+ relation.setExpiryTime(black.getExpiryTime());
|
|
|
+ relation.setStatus(GroupsRelation.Status.validity);
|
|
|
+ relationMapper.updateById(relation);
|
|
|
+ }else {
|
|
|
+ log.info("作为号重复:{}", relation.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void clearUserLockingRelation(GroupsRelation groupsRelation, OrderDon orderDon) {
|
|
|
if (groupsRelation == null) {
|
|
|
return;
|