Your Name пре 4 година
родитељ
комит
6c47ac12a2

+ 4
- 0
src/main/java/com/yunzhi/niucai/common/ArrayUtils.java Прегледај датотеку

@@ -0,0 +1,4 @@
1
+package com.yunzhi.niucai.common;
2
+
3
+public class ArrayUtils {
4
+}

+ 12
- 0
src/main/java/com/yunzhi/niucai/common/BizUtils.java Прегледај датотеку

@@ -112,4 +112,16 @@ public class BizUtils {
112 112
         // 计算排列 7 个 选 3 个
113 113
         return EncryptUtils.combination(leftSize, canUse);
114 114
     }
115
+
116
+    public static int getSameNums(List<String> tar, List<String> src, List<String> dan) {
117
+        if (null == tar || tar.size() == 0) {
118
+            return 0;
119
+        }
120
+
121
+        if (null == src && src.size() == 0) {
122
+            return 0;
123
+        }
124
+
125
+        return 0;
126
+    }
115 127
 }

+ 34
- 0
src/main/java/com/yunzhi/niucai/common/CommConstants.java Прегледај датотеку

@@ -0,0 +1,34 @@
1
+package com.yunzhi.niucai.common;
2
+
3
+public class CommConstants {
4
+
5
+    /**
6
+     * 大乐透
7
+     */
8
+    public final static String LOTTERY_LOTTERY = "lottery";
9
+
10
+    /**
11
+     * 排列三
12
+     */
13
+    public final static String LOTTERY_P3 = "p3";
14
+
15
+    /**
16
+     * 排列五
17
+     */
18
+    public final static String LOTTERY_P5 = "p5";
19
+
20
+    /**
21
+     * 双色球
22
+     */
23
+    public final static String LOTTERY_DOUBLE = "double-color";
24
+
25
+    /**
26
+     * 足球
27
+     */
28
+    public final static String LOTTERY_FOOTBALL = "football";
29
+
30
+    /**
31
+     * 篮球
32
+     */
33
+    public final static String LOTTERY_BASKETBALL = "basketball";
34
+}

+ 7
- 0
src/main/java/com/yunzhi/niucai/entity/TaCustomerBetting.java Прегледај датотеку

@@ -60,6 +60,9 @@ public class TaCustomerBetting implements Serializable {
60 60
     @ApiModelProperty(value = "投注期数")
61 61
     private String issueNo;
62 62
 
63
+    @ApiModelProperty(value = "开奖日期")
64
+    private String openingDate;
65
+
63 66
     @ApiModelProperty(value = "投注倍数")
64 67
     private Integer bettingTimes;
65 68
 
@@ -102,4 +105,8 @@ public class TaCustomerBetting implements Serializable {
102 105
     @ApiModelProperty(value = "体彩相关明细")
103 106
     @TableField(exist = false)
104 107
     List<TaCustomerBettingSport> bettingSports;
108
+
109
+    @ApiModelProperty(value = "投注方案")
110
+    @TableField(exist = false)
111
+    TaBettingPlan bettingPlan;
105 112
 }

+ 5
- 0
src/main/java/com/yunzhi/niucai/service/ITaCustomerBettingService.java Прегледај датотеку

@@ -3,7 +3,10 @@ package com.yunzhi.niucai.service;
3 3
 import com.yunzhi.niucai.entity.TaBettingPlan;
4 4
 import com.yunzhi.niucai.entity.TaCustomerBetting;
5 5
 import com.baomidou.mybatisplus.extension.service.IService;
6
+import com.yunzhi.niucai.entity.TaLotteryResult;
7
+import com.yunzhi.niucai.entity.TdLottery;
6 8
 
9
+import java.util.List;
7 10
 import java.util.Map;
8 11
 
9 12
 /**
@@ -19,4 +22,6 @@ public interface ITaCustomerBettingService extends IService<TaCustomerBetting> {
19 22
     TaCustomerBetting saveByBetting(TaBettingPlan taBettingPlan) throws Exception;
20 23
 
21 24
     Map<String, Object> getSummaryOf(Integer id) throws Exception;
25
+
26
+    List<TaCustomerBetting> getAllUnOpenBettingsBy(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception;
22 27
 }

+ 2
- 0
src/main/java/com/yunzhi/niucai/service/ITaCustomerService.java Прегледај датотеку

@@ -15,4 +15,6 @@ import com.yunzhi.niucai.vo.SignUpParam;
15 15
 public interface ITaCustomerService extends IService<TaCustomer> {
16 16
 
17 17
     boolean signUp(SignUpParam signUpParam) throws Exception;
18
+
19
+    TaCustomer getCustomerByPhone(String phone) throws Exception;
18 20
 }

+ 2
- 0
src/main/java/com/yunzhi/niucai/service/ITdLotteryOnSaleService.java Прегледај датотеку

@@ -17,4 +17,6 @@ import java.util.List;
17 17
 public interface ITdLotteryOnSaleService extends IService<TdLotteryOnSale> {
18 18
 
19 19
     List<TdLotteryOnSale> getByLottery(TdLottery lottery) throws Exception;
20
+
21
+    List<TdLotteryOnSale> getByWeekDay(int weekDay) throws Exception;
20 22
 }

+ 26
- 11
src/main/java/com/yunzhi/niucai/service/impl/TaBettingPlanServiceImpl.java Прегледај датотеку

@@ -2,6 +2,7 @@ package com.yunzhi.niucai.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.yunzhi.niucai.common.BizUtils;
5
+import com.yunzhi.niucai.common.DateUtils;
5 6
 import com.yunzhi.niucai.common.EncryptUtils;
6 7
 import com.yunzhi.niucai.common.StringUtils;
7 8
 import com.yunzhi.niucai.entity.*;
@@ -174,6 +175,14 @@ public class TaBettingPlanServiceImpl extends ServiceImpl<TaBettingPlanMapper, T
174 175
             }
175 176
         }
176 177
 
178
+        // 销售时间
179
+        if (taBettingPlan.getIsSport()) {
180
+            String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm"));
181
+            if (currentTime.compareTo(taShopLottery.getOpeningTime()) < 0 || currentTime.compareTo(taShopLottery.getClosingTime()) > 0) {
182
+                throw new Exception("非当前店铺彩票开售时间");
183
+            }
184
+        }
185
+
177 186
         return;
178 187
     }
179 188
 
@@ -298,7 +307,11 @@ public class TaBettingPlanServiceImpl extends ServiceImpl<TaBettingPlanMapper, T
298 307
                 throw new Exception("投注彩种缺失开奖结果相关数据");
299 308
             }
300 309
 
301
-            Integer newIssueNo = Integer.valueOf(taLotteryResult.getIssueNo()) + 1;
310
+            String lastOpeningDate = taLotteryResult.getOpeningDate();
311
+            Integer lastIssueNo = Integer.valueOf(taLotteryResult.getIssueNo());
312
+
313
+            // 默认期数是最近一次开奖 + 1
314
+            Integer newIssueNo = lastIssueNo + 1;
302 315
 
303 316
             // 查询当前彩种的停售时间
304 317
             List<TdLotteryOnSale> onSaleSettings = tdLottery.getOnSaleSettings();
@@ -306,26 +319,28 @@ public class TaBettingPlanServiceImpl extends ServiceImpl<TaBettingPlanMapper, T
306 319
                 throw new Exception("投注彩种缺失开奖配置相关数据");
307 320
             }
308 321
 
322
+            // 找出今天对应的开奖设置
309 323
             LocalDateTime now = LocalDateTime.now();
310
-
311
-            // 今天是周几
312 324
             int weekDay = now.getDayOfWeek().getValue();
313 325
             TdLotteryOnSale saleSetting = getSaleSetting(onSaleSettings, weekDay);
314
-            if (weekDay == saleSetting.getWeekDay()) {
315
-                // 如果是今天开奖, 要看是否过了开奖时间
326
+
327
+            // 如果是今天开奖
328
+            if (weekDay == saleSetting.getWeekDay() && DateUtils.today().equals(lastOpeningDate)) {
329
+                // 找出店铺设置的停售时间
330
+                TaShopLottery taShopLottery = iTaShopLotteryService.getSettingBy(taBettingPlan.getShopId(), taBettingPlan.getLotteryId());
331
+                if (null == taShopLottery) {
332
+                    throw new Exception("当前店铺没有相关彩种设置");
333
+                }
334
+
335
+                // 如果超过了店铺的停售时间, 那么今天购买的只能是下期
316 336
                 String currentTime = now.format(DateTimeFormatter.ofPattern("HH:mm"));
317
-                if (currentTime.compareTo(saleSetting.getLotteryTime()) >= 0) {
337
+                if (currentTime.compareTo(taShopLottery.getClosingTime()) >= 0) {
318 338
                     newIssueNo += 1;
319 339
                 }
320
-                // 查看是否过了店家开售时间
321
-                // todo
322 340
             }
323 341
 
324 342
             taBettingPlan.setIssueNo(String.valueOf(newIssueNo));
325 343
         }
326
-
327
-        // todo 校验停售时间
328
-
329 344
     }
330 345
 
331 346
     private TdLotteryOnSale getSaleSetting(List<TdLotteryOnSale> onSaleSettings, int weekDay) {

+ 22
- 0
src/main/java/com/yunzhi/niucai/service/impl/TaCustomerBettingServiceImpl.java Прегледај датотеку

@@ -106,6 +106,28 @@ public class TaCustomerBettingServiceImpl extends ServiceImpl<TaCustomerBettingM
106 106
         return result;
107 107
     }
108 108
 
109
+    @Override
110
+    public List<TaCustomerBetting> getAllUnOpenBettingsBy(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
111
+        QueryWrapper<TaCustomerBetting> queryWrapper = new QueryWrapper<>();
112
+        queryWrapper.eq("lottery_id", lottery.getLotteryId());
113
+        queryWrapper.eq("issue_no", lotteryResult.getIssueNo());
114
+        queryWrapper.eq("is_open", false);
115
+        queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
116
+
117
+        List<TaCustomerBetting> list = list(queryWrapper);
118
+        if (null != list && list.size() > 0) {
119
+            for (TaCustomerBetting betting : list) {
120
+                if (lottery.getIsSport()) {
121
+                    betting.setBettingSports(getBettingSportByBetting(betting));
122
+                }
123
+
124
+                betting.setBettingPlan(iTaBettingPlanService.getDetailOfPlanById(betting.getPlanId()));
125
+            }
126
+        }
127
+
128
+        return list;
129
+    }
130
+
109 131
     private List<TaCustomerBettingSport> getBettingSportByBetting(TaCustomerBetting betting) throws Exception {
110 132
         QueryWrapper<TaCustomerBettingSport> queryWrapper = new QueryWrapper<>();
111 133
         queryWrapper.eq("betting_id", betting.getBettingId());

+ 28
- 0
src/main/java/com/yunzhi/niucai/service/impl/TaCustomerServiceImpl.java Прегледај датотеку

@@ -13,10 +13,13 @@ import com.yunzhi.niucai.service.ITaCustomerService;
13 13
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
14 14
 import com.yunzhi.niucai.service.ITaShopService;
15 15
 import com.yunzhi.niucai.vo.SignUpParam;
16
+import org.apache.ibatis.annotations.Param;
16 17
 import org.springframework.beans.factory.annotation.Autowired;
17 18
 import org.springframework.stereotype.Service;
18 19
 import org.springframework.transaction.annotation.Transactional;
19 20
 
21
+import java.util.List;
22
+
20 23
 /**
21 24
  * <p>
22 25
  * 客户 服务实现类
@@ -43,6 +46,23 @@ public class TaCustomerServiceImpl extends ServiceImpl<TaCustomerMapper, TaCusto
43 46
         taCustomer.setReferralCode(signUpParam.getReferralCode());
44 47
         taCustomer.setStatus(StatusEnum.NORMAL.getCode());
45 48
 
49
+        // 手机号唯一
50
+        TaCustomer customerByPhone = getCustomerByPhone(signUpParam.getPhone());
51
+        if (null != customerByPhone) {
52
+            throw new Exception("当前手机号已经注册");
53
+        }
54
+
55
+        // 生成自己的邀请码
56
+        boolean exists = true;
57
+        while (exists) {
58
+            String inviteCode = ReferralCodeEnum.CUSTOMER_START.getCode() + "-" + EncryptUtils.randDigitStr(6);
59
+            TaCustomer exitCust = getByInviteCode(inviteCode);
60
+            if (exitCust == null) {
61
+                exists = false;
62
+                taCustomer.setInviteCode(inviteCode);
63
+            }
64
+        }
65
+
46 66
         if (!save(taCustomer)) {
47 67
             throw new Exception("生成个人信息失败");
48 68
         }
@@ -90,6 +110,14 @@ public class TaCustomerServiceImpl extends ServiceImpl<TaCustomerMapper, TaCusto
90 110
         return true;
91 111
     }
92 112
 
113
+    @Override
114
+    public TaCustomer getCustomerByPhone(String phone) throws Exception {
115
+        QueryWrapper<TaCustomer> queryWrapper = new QueryWrapper<>();
116
+        queryWrapper.eq("phone", phone);
117
+        queryWrapper.gt("status", StatusEnum.DELETED.getCode());
118
+        return getOne(queryWrapper);
119
+    }
120
+
93 121
     private TaCustomer getByInviteCode(String inviteCode) throws Exception {
94 122
         QueryWrapper<TaCustomer> queryWrapper = new QueryWrapper<>();
95 123
         queryWrapper.eq("invite_code", inviteCode);

+ 119
- 3
src/main/java/com/yunzhi/niucai/service/impl/TaLotteryResultServiceImpl.java Прегледај датотеку

@@ -1,15 +1,21 @@
1 1
 package com.yunzhi.niucai.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
-import com.yunzhi.niucai.entity.TaLotteryResult;
5
-import com.yunzhi.niucai.entity.TdLottery;
4
+import com.yunzhi.niucai.common.CommConstants;
5
+import com.yunzhi.niucai.entity.*;
6 6
 import com.yunzhi.niucai.enums.StatusEnum;
7 7
 import com.yunzhi.niucai.mapper.TaLotteryResultMapper;
8
+import com.yunzhi.niucai.service.ITaCustomerBettingService;
8 9
 import com.yunzhi.niucai.service.ITaLotteryResultService;
9 10
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
11
+import com.yunzhi.niucai.service.ITdLotteryOnSaleService;
12
+import com.yunzhi.niucai.service.ITdLotteryService;
13
+import lombok.extern.slf4j.Slf4j;
10 14
 import org.springframework.beans.factory.annotation.Autowired;
11 15
 import org.springframework.stereotype.Service;
12 16
 
17
+import java.time.LocalDateTime;
18
+import java.time.format.DateTimeFormatter;
13 19
 import java.util.List;
14 20
 
15 21
 /**
@@ -20,8 +26,19 @@ import java.util.List;
20 26
  * @author yansen
21 27
  * @since 2020-08-27
22 28
  */
29
+@Slf4j
23 30
 @Service
24 31
 public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMapper, TaLotteryResult> implements ITaLotteryResultService {
32
+
33
+    @Autowired
34
+    ITdLotteryService iTdLotteryService;
35
+
36
+    @Autowired
37
+    ITdLotteryOnSaleService iTdLotteryOnSaleService;
38
+
39
+    @Autowired
40
+    ITaCustomerBettingService iTaCustomerBettingService;
41
+
25 42
     @Autowired
26 43
     TaLotteryResultMapper taLotteryResultMapper;
27 44
 
@@ -36,8 +53,107 @@ public class TaLotteryResultServiceImpl extends ServiceImpl<TaLotteryResultMappe
36 53
         queryWrapper.eq("lottery_id", tdLottery.getLotteryId());
37 54
         queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
38 55
         queryWrapper.orderByDesc("opening_date");
39
-        queryWrapper.last("limti 1");
56
+        queryWrapper.last("limit 1");
57
+
58
+        return getOne(queryWrapper);
59
+    }
60
+
61
+    /**
62
+     * 校验客户是否中奖, 如果中奖,则进行中奖相关更新
63
+     * @throws Exception
64
+     */
65
+    public void checkAndSetLotteryPrize() throws Exception {
66
+        LocalDateTime now = LocalDateTime.now();
67
+        String today = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
68
+        int weekDay = now.getDayOfWeek().getValue();
69
+        List<TdLotteryOnSale> onSaleList = iTdLotteryOnSaleService.getByWeekDay(weekDay);
70
+        if (null == onSaleList || onSaleList.size() == 0) {
71
+            log.info(today + "未找到有开奖设置");
72
+            return;
73
+        }
74
+
75
+        for (TdLotteryOnSale onSale : onSaleList) {
76
+            String lotteryId = onSale.getLotteryId();
77
+            log.info(String.format("彩种 %s %s 开奖, 开始检测中奖人员", lotteryId, today));
78
+
79
+            // 彩种字典
80
+            TdLottery lottery = iTdLotteryService.getById(lotteryId);
81
+
82
+            // 当前彩种的开奖结果
83
+            TaLotteryResult lotteryResult = getLotteryResultBy(onSale.getLotteryId(), today);
84
+            if (null == lotteryResult) {
85
+                log.error(String.format("彩种 %s 未抓取到开奖结果", lotteryId));
86
+                continue;
87
+            }
88
+
89
+            switch (lotteryId) {
90
+                case CommConstants.LOTTERY_LOTTERY:
91
+                    validLotteryCustomer(lottery, lotteryResult);
92
+                    break;
93
+                case CommConstants.LOTTERY_P3:
94
+                    validP3Customer(lottery, lotteryResult);
95
+                    break;
96
+                case CommConstants.LOTTERY_P5:
97
+                    validP5Customer(lottery, lotteryResult);
98
+                    break;
99
+                case CommConstants.LOTTERY_DOUBLE:
100
+                    validDoubleCustomer(lottery, lotteryResult);
101
+                    break;
102
+                case CommConstants.LOTTERY_FOOTBALL:
103
+                    validFootballCustomer(lottery, lotteryResult);
104
+                    break;
105
+                case CommConstants.LOTTERY_BASKETBALL:
106
+                    validBasketballCustomer(lottery, lotteryResult);
107
+                    break;
108
+                default:
109
+                    break;
110
+            }
111
+        }
112
+    }
113
+
114
+    private void validLotteryCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
115
+        List<TaCustomerBetting> customerBettingList = iTaCustomerBettingService.getAllUnOpenBettingsBy(lottery, lotteryResult);
116
+        if (null == customerBettingList || customerBettingList.size() == 0) {
117
+            log.info(String.format("大乐透 %s 期无人投注", lotteryResult.getIssueNo()));
118
+            return;
119
+        }
120
+        
121
+        for (TaCustomerBetting customerBetting : customerBettingList) {
122
+            TaBettingPlan taBettingPlan = customerBetting.getBettingPlan();
123
+            if (null == taBettingPlan) {
124
+                log.error(String.format("ID %s 的投注没有投注方案", customerBetting.getBettingId()));
125
+                continue;
126
+            }
40 127
 
128
+            if (null == taBettingPlan.getItemList() || taBettingPlan.getItemList().size() == 0) {
129
+                log.error(String.format("ID %s 的投注没有投注明细", customerBetting.getBettingId()));
130
+                continue;
131
+            }
132
+
133
+
134
+        }
135
+    }
136
+
137
+    private void validP3Customer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
138
+    }
139
+
140
+    private void validP5Customer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
141
+    }
142
+
143
+    private void validDoubleCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
144
+    }
145
+
146
+    private void validFootballCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
147
+    }
148
+
149
+    private void validBasketballCustomer(TdLottery lottery, TaLotteryResult lotteryResult) throws Exception {
150
+    }
151
+
152
+    public TaLotteryResult getLotteryResultBy(String lotteryId, String openingDate) throws Exception {
153
+        QueryWrapper<TaLotteryResult> queryWrapper = new QueryWrapper<>();
154
+        queryWrapper.eq("lottery_id", lotteryId);
155
+        queryWrapper.eq("opening_date", openingDate);
156
+        queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
41 157
         return getOne(queryWrapper);
42 158
     }
43 159
 }

+ 10
- 0
src/main/java/com/yunzhi/niucai/service/impl/TdLotteryOnSaleServiceImpl.java Прегледај датотеку

@@ -31,4 +31,14 @@ public class TdLotteryOnSaleServiceImpl extends ServiceImpl<TdLotteryOnSaleMappe
31 31
 
32 32
         return list(queryWrapper);
33 33
     }
34
+
35
+    @Override
36
+    public List<TdLotteryOnSale> getByWeekDay(int weekDay) throws Exception {
37
+        QueryWrapper<TdLotteryOnSale> queryWrapper = new QueryWrapper<>();
38
+        queryWrapper.eq("week_day", weekDay);
39
+        queryWrapper.eq("status", StatusEnum.NORMAL.getCode());
40
+        queryWrapper.orderByAsc("serial_no");
41
+
42
+        return list(queryWrapper);
43
+    }
34 44
 }