Преглед на файлове

【admin】用户列表新增余额和退款信息展示

skyline преди 2 години
родител
ревизия
a486d3e0df

+ 12 - 9
admin-web/src/views/admin/account/index.vue

@@ -88,7 +88,7 @@
             :show-overflow-tooltip="!field.fixed&&field.width>150"
         >
           <template #default="{row}">
-            <template v-if="['rechargeAmount','totalMoney'].includes(field.prop)">
+            <template v-if="['rechargeAmount','totalMoney','refundAmount','balance'].includes(field.prop)">
               {{ u.fmt.fmtMoney(row[field.prop]) }}
             </template>
             <template v-else-if="'status'===field.prop">
@@ -152,15 +152,18 @@ const state = reactive({
     loading: false,
     columns: [
       {label: '用户ID',width: 180,  prop: 'userId', resizable: true, fixed: 'left'},
-      {label: '用户名',width: 150,  prop: 'userName', resizable: true, fixed: 'left'},
-      {label: '手机号', width: 150, prop: 'mobilePhone', resizable: true, fixed: 'left'},
+      // {label: '用户名',width: 150,  prop: 'userName', resizable: true, fixed: 'left'},
+      {label: '手机号', width: 120, prop: 'mobilePhone', resizable: true, fixed: 'left'},
+      {label: '余额', width: 80, prop: 'balance', resizable: true, fixed: 'left'},
       {label: '状态', width: 80, prop: 'status', align: 'center'},
-      {label: '注册时间', width: 180, prop: 'registerTime', resizable: true},
-      {label: '充值次数', width: 150, prop: 'rechargeTimes', resizable: true},
-      {label: '充值金额(元)', width: 150, prop: 'rechargeAmount', resizable: true},
-      {label: '充电次数', width: 150, prop: 'chargeTimes', resizable: true},
-      {label: '总电量(千瓦时)', width: 150, prop: 'totalPower', resizable: true},
-      {label: '总金额(元)', width: 150, prop: 'totalMoney', resizable: true},
+      {label: '注册时间', width: 160, prop: 'registerTime', resizable: true},
+      {label: '充值次数', width: 90, prop: 'rechargeTimes', resizable: true},
+      {label: '充值金额', width: 90, prop: 'rechargeAmount', resizable: true},
+      {label: '退款次数', width: 90, prop: 'refundTimes', resizable: true},
+      {label: '退款金额', width: 90, prop: 'refundAmount', resizable: true},
+      {label: '充电次数', width: 90, prop: 'chargeTimes', resizable: true},
+      {label: '总电量(度)', width: 120, prop: 'totalPower', resizable: true},
+      {label: '总金额(元)', width: 120, prop: 'totalMoney', resizable: true},
       // {
       //   label: '操作', prop: 'action', width: 180, align: 'center', fixed: 'right',
       // }

+ 1 - 0
admin-web/src/views/admin/invoice/index.vue

@@ -221,6 +221,7 @@ const state = reactive({
     loading: false,
     columns: [
       {type: 'expand', prop: 'expand', width: 30, fixed: 'left'},
+      {label: '用户手机号', prop: 'mobilePhone', align: 'center', fixed: 'left', width: 150},
       {label: '申请号', prop: 'applyId', align: 'center', fixed: 'left', width: 220},
       {label: '发票状态', prop: 'status', align: 'center', fixed: 'left', width: 100},
       {label: '发票金额(元)', prop: 'invoiceAmount', resizable: true, width: 150},

+ 4 - 1
entity/src/main/java/com/kym/entity/admin/vo/CustomUserVo.java

@@ -7,7 +7,7 @@ import java.time.LocalDateTime;
 
 /**
  * @author skyline
- * @description
+ * @description 用户
  * @date 2023-08-30 14:48
  */
 @Data
@@ -25,5 +25,8 @@ public class CustomUserVo {
     private int chargeTimes;
     private double totalPower;
     private int totalMoney;
+    private int balance;
+    private Long refundTimes;
+    private int refundAmount;
 
 }

+ 24 - 10
service/src/main/java/com/kym/service/miniapp/impl/UserServiceImpl.java

@@ -19,10 +19,7 @@ import com.kym.entity.admin.queryParams.CommonQueryParam;
 import com.kym.entity.admin.vo.ActivityVo;
 import com.kym.entity.admin.vo.CustomUserVo;
 import com.kym.entity.common.PageBean;
-import com.kym.entity.miniapp.Account;
-import com.kym.entity.miniapp.Cars;
-import com.kym.entity.miniapp.User;
-import com.kym.entity.miniapp.UserRechargeRights;
+import com.kym.entity.miniapp.*;
 import com.kym.entity.miniapp.queryParams.WxLoginParams;
 import com.kym.entity.miniapp.vo.UserVo;
 import com.kym.entity.wechat.WxPhoneNum;
@@ -30,10 +27,7 @@ import com.kym.mapper.miniapp.UserMapper;
 import com.kym.service.admin.ActivityService;
 import com.kym.service.admin.BannerService;
 import com.kym.service.admin.RechargeRightsService;
-import com.kym.service.miniapp.AccountService;
-import com.kym.service.miniapp.CarsService;
-import com.kym.service.miniapp.UserRechargeRightsService;
-import com.kym.service.miniapp.UserService;
+import com.kym.service.miniapp.*;
 import lombok.SneakyThrows;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,15 +55,19 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
     private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);
     private final WxConfig wxConfig;
     private final AccountService accountService;
+    private final RefundLogService refundLogService;
     private final CarsService carsService;
     private final UserRechargeRightsService userRechargeRightsService;
     private final RechargeRightsService rechargeRightsService;
     private final ActivityService activityService;
     private final BannerService bannerService;
 
-    public UserServiceImpl(WxConfig wxConfig, AccountService accountService, CarsService carsService, UserRechargeRightsService userRechargeRightsService, RechargeRightsService rechargeRightsService, ActivityService activityService, BannerService bannerService) {
+    public UserServiceImpl(WxConfig wxConfig, AccountService accountService, RefundLogService refundLogService,
+                           CarsService carsService, UserRechargeRightsService userRechargeRightsService,
+                           RechargeRightsService rechargeRightsService, ActivityService activityService, BannerService bannerService) {
         this.wxConfig = wxConfig;
         this.accountService = accountService;
+        this.refundLogService = refundLogService;
         this.carsService = carsService;
         this.userRechargeRightsService = userRechargeRightsService;
 
@@ -252,7 +250,23 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
         }
         PageHelper.startPage(params.getPageNum(), params.getPageSize());
         var result = baseMapper.listUser(userId);
-        return new PageBean<>(result);
+        var page = new PageBean<>(result);
+        // 用户余额,退款次数,退款金额
+        var account = accountService.lambdaQuery().in(Account::getUserId, result.stream().map(CustomUserVo::getUserId).toList()).list();
+        var user2Balance = account.stream().collect(Collectors.groupingBy(Account::getUserId, Collectors.summingInt(Account::getBalance)));
+        var refund = refundLogService.lambdaQuery().in(RefundLog::getUserId, result.stream().map(CustomUserVo::getUserId).toList()).list();
+        // refund按照用户维度计算退款次数和退款总金额
+        var user2RefundAmount = refund.stream().collect(Collectors.groupingBy(RefundLog::getUserId, Collectors.summingInt(RefundLog::getRefund)));
+        var user2RefundTimes = refund.stream().collect(Collectors.groupingBy(RefundLog::getUserId, Collectors.counting()));
+
+        // 将用户余额,退款次数,退款金额放入result中
+        var res = result.stream().peek(vo-> {
+            vo.setBalance(user2Balance.getOrDefault(vo.getUserId(), 0));
+            vo.setRefundTimes(user2RefundTimes.getOrDefault(vo.getUserId(), 0L));
+            vo.setRefundAmount(user2RefundAmount.getOrDefault(vo.getUserId(), 0));
+        }).toList();
+        page.setList(res);
+        return page;
     }