提交 263c9527 authored 作者: Whispa's avatar Whispa

commit

上级 705d3a0a
......@@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
......@@ -150,8 +152,8 @@ public class BonusController extends Controller {
String sharer = bonus.getSharer();
double amount = bonus.getAmount();
bonus.setAmount(amount * 5 / 100);
BigDecimal amount = bonus.getAmount();
bonus.setAmount(amount.multiply(BigDecimal.valueOf(5)).divide(BigDecimal.valueOf(5), RoundingMode.CEILING));
bonus.setPercentage(5);
if (sharer != null && userRepository.existsByCode(sharer)) {
......@@ -161,7 +163,7 @@ public class BonusController extends Controller {
bonus1.setStationItem(itemOptional.get());
bonus1.setPost(post);
bonus1.setUserInfo(byId.get());
bonus1.setAmount(amount * 10 / 100);
bonus1.setAmount(amount.multiply(BigDecimal.valueOf(10)).divide(BigDecimal.valueOf(100),RoundingMode.CEILING));
bonus1.setPercentage(10.0);
repository.save(bonus1);
}
......@@ -199,7 +201,7 @@ public class BonusController extends Controller {
}
double amount = bonus.getAmount();
BigDecimal amount = bonus.getAmount();
if (userIdOptional.isPresent()) {
......@@ -223,7 +225,7 @@ public class BonusController extends Controller {
if (user.invited()) {
double v = amount * 10 / 100;
BigDecimal v = amount.multiply(BigDecimal.valueOf(10)).divide(BigDecimal.valueOf(100),RoundingMode.CEILING);
bonus.setAmount(v);
bonus.setUserInfo(user);
bonus.setPercentage(10);
......@@ -243,14 +245,15 @@ public class BonusController extends Controller {
return new Result<>(bonus);
}
private TbCfUserInfo runBonusInc(TbCfUserInfo user, double amount, int percent,boolean direct,String orderId) {
private TbCfUserInfo runBonusInc(TbCfUserInfo user, BigDecimal amount, int percent,boolean direct,String orderId) {
if (user == null) return null;
Optional<Network> userCode = networkRepository.findByNetworkInfoCode(user.getCode());
if (userCode.isPresent() || direct) {
TbCfUserInfo userInfo = direct ? user : userCode.get().getUserInfo();
Bonus bonus = new Bonus();
bonus.setUserInfo(userInfo);
double v = amount * percent / 100;
BigDecimal v = amount.multiply(BigDecimal.valueOf(percent));
v = v.divide(BigDecimal.valueOf(100),RoundingMode.CEILING);
bonus.setAmount(v);
bonus.setPercentage(percent);
bonus.setOrderId(orderId);
......
......@@ -185,6 +185,7 @@ public class PostController {
visitRepository.removeByPost_Id(id);
bonusRepository.removeByPost_Id(id);
contentRepository.removeByPost_Id(id);
postHashtagRepository.removeByPost_Id(id);
repository.deleteById(id);
} catch (Exception e) {
System.out.println(e.getMessage());
......
......@@ -38,14 +38,14 @@ public class WithdrawController {
code = 0;
}
Optional<TbCfUserInfo> byId = userRepository.findById(withdraw.getUserId());
Optional<TbCfUserInfo> byId = withdraw.getUserId() == null ? Optional.empty() : userRepository.findById(withdraw.getUserId());
if( !byId.isPresent() ){
code = 0;
message = "Service Error";
}
if( byId.isPresent() && byId.get().getWallet() < withdraw.getAmount() ){
if( byId.isPresent() && byId.get().getWallet() < withdraw.getAmount().doubleValue() ){
code = 0;
message = "Insufficient balance";
}
......
......@@ -7,6 +7,8 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.Optional;
......@@ -26,7 +28,7 @@ public class Bonus extends Model {
@ManyToOne()
private TbCfStationItem stationItem;
private double amount;
private BigDecimal amount;
private String orderId;
......@@ -79,11 +81,11 @@ public class Bonus extends Model {
return productSharer;
}
public double getAmount() {
return amount;
public BigDecimal getAmount() {
return amount == null ? BigDecimal.ZERO : amount.setScale(2, RoundingMode.CEILING);
}
public void setAmount(double amount) {
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
......@@ -93,7 +95,7 @@ public class Bonus extends Model {
public void reverseAmount(){
this.withDrawChange();
amount *= -1;
amount = getAmount().multiply(BigDecimal.valueOf(-1));
}
public String getUserId(){
......
package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.PostHashtag;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
public interface PostHashtagRepository extends PagingAndSortingRepository<PostHashtag,String> {
boolean existsByHashtagNameAndPostId(String hashtag_name, String post_id);
@Query(value = "delete c from post_hashtag_v2 c WHERE c.post_id=:post",nativeQuery = true)
@Modifying
@Transactional
void removeByPost_Id(@Param("post") String post_id);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论