Guest User

Untitled

a guest
Jun 25th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. private boolean checkCondition(PageData pd, int type) {
  2. PageData condPd = new PageData();
  3. try {
  4. if (0 == type) {
  5. //当天得到运动币>10 return false else return true
  6. condPd.put("TYPE", 1);
  7. condPd.put("USERID", pd.getString("USERID"));
  8. condPd.put("OPERATORID", 621965); //Admin 3
  9. String today = DateUtil.getDay();
  10. String startTime = today + " 00:00:00";
  11. String endTime = today + " 23:59:59";
  12. condPd.put("STARTTIME", startTime);
  13. condPd.put("ENDTIME", endTime);
  14. condPd = transactionService.getTranByUserIdCurrencyType(condPd);
  15. if (condPd == null) {
  16. return false;
  17. }
  18. if ((long) condPd.get("c") < 10) {
  19. return true;
  20. } else {
  21. return false;
  22. }
  23. } else if (1 == type) {
  24. // A 送 B A +1 B+1 当天内 A 送 B和B送A 都不能再拿 不过第二天 A送 B A+1 B+1
  25. condPd.put("TYPE", 1);
  26. condPd.put("USERID", pd.getString("USERID"));
  27. condPd.put("OPERATORID", 621965); // Admin 3
  28. condPd.put("RECIVEUSER_ID", pd.getString("RECIVEUSER_ID"));
  29. String today = DateUtil.getDay();
  30. condPd.put("CURRENTDATE", today);
  31. condPd = transactionService.getTranBetweenUserGivenSteps(condPd);
  32. if (condPd == null) {
  33. return false;
  34. }
  35. if ((long) condPd.get("c") <= 0) {
  36. return true;
  37. } else {
  38. return false;
  39. }
  40. }
  41. } catch (Exception e) {
  42. return false;
  43. }
  44. return false;
  45. }
  46.  
  47. private PageData deposit(PageData pd, int[] conditions) throws Exception {
  48.  
  49. PageData result = new PageData();
  50. for (int condition : conditions) {
  51. if (!checkCondition(pd, condition)) {
  52. result.put("result", "c=" + condition);
  53. return result;
  54. }
  55. }
  56.  
  57. int currencyType = Integer.parseInt(pd.getString("currencyType"));
  58. pd.put("TYPE", currencyType);
  59. pd.put("TIMESTAMP", DateUtil.getTime());
  60. pd.put("VOLUME", pd.get("volume"));
  61. double volume = (double) (pd.get("volume"));
  62. volume = NumUtil.doubleRound(volume, 2);
  63.  
  64. PageData tmp = new PageData();
  65. try {
  66. double balance = (double) (accountService.getBalance(pd).get(0).get("BALANCE"));
  67. balance = NumUtil.doubleRound(balance, 2);
  68. tmp = accountService.getAccountIdByUserIdCurrencyType(pd);
  69. pd.put("ACCOUNTID", tmp.get("ACCOUNTID").toString());
  70. pd.put("PREBAL", balance);
  71. pd.put("BALANCE", balance + volume);
  72. accountService.edit(pd);
  73. } catch (Exception e) {
  74. // no accountid for user means we need to create an account record for this user
  75. pd.put("BALANCE", pd.get("volume"));
  76. pd.put("PREBAL", 0.0);
  77. accountService.save(pd);
  78. } finally {
  79. if (pd.getOptional("eventId").isPresent()) {
  80. pd.put("EVENTID", pd.get("eventId").toString());
  81. }
  82. transactionService.save(pd);
  83. result.put("result", "01");
  84. }
  85.  
  86. return result;
  87. }
  88.  
  89. private PageData withdraw(PageData pd) throws Exception {
  90. PageData result = new PageData();
  91. int currencyType = Integer.parseInt(pd.getString("currencyType"));
  92. pd.put("TYPE", currencyType);
  93. double balance = (double) (accountService.getBalance(pd).get(0).get("BALANCE"));
  94. balance = NumUtil.doubleRound(balance, 2);
  95. double volume = (double) (pd.get("volume"));
  96. volume = NumUtil.doubleRound(volume, 2);
  97.  
  98. if (balance - volume >= 0.000001) {
  99. PageData tmp = accountService.getAccountIdByUserIdCurrencyType(pd);
  100. pd.put("ACCOUNTID", tmp.get("ACCOUNTID").toString());
  101. if (pd.getOptional("eventId").isPresent()) {
  102. pd.put("EVENTID", pd.getString("eventId"));
  103. }
  104. pd.put("PREBAL", balance);
  105. pd.put("TYPE", pd.getString("currencyType"));
  106. pd.put("VOLUME", 0 - volume);
  107. pd.put("TIMESTAMP", DateUtil.getTime());
  108. transactionService.save(pd);
  109. pd.put("BALANCE", balance - volume);
  110. accountService.edit(pd);
  111. result.put("result", "01");
  112. } else {
  113. result.put("result", "00");
  114. }
  115. return result;
  116. }
  117.  
  118. private List<PageData> getBalance(PageData pd) throws Exception {
  119. if (!pd.getOptional("USERID").isPresent()) {
  120. return new ArrayList<PageData>();
  121. }
  122. int currencyType = Integer.parseInt(pd.getString("currencyType"));
  123. pd.put("TYPE", currencyType);
  124. return accountService.getBalance(pd);
  125. }
  126.  
  127. /**
  128. * 19. Get account balance
  129. *
  130. * @return
  131. */
  132. @RequestMapping(value = "/checkBalance")
  133. @ResponseBody
  134. public Object checkBalance() {
  135. // INPUT userInfoId, currencyType
  136. logBefore(logger, "Check Balance");
  137. Map<String, Object> map = new HashMap<String, Object>();
  138. PageData pd = this.getPageData();
  139. String result = "00";
  140. try {
  141. if (Tools.checkKey("checkBalance", pd.getString("FKEY"))) { //检验请求key值是否合法
  142. if (AppUtil.checkParam("checkBalance", pd)) { //检查参数
  143. // Get internal userId
  144. String userInfoId = pd.getString("userInfoId");
  145. String userId = getInternalUserId(userInfoId);
  146. if (userId.equals("")) {
  147. result = "04";
  148. } else {
  149. pd.put("USERID", userId);
  150. List<PageData> listPd = getBalance(pd);
  151. map.put("pd", listPd);
  152. result = (null == listPd) ? "02" : "01";
  153. }
  154. } else {
  155. result = "03";
  156. }
  157. } else {
  158. result = "05";
  159. }
  160. } catch (Exception e) {
  161. logger.error(e.toString(), e);
  162. } finally {
  163. map.put("result", result);
  164. logAfter(logger);
  165. }
  166. return AppUtil.returnObject(new PageData(), map);
  167. }
Add Comment
Please, Sign In to add comment