| | |
| | | import com.agentdriving.user.modular.system.model.*; |
| | | import com.agentdriving.user.modular.system.service.*; |
| | | import com.agentdriving.user.modular.system.util.*; |
| | | import com.agentdriving.user.modular.system.util.MallBook.model.*; |
| | | import com.agentdriving.user.modular.system.warpper.*; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.agentdriving.user.core.util.ToolUtil; |
| | | import com.agentdriving.user.modular.system.dao.OrderMapper; |
| | | import com.agentdriving.user.modular.system.model.*; |
| | | import com.agentdriving.user.modular.system.service.*; |
| | | import com.agentdriving.user.modular.system.util.*; |
| | | import com.agentdriving.user.modular.system.util.GaoDe.MapUtil; |
| | | import com.agentdriving.user.modular.system.util.GaoDe.model.District; |
| | | import com.agentdriving.user.modular.system.util.MallBook.model.*; |
| | | import com.agentdriving.user.modular.system.util.MallBook.util.Transfer; |
| | | import com.agentdriving.user.modular.system.util.MallBook.util.TrhRequest; |
| | | import com.agentdriving.user.modular.system.util.juhe.WeatherUtil; |
| | | import com.agentdriving.user.modular.system.util.mongodb.model.Location; |
| | | import com.agentdriving.user.modular.system.warpper.*; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.net.InetAddress; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | |
| | | @Autowired |
| | | private IRevenueService revenueService; |
| | | |
| | | @Autowired |
| | | private IAgentService agentService; |
| | | |
| | | @Autowired |
| | | private IPlatformRechargeRecordService platformRechargeRecordService; |
| | | |
| | | @Autowired |
| | | private IDivisionRecordService divisionRecordService; |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath;//支付回调网关地址 |
| | |
| | | JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard"); |
| | | JSONObject extraCost = jsonObject.getJSONObject("ExtraCost"); |
| | | Date date = new Date(); |
| | | for (int i = 0; i < chargeStandard.size(); i++) { |
| | | |
| | | boolean b = true; |
| | | for (int i = 1; i < chargeStandard.size(); i++) {//各种时间段 |
| | | JSONObject jsonObject1 = chargeStandard.getJSONObject(i); |
| | | String num1 = jsonObject1.getString("num1"); |
| | | String num2 = jsonObject1.getString("num2"); |
| | | Double num3 = jsonObject1.getDouble("num3");//起步里程 |
| | | Double num4 = jsonObject1.getDouble("num4");//起步价格 |
| | | Double num5 = jsonObject1.getDouble("num5");//超过公里 |
| | | Double num6 = jsonObject1.getDouble("num6");//超过num3每num5公里收取num6 |
| | | Double num7 = jsonObject1.getDouble("num7");//长途起始公里 |
| | | Double num8 = jsonObject1.getDouble("num8");//长途结束公里 |
| | | Double num9 = jsonObject1.getDouble("num9");//长途费 |
| | | Double num10 = jsonObject1.getDouble("num10");//超出长途里程每num10公里 |
| | | Double num11 = jsonObject1.getDouble("num11");//超过num8每num10公里收取num11 |
| | | JSONArray num3 = jsonObject1.getJSONArray("num3");//起步里程 |
| | | Double num4 = jsonObject1.getDouble("num4");//长途里程 |
| | | Double num5 = jsonObject1.getDouble("num5");//长途里程 |
| | | Double num6 = jsonObject1.getDouble("num6");//长途费 |
| | | Double num7 = jsonObject1.getDouble("num7");//超出长途里程每num10公里 |
| | | Double num8 = jsonObject1.getDouble("num8");//超过num8每num10公里收取num11 |
| | | |
| | | String[] split = num1.split(":"); |
| | | Calendar s = Calendar.getInstance(); |
| | |
| | | e.set(Calendar.SECOND, 0); |
| | | |
| | | if(date.getTime() >= s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){ |
| | | if(num3.compareTo(distance) >= 0){//起步里程内 |
| | | order.setStartDistance(distance);//起步里程 |
| | | order.setStartPrice(num4);//起步价 |
| | | }else{ |
| | | BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num3));//超出起步里程 |
| | | BigDecimal divide = subtract.divide(new BigDecimal(num5), new MathContext(2, RoundingMode.HALF_EVEN)); |
| | | BigDecimal multiply = divide.multiply(new BigDecimal(num6)); |
| | | order.setStartDistance(num3);//起步里程 |
| | | order.setStartPrice(num4);//起步价 |
| | | order.setOverDriveDistance(subtract.doubleValue());//超出起步里程 |
| | | order.setOverDrivePrice(multiply.doubleValue());//超出起步里程费 |
| | | |
| | | b = false; |
| | | Double dd = 0d; |
| | | for (int j = 0; j < num3.size(); j++) { |
| | | JSONObject jsonObject2 = num3.getJSONObject(j); |
| | | Double num1_1 = jsonObject2.getDouble("num1"); |
| | | Double num2_1 = jsonObject2.getDouble("num2"); |
| | | Double num3_1 = jsonObject2.getDouble("num3"); |
| | | if(num1_1.compareTo(distance) <= 0 && num2_1.compareTo(distance) > 0){ |
| | | order.setStartDistance(distance);//起步里程 |
| | | order.setStartPrice(num3_1);//起步价 |
| | | } |
| | | if(j == num3.size() - 1 && order.getStartPrice() == 0){ |
| | | order.setStartDistance(num2_1);//起步里程 |
| | | order.setStartPrice(num3_1);//起步价 |
| | | dd = distance - num2_1; |
| | | } |
| | | } |
| | | if(dd != 0){ |
| | | //计算长途费 |
| | | if(distance.compareTo(num7) > 0){ |
| | | order.setLongDistance(num7 + "-" + num8);//长途里程 |
| | | order.setLongDistancePrice(num9);//长途费 |
| | | if(distance.compareTo(num4) > 0){ |
| | | order.setLongDistance(num4 + "-" + num5);//长途里程 |
| | | order.setLongDistancePrice(num6);//长途费 |
| | | } |
| | | //计算长途里程超出的部分 |
| | | if(distance.compareTo(num8) > 0){ |
| | | BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num8)); |
| | | BigDecimal divide1 = subtract1.divide(new BigDecimal(num10), new MathContext(2, RoundingMode.HALF_EVEN)); |
| | | BigDecimal multiply1 = divide1.multiply(new BigDecimal(num11)); |
| | | if(distance.compareTo(num5) > 0){ |
| | | BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num5)); |
| | | BigDecimal divide1 = subtract1.divide(new BigDecimal(num7), new MathContext(2, RoundingMode.HALF_EVEN)); |
| | | BigDecimal multiply1 = divide1.multiply(new BigDecimal(num8)); |
| | | order.setOverLongDistance(subtract1.doubleValue());//超出长途里程 |
| | | order.setOverLongDistancePrice(multiply1.doubleValue());//超出长途里程费 |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(b){//默认配置 |
| | | JSONObject jsonObject1 = chargeStandard.getJSONObject(0); |
| | | JSONArray num3 = jsonObject1.getJSONArray("num3");//起步里程 |
| | | Double num4 = jsonObject1.getDouble("num4");//长途里程 |
| | | Double num5 = jsonObject1.getDouble("num5");//长途里程 |
| | | Double num6 = jsonObject1.getDouble("num6");//长途费 |
| | | Double num7 = jsonObject1.getDouble("num7");//超出长途里程每num10公里 |
| | | Double num8 = jsonObject1.getDouble("num8");//超过num8每num10公里收取num11 |
| | | |
| | | Double dd = 0d; |
| | | for (int j = 0; j < num3.size(); j++) { |
| | | JSONObject jsonObject2 = num3.getJSONObject(j); |
| | | Double num1_1 = jsonObject2.getDouble("num1"); |
| | | Double num2_1 = jsonObject2.getDouble("num2"); |
| | | Double num3_1 = jsonObject2.getDouble("num3"); |
| | | if(num1_1.compareTo(distance) <= 0 && num2_1.compareTo(distance) > 0){ |
| | | order.setStartDistance(distance);//起步里程 |
| | | order.setStartPrice(num3_1);//起步价 |
| | | } |
| | | if(j == num3.size() - 1 && order.getStartPrice() == 0){ |
| | | order.setStartDistance(num2_1);//起步里程 |
| | | order.setStartPrice(num3_1);//起步价 |
| | | dd = distance - num2_1; |
| | | } |
| | | } |
| | | if(dd != 0){ |
| | | //计算长途费 |
| | | if(distance.compareTo(num4) > 0){ |
| | | order.setLongDistance(num4 + "-" + num5);//长途里程 |
| | | order.setLongDistancePrice(num6);//长途费 |
| | | } |
| | | //计算长途里程超出的部分 |
| | | if(distance.compareTo(num5) > 0){ |
| | | BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num5)); |
| | | BigDecimal divide1 = subtract1.divide(new BigDecimal(num7), new MathContext(2, RoundingMode.HALF_EVEN)); |
| | | BigDecimal multiply1 = divide1.multiply(new BigDecimal(num8)); |
| | | order.setOverLongDistance(subtract1.doubleValue());//超出长途里程 |
| | | order.setOverLongDistancePrice(multiply1.doubleValue());//超出长途里程费 |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | orderPriceWarpper.setDiscountAmount(0D); |
| | | orderPriceWarpper.setPayType(1);//微信支付 |
| | | Double orderMoney = order.getOrderMoney(); |
| | | //先算优惠券 |
| | | // Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); |
| | | // if(null != coupon && null == couponId){ |
| | | // orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); |
| | | // orderPriceWarpper.setCouponId(coupon.getId()); |
| | | // } |
| | | |
| | | if(payType == 1 && null == couponId && appUser.getHavDiscount() == 1 && balance.compareTo(orderMoney) >= 0){//使用余额抵扣 |
| | | orderPriceWarpper.setDiscount(9D); |
| | | orderPriceWarpper.setDiscountAmount(new BigDecimal(orderMoney * 0.1).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | |
| | | if(orderPayment.getPayType() == 3){//线下支付(由司机端操作) |
| | | } |
| | | if(orderPayment.getPayType() == 4){//微信+余额 |
| | | if(appUser.getAccountBalance() == 0){ |
| | | return ResultUtil.error("账户余额不足"); |
| | | } |
| | | return weixinAndBalancePayment(order, appUser, orderPayment.getCouponId()); |
| | | } |
| | | return ResultUtil.success(); |
| | |
| | | } |
| | | order.setPayType(1); |
| | | order.setPayMoney(payMoney); |
| | | this.updateById(order); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + order.getId(); |
| | | // ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | // this.updateById(order); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | if(weixinpay.getCode() == 200){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10) { |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Order order1 = OrderServiceImpl.this.selectById(order.getId()); |
| | | if (order1.getState() != 107) { |
| | | return; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, ""); |
| | | if (resultUtil.getCode() == 200) { |
| | | /** |
| | | * 订单状态 |
| | | * SUCCESS—支付成功, |
| | | * REFUND—转入退款, |
| | | * NOTPAY—未支付, |
| | | * CLOSED—已关闭, |
| | | * REVOKED—已撤销(刷卡支付), |
| | | * USERPAYING--用户支付中, |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | */ |
| | | Map<String, String> data2 = resultUtil.getData(); |
| | | String s = data2.get("state"); |
| | | String transaction_id = data2.get("transaction_id"); |
| | | if ("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | //回退 |
| | | return; |
| | | } |
| | | if ("SUCCESS".equals(s)) { |
| | | order1.setState(108); |
| | | order1.setPayTime(new Date()); |
| | | order1.setOrderNo(transaction_id); |
| | | OrderServiceImpl.this.updateById(order1); |
| | | |
| | | Driver driver = driverService.selectById(order1.getDriverId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order1.getDriverId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(7); |
| | | accountChangeDetail.setOrderId(order1.getId()); |
| | | accountChangeDetail.setExplain("优惠券收入"); |
| | | driver.setCouponBalance(driver.getCouponBalance() + order1.getDiscountedPrice()); |
| | | accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | driverService.updateById(driver); |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | |
| | | |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(String.valueOf(payMoney * 100)); |
| | | paymentOrder.setOrderName("代驾服务费"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |
| | | paymentOrder.setAsynSplitFlag("1"); |
| | | paymentOrder.setAppid(""); |
| | | paymentOrder.setOpenid(appUser.getOpenid()); |
| | | paymentOrder.setTerminalIp(InetAddress.getLocalHost().getHostAddress()); |
| | | List<PaymentOrderGood> goodsDetail = new ArrayList<>(); |
| | | PaymentOrderGood paymentOrderGood = new PaymentOrderGood(); |
| | | paymentOrderGood.setGoodsName("服务费"); |
| | | goodsDetail.add(paymentOrderGood); |
| | | paymentOrder.setGoodsDetail(goodsDetail); |
| | | paymentOrder.setFrontUrl(""); |
| | | paymentOrder.setNotifyUrl(callbackPath + "/base/order/orderPayCallback"); |
| | | paymentOrder.setParameter1(order.getId().toString()); |
| | | |
| | | TrhRequest<PaymentOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(paymentOrder, PaymentOrder.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getResult())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | pushUtil.pushOrderStatus(order1.getUserId(), 1, order1.getId(), order1.getState()); |
| | | if(null != order1.getDriverId()) { |
| | | PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); |
| | | pushOrderInfoWarpper.setId(order1.getId()); |
| | | pushOrderInfoWarpper.setState(order1.getState()); |
| | | pushUtil.pushOrderInfo(order1.getDriverId(), 2, pushOrderInfoWarpper); |
| | | } |
| | | //处理佣金和收入记录 |
| | | saveCommission(order1); |
| | | return; |
| | | } |
| | | if ("USERPAYING".equals(s)) { |
| | | Thread.sleep(wait); |
| | | num++; |
| | | continue; |
| | | } |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | String payCode = jsonObject.getString("payCode"); |
| | | this.updateById(order); |
| | | return ResultUtil.success(payCode); |
| | | return weixinpay; |
| | | } |
| | | |
| | | |
| | |
| | | if(0 < payMoney){//还需要调起微信支付 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + order.getId(); |
| | | // ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(String.valueOf(payMoney * 100)); |
| | | paymentOrder.setOrderName("代驾服务费"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |
| | | paymentOrder.setAsynSplitFlag("1"); |
| | | paymentOrder.setAppid(""); |
| | | paymentOrder.setOpenid(appUser.getOpenid()); |
| | | paymentOrder.setTerminalIp(InetAddress.getLocalHost().getHostAddress()); |
| | | List<PaymentOrderGood> goodsDetail = new ArrayList<>(); |
| | | PaymentOrderGood paymentOrderGood = new PaymentOrderGood(); |
| | | paymentOrderGood.setGoodsName("服务费"); |
| | | goodsDetail.add(paymentOrderGood); |
| | | paymentOrder.setGoodsDetail(goodsDetail); |
| | | paymentOrder.setFrontUrl(""); |
| | | paymentOrder.setNotifyUrl(callbackPath + "/base/order/orderPayCallback"); |
| | | paymentOrder.setParameter1(order.getId().toString()); |
| | | if(weixinpay.getCode() == 200){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10) { |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Order order1 = OrderServiceImpl.this.selectById(order.getId()); |
| | | if (order1.getState() != 107) { |
| | | return; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, ""); |
| | | if (resultUtil.getCode() == 200) { |
| | | /** |
| | | * 订单状态 |
| | | * SUCCESS—支付成功, |
| | | * REFUND—转入退款, |
| | | * NOTPAY—未支付, |
| | | * CLOSED—已关闭, |
| | | * REVOKED—已撤销(刷卡支付), |
| | | * USERPAYING--用户支付中, |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | */ |
| | | Map<String, String> data2 = resultUtil.getData(); |
| | | String s = data2.get("state"); |
| | | String transaction_id = data2.get("transaction_id"); |
| | | if ("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | //回退 |
| | | AccountChangeDetail accountChangeDetail1 = accountChangeDetailService.selectById(accountChangeDetail.getId()); |
| | | double v = accountChangeDetail1.getOldData() - accountChangeDetail1.getNewData(); |
| | | AppUser appUser1 = appUserService.selectById(order1.getUserId()); |
| | | |
| | | TrhRequest<PaymentOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(paymentOrder, PaymentOrder.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getResult())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | String payCode = jsonObject.getString("payCode"); |
| | | this.updateById(order); |
| | | return ResultUtil.success(payCode); |
| | | accountChangeDetail1 = new AccountChangeDetail(); |
| | | accountChangeDetail1.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail1.setUserType(1); |
| | | accountChangeDetail1.setUserId(appUser1.getId()); |
| | | accountChangeDetail1.setCreateTime(new Date()); |
| | | accountChangeDetail1.setOldData(appUser1.getAccountBalance()); |
| | | accountChangeDetail1.setType(1); |
| | | accountChangeDetail1.setChangeType(2); |
| | | accountChangeDetail1.setOrderId(order1.getId()); |
| | | accountChangeDetail1.setExplain("支付失败回退"); |
| | | appUser1.setAccountBalance(appUser1.getAccountBalance() + v); |
| | | accountChangeDetail1.setNewData(appUser1.getAccountBalance()); |
| | | appUserService.updateById(appUser1); |
| | | accountChangeDetailService.insert(accountChangeDetail1); |
| | | return; |
| | | } |
| | | if ("SUCCESS".equals(s)) { |
| | | order1.setState(108); |
| | | order1.setPayTime(new Date()); |
| | | order1.setOrderNo(transaction_id); |
| | | OrderServiceImpl.this.updateById(order1); |
| | | |
| | | // TODO: 2023/5/18 取消支付后需要处理优惠券数据回退 |
| | | // |
| | | // |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // try { |
| | | // int num = 1; |
| | | // int wait = 0; |
| | | // while (num <= 10){ |
| | | // int min = 5000; |
| | | // wait += (min * num); |
| | | // Order order1 = OrderServiceImpl.this.selectById(order.getId()); |
| | | // if(order1.getState() != 107){ |
| | | // return; |
| | | // } |
| | | // |
| | | // /** |
| | | // * SUCCESS--支付成功 |
| | | // * REFUND--转入退款 |
| | | // * NOTPAY--未支付 |
| | | // * CLOSED--已关闭 |
| | | // * REVOKED--已撤销(刷卡支付) |
| | | // * USERPAYING--用户支付中 |
| | | // * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | // * ACCEPT--已接收,等待扣款 |
| | | // */ |
| | | // ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, ""); |
| | | // if(resultUtil.getCode() == 200){ |
| | | // Map<String, String> map = resultUtil.getData(); |
| | | // String trade_type = map.get("trade_type"); |
| | | // String trade_state = map.get("trade_state"); |
| | | // String transaction_id = map.get("transaction_id"); |
| | | // if("REFUND".equals(trade_state) || "NOTPAY".equals(trade_state) || "CLOSED".equals(trade_state) || "REVOKED".equals(trade_state) || "PAYERROR".equals(trade_state)){ |
| | | // AccountChangeDetail accountChangeDetail1 = accountChangeDetailService.selectById(accountChangeDetail.getId()); |
| | | // AppUser appUser1 = appUserService.selectById(accountChangeDetail1.getUserId()); |
| | | // Double b = accountChangeDetail1.getOldData() - accountChangeDetail1.getNewData(); |
| | | // appUser1.setAccountBalance(appUser1.getAccountBalance() + b); |
| | | // appUserService.updateById(appUser1); |
| | | // |
| | | // accountChangeDetailService.deleteById(accountChangeDetail.getId()); |
| | | // return; |
| | | // } |
| | | // if("SUCCESS".equals(trade_state)){ |
| | | // order1.setPayTime(new Date()); |
| | | // order1.setState(108); |
| | | // order1.setOrderNo(transaction_id); |
| | | // OrderServiceImpl.this.updateById(order1); |
| | | // |
| | | // //处理抽成及收入 |
| | | // saveCommission(order1); |
| | | // return; |
| | | // } |
| | | // if("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)){ |
| | | // Thread.sleep(wait); |
| | | // num++; |
| | | // } |
| | | // }else{ |
| | | // Thread.sleep(wait); |
| | | // num++; |
| | | // } |
| | | // if(10 == num){ |
| | | // AccountChangeDetail accountChangeDetail1 = accountChangeDetailService.selectById(accountChangeDetail.getId()); |
| | | // AppUser appUser1 = appUserService.selectById(accountChangeDetail1.getUserId()); |
| | | // Double b = accountChangeDetail1.getOldData() - accountChangeDetail1.getNewData(); |
| | | // appUser1.setAccountBalance(appUser1.getAccountBalance() + b); |
| | | // appUserService.updateById(appUser1); |
| | | // |
| | | // accountChangeDetailService.deleteById(accountChangeDetail.getId()); |
| | | // } |
| | | // } |
| | | // }catch (Exception e){ |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // }).start(); |
| | | // return weixinpay; |
| | | Driver driver = driverService.selectById(order1.getDriverId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order1.getDriverId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(7); |
| | | accountChangeDetail.setOrderId(order1.getId()); |
| | | accountChangeDetail.setExplain("优惠券收入"); |
| | | driver.setCouponBalance(driver.getCouponBalance() + order1.getDiscountedPrice()); |
| | | accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | driverService.updateById(driver); |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | |
| | | pushUtil.pushOrderStatus(order1.getUserId(), 1, order1.getId(), order1.getState()); |
| | | if(null != order1.getDriverId()) { |
| | | PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); |
| | | pushOrderInfoWarpper.setId(order1.getId()); |
| | | pushOrderInfoWarpper.setState(order1.getState()); |
| | | pushUtil.pushOrderInfo(order1.getDriverId(), 2, pushOrderInfoWarpper); |
| | | } |
| | | //处理佣金和收入记录 |
| | | saveCommission(order1); |
| | | return; |
| | | } |
| | | if ("USERPAYING".equals(s)) { |
| | | Thread.sleep(wait); |
| | | num++; |
| | | continue; |
| | | } |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | return weixinpay; |
| | | } |
| | | // order.setPayTime(new Date()); |
| | | // this.updateById(order); |
| | | |
| | | |
| | | return ResultUtil.success(); |
| | | |
| | | } |
| | |
| | | pushOrderInfoWarpper.setState(order.getState()); |
| | | pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); |
| | | } |
| | | |
| | | //支付成功---->异步分账----->10s钟后再进行确认收货 |
| | | //确认收货后才能进行提现(结算接口) |
| | | //异步分账 |
| | | List<Revenue> revenues = revenueService.selectList(new EntityWrapper<Revenue>().eq("orderId", order.getId())); |
| | | Complete complete = new Complete(); |
| | | complete.setOriginalMerOrderId(transaction_id); |
| | | complete.setNotifyUrl(callbackPath + "/base/order/ledgerCallback"); |
| | | List<PamentOrderUser> splitList = new ArrayList<>(); |
| | | for (Revenue revenue : revenues) { |
| | | if(revenue.getUserType() == 2){//司机 |
| | | Driver driver = driverService.selectById(revenue.getUserId()); |
| | | PamentOrderUser pamentOrderUser = new PamentOrderUser(); |
| | | pamentOrderUser.setSplitUserId(driver.getMerchantNumber()); |
| | | pamentOrderUser.setSplitAmount(revenue.getAmount().toString()); |
| | | pamentOrderUser.setSplitType("2"); |
| | | splitList.add(pamentOrderUser); |
| | | |
| | | DivisionRecord divisionRecord = new DivisionRecord(); |
| | | divisionRecord.setUserType(1); |
| | | divisionRecord.setUserId(revenue.getUserId()); |
| | | divisionRecord.setOrderId(order.getId()); |
| | | divisionRecord.setMerOrderId(transaction_id); |
| | | divisionRecord.setSourceType(1); |
| | | divisionRecord.setAmount(revenue.getAmount()); |
| | | divisionRecord.setMerchantNumber(driver.getMerchantNumber()); |
| | | divisionRecord.setState(1); |
| | | divisionRecord.setCreateTime(new Date()); |
| | | divisionRecordService.insert(divisionRecord); |
| | | } |
| | | if(revenue.getUserType() == 3){//代理商 |
| | | Agent agent = agentService.selectById(revenue.getUserId()); |
| | | PamentOrderUser pamentOrderUser = new PamentOrderUser(); |
| | | pamentOrderUser.setSplitUserId(agent.getMerchantNumber()); |
| | | pamentOrderUser.setSplitAmount(revenue.getAmount().toString()); |
| | | pamentOrderUser.setSplitType("2"); |
| | | splitList.add(pamentOrderUser); |
| | | |
| | | DivisionRecord divisionRecord = new DivisionRecord(); |
| | | divisionRecord.setUserType(2); |
| | | divisionRecord.setUserId(revenue.getUserId()); |
| | | divisionRecord.setOrderId(order.getId()); |
| | | divisionRecord.setMerOrderId(transaction_id); |
| | | divisionRecord.setSourceType(1); |
| | | divisionRecord.setAmount(revenue.getAmount()); |
| | | divisionRecord.setMerchantNumber(agent.getMerchantNumber()); |
| | | divisionRecord.setState(1); |
| | | divisionRecord.setCreateTime(new Date()); |
| | | divisionRecordService.insert(divisionRecord); |
| | | } |
| | | |
| | | } |
| | | complete.setSplitList(splitList); |
| | | TrhRequest<Complete> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(complete, Complete.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getResult())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | |
| | | //使用优惠券的情况,通过转账接口将优惠券的收入转到司机电子账簿 |
| | | if(null != order.getCouponId()){ |
| | | List<PlatformRechargeRecord> platformRechargeRecords = platformRechargeRecordService.selectList(new EntityWrapper<PlatformRechargeRecord>().eq("state", 2).last(" and balance > 0 order by payTime")); |
| | | Double discountedPrice = order.getDiscountedPrice(); |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | |
| | | UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId()); |
| | | Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order.getDriverId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(7); |
| | | accountChangeDetail.setOrderId(order.getId()); |
| | | accountChangeDetail.setExplain("优惠券收入"); |
| | | driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount()); |
| | | accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | driverService.updateById(driver); |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | |
| | | |
| | | for (PlatformRechargeRecord platformRechargeRecord : platformRechargeRecords) { |
| | | if(discountedPrice == 0){ |
| | | break; |
| | | } |
| | | |
| | | if(platformRechargeRecord.getBalance().compareTo(discountedPrice) >= 0){ |
| | | discountedPrice = 0D; |
| | | platformRechargeRecord.setBalance(platformRechargeRecord.getBalance() - discountedPrice); |
| | | platformRechargeRecordService.updateById(platformRechargeRecord); |
| | | }else{ |
| | | |
| | | } |
| | | |
| | | Transfer transfer = new Transfer(); |
| | | transfer.setDepositMerOrderId("6831518911582834611"); |
| | | transfer.setToUserId(driver.getMerchantNumber()); |
| | | transfer.setAmount(discountedPrice.toString()); |
| | | transfer.setOrderName(""); |
| | | transfer.setNotifyUrl(""); |
| | | transfer.setParameter1(order.getId().toString()); |
| | | |
| | | TrhRequest<Transfer> request1 = new TrhRequest(); |
| | | InterfaceResponse execute1 = request1.execute(transfer, Transfer.SERVICE_CODE); |
| | | if(!"0000".equals(execute1.getResult())){ |
| | | return ResultUtil.error(execute1.getMsg()); |
| | | } |
| | | JSONObject jsonObject1 = JSON.parseObject(execute1.getResult()); |
| | | String status1 = jsonObject1.getString("status"); |
| | | if("2".equals(status1)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status1)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | return ResultUtil.success(); |
| | | } |
| | | |