| | |
| | | import com.google.gson.stream.JsonWriter; |
| | | import com.taoke.autopay.dao.KeyOrderMapper; |
| | | import com.taoke.autopay.dto.DYOrderDto; |
| | | import com.taoke.autopay.entity.ClientInfo; |
| | | import com.taoke.autopay.entity.KeyOrder; |
| | | import com.taoke.autopay.entity.*; |
| | | |
| | | import com.taoke.autopay.exception.KeyOrderException; |
| | | import com.taoke.autopay.exception.KeyVerifyException; |
| | | import com.taoke.autopay.exception.WxOrderCountException; |
| | | import com.taoke.autopay.factory.OrderFactory; |
| | | import com.taoke.autopay.service.ClientInfoService; |
| | | import com.taoke.autopay.service.KeyOrderService; |
| | | import com.taoke.autopay.utils.JsonUtil; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.manager.OrderPayFailProcessor; |
| | | import com.taoke.autopay.service.*; |
| | | import com.taoke.autopay.utils.*; |
| | | import com.taoke.autopay.utils.order.DYOrderApi; |
| | | import com.taoke.autopay.vo.AcceptData; |
| | | import com.taoke.autopay.vo.KeyOrderVO; |
| | | import com.taoke.autopay.vo.OrderFilter; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * @author hxh |
| | |
| | | // 判断是否是同一天 |
| | | desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"); |
| | | out.value(desc); |
| | | } else |
| | | } else { |
| | | out.value(""); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Resource |
| | | private ClientInfoService clientInfoService; |
| | | |
| | | @Resource |
| | | private WxUserOrderCountService wxUserOrderCountService; |
| | | |
| | | @Resource |
| | | private WxUserSettingService wxUserSettingService; |
| | | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | @Resource |
| | | private OrderPayFailProcessor orderPayFailProcessor; |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("listOrder") |
| | |
| | | } |
| | | |
| | | /** |
| | | * @author hxh |
| | | * @return java.lang.String 返回是否可以去支付 |
| | | * @author hxh |
| | | * @description 设置订单号 |
| | | * @date 23:08 2024/6/24 |
| | | * @param: acceptData |
| | | * @param: id 订单ID |
| | | * @param: orderNo 订单号 |
| | | * @param: orderStatus 订单状态:订单已取消/已支付 |
| | | * @return java.lang.String |
| | | **/ |
| | | @ResponseBody |
| | | @RequestMapping("setOrderNo") |
| | |
| | | } |
| | | |
| | | try { |
| | | if (!StringUtil.isNullOrEmpty(orderStatus)) { |
| | | throw new KeyOrderException(orderStatus); |
| | | } |
| | | DYOrderDto dto = DYOrderApi.getOrderDetail(orderNo); |
| | | // dto.setOrder_status(1); |
| | | if (dto.getOrder_status() != DYOrderDto.ORDER_STATUS_NOT_PAY) { |
| | |
| | | orderUpdate.setOrderState(dto.getOrder_status()); |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderChannel(dto.getOrderChannel()); |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO); |
| | | if (order.getState() == KeyOrder.STATE_NOT_PROCESS) { |
| | | if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) { |
| | | if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) { |
| | | orderUpdate.setState(KeyOrder.STATE_PAY); |
| | | orderUpdate.setStateDesc(dto.getOrder_status_desc()); |
| | | } else { |
| | |
| | | throw new Exception("订单已支付"); |
| | | } |
| | | } |
| | | |
| | | if (order.getUid() != null) { |
| | | WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); |
| | | if (countInfo != null) { |
| | | WxUserSettings settings = wxUserSettingService.getUserSettings(order.getUid()); |
| | | if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) { |
| | | throw new Exception("今日已达支付次数上限:" + settings.getDyOrderCountPerDay()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置进入 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderState(dto.getOrder_status()); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderChannel(dto.getOrderChannel()); |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO); |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | keyOrderService.update(orderUpdate); |
| | | order = keyOrderService.selectById(id); |
| | | return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order))); |
| | |
| | | orderUpdate.setOrderState(0); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setState(KeyOrder.STATE_REJECT_PAY); |
| | | if (order.getExcutePayTime() == null) { |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | } |
| | | orderUpdate.setStateDesc(e.getMessage()); |
| | | keyOrderService.update(orderUpdate); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("setOrderNoV2") |
| | | public String setOrderNoV2(AcceptData acceptData, String id, String orderNoDesc, String orderStatus, String money) { |
| | | loggerPay.info("setOrderNo: {}-{}-{}-{}", id, orderNoDesc, orderStatus, money); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(money)) { |
| | | return JsonUtil.loadFalseResult("请上传money"); |
| | | } |
| | | |
| | | KeyOrder order = keyOrderService.selectById(id); |
| | | if (order == null) { |
| | | return JsonUtil.loadFalseResult("口令不存在"); |
| | | } |
| | | |
| | | money = money.replace("¥",""); |
| | | |
| | | int orderType=Constant.ORDER_TYPE_UNKNOWN; |
| | | |
| | | if(orderNoDesc.contains("抖音")||orderNoDesc.contains("上海格物致品")){ |
| | | orderType = Constant.ORDER_TYPE_DY; |
| | | }else if(orderNoDesc.contains("快手")){ |
| | | orderType = Constant.ORDER_TYPE_KS; |
| | | } |
| | | |
| | | String orderNo= ""; |
| | | try { |
| | | if(orderType==Constant.ORDER_TYPE_UNKNOWN){ |
| | | throw new KeyOrderException("未定义的订单类型"); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(orderStatus)) { |
| | | throw new KeyOrderException(orderStatus); |
| | | } |
| | | |
| | | DYOrderDto dyOrderDto =null; |
| | | try { |
| | | dyOrderDto = keyOrderService.verifyKey(orderNoDesc, orderStatus, money); |
| | | }catch(KeyVerifyException ve){ |
| | | throw new KeyOrderException("口令验证失败:" + ve.getMessage()); |
| | | } |
| | | // if(dyOrderDto!=null&&order.getOrderMoney()!=null){ |
| | | // // 判断订单支付金额与用户提交的金额是否匹配 |
| | | // if(dyOrderDto.getPay_amount()!=order.getOrderMoney().multiply(new BigDecimal(100)).setScale(0, RoundingMode.FLOOR).intValue()){ |
| | | // throw new KeyOrderException(String.format("订单接口金额不匹配:%s-%s",dyOrderDto.getPay_amount(),MoneyUtil.getMoneyStr(order.getOrderMoney()))); |
| | | // } |
| | | // } |
| | | if(dyOrderDto!=null){ |
| | | orderNo = dyOrderDto.getOrder_id(); |
| | | } |
| | | |
| | | |
| | | if (order.getUid() != null) { |
| | | OrderCountTypeEnum orderCountType=null; |
| | | switch (orderType){ |
| | | case Constant.ORDER_TYPE_DY: |
| | | orderCountType= OrderCountTypeEnum.DY_ORDER_PAY; |
| | | break; |
| | | case Constant.ORDER_TYPE_KS: |
| | | orderCountType= OrderCountTypeEnum.KS_ORDER_PAY; |
| | | break; |
| | | } |
| | | |
| | | WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), orderCountType, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); |
| | | if (countInfo != null) { |
| | | WxUserSettings settings = wxUserSettingService.getUserSettings(order.getUid()); |
| | | int maxOrderCount = settings.getDyOrderCountPerDay(); |
| | | if(orderCountType == OrderCountTypeEnum.KS_ORDER_PAY){ |
| | | maxOrderCount = settings.getKsOrderCountPerDay(); |
| | | } |
| | | if (maxOrderCount <= countInfo.getOrderCount()) { |
| | | throw new Exception("老铁今日已达支付次数上限:" + settings.getDyOrderCountPerDay()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置进入 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(orderType); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderMoney(new BigDecimal(money)); |
| | | if(dyOrderDto!=null){ |
| | | orderUpdate.setOrderState(dyOrderDto.getOrder_status()); |
| | | orderUpdate.setOrderChannel(dyOrderDto.getOrderChannel()); |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO); |
| | | }else{ |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_MONEY); |
| | | } |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | keyOrderService.update(orderUpdate); |
| | | order = keyOrderService.selectById(id); |
| | | return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order))); |
| | | } catch (KeyOrderException e) { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(orderType); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderMoney(new BigDecimal(money)); |
| | | orderUpdate.setOrderState(0); |
| | | orderUpdate.setState(KeyOrder.STATE_REJECT_PAY); |
| | | if (order.getExcutePayTime() == null) { |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | } |
| | | orderUpdate.setStateDesc(e.getMessage()); |
| | | keyOrderService.update(orderUpdate); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("setPayResult") |
| | | public String setPayResult(AcceptData acceptData, String id, boolean paySuccess, String msg) { |
| | | loggerPay.info("setPayResult: {}-{}", id, paySuccess); |
| | | loggerPay.info("setPayResult: {}-{}-{}", id, paySuccess, msg); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | |
| | | if (order == null) { |
| | | return JsonUtil.loadFalseResult("口令不存在"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(order.getOrderNo())) { |
| | | return JsonUtil.loadFalseResult("没有匹配到订单号"); |
| | | } |
| | | // if (StringUtil.isNullOrEmpty(order.getOrderNo())) { |
| | | // return JsonUtil.loadFalseResult("没有匹配到订单号"); |
| | | // } |
| | | |
| | | if(order.getState()==KeyOrder.STATE_NOT_PROCESS) { |
| | | if (order.getState() == KeyOrder.STATE_NOT_PROCESS) { |
| | | if (!paySuccess) { |
| | | // 支付失败 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_NOT_PAY); |
| | | orderUpdate.setStateDesc("支付失败"); |
| | | keyOrderService.update(orderUpdate); |
| | | if(msg!=null&&msg.contains("超时")) |
| | | { |
| | | loggerPay.info(String.format("因为超时支付失败不处理:%s-%s", order.getId(), msg)); |
| | | orderPayFailProcessor.processPayFail(order.getId(), msg); |
| | | }else { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_NOT_PAY); |
| | | orderUpdate.setStateDesc("支付失败"); |
| | | keyOrderService.update(orderUpdate); |
| | | } |
| | | loggerPay.info("处理支付失败完成"); |
| | | } else { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_PAY); |
| | | orderUpdate.setStateDesc("支付成功"); |
| | | keyOrderService.update(orderUpdate); |
| | | try { |
| | | keyOrderService.paySuccess(id, "支付成功", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); |
| | | loggerPay.info("处理支付成功完成"); |
| | | } catch (WxOrderCountException e) { |
| | | loggerPay.error(e.getMessage()); |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | return JsonUtil.loadTrueResult(""); |
| | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("deleteAll") |
| | | public String deleteAll(AcceptData acceptData,Long uid) { |
| | | public String deleteAll(AcceptData acceptData, Long uid) { |
| | | |
| | | ClientInfo user= clientInfoService.selectByPrimaryKey(uid); |
| | | if(user==null){ |
| | | return JsonUtil.loadFalseResult("用户不存在"); |
| | | } |
| | | ClientInfo user = clientInfoService.selectByPrimaryKey(uid); |
| | | if (user == null) { |
| | | return JsonUtil.loadFalseResult("用户不存在"); |
| | | } |
| | | |
| | | if(user.getRule() != ClientInfo.RULE_ADMIN){ |
| | | return JsonUtil.loadFalseResult("只有管理员才能删除"); |
| | | } |
| | | if (user.getRule() != ClientInfo.RULE_ADMIN) { |
| | | return JsonUtil.loadFalseResult("只有管理员才能删除"); |
| | | } |
| | | |
| | | // 删除24小时之前的数据 |
| | | // keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 24*60*60*1000L)); |