diff --git a/src/main/java/au/com/royalpay/payment/manage/actchairty/core/impls/ActChairtyServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/actchairty/core/impls/ActChairtyServiceImp.java index 494d041c8..30c3c928f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/actchairty/core/impls/ActChairtyServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/actchairty/core/impls/ActChairtyServiceImp.java @@ -17,8 +17,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -68,48 +66,48 @@ public class ActChairtyServiceImp implements ActChairtyService { List result = new ArrayList<>(); List getAnalysis = actChairtyMapper.getChairtyWeekAnalysis(params.getDate("begin"), params.getDate("end")); DateFormatUtils df = new DateFormatUtils(); - Calendar cal = Calendar.getInstance(); - cal.setTime(params.getDate("begin")); - cal.add(cal.DAY_OF_MONTH, -1); - long beginTime = params.getDate("begin").getTime(); - long endTime = params.getDate("end").getTime(); - long betweenDays = (long)((endTime - beginTime) / (1000 * 60 * 60 *24)); - List weekStart = new ArrayList<>(); - for(int i=0;i<=betweenDays;i++){ - cal.add(cal.DAY_OF_MONTH, 1);//DATE=日 - if ((cal.get(Calendar.DAY_OF_WEEK)) == 2) { - weekStart.add(df.format(cal.getTime(),"yyyy-MM-dd")); + Calendar cal = Calendar.getInstance(); + cal.setTime(params.getDate("begin")); + cal.add(cal.DAY_OF_MONTH, -1); + long beginTime = params.getDate("begin").getTime(); + long endTime = params.getDate("end").getTime(); + long betweenDays = (long)((endTime - beginTime) / (1000 * 60 * 60 *24)); + List weekStart = new ArrayList<>(); + for(int i=0;i<=betweenDays;i++){ + cal.add(cal.DAY_OF_MONTH, 1);//DATE=日 + if ((cal.get(Calendar.DAY_OF_WEEK)) == 2) { + weekStart.add(df.format(cal.getTime(),"yyyy-MM-dd")); + } } - } - for(int i=0;i= dateStar.getTime() && orderDate < dateEnd.getTime()) { - count_ordernum = count_ordernum.add(getAnalysis.get(b).getBigDecimal("count_ordernum")); - sum_ordernum = sum_ordernum.add(getAnalysis.get(b).getBigDecimal("sum_ordernum")); + for(int i=0;i= dateStar.getTime() && orderDate < dateEnd.getTime()) { + count_ordernum = count_ordernum.add(getAnalysis.get(b).getBigDecimal("count_ordernum")); + sum_ordernum = sum_ordernum.add(getAnalysis.get(b).getBigDecimal("sum_ordernum")); + } } - } - BigDecimal chairty = new BigDecimal(0.01); - BigDecimal chairty_amount = count_ordernum.multiply(chairty); - BigDecimal f1 = sum_ordernum.setScale(2, BigDecimal.ROUND_HALF_UP); - BigDecimal f2 = chairty_amount.setScale(2, BigDecimal.ROUND_HALF_UP); - weekDay.put("weekstart", weekStart.get(i)); - weekDay.put("count_ordernum", count_ordernum); - weekDay.put("sum_ordernum", f1); - weekDay.put("chairty_amount",f2 ); - result.add(weekDay); - } catch (Exception e) { - logger.info("Act_Chairty Error:",e); + BigDecimal chairty = new BigDecimal(0.01); + BigDecimal chairty_amount = count_ordernum.multiply(chairty); + BigDecimal f1 = sum_ordernum.setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal f2 = chairty_amount.setScale(2, BigDecimal.ROUND_HALF_UP); + weekDay.put("weekstart", weekStart.get(i)); + weekDay.put("count_ordernum", count_ordernum); + weekDay.put("sum_ordernum", f1); + weekDay.put("chairty_amount",f2 ); + result.add(weekDay); + } catch (Exception e) { + logger.info("Act_Chairty Error:",e); + } } - } return result; } diff --git a/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java b/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java index 841bc9b33..907c34b6a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java +++ b/src/main/java/au/com/royalpay/payment/manage/customers/web/EncourageMoneyController.java @@ -3,9 +3,19 @@ package au.com.royalpay.payment.manage.customers.web; import au.com.royalpay.payment.manage.customers.core.EncourageService; import au.com.royalpay.payment.tools.CommonConsts; import au.com.royalpay.payment.tools.connections.mpsupport.beans.WxOauthType; +import au.com.royalpay.payment.tools.permission.alipay.AlipayMapping; import au.com.royalpay.payment.tools.permission.wechat.WechatMapping; + import com.alibaba.fastjson.JSONObject; -import org.springframework.web.bind.annotation.*; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; @@ -13,38 +23,46 @@ import javax.annotation.Resource; /** * Created by yixian on 2017-04-28. */ -@RestController +@Controller @RequestMapping("/act/encourage_money") public class EncourageMoneyController { + Logger logger = LoggerFactory.getLogger(getClass()); @Resource private EncourageService encourageService; - @RequestMapping(value = "/orders/{orderId}", method = RequestMethod.PUT) - public String takeEncourageMoney(@PathVariable String orderId,@RequestHeader("User-Agent") String ua) { - ua = ua.toLowerCase(); - if (ua.contains("micromessenger")) { - return "redirect:/act/encourage_money/orders/" + orderId + "/wechat"; + @RequestMapping(value = "/orders/{orderId}", method = RequestMethod.GET) + public JSONObject takeEncourageMoney(@PathVariable String orderId,@ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser,@ModelAttribute(CommonConsts.ALIUSER) JSONObject aliuser) { + String user_id = ""; + if(wxUser==null){ + user_id = aliuser.getString("user_id"); + }else { + user_id = wxUser.getString("openid"); } - if (ua.contains("alipayclient")) { - return "redirect:/act/encourage_money/orders/" + orderId + "/alipay"; + if(StringUtils.isEmpty(user_id)){ + return new JSONObject(); } - return null; + return encourageService.takeEncourageMoney(orderId, user_id); } - @RequestMapping(value = "/orders/{orderId}/wechat", method = RequestMethod.PUT) + @RequestMapping(value = "/orders/{orderId}/wechat", method = RequestMethod.GET) public JSONObject takeEncourageMoneyWeChat(@PathVariable String orderId, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser) { + logger.info("kiratest---wechat"); if (wxUser == null) { return new JSONObject(); } + logger.info(wxUser.toJSONString()); return encourageService.takeEncourageMoney(orderId, wxUser.getString("openid")); } - @RequestMapping(value = "/orders/{orderId}/alipay", method = RequestMethod.PUT) + @AlipayMapping(value = "/orders/{orderId}/alipay", method = RequestMethod.GET) public JSONObject takeEncourageMoneyAlipay(@PathVariable String orderId, @ModelAttribute(CommonConsts.ALIUSER) JSONObject alipayInfo) { + logger.info("kiratest---alipay"); + if (alipayInfo == null) { return new JSONObject(); } + logger.info(alipayInfo.toJSONString()); return encourageService.takeEncourageMoney(orderId, alipayInfo.getString("user_id")); } diff --git a/src/main/ui/static/templates/payment/success.js b/src/main/ui/static/templates/payment/success.js index 8bb8587a3..2fff056c0 100644 --- a/src/main/ui/static/templates/payment/success.js +++ b/src/main/ui/static/templates/payment/success.js @@ -33,7 +33,7 @@ $(function () { function loadEncourage() { $.ajax({ url: '/act/encourage_money/orders/' + window.order_id, - method: 'PUT', + method: 'GET', dataType: 'json', success: function (encourage) { if (encourage.access_amount) {