Selaa lähdekoodia

分销/员工统计

licailing 5 vuotta sitten
vanhempi
commit
80f0222c03

+ 1 - 1
src/main/java/com/izouma/jiashanxia/enums/Member.java

@@ -6,7 +6,7 @@ public enum Member {
      */
     NORMAL,
     /*
-    佳客
+    团长
      */
     EXPERT,
     /*

+ 1 - 1
src/main/java/com/izouma/jiashanxia/enums/TransactionType.java

@@ -4,7 +4,7 @@ public enum TransactionType {
     WITHDRAW("提现"),
     PROMOTE("推广新会员"),
     CHILD_PROMOTE("下级推广新会员"),
-//    BIG_EXPERT("成为大达人额外奖励"),
+//    EXPERT("团长奖励"),
     MAKER("创客奖励"),
     GENERAL("108将奖励"),
     EMPLOYEES_PROMOTE("员工推广新会员"),

+ 2 - 0
src/main/java/com/izouma/jiashanxia/repo/OrderInfoRepo.java

@@ -29,4 +29,6 @@ public interface OrderInfoRepo extends JpaRepository<OrderInfo, Long>, JpaSpecif
     long countByUserId(Long userId);
 
     OrderInfo findByTransactionId(String transactionId);
+
+    List<OrderInfo> findAllByUserId(Long userId);
 }

+ 85 - 26
src/main/java/com/izouma/jiashanxia/service/OrderInfoService.java

@@ -114,6 +114,29 @@ public class OrderInfoService {
         return orderInfoRepo.save(orderInfo);
     }
 
+    /*
+    新用户点进分享链接
+     */
+    public void saveParent(Long parent, Long userId) {
+        User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
+        // 判断上级是否为空
+        if (ObjectUtil.isNotEmpty(user.getParent())) {
+            return;
+        }
+        // 判断新用户
+        List<OrderInfo> orderInfos = orderInfoRepo.findAllByUserId(userId);
+        long count = orderInfos.stream()
+                .filter(orderInfo -> !OrderInfoStatus.CANCELLED.equals(orderInfo.getStatus()) || !OrderInfoStatus.UNPAID
+                        .equals(orderInfo.getStatus()))
+                .count();
+        if (count > 0) {
+            return;
+        }
+        // 保存
+        user.setParent(parent);
+        userRepo.save(user);
+    }
+
     /*
     完成付款
      */
@@ -178,10 +201,27 @@ public class OrderInfoService {
             userRepo.save(user);
         }
 
+        Long parent = user.getParent();
         // 用户id和上级id相同
-        if (user.getParent() != null && !userId.equals(user.getParent())) {
+        if (!userId.equals(parent)) {
+            // 如果是别人分享的链接购买的
+            if (ObjectUtil.isNotEmpty(order.getParentUserId())) {
+                parent = order.getParentUserId();
+                // 是否设为上级
+                if (ObjectUtil.isEmpty(user.getParent())) {
+                    List<OrderInfo> orderInfos = orderInfoRepo.findAllByUserId(userId);
+                    long count = orderInfos.stream()
+                            .filter(orderInfo -> !OrderInfoStatus.UNPAID.equals(orderInfo.getStatus()) || !OrderInfoStatus.CANCELLED
+                                    .equals(orderInfo.getStatus()))
+                            .count();
+                    if (count <= 0) {
+                        user.setParent(parent);
+                        userRepo.save(user);
+                    }
+                }
+            }
             // 上级分销
-            this.distribution1(userId, user.getParent(), order);
+            this.distribution1(userId, parent, order);
         }
     }
 
@@ -273,36 +313,36 @@ public class OrderInfoService {
         User parentUser = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
         BigDecimal amount = orderInfo.getPrice();
 
-        // 无限级找创客/108将
+        // 无限级找创客/108将/团长
         this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
 
-        // 不成为佳客没有奖励
-        if (Member.NORMAL.equals(parentUser.getMember())) {
-            return;
-        }
+        // 不成为团长没有奖励
+//        if (Member.NORMAL.equals(parentUser.getMember())) {
+//            return;
+//        }
 
         String transactionId = orderInfo.getId().toString();
 
-        BigDecimal ratio = aPackage.getPersonalRatio0();
-        if (ObjectUtil.isNull(ratio) || !aPackage.isSeparateDistribution()) {
-            ratio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
-        }
+//        BigDecimal ratio = aPackage.getPersonalRatio0();
+//        if (ObjectUtil.isNull(ratio) || !aPackage.isSeparateDistribution()) {
+//            ratio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
+//        }
 
         // 钱和流水
-        if (BigDecimal.ZERO.compareTo(ratio) < 0) {
-            BigDecimal directPushAmount = amount.multiply(ratio);
-            parentUser.setCacheAmount(directPushAmount.add(parentUser.getCacheAmount()));
-            userRepo.save(parentUser);
-            CommissionRecord commissionRecord1 = CommissionRecord.builder()
-                    .userId(parent)
-                    .amount(directPushAmount)
-                    .payMethod(PayMethod.YUE)
-                    .fromUserId(userId)
-                    .transactionType(TransactionType.PROMOTE)
-                    .transactionId(transactionId)
-                    .build();
-            commissionRecordRepo.save(commissionRecord1);
-        }
+//        if (BigDecimal.ZERO.compareTo(ratio) < 0) {
+//            BigDecimal directPushAmount = amount.multiply(ratio);
+//            parentUser.setCacheAmount(directPushAmount.add(parentUser.getCacheAmount()));
+//            userRepo.save(parentUser);
+//            CommissionRecord commissionRecord1 = CommissionRecord.builder()
+//                    .userId(parent)
+//                    .amount(directPushAmount)
+//                    .payMethod(PayMethod.YUE)
+//                    .fromUserId(userId)
+//                    .transactionType(TransactionType.PROMOTE)
+//                    .transactionId(transactionId)
+//                    .build();
+//            commissionRecordRepo.save(commissionRecord1);
+//        }
 
         // 间推
         this.indirect(parentUser, aPackage, userId, transactionId, amount);
@@ -409,7 +449,7 @@ public class OrderInfoService {
     }
 
     /*
-    创客和108将分销
+    创客和108将分销和团长
      */
     public void makerGeneralDistribution(User parent, BigDecimal amount, Long orderId, Long userId, Package aPackage) {
         // 创客比例
@@ -425,8 +465,16 @@ public class OrderInfoService {
         }
         BigDecimal general = amount.multiply(generalRatio);
 
+        // 团长比例
+        BigDecimal headRatio = aPackage.getPersonalRatio0();
+        if (ObjectUtil.isNull(headRatio) || !aPackage.isSeparateDistribution()) {
+            headRatio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
+        }
+        BigDecimal head = amount.multiply(headRatio);
+
         boolean isGeneral = true;
         boolean isMaker = true;
+        boolean isHead = true;
 
         CommissionRecord record = CommissionRecord.builder()
                 .userId(parent.getId())
@@ -484,6 +532,17 @@ public class OrderInfoService {
                         isGeneral = false;
                     }
                     break;
+                case EXPERT:
+                    if (isHead) {
+                        parent.setCacheAmount(parent.getCacheAmount().add(head));
+                        userRepo.save(parent);
+                        // 流水
+                        record.setAmount(head);
+                        record.setTransactionType(TransactionType.PROMOTE);
+                        commissionRecordRepo.save(record);
+                        isHead = false;
+                        break;
+                    }
                 default:
                     break;
             }

+ 1 - 0
src/main/java/com/izouma/jiashanxia/service/PackageService.java

@@ -117,4 +117,5 @@ public class PackageService {
         userPackageService.joinUserPackage(userId, setGoodsList, num, PackageType.TEAM);
     }
 
+
 }

+ 4 - 3
src/main/java/com/izouma/jiashanxia/service/StatisticService.java

@@ -9,6 +9,7 @@ import com.izouma.jiashanxia.dto.StatisticDTO;
 import com.izouma.jiashanxia.enums.OrderInfoStatus;
 import com.izouma.jiashanxia.enums.WithdrawStatus;
 import com.izouma.jiashanxia.repo.*;
+import com.izouma.jiashanxia.utils.DateTimeUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
@@ -108,8 +109,8 @@ public class StatisticService {
         return this.getDTOS(orderInfos, start, day);
     }
 
-    public List<StatisticDTO> employeeOrder(int year, int month, Long userId) {
-        LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0);
+    public List<StatisticDTO> employeeOrder(String time, Long userId) {
+        LocalDateTime start = DateTimeUtils.toLocalDateTime(time, "yyyy-MM-dd HH:mm:ss");
         LocalDateTime end = start.plusMonths(1);
         List<Long> childrenId = userService.childrenId(userId);
         List<OrderInfo> orderInfos = orderInfoRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
@@ -120,7 +121,7 @@ public class StatisticService {
             and.add(criteriaBuilder.lessThan(root.get("paidAt"), end));
             return criteriaBuilder.and(and.toArray(new Predicate[0]));
         }));
-        long day = end.toLocalDate().toEpochDay() - start.toLocalDate().toEpochDay() - 1;
+        long day = end.toLocalDate().toEpochDay() - start.toLocalDate().toEpochDay();
         return this.getDTOS(orderInfos, start, (int) day);
     }
 

+ 4 - 2
src/main/java/com/izouma/jiashanxia/web/StatisticController.java

@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -37,8 +38,8 @@ public class StatisticController {
 
     @ApiOperation("员工订单日销售")
     @GetMapping("/dayAddEmployee")
-    public List<StatisticDTO> dayAddEmployee(int year, int month, Long userId) {
-        return statisticService.employeeOrder(year, month, userId);
+    public List<StatisticDTO> dayAddEmployee(String start, Long userId) {
+        return statisticService.employeeOrder(start, userId);
     }
 
     @ApiOperation("员工订单金额日销售")
@@ -46,6 +47,7 @@ public class StatisticController {
     public List<StatisticDTO> dayAddEmployee1(int year, int month, Long userId) {
         return statisticService.employeeOrderFee(year, month, userId);
     }
+
     @ApiOperation("员工收益金额日销售")
     @GetMapping("/dayAddEmployee2")
     public List<StatisticDTO> dayAddEmployee2(int year, int month, Long userId) {

+ 3 - 0
src/main/vue/src/main.js

@@ -16,6 +16,8 @@ import DistrictChoose from '@/components/DistrictChoose';
 import Formatters from '@/mixins/formatters';
 import 'normalize.css/normalize.css';
 import 'element-ui/lib/theme-chalk/index.css';
+import { DropdownMenu, DropdownItem } from 'vant';
+import 'vant/lib/index.less';
 
 // import VueAMap from "vue-amap";
 // Vue.use(VueAMap);
@@ -51,6 +53,7 @@ Vue.component('rich-text', RichText);
 Vue.component('crop-upload', CropUpload);
 Vue.component('district-choose', DistrictChoose);
 Vue.mixin(Formatters);
+Vue.use(DropdownMenu).use(DropdownItem);
 
 new Vue({
     router,

+ 2 - 2
src/main/vue/src/views/employee/EmployeeDashboard.vue

@@ -37,7 +37,7 @@ import OrderWidget from '@/widgets/OrderWidget';
 import CompanyWidget from '@/widgets/CompanyWidget';
 import FeeWidget from '@/widgets/FeeWidget';
 import RecentSales from '@/widgets/RecentSales';
-import RecentOrder from '@/widgets/RecentOrder';
+import RecentOrderEmployee from '@/widgets/RecentOrderEmployee';
 import { mapState } from 'vuex';
 
 export default {
@@ -57,7 +57,7 @@ export default {
                 // { x: 3, y: 0, w: 3, h: 3, i: '1', name: 'CompanyWidget', key: 'company' },
                 // { x: 6, y: 0, w: 3, h: 3, i: '2', name: 'OrderWidget', key: 'order' },
                 // { x: 9, y: 0, w: 3, h: 3, i: '3', name: 'FeeWidget', key: 'fee' },
-                { x: 0, y: 4, w: 12, h: 12, i: '0', name: 'RecentOrder' },
+                { x: 0, y: 4, w: 12, h: 12, i: '0', name: 'RecentOrderEmployee' },
                 { x: 0, y: 10, w: 12, h: 12, i: '1', name: 'RecentSales' }
                 /*{ x: 6, y: 4, w: 6, h: 12, i: '6', name: 'PieChartWidget' }*/
             ],

+ 43 - 14
src/main/vue/src/widgets/RecentOrderEmployee.vue

@@ -1,11 +1,10 @@
 <template>
     <widget-card :bodyStyle="bodyStyle" ref="container">
         <div style="width:100%;min-height:80px;" :loading="loading">
-            <div style="margin-bottom:5px">
-                <el-radio-group v-model="recentDays" size="mini" @change="getData">
-                    <el-radio-button label="7">近7天</el-radio-button>
-                    <el-radio-button label="30">近30天</el-radio-button>
-                </el-radio-group>
+            <div style="margin-bottom:1px">
+                <van-dropdown-menu class="van-width">
+                    <van-dropdown-item v-model="chooseDate" @change="changeDate" :options="dateList" />
+                </van-dropdown-menu>
             </div>
             <bar-chart :chart-data="chartData" v-if="chartData"> </bar-chart>
         </div>
@@ -14,6 +13,7 @@
 <script>
 import WidgetCard from './WidgetCard';
 import BarChart from '../components/BarChart';
+import { parse, addYears, format, addMonths, addDays } from 'date-fns';
 
 export default {
     data() {
@@ -21,28 +21,53 @@ export default {
             bodyStyle: {
                 alignItems: 'center'
             },
-            year: 2021,
-            month: 1,
             chartData: null,
-            loading: false
+            loading: false,
+            chooseDate: ''
         };
     },
-    created() {
-        this.getData();
+    // created() {
+    //     this.getData();
+    // },
+    computed: {
+        dateList() {
+            var list = [];
+            for (var i = 0; i < 6; i++) {
+                let time = parse(format(addMonths(new Date(), 0 - i), 'yyyy-MM') + '-01', 'yyyy-MM-dd', new Date());
+                list.push({
+                    text: format(time, 'yyyy年MM月'),
+                    value: format(time, 'yyyy-MM') + '-01 00:00:00'
+                    // '-01 00:00:00,' +
+                    // format(addDays(addMonths(time, 1), 0 - 1), 'yyyy-MM-dd') +
+                    // ' 23:59:59'
+                });
+            }
+            return list;
+        }
+    },
+    mounted() {
+        this.$nextTick(() => {
+            this.chooseDate = this.dateList[0].value;
+            this.getData();
+        });
     },
     methods: {
+        changeDate() {
+            this.page = 0;
+            this.last = false;
+            this.getData();
+        },
         getData() {
             this.loading = true;
             this.$http
                 .get('/statistic/dayAddEmployee', {
-                    year: this.year,
-                    month: this.month,
+                    start: this.chooseDate,
                     userId: this.$route.query.id
                 })
                 .then(res => {
                     this.loading = false;
                     this.chartData = {
-                        labels: res.map(i => i.date),
+                        labels: res.map(i => format(parse(i.date, 'yyyy-MM-dd', new Date()), 'dd')),
                         datasets: [
                             {
                                 label: '订单数',
@@ -66,4 +91,8 @@ export default {
     }
 };
 </script>
-<style lang="less" scoped></style>
+<style lang="less" scoped>
+.van-width {
+    width: 200px;
+}
+</style>

+ 3 - 1
src/test/java/com/izouma/jiashanxia/service/StatisticServiceTest.java

@@ -33,13 +33,15 @@ public class StatisticServiceTest {
 
     @Test
     public void test1() {
-        List<StatisticDTO> employee = statisticService.employeeOrder(2021, 1, 916L);
+        List<StatisticDTO> employee = statisticService.employeeOrder("2021-01-01 00:00:00",921L);
         employee.forEach(System.out::println);
     }
 
     @Test
     public void test2() {
         List<StatisticDTO> employee = statisticService.employeeOrderFee(2021, 1, 921L);
+//        List<StatisticDTO> employee = statisticService.employeeOrderFee(LocalDateTime.of(2021, 1, 1, 0, 0), LocalDateTime
+//                .of(2021, 1, 31, 59, 59), 921L);
         employee.forEach(System.out::println);
     }