package com.stylefeng.guns.modular.system.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService; import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService; import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; import com.stylefeng.guns.modular.system.service.IOrderService; import com.stylefeng.guns.modular.system.service.IUserInfoService; //import com.stylefeng.guns.modular.system.util.ChinaMobileUtil; import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.warpper.BaseWarpper; import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import java.util.Map; @Service public class OrderServiceImpl implements IOrderService { @Autowired private IOrderTaxiService orderTaxiService; @Autowired private RestTemplate internalRestTemplate; // @Autowired // private ChinaMobileUtil chinaMobileUtil; @Autowired private IUserInfoService userInfoService; @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; @Autowired private IOrderCrossCityService orderCrossCityService; @Autowired private IOrderPrivateCarService orderPrivateCarService; @Autowired private IOrderLogisticsService orderLogisticsService; /** * 获取预计行驶时间 * @param slon 起点经度 * @param slat 起点纬度 * @param elon 终点经度 * @param elat 终点纬度 * @return * @throws Exception */ @Override public ResultUtil queryExpectedTime(Double slon, Double slat, Double elon, Double elat) throws Exception { Map distance = gdMapElectricFenceUtil.getDistance(slon + "," + slat, elon + "," + elat, 1); int duration = Integer.valueOf(distance.get("duration")) / 60; BaseWarpper baseWarpper = new BaseWarpper(); baseWarpper.setMinute(duration); return ResultUtil.success(baseWarpper); } /** * APP调用微信小程序完成支付 * @param orderId * @param orderType * @param type * @return * @throws Exception */ @Override public ResultUtil weChatPay(Integer orderId, Integer orderType, Integer type, Integer userType, Integer uid, String content) throws Exception { JSONObject jsonObject = JSON.parseObject(content); switch (type){ case 1://订单完成支付 switch (orderType){ case 1: return orderPrivateCarService.payPrivateCarOrder(1, orderId, (null == jsonObject ? null : jsonObject.getIntValue("couponId")), 3); case 2: return orderTaxiService.payTaxiOrder(1, orderId, (null == jsonObject ? null : jsonObject.getIntValue("couponId")), 3); case 3: return orderCrossCityService.payCrossCityOrder(1, orderId, (null == jsonObject ? null : jsonObject.getIntValue("couponId")), 3); case 4: return orderLogisticsService.payLogisticsOrder(1, orderId, 3); case 5: return orderLogisticsService.payLogisticsOrder(1, orderId, 3); } case 2://订单取消支付 switch (orderType){ case 1: return orderPrivateCarService.cancleOrderPrivateCar(orderId, 1, null == jsonObject ? null : jsonObject.getIntValue("cancelId"), 3); case 2: return orderTaxiService.cancleOrderTaxi(orderId, 1, null == jsonObject ? null : jsonObject.getIntValue("cancelId"), 3); case 3: return orderCrossCityService.cancleOrderCrossCity(orderId, 1, null == jsonObject ? null : jsonObject.getIntValue("cancelId"), 3); } case 3://司机端改派支付 HttpHeaders headers = new HttpHeaders(); // 以表单的方式提交 headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); //将请求头部和参数合成一个请求 MultiValueMap params = new LinkedMultiValueMap<>(); params.add("orderId", orderId.toString()); params.add("orderType", orderType.toString()); params.add("payType", "1"); params.add("reason", null == jsonObject ? "" : jsonObject.getString("reason")); params.add("remark", null == jsonObject ? "" : jsonObject.getString("remark")); params.add("uid", jsonObject.getString("uid")); HttpEntity> requestEntity = new HttpEntity<>(params, headers); String s = internalRestTemplate.postForObject("http://driver-server/base/order/reassign_", requestEntity, String.class); JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); return ResultUtil.success(jsonObject1.getString("msg"), jsonObject1.getString("data")); case 4://余额充值 if(userType == 1){ return userInfoService.depositBalance(1, jsonObject.getDoubleValue("money"), uid, 3); } if(userType == 2){ } case 5://小件物流补差价 return orderLogisticsService.payLogisticsOrder_(1, orderId, 3); } return ResultUtil.success(); } }