|
|
@@ -3,18 +3,24 @@ package com.cyksj.web.controller.manage;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
+import com.cyksj.mapper.OrderDonMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
-import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
+import com.cyksj.mapper.corp.CorpUserFollowRelationMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.UserView;
|
|
|
+import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
import com.cyksj.model.views.RenewalView;
|
|
|
+import com.cyksj.model.views.UserDistributeBusinessInfoView;
|
|
|
+import com.cyksj.model.views.UserOrderDonDetail;
|
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -22,6 +28,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
@@ -49,36 +57,46 @@ public class CmsUserController{
|
|
|
|
|
|
private final GroupRelationFrontService groupRelationFrontService;
|
|
|
|
|
|
- private final UserDistributeSharedMapper userDistributeSharedMapper;
|
|
|
+ private final CorpUserFollowRelationMapper cmsUserFollowRelationMapper;
|
|
|
|
|
|
+ private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
@GetMapping("/get")
|
|
|
@SaCheckPermission("user:view")
|
|
|
- public Result<SearchResult<UserView>> get(String otherPhone) {
|
|
|
+ public Result<SearchResult<UserView>> get(String otherPhone, Long sharedId, String userid, Long businessId, String sort, String order) {
|
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
+ String otherSql = StrUtil.EMPTY;
|
|
|
if (StrUtil.isNotBlank(otherPhone)) {
|
|
|
- builder.put("otherPhone", String.format("(up.phone like '%s%%' or u.login_phone like '%s%%')", otherPhone, otherPhone));
|
|
|
+ otherSql += String.format("(u.id in (select user_id from user_bind_detail where phone like '%s%%') or u.login_phone like '%s%%')", otherPhone, otherPhone);
|
|
|
+ }
|
|
|
+ if (businessId != null) {
|
|
|
+ if (StrUtil.isNotBlank(otherSql)) {
|
|
|
+ otherSql += " and ";
|
|
|
+ }
|
|
|
+ otherSql += String.format("us.shared_id in (select user_id from user_distribute where business_id = %s)", businessId);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(otherSql)) {
|
|
|
+ builder.put("otherConditionSql", otherSql);
|
|
|
}
|
|
|
SearchResult<UserView> search = beanSearcher.search(UserView.class, builder.build());
|
|
|
- search.getDataList().forEach((userView)->{
|
|
|
- userView.setAccountNum(relationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getUserId,userView.getId())));
|
|
|
- UserDistributeShared userDistributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class)
|
|
|
- .eq(UserDistributeShared::getUserId, userView.getId()).last("limit 1"));
|
|
|
- if (userDistributeShared != null) {
|
|
|
- userView.setSharedId(userDistributeShared.getSharedId());
|
|
|
- if (userView.getSharedId() != null) {
|
|
|
- User user = userMapper.selectById(userView.getSharedId());
|
|
|
- if (user != null) {
|
|
|
- userView.setSharedNickName(user.getNickname());
|
|
|
- userView.setSharedHeadimgurl(user.getHeadimgurl());
|
|
|
- }
|
|
|
- }
|
|
|
+ search.getDataList().forEach(data->{
|
|
|
+ Long userId = data.getId();
|
|
|
+ UserBindDetail userBindDetail = beanSearcher.searchFirst(UserBindDetail.class, MapUtils.builder().field(UserBindDetail::getUserId, userId).onlySelect(UserBindDetail::getPhone, UserBindDetail::getEmail).build());
|
|
|
+ Optional.ofNullable(userBindDetail).ifPresent(bind->{
|
|
|
+ data.setBindEmail(bind.getEmail());
|
|
|
+ data.setBindPhone(bind.getPhone());
|
|
|
+ });
|
|
|
+ if (data.getSharedId() != null) {
|
|
|
+ UserDistributeBusinessInfoView userDistributeBusinessInfoView = beanSearcher.searchFirst(UserDistributeBusinessInfoView.class, MapUtils.builder().field(UserDistributeBusinessInfoView::getUserId, data.getSharedId()).build());
|
|
|
+ Optional.ofNullable(userDistributeBusinessInfoView).ifPresent(info->{
|
|
|
+ data.setDistributeName(info.getDistributeName());
|
|
|
+ data.setBusinessName(info.getBusinessName());
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 修改用户的拉黑状态
|
|
|
*/
|
|
|
@@ -86,7 +104,7 @@ public class CmsUserController{
|
|
|
@SaCheckPermission("user:black")
|
|
|
public Result<String> putBlackStatus(@PathVariable Long id) {
|
|
|
User user = userMapper.selectById(id);
|
|
|
- Optional.ofNullable(user).ifPresent(u->{
|
|
|
+ Optional.ofNullable(user).ifPresent(u -> {
|
|
|
u.setIsBlack(!u.getIsBlack());
|
|
|
if (u.getIsBlack()) {
|
|
|
List<RenewalView> groupsRelations = groupRelationFrontService.getMyTicket(u.getId(), null);
|
|
|
@@ -100,5 +118,95 @@ public class CmsUserController{
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 用户加入企业微信客服详情
|
|
|
+ */
|
|
|
+ @GetMapping("/get/corpFollow/detail/{userId}")
|
|
|
+ public Result<String> getCorpFollowDetailById(@PathVariable Long userId) {
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ if (user == null || StrUtil.isEmpty(user.getUnionid())) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+ String corpCustomers = cmsUserFollowRelationMapper.selectCorpCustomers(user.getUnionid());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(corpCustomers);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 企业微信客服列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/corpFollow")
|
|
|
+ public Result<List<CorpFollow>> getCorpFollow() {
|
|
|
+ List<CorpFollow> corpFollows = beanSearcher.searchAll(CorpFollow.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(CorpFollow::getWxCorpId, 2)
|
|
|
+ .build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(corpFollows);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 用户订单详情title
|
|
|
+ */
|
|
|
+ @GetMapping("/get/order/title")
|
|
|
+ public Result<UserView> getUserOrderDetailTitle(Long userId) {
|
|
|
+ UserView userView = new UserView();
|
|
|
+ List<OrderDon> orderDons = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getUserId, userId)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderStatus)
|
|
|
+ .orderByAsc(OrderDon::getId));
|
|
|
+ //首单产品
|
|
|
+ Optional<OrderDon> firstOrder = orderDons.stream().filter(don -> don.getStatus() != OrderDon.Status.refund).findFirst();
|
|
|
+ if (firstOrder.isPresent()) {
|
|
|
+ OrderDon orderDon = firstOrder.get();
|
|
|
+ BigDecimal money = orderDon.getMoney().divide(BigDecimal.valueOf(100));
|
|
|
+ Optional.ofNullable(beanSearcher.searchFirst(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, orderDon.getSkuId()).onlySelect(GoodsDonSkuView::getGoodsTitle, GoodsDonSkuView::getSpecVal).build()))
|
|
|
+ .ifPresent(goodsDonSkuView -> {
|
|
|
+ String msg = String.format("%s%s %s元", goodsDonSkuView.getGoodsTitle(), goodsDonSkuView.getSpecVal(), money);
|
|
|
+ if (orderDon.getCouponUserId() != 0) {
|
|
|
+ BigDecimal subMoney = orderDon.getCouponMoney().divide(BigDecimal.valueOf(100));
|
|
|
+ msg = String.format("%s(减免%s元)", msg, subMoney);
|
|
|
+ }
|
|
|
+ userView.setFirstOrderDetail(msg);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //有无路由器订单
|
|
|
+ Optional<OrderDon> routeOrder = orderDons.stream().filter(don -> don.getGoodsId() == 15).findFirst();
|
|
|
+ userView.setIsHadRouteOrder(routeOrder.isPresent() ? true : false);
|
|
|
+
|
|
|
+ Integer noRefundOrders = 0;
|
|
|
+ Integer refundOrders = 0;
|
|
|
+ //除去退款 下单金额
|
|
|
+ BigDecimal orderMoney = BigDecimal.ZERO;
|
|
|
+ BigDecimal refundMoney = BigDecimal.ZERO;
|
|
|
+ for (OrderDon orderDon : orderDons) {
|
|
|
+ if (orderDon.getStatus() == OrderDon.Status.refund) {
|
|
|
+ refundOrders++;
|
|
|
+ if (orderDon.getRefundMoney() != null) {
|
|
|
+ refundMoney = refundMoney.add(orderDon.getRefundMoney());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ noRefundOrders++;
|
|
|
+ orderMoney = orderMoney.add(orderDon.getMoney());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal refundRate = BigDecimal.ZERO;
|
|
|
+ if (!orderDons.isEmpty()) {
|
|
|
+ //退款率
|
|
|
+ refundRate = BigDecimal.valueOf(refundOrders).divide(BigDecimal.valueOf(orderDons.size()), 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ userView.setOrderMoney(orderMoney);
|
|
|
+ userView.setNumOfOrder(noRefundOrders);
|
|
|
+ userView.setRefundMoney(refundMoney);
|
|
|
+ userView.setRefundRate(refundRate);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(userView);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户下单详情
|
|
|
+ */
|
|
|
+ @GetMapping("/get/order/list")
|
|
|
+ public Result<SearchResult<UserOrderDonDetail>> getUserOrderDetails() {
|
|
|
+ SearchResult<UserOrderDonDetail> search = beanSearcher.search(UserOrderDonDetail.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(UserOrderDonDetail::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
|
|
|
+ .build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
}
|