提交 c14cc3db authored 作者: 吴德鹏's avatar 吴德鹏

修改佣金bug

上级 0fed986b
......@@ -28,13 +28,12 @@ public class BonusController extends Controller {
private final NetworkRepository networkRepository;
// @PersistenceContext(unitName = "afrishop_v3")
// @PersistenceContext(unitName = "afrishop_v3")
private final EntityManager entityManager;
private final AuthenticationUser user;
private final TbCfOrderRepository orderRepository;
public BonusController(BonusRepository repository, TbCfStationItemRepository itemRepository, UserRepository userRepository, PostRepository postRepository, NetworkRepository networkRepository, AuthenticationUser user, TbCfOrderRepository orderRepository,EntityManager entityManager) {
public BonusController(BonusRepository repository, TbCfStationItemRepository itemRepository, UserRepository userRepository, PostRepository postRepository, NetworkRepository networkRepository, AuthenticationUser user, TbCfOrderRepository orderRepository, EntityManager entityManager) {
this.repository = repository;
this.itemRepository = itemRepository;
this.userRepository = userRepository;
......@@ -69,8 +68,8 @@ public class BonusController extends Controller {
//Get bonuses in current month
@GetMapping(value = "/list/currentMonth")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public Map<String, Object> getListByUserAndCurrentMonth( @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return getListByUserAndCurrentMonth(user.userId(),pageNo,pageSize);
public Map<String, Object> getListByUserAndCurrentMonth(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return getListByUserAndCurrentMonth(user.userId(), pageNo, pageSize);
}
@Deprecated
......@@ -90,7 +89,7 @@ public class BonusController extends Controller {
nativeQuery.setParameter("year", year);
List<Bonus> bonuses = repository.findAllByUser_IdAndCreateDateMonthAndCreateDateYear(byId.get(), month, year, PageRequest.of(pageNo, pageSize)).toList();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("total", BigDecimal.valueOf((double)nativeQuery.getSingleResult()).setScale(3,RoundingMode.HALF_UP));
hashMap.put("total", BigDecimal.valueOf((double) nativeQuery.getSingleResult()).setScale(3, RoundingMode.HALF_UP));
hashMap.put("list", bonuses);
return hashMap;
}
......@@ -99,7 +98,7 @@ public class BonusController extends Controller {
@GetMapping(value = "/list/prevMonth")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public Map<String, Object> getListByUserAndPreviousMonth(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return getListByUserAndPreviousMonth(user.userId(),pageNo,pageSize);
return getListByUserAndPreviousMonth(user.userId(), pageNo, pageSize);
}
@Deprecated
......@@ -110,6 +109,11 @@ public class BonusController extends Controller {
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int month = localDate.getMonthValue() - 1;
int year = localDate.getYear();
//如果是1月,上个月则是去年12月
if (localDate.getMonthValue() == 1) {
month = 12;
year = year - 1;
}
Optional<TbCfUserInfo> byId = userRepository.findById(id);
if (!byId.isPresent()) return null;
//Calculate sum of bonus in single month
......@@ -119,7 +123,7 @@ public class BonusController extends Controller {
nativeQuery.setParameter("year", year);
List<Bonus> bonuses = repository.findAllByUser_IdAndCreateDateMonthAndCreateDateYear(byId.get(), month, year, PageRequest.of(pageNo, pageSize)).toList();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("total", BigDecimal.valueOf((double)nativeQuery.getSingleResult()).setScale(3,RoundingMode.HALF_UP));
hashMap.put("total", BigDecimal.valueOf((double) nativeQuery.getSingleResult()).setScale(3, RoundingMode.HALF_UP));
hashMap.put("list", bonuses);
return hashMap;
}
......@@ -127,7 +131,7 @@ public class BonusController extends Controller {
@GetMapping(value = "/list/today")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public Map<String, Object> getListByUserAndToday(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return getListByUserAndToday(user.userId(),pageNo,pageSize);
return getListByUserAndToday(user.userId(), pageNo, pageSize);
}
@Deprecated
......@@ -147,7 +151,7 @@ public class BonusController extends Controller {
nativeQuery.setParameter("year", year);
List<Bonus> bonuses = repository.findAllByUser_IdAndCreateDate(byId.get(), dayOfYear, year, PageRequest.of(pageNo, pageSize)).toList();
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("total", BigDecimal.valueOf((double)nativeQuery.getSingleResult()).setScale(3,RoundingMode.HALF_UP));
hashMap.put("total", BigDecimal.valueOf((double) nativeQuery.getSingleResult()).setScale(3, RoundingMode.HALF_UP));
hashMap.put("list", bonuses);
return hashMap;
}
......@@ -174,7 +178,7 @@ public class BonusController extends Controller {
bonus1.setStationItem(itemOptional.get());
bonus1.setPost(post);
bonus1.setUserInfo(byId.get());
bonus1.setAmount(amount.multiply(BigDecimal.valueOf(10)).divide(BigDecimal.valueOf(100),RoundingMode.CEILING));
bonus1.setAmount(amount.multiply(BigDecimal.valueOf(10)).divide(BigDecimal.valueOf(100), RoundingMode.CEILING));
bonus1.setPercentage(10.0);
repository.save(bonus1);
}
......@@ -260,23 +264,23 @@ public class BonusController extends Controller {
return new Result<>(bonus);
}
private TbCfUserInfo runBonusInc(TbCfUserInfo user, BigDecimal 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.findFirstByNetworkInfoCode(user.getCode());
if (userCode.isPresent() || direct) {
TbCfUserInfo userInfo = direct ? user : userCode.get().getUserInfo();
Bonus bonus = new Bonus();
bonus.setUserInfo(userInfo);
BigDecimal v = amount.multiply(BigDecimal.valueOf(percent));
v = v.divide(BigDecimal.valueOf(100),RoundingMode.CEILING);
BigDecimal v = amount.multiply(BigDecimal.valueOf(percent));
v = v.divide(BigDecimal.valueOf(100), RoundingMode.CEILING);
bonus.setAmount(v);
bonus.setPercentage(percent);
bonus.setOrderId(orderId);
if (userInfo.invited()){
if (userInfo.invited()) {
repository.save(bonus);
bonus = repository.save(bonus);
if( userInfo.hasFcm() ){
sendNotification(userInfo.getFcm(),"Bonus alert !!",userInfo.display()+", You received bonus of $"+formatter.format(v)+" in your account");
if (userInfo.hasFcm()) {
sendNotification(userInfo.getFcm(), "Bonus alert !!", userInfo.display() + ", You received bonus of $" + formatter.format(v) + " in your account");
}
}
return userInfo;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论