From 2464548977f4720bc8fceeb5d999c1a3852c2d10 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 21 四月 2022 19:38:30 +0800
Subject: [PATCH] 签到与任务

---
 app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java |   93 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 82 insertions(+), 11 deletions(-)

diff --git a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java
index 02c022b..4d32bb9 100644
--- a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java
+++ b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java
@@ -1,10 +1,9 @@
 package com.yeshi.makemoney.app.service.impl.goldcorn;
 
+import com.ks.lib.common.exception.ParamsException;
 import com.yeshi.makemoney.app.entity.config.SystemConfigKey;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetFrequencyConfig;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetPrice;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord;
-import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType;
+import com.yeshi.makemoney.app.entity.goldcorn.*;
+import com.yeshi.makemoney.app.entity.money.UserMoneyRecord;
 import com.yeshi.makemoney.app.entity.user.UserInfo;
 import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetFrequencyConfigException;
 import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetPriceException;
@@ -16,9 +15,13 @@
 import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetPriceService;
 import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService;
 import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornMakeService;
+import com.yeshi.makemoney.app.service.inter.money.UserMoneyRecordService;
 import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService;
 import com.yeshi.makemoney.app.service.inter.user.UserInfoService;
 import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetRecordQuery;
+import com.yeshi.makemoney.app.utils.factory.UserMoneyRecordFactory;
+import com.yeshi.makemoney.app.utils.factory.goldcorn.GoldCornConsumeRecordFactory;
+import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.yeshi.utils.TimeUtil;
@@ -59,6 +62,9 @@
 
     @Resource
     private SystemConfigService systemConfigService;
+
+    @Resource
+    private UserMoneyRecordService userMoneyRecordService;
 
 
     private void frequencyVerify(UserInfo user, GoldCornGetType type, Date time) throws GoldCornGetFrequencyConfigException, GoldCornMakeException {
@@ -115,7 +121,7 @@
 
     @RequestSerializableByKey(key = "'addgoldcorn-'+#uid+'-'+#type")
     @Override
-    public void addGoldCorn(Long uid, GoldCornGetType type, boolean isDouble, Date currentTime) throws UserInfoException, GoldCornGetPriceException, GoldCornGetFrequencyConfigException, GoldCornMakeException {
+    public GoldCornGetRecord addGoldCorn(Long uid, GoldCornGetType type, boolean isDouble, Date currentTime, Integer price) throws UserInfoException, GoldCornGetPriceException, GoldCornGetFrequencyConfigException, GoldCornMakeException {
         if (uid == null || type == null || currentTime == null) {
             throw new GoldCornMakeException(GoldCornMakeException.CODE_PARAMS_NOT_ENOUGH, "鍙傛暟涓嶅畬鏁�");
         }
@@ -126,18 +132,18 @@
         //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒�
         frequencyVerify(user, type, currentTime);
         //鑾峰彇浠锋牸
-        GoldCornGetPrice price = goldCornGetPriceService.getPrice(user.getSystem(), type, currentTime);
+        GoldCornGetPrice getPrice = goldCornGetPriceService.getPrice(user.getSystem(), type, currentTime);
         if (price == null) {
             throw new GoldCornGetPriceException(GoldCornGetPriceException.CODE_NOT_EXIST, "浠锋牸淇℃伅缂哄け");
         }
 
-        //鍩虹浠锋牸
-        int baseCornNum = price.getCornNum();
+        //鍩虹浠锋牸,澶栭儴浼犲叆鐨勪环鏍间紭鍏�
+        int baseCornNum = (price != null ? price : getPrice.getCornNum());
 
         //鏄惁鍔犲叆鍥㈤槦
         Long bossUid = teamInviteRelationService.getBossUid(uid);
         if (bossUid != null) {
-            baseCornNum = new BigDecimal(baseCornNum).multiply(new BigDecimal(1).add(price.getTeamGainRate())).intValue();
+            baseCornNum = new BigDecimal(baseCornNum).multiply(new BigDecimal(1).add(getPrice.getTeamGainRate())).intValue();
         }
 
         GoldCornGetRecord record = new GoldCornGetRecord();
@@ -167,7 +173,7 @@
                 goldCornGetRecordService.add(recordD);
             }
             //鏄惁鏈変笂绾�
-            if (price.getTeamDivide() != null && price.getTeamDivide()) {
+            if (getPrice.getTeamDivide() != null && getPrice.getTeamDivide()) {
                 if (bossUid != null) {
                     BigDecimal rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamFirstDivideRate));
                     GoldCornGetRecord cRecord = new GoldCornGetRecord();
@@ -205,11 +211,76 @@
             throw new GoldCornMakeException(GoldCornMakeException.CODE_ADD_RECORD_ERROR, e.getMsg());
         }
 
+        return record;
     }
 
     @Override
-    public Long getGoldCornByDay(Long uid, String day) {
+    public Long getGoldCornByDay(Long uid, Date day) {
         //TODO redis缂撳瓨
         return goldCornGetRecordService.getGoldCornByDay(uid, day);
     }
+
+    @Override
+    public Long getExchangingGoldCorn(Long uid, int dayCount) {
+        long goldCornNum = 0;
+        long now = System.currentTimeMillis();
+        //鏌ヨ鏈�杩�3澶╂湭鍏戞崲鐨勯噾甯佹暟閲忥紝
+        for (int i = 1; i <= dayCount; i++) {
+            Date date = new Date(now - 1000 * 60 * 60 * 24L * i);
+            long count = getGoldCornByDay(uid, date);
+            if (count == 0L) {
+                continue;
+            }
+            //鑾峰彇鍏戞崲璁板綍鐨勪富閿甀D
+            GoldCornConsumeRecord record = GoldCornConsumeRecordFactory.createExchange(uid, GoldCornUtil.getFormatDay(date), 0, new BigDecimal(0.1));
+            //鏌ヨ璧勯噾璁板綍鏄惁鏈夎璁板綍
+            try {
+                UserMoneyRecord userMoneyRecord = UserMoneyRecordFactory.createGoldCornExchange(record);
+                //鏌ヨ璁板綍
+                userMoneyRecord = userMoneyRecordService.selectBySerialNo(userMoneyRecord.getSerialNo());
+
+                if (userMoneyRecord == null) {
+                    //鏈厬鎹�
+                    goldCornNum += count;
+                }
+
+            } catch (ParamsException e) {
+                e.printStackTrace();
+            }
+        }
+        return goldCornNum;
+    }
+
+    @Override
+    public int getContinueSignDay(Long uid) {
+        Date now = new Date();
+        //鏌ヨ浠婃棩鏄惁宸茬粡绛惧埌
+        boolean isSignIn = isSignIn(uid, now);
+        //浠婃棩鏈鍒扮殑锛屾煡璇㈣繛缁鍒版鏁板簲璇ヤ粠鍓嶄竴澶╁紑濮嬭绠�
+        int continueDay = goldCornGetRecordService.getContinueDay(uid, GoldCornGetType.signIn, !isSignIn ? new Date(now.getTime() - 1000 * 60 * 60 * 24L) : now);
+        return continueDay;
+    }
+
+    @Override
+    public boolean isSignIn(Long uid, Date date) {
+        GoldCornGetRecordQuery query = new GoldCornGetRecordQuery();
+        query.setUid(uid);
+        query.setType(GoldCornGetType.signIn);
+        query.setDay(GoldCornUtil.getFormatDay(date));
+        long count = goldCornGetRecordService.count(query);
+        return count > 0L;
+    }
+
+    @Override
+    public GoldCornGetRecord signIn(Long uid) throws GoldCornGetFrequencyConfigException, UserInfoException, GoldCornGetPriceException, GoldCornMakeException {
+
+        UserInfo user = userInfoService.get(uid);
+        //鑾峰彇杩炵画绛惧埌娆℃暟
+        Integer price = goldCornGetPriceService.getSingInPrice(user.getSystem(), getContinueSignDay(uid) + 1);
+
+
+        return addGoldCorn(uid, GoldCornGetType.signIn, false, new Date(), price);
+    }
+
+
 }

--
Gitblit v1.8.0