Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean checkCondition(PageData pd, int type) {
- PageData condPd = new PageData();
- try {
- if (0 == type) {
- //当天得到运动币>10 return false else return true
- condPd.put("TYPE", 1);
- condPd.put("USERID", pd.getString("USERID"));
- condPd.put("OPERATORID", 621965); //Admin 3
- String today = DateUtil.getDay();
- String startTime = today + " 00:00:00";
- String endTime = today + " 23:59:59";
- condPd.put("STARTTIME", startTime);
- condPd.put("ENDTIME", endTime);
- condPd = transactionService.getTranByUserIdCurrencyType(condPd);
- if (condPd == null) {
- return false;
- }
- if ((long) condPd.get("c") < 10) {
- return true;
- } else {
- return false;
- }
- } else if (1 == type) {
- // A 送 B A +1 B+1 当天内 A 送 B和B送A 都不能再拿 不过第二天 A送 B A+1 B+1
- condPd.put("TYPE", 1);
- condPd.put("USERID", pd.getString("USERID"));
- condPd.put("OPERATORID", 621965); // Admin 3
- condPd.put("RECIVEUSER_ID", pd.getString("RECIVEUSER_ID"));
- String today = DateUtil.getDay();
- condPd.put("CURRENTDATE", today);
- condPd = transactionService.getTranBetweenUserGivenSteps(condPd);
- if (condPd == null) {
- return false;
- }
- if ((long) condPd.get("c") <= 0) {
- return true;
- } else {
- return false;
- }
- }
- } catch (Exception e) {
- return false;
- }
- return false;
- }
- private PageData deposit(PageData pd, int[] conditions) throws Exception {
- PageData result = new PageData();
- for (int condition : conditions) {
- if (!checkCondition(pd, condition)) {
- result.put("result", "c=" + condition);
- return result;
- }
- }
- int currencyType = Integer.parseInt(pd.getString("currencyType"));
- pd.put("TYPE", currencyType);
- pd.put("TIMESTAMP", DateUtil.getTime());
- pd.put("VOLUME", pd.get("volume"));
- double volume = (double) (pd.get("volume"));
- volume = NumUtil.doubleRound(volume, 2);
- PageData tmp = new PageData();
- try {
- double balance = (double) (accountService.getBalance(pd).get(0).get("BALANCE"));
- balance = NumUtil.doubleRound(balance, 2);
- tmp = accountService.getAccountIdByUserIdCurrencyType(pd);
- pd.put("ACCOUNTID", tmp.get("ACCOUNTID").toString());
- pd.put("PREBAL", balance);
- pd.put("BALANCE", balance + volume);
- accountService.edit(pd);
- } catch (Exception e) {
- // no accountid for user means we need to create an account record for this user
- pd.put("BALANCE", pd.get("volume"));
- pd.put("PREBAL", 0.0);
- accountService.save(pd);
- } finally {
- if (pd.getOptional("eventId").isPresent()) {
- pd.put("EVENTID", pd.get("eventId").toString());
- }
- transactionService.save(pd);
- result.put("result", "01");
- }
- return result;
- }
- private PageData withdraw(PageData pd) throws Exception {
- PageData result = new PageData();
- int currencyType = Integer.parseInt(pd.getString("currencyType"));
- pd.put("TYPE", currencyType);
- double balance = (double) (accountService.getBalance(pd).get(0).get("BALANCE"));
- balance = NumUtil.doubleRound(balance, 2);
- double volume = (double) (pd.get("volume"));
- volume = NumUtil.doubleRound(volume, 2);
- if (balance - volume >= 0.000001) {
- PageData tmp = accountService.getAccountIdByUserIdCurrencyType(pd);
- pd.put("ACCOUNTID", tmp.get("ACCOUNTID").toString());
- if (pd.getOptional("eventId").isPresent()) {
- pd.put("EVENTID", pd.getString("eventId"));
- }
- pd.put("PREBAL", balance);
- pd.put("TYPE", pd.getString("currencyType"));
- pd.put("VOLUME", 0 - volume);
- pd.put("TIMESTAMP", DateUtil.getTime());
- transactionService.save(pd);
- pd.put("BALANCE", balance - volume);
- accountService.edit(pd);
- result.put("result", "01");
- } else {
- result.put("result", "00");
- }
- return result;
- }
- private List<PageData> getBalance(PageData pd) throws Exception {
- if (!pd.getOptional("USERID").isPresent()) {
- return new ArrayList<PageData>();
- }
- int currencyType = Integer.parseInt(pd.getString("currencyType"));
- pd.put("TYPE", currencyType);
- return accountService.getBalance(pd);
- }
- /**
- * 19. Get account balance
- *
- * @return
- */
- @RequestMapping(value = "/checkBalance")
- @ResponseBody
- public Object checkBalance() {
- // INPUT userInfoId, currencyType
- logBefore(logger, "Check Balance");
- Map<String, Object> map = new HashMap<String, Object>();
- PageData pd = this.getPageData();
- String result = "00";
- try {
- if (Tools.checkKey("checkBalance", pd.getString("FKEY"))) { //检验请求key值是否合法
- if (AppUtil.checkParam("checkBalance", pd)) { //检查参数
- // Get internal userId
- String userInfoId = pd.getString("userInfoId");
- String userId = getInternalUserId(userInfoId);
- if (userId.equals("")) {
- result = "04";
- } else {
- pd.put("USERID", userId);
- List<PageData> listPd = getBalance(pd);
- map.put("pd", listPd);
- result = (null == listPd) ? "02" : "01";
- }
- } else {
- result = "03";
- }
- } else {
- result = "05";
- }
- } catch (Exception e) {
- logger.error(e.toString(), e);
- } finally {
- map.put("result", result);
- logAfter(logger);
- }
- return AppUtil.returnObject(new PageData(), map);
- }
Add Comment
Please, Sign In to add comment