Browse Source

2019/08/19

x1ongzhu 6 years ago
parent
commit
e2936c8db1

+ 1 - 0
src/main/java/com/izouma/walkchina/constant/AppConstants.java

@@ -48,6 +48,7 @@ public interface AppConstants {
         int NORMAL          = 1;
         int NORMAL          = 1;
         int TEAM            = 2;
         int TEAM            = 2;
         int PROGRESS_UPDATE = 3;
         int PROGRESS_UPDATE = 3;
+        int STEP_CONTRIBUTE = 4;
     }
     }
 
 
     interface CoinRecordType {
     interface CoinRecordType {

+ 11 - 3
src/main/java/com/izouma/walkchina/domain/StageAward.java

@@ -14,6 +14,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
 import javax.persistence.*;
 import javax.persistence.*;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
+import java.util.List;
 
 
 @Entity
 @Entity
 @Data
 @Data
@@ -44,11 +45,18 @@ public class StageAward {
     @Column(precision = 10, scale = 2)
     @Column(precision = 10, scale = 2)
     private BigDecimal coin;
     private BigDecimal coin;
 
 
-    private Boolean received;
+    @Column(precision = 10, scale = 2)
+    private BigDecimal originCoin;
 
 
-    private Long receiveUser;
+    @Column(columnDefinition = "bit(1) default 0", nullable = false)
+    @Builder.Default
+    private Boolean arrival = false;
+
+    private Boolean received;
 
 
-    private LocalDateTime receiveTime;
+    @OneToMany
+    @JoinColumn(name = "stageAwardId", insertable = false, updatable = false)
+    private List<StageAwardRecord> receiveRecords;
 
 
     @CreatedBy
     @CreatedBy
     private String createdBy;
     private String createdBy;

+ 47 - 0
src/main/java/com/izouma/walkchina/domain/StageAwardRecord.java

@@ -0,0 +1,47 @@
+package com.izouma.walkchina.domain;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.CreatedBy;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedBy;
+import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+
+import javax.persistence.*;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Entity
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@EntityListeners(AuditingEntityListener.class)
+public class StageAwardRecord {
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long   id;
+    @CreatedBy
+    private String createdBy;
+
+    @CreatedDate
+    private LocalDateTime createdAt;
+
+    @LastModifiedBy
+    private String modifiedBy;
+
+    @LastModifiedDate
+    private LocalDateTime modifiedAt;
+
+    private Long stageAwardId;
+
+    @Column(precision = 10, scale = 2)
+    private BigDecimal amount;
+
+    private Long userId;
+}

+ 4 - 2
src/main/java/com/izouma/walkchina/repo/CityRepository.java

@@ -10,7 +10,9 @@ import java.util.List;
 public interface CityRepository extends JpaRepository<City, Long>, JpaSpecificationExecutor<City> {
 public interface CityRepository extends JpaRepository<City, Long>, JpaSpecificationExecutor<City> {
     City findByName(String name);
     City findByName(String name);
 
 
-    @Query(value = "SELECT * FROM city c1, (SELECT * FROM city WHERE city.id = ?1) c2 WHERE c1.id <> ?1 " +
+    @Query(value = "SELECT * FROM city c1, (SELECT * FROM city WHERE city.id = ?1) c2 WHERE c1.id <> ?1 AND c1.id NOT IN " +
+                   "(SELECT origin_id AS city_id FROM journey_stage WHERE user_id = ?2 " +
+                   "UNION SELECT destination_id AS city_id FROM journey_stage WHERE user_id = ?2) " +
                    "ORDER BY pow(c2.latitude - c1.latitude, 2) + pow(c2.longitude - c1.longitude, 2) LIMIT 5", nativeQuery = true)
                    "ORDER BY pow(c2.latitude - c1.latitude, 2) + pow(c2.longitude - c1.longitude, 2) LIMIT 5", nativeQuery = true)
-    List<City> findNear(Long id);
+    List<City> findNear(Long id, Long userId);
 }
 }

+ 2 - 3
src/main/java/com/izouma/walkchina/repo/JourneyStageRepository.java

@@ -5,13 +5,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.jpa.repository.Query;
 
 
 import java.util.List;
 import java.util.List;
-import java.util.Optional;
 
 
 public interface JourneyStageRepository extends JpaRepository<JourneyStage, Long> {
 public interface JourneyStageRepository extends JpaRepository<JourneyStage, Long> {
     List<JourneyStage> findAllByJourneyIdOrderById(Long journeyId);
     List<JourneyStage> findAllByJourneyIdOrderById(Long journeyId);
 
 
     @Query("select j from JourneyStage j where j.userId = ?1 and j.active = true order by j.createdAt desc")
     @Query("select j from JourneyStage j where j.userId = ?1 and j.active = true order by j.createdAt desc")
-    Optional<JourneyStage> findUserLatest(Long userId);
+    List<JourneyStage> findUserLatest(Long userId);
 
 
-    JourneyStage findByUserIdAndJourneyIdOrderByIdDesc(Long userId, Long journeyId);
+    List<JourneyStage> findByUserIdAndJourneyIdOrderByCreatedAtDesc(Long userId, Long journeyId);
 }
 }

+ 7 - 0
src/main/java/com/izouma/walkchina/repo/StageAwardRecordRepository.java

@@ -0,0 +1,7 @@
+package com.izouma.walkchina.repo;
+
+import com.izouma.walkchina.domain.StageAwardRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface StageAwardRecordRepository extends JpaRepository<StageAwardRecord, Long> {
+}

+ 1 - 1
src/main/java/com/izouma/walkchina/repo/StageAwardRepository.java

@@ -11,6 +11,6 @@ public interface StageAwardRepository extends JpaRepository<StageAward, Long> {
 
 
     List<StageAward> findAllByUserIdAndStageId(Long userId, Long stageId);
     List<StageAward> findAllByUserIdAndStageId(Long userId, Long stageId);
 
 
-    @Query(value = "SELECT * FROM stage_award WHERE user_id = ?1 AND stage_id = ?2 ORDER BY created_at DESC LIMIT 1", nativeQuery = true)
+    @Query(value = "SELECT * FROM stage_award WHERE user_id = ?1 AND stage_id = ?2 AND arrival = 0 ORDER BY created_at DESC LIMIT 1", nativeQuery = true)
     StageAward findLatest(Long userId, Long stageId);
     StageAward findLatest(Long userId, Long stageId);
 }
 }

+ 68 - 31
src/main/java/com/izouma/walkchina/service/AwardService.java

@@ -11,33 +11,51 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
+import java.math.RoundingMode;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Optional;
+import java.util.function.Predicate;
 
 
 @ToString
 @ToString
 @Slf4j
 @Slf4j
 @Service
 @Service
 public class AwardService {
 public class AwardService {
     @Autowired
     @Autowired
-    private StageAwardRepository     stageAwardRepository;
+    private StageAwardRepository       stageAwardRepository;
     @Autowired
     @Autowired
-    private MessageRepository        messageRepository;
+    private MessageRepository          messageRepository;
     @Autowired
     @Autowired
-    private UserInfoRepository       userInfoRepository;
+    private UserInfoRepository         userInfoRepository;
     @Autowired
     @Autowired
-    private UserCoinRecordRepository userCoinRecordRepository;
+    private UserCoinRecordRepository   userCoinRecordRepository;
     @Autowired
     @Autowired
-    private JourneyStageRepository   journeyStageRepository;
+    private JourneyStageRepository     journeyStageRepository;
+    @Autowired
+    private StageAwardRecordRepository stageAwardRecordRepository;
 
 
-    public BigDecimal receiveStageAward(Long userId, Long stageAwardId) {
+    public Map<String, Object> receiveStageAward(Long userId, Long stageAwardId) {
         StageAward stageAward = stageAwardRepository.findById(stageAwardId).orElseThrow(new ServiceException("无记录"));
         StageAward stageAward = stageAwardRepository.findById(stageAwardId).orElseThrow(new ServiceException("无记录"));
         if (stageAward.getReceived()) {
         if (stageAward.getReceived()) {
-            throw new ServiceException("重复领取");
+            throw new ServiceException("你来晚了,奖金已经被领完了~");
+        }
+        if (!userId.equals(stageAward.getUserId()) && stageAward.getReceiveRecords().size() >= 3) {
+            throw new ServiceException("你来晚了,奖金已经被偷完了~");
+        }
+        if (!userId.equals(stageAward.getUserId()) && stageAward.getReceiveRecords().stream().filter(new Predicate<StageAwardRecord>() {
+            @Override
+            public boolean test(StageAwardRecord stageAwardRecord) {
+                return stageAwardRecord.getUserId().equals(userId);
+            }
+        }).findAny().orElse(null) != null) {
+            throw new ServiceException("你已经偷过了,不要太贪心哦~");
         }
         }
+
         JourneyStage journeyStage = journeyStageRepository.findById(stageAward.getStageId()).orElseThrow(new ServiceException("无记录"));
         JourneyStage journeyStage = journeyStageRepository.findById(stageAward.getStageId()).orElseThrow(new ServiceException("无记录"));
         if (journeyStage.getProgress() < stageAward.getNeedProgress()) {
         if (journeyStage.getProgress() < stageAward.getNeedProgress()) {
-            throw new ServiceException("步数不足");
+            throw new ServiceException("步数未达到无法领取哦~");
         }
         }
+
         UserInfo owner = userInfoRepository.findById(stageAward.getUserId()).orElseThrow(new ServiceException("用户不存在"));
         UserInfo owner = userInfoRepository.findById(stageAward.getUserId()).orElseThrow(new ServiceException("用户不存在"));
         UserInfo receiver;
         UserInfo receiver;
         if (userId.equals(stageAward.getUserId())) {
         if (userId.equals(stageAward.getUserId())) {
@@ -46,41 +64,60 @@ public class AwardService {
             receiver = owner;
             receiver = owner;
         }
         }
 
 
-        stageAward.setReceived(true);
-        stageAward.setReceiveUser(userId);
-        stageAward.setReceiveTime(LocalDateTime.now());
+        BigDecimal amount;
+
+        if (!userId.equals(stageAward.getUserId())) {
+            do {
+                amount = BigDecimal.valueOf(Math.random() * stageAward.getCoin().doubleValue()).setScale(2, RoundingMode.HALF_EVEN);
+                System.out.println(amount);
+            } while (amount.compareTo(BigDecimal.valueOf(0.01)) <= 0
+                     || amount.compareTo(stageAward.getCoin().min(BigDecimal.valueOf(0.01))) <= 0);
+        } else {
+            amount = stageAward.getCoin();
+            stageAward.setReceived(true);
+        }
+        stageAward.setCoin(stageAward.getCoin().subtract(amount));
         stageAwardRepository.save(stageAward);
         stageAwardRepository.save(stageAward);
 
 
         BigDecimal balance = Optional.ofNullable(receiver.getCoin()).orElse(BigDecimal.ZERO);
         BigDecimal balance = Optional.ofNullable(receiver.getCoin()).orElse(BigDecimal.ZERO);
-        balance = balance.add(stageAward.getCoin());
+        balance = balance.add(amount);
         receiver.setCoin(balance);
         receiver.setCoin(balance);
         userInfoRepository.save(receiver);
         userInfoRepository.save(receiver);
 
 
+        stageAwardRecordRepository.save(StageAwardRecord.builder()
+                                                        .userId(userId)
+                                                        .amount(amount)
+                                                        .stageAwardId(stageAward.getId())
+                                                        .build());
+
         if (userId.equals(stageAward.getUserId())) {
         if (userId.equals(stageAward.getUserId())) {
             userCoinRecordRepository.save(UserCoinRecord.builder()
             userCoinRecordRepository.save(UserCoinRecord.builder()
-                    .userId(userId)
-                    .balance(balance)
-                    .modify(stageAward.getCoin())
-                    .remark(Strings.REMARK_RECEIVE_STAGE_AWARD)
-                    .type(AppConstants.CoinRecordType.STAGE)
-                    .build());
+                                                        .userId(userId)
+                                                        .balance(balance)
+                                                        .modify(amount)
+                                                        .remark(Strings.REMARK_RECEIVE_STAGE_AWARD)
+                                                        .type(AppConstants.CoinRecordType.STAGE)
+                                                        .build());
         } else {
         } else {
             userCoinRecordRepository.save(UserCoinRecord.builder()
             userCoinRecordRepository.save(UserCoinRecord.builder()
-                    .userId(receiver.getId())
-                    .balance(balance)
-                    .modify(stageAward.getCoin())
-                    .remark(Strings.REMARK_STEAL_STAGE_AWARD)
-                    .type(AppConstants.CoinRecordType.STEAL)
-                    .build());
+                                                        .userId(receiver.getId())
+                                                        .balance(balance)
+                                                        .modify(amount)
+                                                        .remark(Strings.REMARK_STEAL_STAGE_AWARD)
+                                                        .type(AppConstants.CoinRecordType.STEAL)
+                                                        .build());
 
 
             Message stolenMsg = Message.builder()
             Message stolenMsg = Message.builder()
-                    .userId(stageAward.getUserId())
-                    .content(String.format(Strings.MSG_AWARD_STOLEN, receiver.getNickname(), stageAward.getCoin()))
-                    .isRead(false)
-                    .active(true)
-                    .build();
+                                       .userId(stageAward.getUserId())
+                                       .content(String.format(Strings.MSG_AWARD_STOLEN, receiver.getNickname(), amount))
+                                       .isRead(false)
+                                       .active(true)
+                                       .build();
             messageRepository.save(stolenMsg);
             messageRepository.save(stolenMsg);
         }
         }
-        return stageAward.getCoin();
+        Map<String, Object> map = new HashMap<>();
+        map.put("coin", amount);
+        map.put("arrival", stageAward.getArrival());
+        return map;
     }
     }
 }
 }

+ 58 - 9
src/main/java/com/izouma/walkchina/service/JourneyService.java

@@ -11,6 +11,7 @@ import com.izouma.walkchina.exception.ServiceException;
 import com.izouma.walkchina.repo.*;
 import com.izouma.walkchina.repo.*;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
@@ -90,6 +91,19 @@ public class JourneyService {
                                                 .build();
                                                 .build();
         journeyStageRepository.save(journeyStage);
         journeyStageRepository.save(journeyStage);
 
 
+        stageAwardRepository.save(StageAward.builder()
+                                            .userId(userId)
+                                            .journeyId(userJourney.getId())
+                                            .stageId(journeyStage.getId())
+                                            .latitude(destination.getLatitude())
+                                            .longitude(destination.getLongitude())
+                                            .needProgress(1D)
+                                            .needSteps(journeyStage.getSteps())
+                                            .coin(BigDecimal.ZERO)
+                                            .arrival(true)
+                                            .received(false)
+                                            .build());
+
         userInfo.setWalkCities(Optional.ofNullable(userInfo.getWalkCities()).orElse(0) + 1);
         userInfo.setWalkCities(Optional.ofNullable(userInfo.getWalkCities()).orElse(0) + 1);
         userInfoRepository.save(userInfo);
         userInfoRepository.save(userInfo);
     }
     }
@@ -97,8 +111,8 @@ public class JourneyService {
     public void newDestination(Long userId, Long id) {
     public void newDestination(Long userId, Long id) {
         City destination = cityRepository.findById(id).orElseThrow(new ServiceException("目的地不存在"));
         City destination = cityRepository.findById(id).orElseThrow(new ServiceException("目的地不存在"));
         UserJourney userJourney = userJourneyRepository.findByUserId(userId);
         UserJourney userJourney = userJourneyRepository.findByUserId(userId);
-        JourneyStage journeyStage = journeyStageRepository.findByUserIdAndJourneyIdOrderByIdDesc(userId, userJourney
-            .getId());
+        JourneyStage journeyStage = journeyStageRepository.findByUserIdAndJourneyIdOrderByCreatedAtDesc(userId, userJourney
+            .getId()).stream().findFirst().orElseThrow(new ServiceException("无记录"));
         DirectionResponse directionResponse = mapService.direction(new Location(journeyStage.getDestination()
         DirectionResponse directionResponse = mapService.direction(new Location(journeyStage.getDestination()
                                                                                             .getLatitude(), journeyStage
                                                                                             .getLatitude(), journeyStage
                                                                                     .getDestination().getLongitude()),
                                                                                     .getDestination().getLongitude()),
@@ -127,6 +141,19 @@ public class JourneyService {
         newPolyline.set(1, newPolyline.get(1) * 1000000 - polyline.get(polyline.size() - 1) * 1000000);
         newPolyline.set(1, newPolyline.get(1) * 1000000 - polyline.get(polyline.size() - 1) * 1000000);
         userJourney.getPolyline().addAll(newPolyline);
         userJourney.getPolyline().addAll(newPolyline);
         userJourneyRepository.save(userJourney);
         userJourneyRepository.save(userJourney);
+
+        stageAwardRepository.save(StageAward.builder()
+                                            .userId(userId)
+                                            .journeyId(userJourney.getId())
+                                            .stageId(newStage.getId())
+                                            .latitude(destination.getLatitude())
+                                            .longitude(destination.getLongitude())
+                                            .needProgress(1D)
+                                            .needSteps(newStage.getSteps())
+                                            .coin(BigDecimal.ZERO)
+                                            .arrival(true)
+                                            .received(false)
+                                            .build());
     }
     }
 
 
     private void createStageAward(UserJourney userJourney, JourneyStage journeyStage, Long needSteps) {
     private void createStageAward(UserJourney userJourney, JourneyStage journeyStage, Long needSteps) {
@@ -152,6 +179,7 @@ public class JourneyService {
                                           .longitude(extracted.get(end))
                                           .longitude(extracted.get(end))
                                           .journeyId(userJourney.getId())
                                           .journeyId(userJourney.getId())
                                           .coin(coin)
                                           .coin(coin)
+                                          .originCoin(coin)
                                           .needProgress(progress)
                                           .needProgress(progress)
                                           .needSteps((long) (progress * journeyStage
                                           .needSteps((long) (progress * journeyStage
                                               .getDistance() / AppConstants.STEP_TO_DISTANCE_RATE))
                                               .getDistance() / AppConstants.STEP_TO_DISTANCE_RATE))
@@ -187,7 +215,7 @@ public class JourneyService {
         latestStage.setSteps((long) (latestStage.getDistance() / AppConstants.STEP_TO_DISTANCE_RATE));
         latestStage.setSteps((long) (latestStage.getDistance() / AppConstants.STEP_TO_DISTANCE_RATE));
         latestStage.setCurrentSteps(steps);
         latestStage.setCurrentSteps(steps);
         double progress = steps * AppConstants.STEP_TO_DISTANCE_RATE / latestStage.getDistance();
         double progress = steps * AppConstants.STEP_TO_DISTANCE_RATE / latestStage.getDistance();
-        progress = progress > 1 ? 1 : (progress < 0 ? 0 : progress);
+        progress = Math.max(0, Math.min(1, progress));
         latestStage.setProgress(progress);
         latestStage.setProgress(progress);
         journeyStageRepository.save(latestStage);
         journeyStageRepository.save(latestStage);
 
 
@@ -208,12 +236,30 @@ public class JourneyService {
             messageRepository.save(msg);
             messageRepository.save(msg);
         }
         }
 
 
-        createStageAward(userJourney, latestStage, steps + AppConstants.STAGE_AWARD_STEPS);
+        if (progress == 1) {
+            StageAward example = StageAward.builder()
+                                           .stageId(latestStage.getId())
+                                           .journeyId(latestStage.getJourneyId())
+                                           .arrival(true)
+                                           .received(false)
+                                           .build();
+            StageAward stageAward = stageAwardRepository.findAll(Example.of(example)).stream().findFirst().orElse(null);
+            if (stageAward != null) {
+                if (Optional.ofNullable(stageAward.getCoin()).orElse(BigDecimal.ZERO).compareTo(BigDecimal.ZERO) == 0) {
+                    UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
+                    stageAward.setCoin(userInfo.getPrice());
+                    stageAward.setOriginCoin(userInfo.getPrice());
+                    stageAwardRepository.save(stageAward);
+                }
+            }
+        } else {
+            createStageAward(userJourney, latestStage, steps + AppConstants.STAGE_AWARD_STEPS);
+        }
     }
     }
 
 
     public JourneyStageStat finishJourneyStage(Long userId) {
     public JourneyStageStat finishJourneyStage(Long userId) {
         UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
         UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
-        JourneyStage latestStage = journeyStageRepository.findUserLatest(userId)
+        JourneyStage latestStage = journeyStageRepository.findUserLatest(userId).stream().findFirst()
                                                          .orElseThrow(new ServiceException("无数据"));
                                                          .orElseThrow(new ServiceException("无数据"));
         if (latestStage.getProgress() < 1) {
         if (latestStage.getProgress() < 1) {
             throw new ServiceException("当前阶段未完成");
             throw new ServiceException("当前阶段未完成");
@@ -221,9 +267,6 @@ public class JourneyService {
 
 
         LocalDateTime finishAt = LocalDateTime.now();
         LocalDateTime finishAt = LocalDateTime.now();
         if (latestStage.getFinishAt() == null) {
         if (latestStage.getFinishAt() == null) {
-            coinService.balanceChange(userInfo, latestStage
-                                          .getAward(), AppConstants.CoinRecordType.ARRIVAL, Strings.REMARK_ARRIVAL,
-                                      String.format(Strings.MSG_ARRIVAL, latestStage.getDestination().getName(), latestStage.getAward()));
             userInfo.setWalkCities(Optional.ofNullable(userInfo.getWalkCities()).orElse(0) + 1);
             userInfo.setWalkCities(Optional.ofNullable(userInfo.getWalkCities()).orElse(0) + 1);
             userInfoService.updateUserLevel(userInfo);
             userInfoService.updateUserLevel(userInfo);
 
 
@@ -234,8 +277,14 @@ public class JourneyService {
         }
         }
         Long mySteps = walkDataRepository.sumUserWalkSteps(userId, latestStage.getCreatedAt(), finishAt).orElse(0L);
         Long mySteps = walkDataRepository.sumUserWalkSteps(userId, latestStage.getCreatedAt(), finishAt).orElse(0L);
         Long teamSteps = walkDataRepository.sumTeamWalkSteps(userId, latestStage.getCreatedAt(), finishAt).orElse(0L);
         Long teamSteps = walkDataRepository.sumTeamWalkSteps(userId, latestStage.getCreatedAt(), finishAt).orElse(0L);
+        StageAward example = StageAward.builder()
+                                       .stageId(latestStage.getId())
+                                       .journeyId(latestStage.getJourneyId())
+                                       .arrival(true)
+                                       .build();
+        StageAward stageAward = stageAwardRepository.findAll(Example.of(example)).stream().findFirst().orElseThrow(new ServiceException(""));
         JourneyStageStat stageStat = JourneyStageStat.builder()
         JourneyStageStat stageStat = JourneyStageStat.builder()
-                                                     .award(latestStage.getAward())
+                                                     .award(stageAward.getOriginCoin())
                                                      .mySteps(mySteps)
                                                      .mySteps(mySteps)
                                                      .teamSteps(teamSteps)
                                                      .teamSteps(teamSteps)
                                                      .days((int) DAYS
                                                      .days((int) DAYS

+ 2 - 2
src/main/java/com/izouma/walkchina/service/MapService.java

@@ -59,8 +59,8 @@ public class MapService {
         return cityRepository.findAll(specification);
         return cityRepository.findAll(specification);
     }
     }
 
 
-    public List<City> findNearCities(Long id) {
-        return cityRepository.findNear(id);
+    public List<City> findNearCities(Long id, Long userId) {
+        return cityRepository.findNear(id, userId);
     }
     }
 
 
     public Collection<UserMarker> usersInRegion(Long userId, MapRegion mapRegion) {
     public Collection<UserMarker> usersInRegion(Long userId, MapRegion mapRegion) {

+ 1 - 1
src/main/java/com/izouma/walkchina/service/OrderService.java

@@ -191,7 +191,7 @@ public class OrderService {
             userOrderRepository.save(userOrder);
             userOrderRepository.save(userOrder);
 
 
             UserInfo userInfo = userInfoRepository.findById(userOrder.getUserId()).orElseThrow(new ServiceException("用户不存在"));
             UserInfo userInfo = userInfoRepository.findById(userOrder.getUserId()).orElseThrow(new ServiceException("用户不存在"));
-            coinService.balanceChange(userInfo, userOrder.getCoin(), AppConstants.CoinRecordType.BUY, Strings.REMARK_BUY, null);
+            coinService.balanceChange(userInfo, userOrder.getCoin().negate(), AppConstants.CoinRecordType.BUY, Strings.REMARK_BUY, null);
 
 
         } catch (WxPayException e) {
         } catch (WxPayException e) {
             log.error("handleWxNotify error", e);
             log.error("handleWxNotify error", e);

+ 3 - 3
src/main/java/com/izouma/walkchina/service/UserInfoService.java

@@ -240,6 +240,9 @@ public class UserInfoService {
         if (monthWalkData != null) {
         if (monthWalkData != null) {
             price = BigDecimal.valueOf(monthWalkData.getSteps() / 10000D);
             price = BigDecimal.valueOf(monthWalkData.getSteps() / 10000D);
         }
         }
+        if (price.compareTo(AppConstants.MIN_PRICE) < 0) {
+            price = AppConstants.MIN_PRICE;
+        }
         int hireCount = teamMemberRepository.countAllByUserId(userInfo.getId());
         int hireCount = teamMemberRepository.countAllByUserId(userInfo.getId());
         double scale = 1.0;
         double scale = 1.0;
         for (int i = 0; i < Math.min(hireCount, 10); i++) {
         for (int i = 0; i < Math.min(hireCount, 10); i++) {
@@ -252,9 +255,6 @@ public class UserInfoService {
             scale += .01;
             scale += .01;
         }
         }
         price = price.multiply(BigDecimal.valueOf(scale));
         price = price.multiply(BigDecimal.valueOf(scale));
-        if (price.compareTo(AppConstants.MIN_PRICE) < 0) {
-            price = AppConstants.MIN_PRICE;
-        }
 
 
         userInfo.setPrice(price);
         userInfo.setPrice(price);
         userInfoRepository.save(userInfo);
         userInfoRepository.save(userInfo);

+ 1 - 3
src/main/java/com/izouma/walkchina/web/AwardController.java

@@ -1,6 +1,5 @@
 package com.izouma.walkchina.web;
 package com.izouma.walkchina.web;
 
 
-import com.izouma.walkchina.domain.UserInfo;
 import com.izouma.walkchina.dto.Result;
 import com.izouma.walkchina.dto.Result;
 import com.izouma.walkchina.service.AwardService;
 import com.izouma.walkchina.service.AwardService;
 import com.izouma.walkchina.utils.SecurityUtils;
 import com.izouma.walkchina.utils.SecurityUtils;
@@ -19,7 +18,6 @@ public class AwardController {
 
 
     @GetMapping("/receiveStageAward")
     @GetMapping("/receiveStageAward")
     public Result receiveStageAward(@RequestParam("stageAwardId") Long stageAwardId) {
     public Result receiveStageAward(@RequestParam("stageAwardId") Long stageAwardId) {
-        UserInfo userInfo = SecurityUtils.getAuthenticatedUser();
-        return Result.ok(awardService.receiveStageAward(userInfo.getId(), stageAwardId));
+        return Result.ok(awardService.receiveStageAward(SecurityUtils.getAuthenticatedUser().getId(), stageAwardId));
     }
     }
 }
 }

+ 1 - 1
src/main/java/com/izouma/walkchina/web/MapController.java

@@ -27,7 +27,7 @@ public class MapController {
 
 
     @GetMapping("/nearCities")
     @GetMapping("/nearCities")
     public Result nearCities(@RequestParam("id") Long id) {
     public Result nearCities(@RequestParam("id") Long id) {
-        return Result.ok(mapService.findNearCities(id));
+        return Result.ok(mapService.findNearCities(id, SecurityUtils.getAuthenticatedUser().getId()));
     }
     }
 
 
     @PostMapping("/usersInRegion")
     @PostMapping("/usersInRegion")

+ 29 - 20
src/test/java/com/izouma/walkchina/CommonTest.java

@@ -26,12 +26,12 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.Paths;
 import java.text.MessageFormat;
 import java.text.MessageFormat;
 import java.time.Instant;
 import java.time.Instant;
-import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashMap;
@@ -59,13 +59,13 @@ public class CommonTest {
     @Test
     @Test
     public void testCopyProperties() throws InvocationTargetException, IllegalAccessException {
     public void testCopyProperties() throws InvocationTargetException, IllegalAccessException {
         UserInfo u1 = UserInfo.builder()
         UserInfo u1 = UserInfo.builder()
-            .nickname("aaa")
-            .phone("111")
-            .build();
+                              .nickname("aaa")
+                              .phone("111")
+                              .build();
         UserInfo u2 = UserInfo.builder()
         UserInfo u2 = UserInfo.builder()
-            .nickname("bbb")
-            .sex(1)
-            .build();
+                              .nickname("bbb")
+                              .sex(1)
+                              .build();
         BeanUtils.copyProperties(u1, u2);
         BeanUtils.copyProperties(u1, u2);
         System.out.println();
         System.out.println();
     }
     }
@@ -92,14 +92,14 @@ public class CommonTest {
             Location location = search(fullname);
             Location location = search(fullname);
             if (location != null) {
             if (location != null) {
                 City city = City.builder()
                 City city = City.builder()
-                    .id(Long.parseLong(code.substring(0, 6)))
-                    .fullname(fullname)
-                    .name(name)
-                    .pinyin(getpinyin(name))
-                    .latitude(location.getLatitude())
-                    .longitude(location.getLongitude())
-                    .provinceId(provinceId)
-                    .build();
+                                .id(Long.parseLong(code.substring(0, 6)))
+                                .fullname(fullname)
+                                .name(name)
+                                .pinyin(getpinyin(name))
+                                .latitude(location.getLatitude())
+                                .longitude(location.getLongitude())
+                                .provinceId(provinceId)
+                                .build();
                 cityList.add(city);
                 cityList.add(city);
             }
             }
         }
         }
@@ -174,8 +174,8 @@ public class CommonTest {
     public void testLogistic() throws JSONException {
     public void testLogistic() throws JSONException {
         String url = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?appid=4001&com=&nu=1121271618192";
         String url = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?appid=4001&com=&nu=1121271618192";
         String body = HttpRequest.get(url, true)
         String body = HttpRequest.get(url, true)
-            .header("Cookie", "BAIDUID=0B261C5E2F8B53A17D49E0CE5033E19B:FG=1; BIDUPSID=0B261C5E2F8B53A17D49E0CE5033E19B; PSTM=1551535964; BDUSS=ElnRXAwdkcyMmNEdUVuQjIwcFl5ejl5YzB5elNSOFdEbi02UVBiZXdNZmo3S1ZjQVFBQUFBJCQAAAAAAAAAAAEAAACQUvsNzvu5~rTz0NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAONfflzjX35cM; MCITY=-315%3A; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_PS_PSSID=26524_1450_21125_29522_29520_29098_29567_28838_29221_26350_29589; delPer=0; BDRCVFR[feWj1Vr5u3D]=mk3SLVN4HKm; PSINO=7")
-            .body();
+                                 .header("Cookie", "BAIDUID=0B261C5E2F8B53A17D49E0CE5033E19B:FG=1; BIDUPSID=0B261C5E2F8B53A17D49E0CE5033E19B; PSTM=1551535964; BDUSS=ElnRXAwdkcyMmNEdUVuQjIwcFl5ejl5YzB5elNSOFdEbi02UVBiZXdNZmo3S1ZjQVFBQUFBJCQAAAAAAAAAAAEAAACQUvsNzvu5~rTz0NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAONfflzjX35cM; MCITY=-315%3A; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_PS_PSSID=26524_1450_21125_29522_29520_29098_29567_28838_29221_26350_29589; delPer=0; BDRCVFR[feWj1Vr5u3D]=mk3SLVN4HKm; PSINO=7")
+                                 .body();
         JSONObject jsonObject = new JSONObject(StringEscapeUtils.unescapeJava(body));
         JSONObject jsonObject = new JSONObject(StringEscapeUtils.unescapeJava(body));
         try {
         try {
             JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONObject("info").getJSONArray("context");
             JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONObject("info").getJSONArray("context");
@@ -184,9 +184,9 @@ public class CommonTest {
             for (int i = 0; i < jsonArray.length(); i++) {
             for (int i = 0; i < jsonArray.length(); i++) {
                 JSONObject jsonInfo = jsonArray.getJSONObject(i);
                 JSONObject jsonInfo = jsonArray.getJSONObject(i);
                 LogisticsInfo.TrackingInfo info = LogisticsInfo.TrackingInfo.builder()
                 LogisticsInfo.TrackingInfo info = LogisticsInfo.TrackingInfo.builder()
-                    .time(Instant.ofEpochSecond(jsonInfo.getLong("time")).atZone(ZoneId.systemDefault()).toLocalDateTime())
-                    .desc(jsonInfo.getString("desc"))
-                    .build();
+                                                                            .time(Instant.ofEpochSecond(jsonInfo.getLong("time")).atZone(ZoneId.systemDefault()).toLocalDateTime())
+                                                                            .desc(jsonInfo.getString("desc"))
+                                                                            .build();
                 trackingList.add(info);
                 trackingList.add(info);
                 if (i == 0) {
                 if (i == 0) {
                     logisticsInfo.setLatest(info);
                     logisticsInfo.setLatest(info);
@@ -200,4 +200,13 @@ public class CommonTest {
         }
         }
     }
     }
 
 
+    @Test
+    public void aaa() {
+        BigDecimal amount;
+        do {
+            amount = BigDecimal.valueOf(Math.random() * 1.00).setScale(2, RoundingMode.HALF_EVEN);
+        } while (amount.compareTo(BigDecimal.valueOf(0.01)) <= 0 || amount.compareTo(BigDecimal.valueOf(1)) >= 0);
+        System.out.println(amount);
+    }
+
 }
 }