|
|
@@ -1,16 +1,30 @@
|
|
|
package com.cyksj.web.controller.manage.group;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
-import com.cyksj.model.entity.GroupsRelation;
|
|
|
+import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
+import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
+import com.cyksj.mapper.OrderDonMapper;
|
|
|
+import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
+import com.cyksj.model.views.GroupsRelationRechargeView;
|
|
|
import com.cyksj.service.scheduler.SchedulerService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -32,6 +46,14 @@ public class CmsGroupRelationController {
|
|
|
|
|
|
private final SchedulerService schedulerService;
|
|
|
|
|
|
+ private final GroupsRelationMapper groupsRelationMapper;
|
|
|
+
|
|
|
+ private final CmsUserMapper cmsUserMapper;
|
|
|
+
|
|
|
+ private final OrderDonMapper orderDonMapper;
|
|
|
+
|
|
|
+ private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
+
|
|
|
@GetMapping("/get")
|
|
|
public Result<List<GroupsRelationView>> get(){
|
|
|
List<GroupsRelationView> search = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
@@ -50,4 +72,82 @@ public class CmsGroupRelationController {
|
|
|
schedulerService.assignUserGroupsRelation(groupsId);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("车队账号禁用成功");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代充平台 用户账号车票列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/recharge")
|
|
|
+ public Result<SearchResult<GroupsRelationRechargeView>> getRechargeList() {
|
|
|
+ SearchResult<GroupsRelationRechargeView> search = beanSearcher.search(GroupsRelationRechargeView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(GroupsRelationRechargeView::getStatus, List.of(GroupsRelation.Status.validity.name(), GroupsRelation.Status.outside.name())).op(Operator.InList)
|
|
|
+ .field(GroupsRelationRechargeView::getSpecialType, GoodsDon.SpecialType.recharge.name())
|
|
|
+ .build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代充账号 状态变更
|
|
|
+ */
|
|
|
+ @PostMapping("/set/recharge")
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public Result<String> updateRechargeStatus(@RequestBody GroupsRelationRechargeView rechargeView) {
|
|
|
+ long adminId = StpUtil.getLoginIdAsLong();
|
|
|
+ Long relationId = rechargeView.getRelationId();
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
+ Assert.notNull(relation, "代充车票不存在");
|
|
|
+ if (relation.getRenewStatus() == null || relation.getRechargeStatus() == GroupsRelation.RechargeStatus.complete) {
|
|
|
+ throw BusinessRuntimeException.getInstance("");
|
|
|
+ }
|
|
|
+ CmsUser cmsUser = cmsUserMapper.selectById(adminId);
|
|
|
+ GroupsRelation.RechargeStatus relation_rechargeStatus = relation.getRechargeStatus();
|
|
|
+ GroupsRelation.RechargeStatus rechargeStatus = rechargeView.getRechargeStatus();
|
|
|
+ if (relation_rechargeStatus == rechargeStatus) {
|
|
|
+ throw BusinessRuntimeException.getInstance("状态重复");
|
|
|
+ }
|
|
|
+ relation.setRechargeStatus(rechargeStatus);
|
|
|
+ relation.setOperator(cmsUser.getNickname());
|
|
|
+ if (rechargeStatus == GroupsRelation.RechargeStatus.complete) {
|
|
|
+ relation.setSendTime(DateTime.now());
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getUserId, relation.getUserId())
|
|
|
+ .eq(OrderDon::getRelationId, relationId)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderStatus)
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (orderDon == null) throw BusinessRuntimeException.getInstance("该代充订单不存在");
|
|
|
+ if (orderDon.getStatus() == OrderDon.Status.refund){
|
|
|
+ throw BusinessRuntimeException.getInstance("该代充订单已退款");
|
|
|
+ }
|
|
|
+ orderDon.setStatus(OrderDon.Status.complete);
|
|
|
+
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
+
|
|
|
+ relation.setStartTime(DateTime.now());
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
+ DateTime expiryTime;
|
|
|
+ if (sku.getDays() != null && sku.getDays() > 0) {
|
|
|
+ expiryTime = DateUtil.offsetDay(relation.getStartTime(), sku.getDays());
|
|
|
+ } else {
|
|
|
+ expiryTime = DateUtil.offsetMonth(relation.getStartTime(), sku.getMonths());
|
|
|
+ }
|
|
|
+ relation.setExpiryTime(expiryTime);
|
|
|
+ }
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("状态修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代充账号 待处理列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/recharge/waiting")
|
|
|
+ public Result<Boolean> getRechargeWaiting() {
|
|
|
+ Number number = beanSearcher.searchCount(GroupsRelationRechargeView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(GroupsRelationRechargeView::getSpecialType, GoodsDon.SpecialType.recharge.name())
|
|
|
+ .field(GroupsRelationRechargeView::getRechargeStatus, GroupsRelation.RechargeStatus.waiting.name())
|
|
|
+ .build());
|
|
|
+ if (number.intValue() > 0) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(true);
|
|
|
+ }
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(false);
|
|
|
+ }
|
|
|
}
|