yujian
2020-03-25 010760fd974453a70948fef465284d8c817314f5
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserOrderControllerV2.java
@@ -14,10 +14,13 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.NumberUtil;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.order.ESOrder;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
@@ -33,7 +36,10 @@
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.vo.order.CommonOrderVO;
import com.yeshi.fanli.vo.order.GoodsRebateVO;
import com.yeshi.fanli.vo.order.OrderCountVO;
import com.yeshi.fanli.vo.order.OrderRebateVO;
import com.yeshi.fanli.vo.order.TeamBonusVO;
import com.yeshi.fanli.vo.user.UserInfoExtraVO;
import com.yeshi.fanli.vo.user.UserSettingsVO;
@@ -110,7 +116,7 @@
      
      // 搜索内容、订单号
      if (!StringUtil.isNullOrEmpty(orderNo) && VersionUtil.greaterThan_2_0_6(acceptData.getPlatform(), acceptData.getVersion())) {
         searchOrder(orderNo, page, uid, out);
         searchOrder(acceptData, orderNo, page, uid, out);
         return;
      }
      
@@ -180,18 +186,23 @@
         endTime += " 23:59:59";
      }
      List<Integer> listSource = new ArrayList<>();
      if (goodsType != null) {
         listSource.add(goodsType);
      }
      try {
         // 筛选结果顶部统计
         String validMoney = "0.00";
         String invalidMoney = "0.00";
         if (page == 1) {
            BigDecimal predictMoney = hongBaoV2CountService.getRewardMoneyByToSearch(uid, dateType, orderType, 1,
                  orderNo, state, goodsType, startTime, endTime);
                  orderNo, state, startTime, endTime, listSource);
            if (predictMoney != null) 
               validMoney = predictMoney.setScale(2, BigDecimal.ROUND_DOWN).toString();
            
            BigDecimal postSaleMoney = hongBaoV2CountService.getRewardMoneyByToSearch(uid, dateType, orderType, 2,
                  orderNo, state, goodsType, startTime, endTime);
                  orderNo, state, startTime, endTime, listSource);
            if (postSaleMoney != null) 
               invalidMoney = postSaleMoney.setScale(2, BigDecimal.ROUND_DOWN).toString();
            
@@ -206,23 +217,24 @@
                  
         // 查询列表
         List<CommonOrderVO> list = commonOrderService.getOrderByUid(acceptData, page, uid, state, orderType, orderState,
               orderNo, startTime, endTime, dateType, goodsType);
               orderNo, startTime, endTime, dateType, listSource);
         // 统计总数
         long count = commonOrderService.countGroupOrderNoByUid(uid, state, orderType, orderState, orderNo, startTime,
               endTime, dateType, goodsType);
               endTime, dateType, listSource);
         // 判断是否需要显示订单找回提示   8秒内请求3次触发
         String orderFindUrl = null;
         if (state ==null && page == 1) {
            if (redisManager.frequencyLimit("orderlist-" + acceptData.getDevice(), 8, 4)||count==0L) {
               orderFindUrl = configService.get("order_find_notify_url");
               orderFindUrl = configService.get(ConfigKeyEnum.orderFindNotifyUrl.getKey());
            }
         }
         
         JSONObject data = new JSONObject();
         data.put("count", count);
         data.put("result_list", JsonUtil.getApiCommonGson().toJson(list));
         data.put("helpUrl", configService.get("order_list_help"));
         data.put("helpUrl", configService.get(ConfigKeyEnum.orderListHelp.getKey()));
         data.put("bonusLink", configService.get(ConfigKeyEnum.orderBonusLink.getKey()));
         data.put("validMoney", "¥ " + validMoney);
         data.put("invalidMoney", "¥ " + invalidMoney);
         data.put("findOrderHelpUrl", orderFindUrl);
@@ -240,15 +252,24 @@
    * @param key
    * @param out
    */
   private void searchOrder(String key, Integer page, Long uid, PrintWriter out) {
   private void searchOrder(AcceptData acceptData, String key, Integer page, Long uid, PrintWriter out) {
      try {
         long count = 0;
         List<CommonOrderVO> list = null;
         List<ESOrder> listES = esOrderService.multiMatchQuery(key, uid.toString());
         if (listES.size() != 0) {
            list = commonOrderService.searchOrderByUid(page, Constant.PAGE_SIZE, uid, listES);
            count = commonOrderService.countSearchOrderByUid(uid, listES);
         if (NumberUtil.isNumeric(key.replace("-", ""))) {
            list = commonOrderService.getOrderByUid(acceptData, page, uid, null, null, null, key, null, null, null, null);
         }
         if (list == null || list.size() == 0) {
            List<ESOrder> listES = esOrderService.query(key, uid.toString(), null);
            if (listES.size() != 0) {
               list = commonOrderService.searchOrderByUid(acceptData, page, Constant.PAGE_SIZE, uid, listES);
               count = commonOrderService.countSearchOrderByUid(uid, listES);
            }
         } else {
            count = list.size();
         }
         if (list == null) {
            list = new ArrayList<>();
         }
@@ -271,6 +292,7 @@
    * @param acceptData
    * @param uid
    *            用户id
    *    type 类型:0全部、1淘宝 2京东、拼多多
    * @param out
    */
   @RequestMapping(value = "getOrderCount", method = RequestMethod.POST)
@@ -296,8 +318,9 @@
         JSONObject data = new JSONObject();
         data.put("userInfo", userInfo);
         
         List<Integer> listSource = new ArrayList<>();
         if (type == null || type == 0) {
            OrderCountVO total = commonOrderService.getOrderCount(uid, null, type);
            OrderCountVO total = commonOrderService.getOrderCount(uid, null, null);
            data.put("total", total.getSelf() + total.getShared() + total.getInvite());
            data.put("self", total.getSelf());
            data.put("shared", total.getShared());
@@ -307,19 +330,21 @@
            data.put("self", 0);
            data.put("shared", 0);
            data.put("invite", 0);
            listSource.add(type);
         }
                  
         // 今天
         OrderCountVO today = commonOrderService.getOrderCount(uid, 1, type);
         OrderCountVO today = commonOrderService.getOrderCount(uid, 1, listSource);
         today.setTotal(today.getSelf() + today.getShared() + today.getInvite());
         // 昨天
         OrderCountVO yesterday = commonOrderService.getOrderCount(uid, 2, type);
         OrderCountVO yesterday = commonOrderService.getOrderCount(uid, 2, listSource);
         yesterday.setTotal(yesterday.getSelf() + yesterday.getShared() + yesterday.getInvite());
         // 本月
         OrderCountVO thisMonth = commonOrderService.getOrderCount(uid, 3, type);
         OrderCountVO thisMonth = commonOrderService.getOrderCount(uid, 3, listSource);
         thisMonth.setTotal(thisMonth.getSelf() + thisMonth.getShared() + thisMonth.getInvite());
         // 上月
         OrderCountVO lastMonth = commonOrderService.getOrderCount(uid, 4, type);
         OrderCountVO lastMonth = commonOrderService.getOrderCount(uid, 4, listSource);
         lastMonth.setTotal(lastMonth.getSelf() + lastMonth.getShared() + lastMonth.getInvite());
         data.put("today", today);
@@ -366,17 +391,136 @@
         show = hongBaoV2CountService.getHongBaoCount(uid, null) > 0;
      }
      
      BigDecimal selfMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 1);
      BigDecimal shareMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 2);
      BigDecimal inviteMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 3);
      BigDecimal selfMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 1, null);
      BigDecimal shareMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 2, null);
      BigDecimal inviteMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 3, null);
      
      JSONObject data = new JSONObject();
      data.put("show", show);
      data.put("selfMoney", selfMoney.setScale(2,BigDecimal.ROUND_DOWN).toString());
      data.put("shareMoney", shareMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
      data.put("inviteMoney", inviteMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
      // 团队奖励 TODO
      if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
         data.put("teamSubsidy", "999.66");
         data.put("teamReward", "777.66");
         data.put("tutorSubsidy", "888.66");
      }
      out.print(JsonUtil.loadTrueResult(data));
   }
   
   /**
    * 团队收益统计
    * @param acceptData
    * @param uid
    * @param type 1-团队补贴   2-团队奖励 3-导师津贴
    */
   @RequestMapping(value = "getTeamBonus", method = RequestMethod.POST)
   public void getTeamBonus(AcceptData acceptData, Long uid, Integer type, PrintWriter out) {
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
         return;
      }
      UserInfo user = userInfoService.selectByPKey(uid);
      if (user == null) {
         out.print(JsonUtil.loadFalseResult(1, "用户不存在"));
         return;
      }
      if (type == null || type < 1 || type > 3) {
         type = 1;
      }
      JSONObject data = new JSONObject();
      data.put("link", "https://www.baidu.com/");
      String total = "";
      if (type == 1) {
         total = "111.3";
      } else if (type == 2) {
         total = "222.3";
      } else if (type == 3) {
         total = "333.3";
      }
      if (StringUtil.isNullOrEmpty(total)) {
         data.put("exist", false);
      } else {
         data.put("exist",  true);
         data.put("portrait", user.getPortrait());
         TeamBonusVO today = new TeamBonusVO("1.3", "2.3" ,"3.6");
         TeamBonusVO yesterday = new TeamBonusVO("1.3", "2.3" ,"3.6");
         TeamBonusVO thisMonth = new TeamBonusVO("1.3", "2.3" ,"3.6");
         TeamBonusVO lastMonth = new TeamBonusVO("1.3", "2.3" ,"3.6");
         data.put("total", total);
         data.put("direct", "655.36");
         data.put("indirect", "236.58");
         data.put("today", today);
         data.put("yesterday", yesterday);
         data.put("thisMonth", thisMonth);
         data.put("lastMonth", lastMonth);
      }
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 返利说明
    * @param acceptData
    * @param uid
    * @param orderNo
    * @param sourceType
    * @param out
    */
   @RequestMapping(value = "getReBateInfo")
   public void getReBateInfo(String callback, AcceptData acceptData, Long uid, String orderNo, Integer sourceType, PrintWriter out) {
      if (uid == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户未登录"));
         return;
      }
      UserInfo user = userInfoService.selectByPKey(uid);
      if (user == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户不存在"));
         return;
      }
      GoodsRebateVO goodsVO = new GoodsRebateVO();
      goodsVO.setTitle("舒客舒克光感炫白牙片美白牙齿牙膜套装去黄牙清新口气");
      goodsVO.setPicture("https://img.alicdn.com/bao/uploaded/i4/355739614/O1CN01RB6Hlg2KtGMWR4mON_!!0-item_pic.jpg");
      goodsVO.setActualPay("¥60.00");
      goodsVO.setFanliRate("X20%");
      goodsVO.setFanliExpect("¥25.00");
      goodsVO.setCommision("10.00");
      goodsVO.setSubsidy("6.00");
      GoodsRebateVO goodsVO2 = new GoodsRebateVO();
      goodsVO2.setTitle("馥佩美白柔肤水爽肤水补水保湿女化妆湿敷精华水男旗舰店官网正品");
      goodsVO2.setPicture("https://img.alicdn.com/bao/uploaded/i4/738252756/O1CN01MgFdXy1WEI8zmkyg7_!!0-item_pic.jpg");
      goodsVO2.setActualPay("¥62.00");
      goodsVO2.setFanliRate("X22%");
      goodsVO2.setFanliExpect("¥26.00");
      goodsVO2.setCommision("12.00");
      goodsVO2.setSubsidy("8.00");
      List<GoodsRebateVO> listGoods= new ArrayList<>();
      listGoods.add(goodsVO);
      listGoods.add(goodsVO2);
      OrderRebateVO orderRebateVO = new OrderRebateVO();
      orderRebateVO.setTotalFanLi("¥50.00");
      orderRebateVO.setUpperFanLi("¥60.00");
      orderRebateVO.setUserLevel(UserLevelEnum.daRen.name());
      orderRebateVO.setJumpLink("https://www.baidu.com/");
      orderRebateVO.setListGoods(listGoods);
      JSONObject data = new JSONObject();
      data.put("result", orderRebateVO);
      JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
   }
}