package com.agentdriving.user.modular.system.service.impl;
|
|
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.warpper.*;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
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.util.GaoDe.MapUtil;
|
import com.agentdriving.user.modular.system.util.GaoDe.model.District;
|
import com.agentdriving.user.modular.system.util.juhe.WeatherUtil;
|
import com.agentdriving.user.modular.system.util.mongodb.model.Location;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.data.geo.Circle;
|
import org.springframework.data.geo.Distance;
|
import org.springframework.data.geo.Metrics;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.math.MathContext;
|
import java.math.RoundingMode;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 订单
|
* @author pzb
|
* @Date 2023/2/16 15:57
|
*/
|
@Service
|
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
|
|
@Autowired
|
private ISystemConfigService systemConfigService;
|
|
@Autowired
|
private IWeatherCityService weatherCityService;
|
|
@Autowired
|
private IUserToCouponService userToCouponService;
|
|
@Autowired
|
private IAppUserService appUserService;
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private PushUtil pushUtil;
|
|
@Autowired
|
private IYouTuiDriverService youTuiDriverService;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private MongoTemplate mongoTemplate;
|
|
@Autowired
|
private IDriverWorkService driverWorkService;
|
|
@Autowired
|
private ICancelOrderService cancelOrderService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
@Autowired
|
private ICouponService couponService;
|
|
@Autowired
|
private IAccountChangeDetailService accountChangeDetailService;
|
|
@Autowired
|
private IEvaluateService evaluateService;
|
|
@Autowired
|
private IRevenueService revenueService;
|
|
@Value("${callbackPath}")
|
private String callbackPath;//支付回调网关地址
|
|
|
|
|
|
/**
|
* 获取预估费用
|
* @param uid
|
* @param estimatedCosts
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil<EstimatedCostsWarpper> getEstimatedCosts(Integer uid, EstimatedCosts estimatedCosts) throws Exception {
|
EstimatedCostsWarpper estimatedCostsWarpper = new EstimatedCostsWarpper();
|
Double d = 0D;
|
if(ToolUtil.isNotEmpty(estimatedCosts.getEndAddress())){
|
Map<String, String> distance = MapUtil.getDistance(estimatedCosts.getStartLng() + "," + estimatedCosts.getStartLat(),
|
estimatedCosts.getEndLng() + "," + estimatedCosts.getEndLat(), 1);
|
if(null == distance){
|
return ResultUtil.error("获取预估距离出错");
|
}
|
d = Double.valueOf(distance.get("distance")) / 1000;
|
estimatedCostsWarpper.setEstimatedMileage(d);
|
estimatedCostsWarpper.setTravelTime(Integer.valueOf(distance.get("duration")) / 60);
|
}
|
String city = "";
|
District geocode = MapUtil.geocode(estimatedCosts.getStartLng().toString(), estimatedCosts.getStartLat().toString());
|
if(null != geocode){
|
WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
|
.where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
|
city = null != weatherCity ? weatherCity.getId().toString() : "";
|
}
|
Order order = getOrderPrice(1, d, 0, new Order(), city);
|
Double estimatedPrice = order.getEstimatedPrice();
|
Coupon coupon = userToCouponService.queryCoupon(uid, estimatedPrice);
|
if(null != coupon){
|
Double couponPreferentialAmount = coupon.getCouponPreferentialAmount();
|
estimatedCostsWarpper.setPrice(estimatedPrice - couponPreferentialAmount);
|
estimatedCostsWarpper.setDiscountAmount(couponPreferentialAmount);
|
}else{
|
estimatedCostsWarpper.setPrice(estimatedPrice);
|
estimatedCostsWarpper.setDiscountAmount(0D);
|
}
|
//预估接驾时间
|
int i = 0;
|
Double scope = 5D;
|
while (true){
|
List<NearbyDriverWarpper> nearbyDriverWarppers = driverService.queryDriverPosition(estimatedCosts.getLng().toString(), estimatedCosts.getLat().toString(), scope);
|
if(nearbyDriverWarppers.size() == 0){
|
scope += 5;
|
i++;
|
if(i >= 10){
|
estimatedCostsWarpper.setPickUpTime(60);
|
break;
|
}
|
continue;
|
}
|
if(nearbyDriverWarppers.size() > 0){
|
NearbyDriverWarpper nearbyDriverWarpper = nearbyDriverWarppers.get(0);
|
Map<String, String> distance = MapUtil.getDistance(nearbyDriverWarpper.getLonLat(), estimatedCosts.getStartLng() + "," + estimatedCosts.getStartLat(), 1);
|
if(null != distance){
|
distance.get("distance");//距离(M)
|
String duration = distance.get("duration");//时间(S)
|
estimatedCostsWarpper.setPickUpTime(Integer.valueOf(duration) / 60);
|
}
|
break;
|
}
|
}
|
return ResultUtil.success(estimatedCostsWarpper);
|
}
|
|
|
|
|
/**
|
* 获取订单价格
|
* @param type 计算类型(1=预估价,2=订单费)
|
* @param distance 行驶公里
|
* @param waitTime 等待时长
|
* @param order 订单数据
|
* @param city 查询天气的城市
|
* @return
|
*/
|
public Order getOrderPrice(Integer type, Double distance, Integer waitTime, Order order, String city){
|
order = getOrderInitialPrice(order);
|
SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5));
|
if(null == systemConfig){
|
if(type == 1){//预估金额
|
order.setEstimatedPrice(0D);
|
}
|
if(type == 2){//订单金额
|
order.setOrderMoney(0D);
|
}
|
return order;
|
}
|
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
|
JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard");
|
JSONObject extraCost = jsonObject.getJSONObject("ExtraCost");
|
Date date = new Date();
|
|
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");
|
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();
|
s.setTime(date);
|
s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
|
s.set(Calendar.MINUTE, Integer.valueOf(split[1]));
|
s.set(Calendar.SECOND, 0);
|
|
split = num2.split(":");
|
Calendar e = Calendar.getInstance();
|
e.setTime(date);
|
e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
|
e.set(Calendar.MINUTE, Integer.valueOf(split[1]));
|
e.set(Calendar.SECOND, 0);
|
|
if(date.getTime() >= s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){
|
b = false;
|
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);//起步价
|
break;
|
}
|
if(j == num3.size() - 1 && order.getStartPrice() == 0){
|
order.setStartDistance(num2_1);//起步里程
|
order.setStartPrice(num3_1);//起步价
|
}
|
}
|
//计算长途费
|
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());//超出长途里程费
|
}
|
}
|
}
|
|
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
|
|
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);//起步价
|
break;
|
}
|
if(j == num3.size() - 1 && order.getStartPrice() == 0){
|
order.setStartDistance(num2_1);//起步里程
|
order.setStartPrice(num3_1);//起步价
|
}
|
}
|
//计算长途费
|
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());//超出长途里程费
|
}
|
}
|
|
//计算额外费用
|
Integer num1 = extraCost.getInteger("num1");//等待时长
|
Double num2 = extraCost.getDouble("num2");//等待费
|
Integer num3 = extraCost.getInteger("num3");//等待超出时长
|
Double num4 = extraCost.getDouble("num4");//等到超出时长费用单价 X/分钟
|
Double num5 = extraCost.getDouble("num5");//恶劣天气公里
|
Double num6 = extraCost.getDouble("num6");//恶劣天气费
|
Double num7 = extraCost.getDouble("num7");//恶劣天气超出公里
|
Double num8 = extraCost.getDouble("num8");//恶劣天气超出公里单价 X/公里
|
Double num9 = extraCost.getDouble("num9");//恶劣天气最高收取金额
|
|
//等待费用
|
if(waitTime.compareTo(num1) >= 0){
|
order.setWaitTime(num1);//等待时长
|
order.setWaitTimePrice(num2);//等待费用
|
|
Integer w = waitTime - num3;
|
BigDecimal multiply = new BigDecimal(w).multiply(new BigDecimal(num4));
|
order.setOutWaitTime(w);//等待时长超出分钟
|
order.setOutWaitTimePrice(multiply.doubleValue());//等待时长超出费用
|
}
|
|
//恶劣天气
|
systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8));
|
if(null != systemConfig){
|
JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent());
|
Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价
|
if(1 == num11){
|
boolean badWeather = WeatherUtil.isBadWeather(city);
|
if(badWeather){
|
order.setBadWeatherDistance(num5);//恶劣天气公里
|
order.setBadWeatherPrice(num6);//恶劣天气费
|
if(distance.compareTo(num7) > 0){
|
BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7));
|
BigDecimal multiply = subtract.multiply(new BigDecimal(num8));
|
order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里
|
order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费
|
}
|
|
double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额)
|
if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额
|
order.setBadWeatherPrice(num9);//恶劣天气费
|
order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费
|
}else{
|
BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add));
|
order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费
|
}
|
}
|
}
|
}
|
}
|
|
|
//计算总金额
|
BigDecimal bigDecimal = new BigDecimal(order.getStartPrice() + order.getOverDrivePrice() + order.getLongDistancePrice() + order.getOverLongDistancePrice() +
|
order.getWaitTimePrice() + order.getOutWaitTimePrice() + order.getBadWeatherPrice() + order.getOverBadWeatherPrice() - order.getDiscountAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN);
|
|
if(type == 1){//预估价
|
order.setEstimatedPrice(bigDecimal.doubleValue());
|
}
|
if(type == 2){//订单金额
|
order.setOrderMoney(bigDecimal.doubleValue());
|
}
|
return order;
|
}
|
|
|
|
/**
|
* 初始订单费用
|
* @param order
|
* @return
|
*/
|
public Order getOrderInitialPrice(Order order){
|
order.setStartDistance(0D);//起步里程
|
order.setStartPrice(0D);//起步价
|
order.setOverDriveDistance(0D);//超出起步里程
|
order.setOverDrivePrice(0D);//超出起步里程费
|
order.setLongDistance("");//长途里程
|
order.setLongDistancePrice(0D);//长途里程费
|
order.setOverLongDistance(0D);//超出长途里程
|
order.setOverLongDistancePrice(0d);//超出长途里程费
|
order.setWaitTime(0);//等待时长
|
order.setWaitTimePrice(0D);//等待费
|
order.setOutWaitTime(0);//超出等待时长
|
order.setOutWaitTimePrice(0D);//超出等待时长费
|
order.setBadWeatherDistance(0D);//恶劣天气里程
|
order.setBadWeatherPrice(0D);//恶劣天气里程费
|
order.setOverBadWeatherDistance(0D);//恶劣天气超出里程
|
order.setOverBadWeatherPrice(0D);//恶劣天气超出里程费
|
order.setDiscountedPrice(0D);//优惠金额
|
order.setCouponId(null);//优惠券
|
order.setDiscountAmount(0D);//折扣优惠金额
|
order.setDiscount(0D);//折扣
|
return order;
|
}
|
|
|
/**
|
* 下单操作
|
* @param uid
|
* @param travelOrder
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil travelOrder(Integer uid, TravelOrder travelOrder) throws Exception {
|
List<Integer> state = Arrays.asList(101, 102, 103, 104, 105, 106, 107, 201, 401);
|
Order order = this.selectOne(new EntityWrapper<Order>().eq("userId", uid).eq("status", 1).in("state", state));
|
if(null != order){
|
return ResultUtil.error("您还有正在进行的订单");
|
}
|
AppUser appUser = appUserService.selectById(uid);
|
order = this.selectOne(new EntityWrapper<Order>().eq("userPhone", appUser.getPhone()).eq("status", 1).in("state", state));
|
if(null != order){
|
return ResultUtil.error("您还有正在进行的订单");
|
}
|
|
String startAddress = travelOrder.getStartAddress();
|
startAddress = startAddress.replaceAll("& #40;", "(");
|
startAddress = startAddress.replaceAll("& #41;", ")");
|
travelOrder.setStartAddress(startAddress);
|
if(ToolUtil.isNotEmpty(travelOrder.getEndAddress())){
|
String endAddress = travelOrder.getEndAddress();
|
endAddress = endAddress.replaceAll("& #40;", "(");
|
endAddress = endAddress.replaceAll("& #41;", ")");
|
travelOrder.setEndAddress(endAddress);
|
}
|
|
order = new Order();
|
BeanUtils.copyProperties(travelOrder, order);
|
if(ToolUtil.isEmpty(travelOrder.getUserPhone())){
|
order.setUserPhone(appUser.getPhone());
|
order.setUserName(appUser.getNickname());
|
}
|
order.setUserId(uid);
|
order.setSource(1);
|
order.setHallOrder(0);
|
order.setStatus(1);
|
order.setCreateTime(new Date());
|
order.setState(null != travelOrder.getDriverId() ? 102 : 101);
|
Double d = 0D;
|
if(ToolUtil.isNotEmpty(travelOrder.getEndAddress())){
|
Map<String, String> distance = MapUtil.getDistance(order.getStartLng() + "," + order.getStartLat(), order.getEndLng() + "," + order.getEndLat(), 1);
|
if(null == distance){
|
return ResultUtil.error("获取预估距离出错");
|
}
|
d = Double.valueOf(distance.get("distance")) / 1000;
|
order.setEstimatedMileage(d);
|
order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60);
|
}
|
String city = "";
|
District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat());
|
if(null != geocode){
|
WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
|
.where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
|
city = null != weatherCity ? weatherCity.getId().toString() : "";
|
}
|
order = getOrderPrice(1, d, 0, order, city);
|
if(null != travelOrder.getDriverId()){
|
DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", travelOrder.getDriverId()).eq("status", 1));
|
if(null == driverWork){
|
return ResultUtil.error("司机还未上班");
|
}
|
Driver driver = driverService.selectById(travelOrder.getDriverId());
|
if(driver.getServerStatus() == 1){
|
order.setAgentId(driver.getAgentId());
|
order.setBranchOfficeId(driver.getBranchOfficeId());
|
order.setOrderTakingTime(new Date());
|
|
driver.setServerStatus(2);
|
driverService.updateById(driver);
|
}
|
|
appUser.setCancelCount(0);
|
appUser.setIsException(1);
|
appUserService.updateById(appUser);
|
}
|
|
for (Integer i = 0; i < travelOrder.getDriverNum(); i++) {
|
order.setId(null);
|
order.setCode(UUIDUtil.getTimeStr() + UUIDUtil.getNumberRandom(3));
|
boolean insert = this.insert(order);
|
if(insert){
|
//推送状态
|
pushUtil.pushOrderStatus(uid, 1, order.getId(), order.getState());
|
if(null != order.getDriverId()){
|
PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
|
pushOrderInfoWarpper.setId(order.getId());
|
pushOrderInfoWarpper.setState(order.getState());
|
pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
|
}else{
|
//推单
|
pushOrder(order.getId());
|
}
|
}
|
}
|
return ResultUtil.success(order.getId());
|
}
|
|
|
|
|
/**
|
* 订单推送逻辑
|
*/
|
public void pushOrder(Long orderId){
|
Order order = this.selectById(orderId);
|
/**
|
* 1.先找最大推单范围内的优推司机 -》 距离最近
|
* 没有1 - 》
|
* 2.按照后台推送配置在范围内查找合适司机
|
* 合适司:积分 > 评分 > 距离
|
* 3.司机没有接单直接将订单置入大厅
|
*/
|
SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1));
|
if(null == systemConfig){
|
return;
|
}
|
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
|
Double num3 = jsonObject.getDouble("num3");//推单最大范围
|
Integer num4 = jsonObject.getInteger("num4");//接单时间
|
String startLat = order.getStartLat();
|
String startLng = order.getStartLng();
|
|
//1
|
//找到中心点
|
GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat));
|
Double num = num3 / 1000;//范围公里
|
//构造半径
|
Distance distanceR = new Distance(num, Metrics.KILOMETERS);
|
//画圆
|
Circle circle = new Circle(geoJsonPoint, distanceR);
|
// 构造query对象
|
Query query = Query.query(Criteria.where("location").withinSphere(circle));
|
List<Location> locations = mongoTemplate.find(query, Location.class);
|
List<Integer> driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList());
|
Integer driver = null;
|
YouTuiDriver youTuiDriver1 = null;
|
if(driverIds.size() > 0){
|
List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds)
|
.eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime"));
|
Double d = null;
|
for (YouTuiDriver youTuiDriver : youTuiDrivers) {
|
String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId());
|
if(ToolUtil.isEmpty(value)){
|
continue;
|
}
|
Driver driver1 = driverService.selectById(youTuiDriver.getDriverId());
|
if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){
|
continue;
|
}
|
Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
|
Double wgs84 = distance.get("WGS84");
|
if(d == null || d.compareTo(wgs84) > 0){
|
d = wgs84;
|
driver = youTuiDriver.getDriverId();
|
youTuiDriver1 = youTuiDriver;
|
}
|
}
|
}
|
if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){
|
youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1);
|
youTuiDriverService.updateById(youTuiDriver1);
|
}
|
|
//开始范围查找
|
if(null == driver){
|
for (int i = 1; i < 4; i++) {
|
if(null != driver){
|
break;
|
}
|
num = jsonObject.getDouble("num" + i) / 1000;//范围公里
|
//构造半径
|
distanceR = new Distance(num, Metrics.KILOMETERS);
|
//画圆
|
circle = new Circle(geoJsonPoint, distanceR);
|
// 构造query对象
|
query = Query.query(Criteria.where("location").withinSphere(circle));
|
locations = mongoTemplate.find(query, Location.class);
|
|
driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList());
|
if(driverIds.size() > 0){
|
List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2)
|
.eq("serverStatus", 1).eq("openOrderQRCode", 0).eq("status", 1).in("id", driverIds));
|
if(drivers.size() == 0){
|
continue;
|
}
|
|
Integer integral = null;//积分
|
Double score = null;//评分
|
Double d = null;
|
for (Driver driver1 : drivers) {
|
String value = redisUtil.getValue("DRIVER" + driver1.getId());
|
if(ToolUtil.isEmpty(value)){
|
continue;
|
}
|
if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大
|
integral = driver1.getIntegral();
|
score = driver1.getScore();
|
driver = driver1.getId();
|
Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
|
Double wgs84 = distance.get("WGS84");
|
d = wgs84;
|
continue;
|
}
|
if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分
|
integral = driver1.getIntegral();
|
score = driver1.getScore();
|
driver = driver1.getId();
|
Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
|
Double wgs84 = distance.get("WGS84");
|
d = wgs84;
|
continue;
|
}
|
if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离
|
Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
|
Double wgs84 = distance.get("WGS84");
|
if(d.compareTo(wgs84) > 0){
|
d = wgs84;
|
integral = driver1.getIntegral();
|
score = driver1.getScore();
|
driver = driver1.getId();
|
continue;
|
}
|
}
|
}
|
|
}
|
}
|
}
|
|
if(null != driver){
|
pushUtil.pushGrabOrder(driver, 2, order.getId(), num4);
|
//创建定时任务处理订单到大厅
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
Order order1 = OrderServiceImpl.this.selectById(order.getId());
|
if(order1.getState() == 101 || order1.getState() == 201){
|
order1.setHallOrder(1);
|
OrderServiceImpl.this.updateById(order1);
|
}
|
}
|
}, num4 * 1000);
|
}else{
|
order.setHallOrder(1);
|
this.updateById(order);
|
}
|
}
|
|
|
/**
|
* 取消订单
|
* @param uid
|
* @param orderId
|
* @param cause
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil cancelOrder(Integer uid, Long orderId, String cause) throws Exception {
|
Order order = this.selectById(orderId);
|
if(order.getState() >= 105){
|
return ResultUtil.error("不能取消订单");
|
}
|
CancelOrder cancelOrder = new CancelOrder();
|
cancelOrder.setOrderId(orderId);
|
cancelOrder.setUserType(1);
|
cancelOrder.setUserId(uid);
|
cancelOrder.setCause(cause);
|
cancelOrder.setStatus(1);
|
cancelOrder.setCreateTime(new Date());
|
cancelOrderService.insert(cancelOrder);
|
order.setState(301);
|
this.updateById(order);
|
AppUser appUser = appUserService.selectById(uid);
|
appUser.setCancelCount(appUser.getCancelCount() + 1);
|
if(appUser.getCancelCount() >= 3){
|
appUser.setIsException(2);
|
}
|
appUserService.updateById(appUser);
|
Driver driver = driverService.selectById(order.getDriverId());
|
if(null != driver){
|
driver.setServerStatus(1);
|
driverService.updateById(driver);
|
}
|
|
pushUtil.pushOrderStatus(uid, 1, orderId, order.getState());
|
if(null != order.getDriverId()){
|
PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
|
pushOrderInfoWarpper.setId(order.getId());
|
pushOrderInfoWarpper.setState(order.getState());
|
pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
|
}
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 获取订单详情
|
* @param uid
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public OrderInfoWarpper queryOrderInfo(Integer uid, Long orderId) throws Exception {
|
OrderInfoWarpper orderInfoWarpper = this.baseMapper.queryOrderInfo(uid, orderId);
|
SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 7));
|
if(null != systemConfig){
|
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
|
orderInfoWarpper.setServiceCell(jsonObject.getString("num1"));
|
}
|
String value = redisUtil.getValue("DRIVER" + orderInfoWarpper.getDriverId());
|
if(ToolUtil.isNotEmpty(value)){
|
String[] split = value.split(",");
|
orderInfoWarpper.setDriverLon(split[0]);
|
orderInfoWarpper.setDriverLat(split[1]);
|
}
|
return orderInfoWarpper;
|
}
|
|
|
/**
|
* 修改订单终点
|
* @param uid
|
* @param editOrderEndAddress
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil editOrderEndAddress(Integer uid, EditOrderEndAddress editOrderEndAddress) throws Exception {
|
Order order = this.selectById(editOrderEndAddress.getOrderId());
|
order.setEndAddress(editOrderEndAddress.getEndAddress());
|
order.setEndLat(editOrderEndAddress.getEndLat().toString());
|
order.setEndLng(editOrderEndAddress.getEndLng().toString());
|
Double d = 0D;
|
if(ToolUtil.isNotEmpty(order.getEndAddress())){
|
Map<String, String> distance = MapUtil.getDistance(order.getStartLng() + "," + order.getStartLat(),
|
order.getEndLng() + "," + order.getEndLat(), 1);
|
if(null == distance){
|
return ResultUtil.error("获取预估距离出错");
|
}
|
d = Double.valueOf(distance.get("distance")) / 1000;
|
order.setEstimatedMileage(d);
|
order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60);
|
}
|
String city = "";
|
District geocode = MapUtil.geocode(order.getStartLng().toString(), order.getStartLat().toString());
|
if(null != geocode){
|
WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
|
.where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
|
city = null != weatherCity ? weatherCity.getId().toString() : "";
|
}
|
Order order1 = new Order();
|
BeanUtils.copyProperties(order, order1);
|
Order orderPrice = getOrderPrice(1, d, 0, order1, city);
|
order.setEstimatedPrice(orderPrice.getEstimatedPrice());
|
this.updateById(order);
|
|
PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
|
pushOrderInfoWarpper.setId(order.getId());
|
pushOrderInfoWarpper.setState(order.getState());
|
pushOrderInfoWarpper.setEndAddress(order.getEndAddress());
|
pushOrderInfoWarpper.setEndLat(order.getEndLat());
|
pushOrderInfoWarpper.setEndLng(order.getEndLng());
|
pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
|
return ResultUtil.success();
|
}
|
|
/**
|
* 获取费用明细
|
* @param uid
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public OrderPriceWarpper queryOrderPrice(Integer uid, Long orderId) throws Exception {
|
Order order = this.selectById(orderId);
|
OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper();
|
BeanUtils.copyProperties(order, orderPriceWarpper);
|
orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue());
|
return orderPriceWarpper;
|
}
|
|
|
/**
|
* 重新计算费用明细
|
* @param orderId
|
* @param couponId
|
* @param payType
|
* @param balance
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public OrderPriceWarpper calculationOfExpenses(Integer uid, Long orderId, Integer couponId, Integer payType, Double balance) throws Exception {
|
Order order = this.selectById(orderId);
|
OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper();
|
BeanUtils.copyProperties(order, orderPriceWarpper);
|
AppUser appUser = appUserService.selectById(uid);
|
orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue());
|
orderPriceWarpper.setBalance(appUser.getAccountBalance());
|
orderPriceWarpper.setDiscount(0D);
|
orderPriceWarpper.setDiscountAmount(0D);
|
orderPriceWarpper.setPayType(1);//微信支付
|
Double orderMoney = order.getOrderMoney();
|
|
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());
|
orderMoney = new BigDecimal(orderMoney * 0.9).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
|
}
|
if(null != couponId){
|
UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
|
Coupon coupon1 = couponService.selectById(userToCoupon.getCouponId());
|
orderMoney = orderMoney - coupon1.getCouponPreferentialAmount();
|
orderPriceWarpper.setDiscountedPrice(coupon1.getCouponPreferentialAmount());
|
orderPriceWarpper.setCouponId(couponId);
|
}
|
if(payType == 0){//不使用余额抵扣
|
orderPriceWarpper.setPayType(1);
|
}
|
if(payType == 1 && balance.compareTo(orderMoney) >= 0){//使用余额抵扣
|
orderPriceWarpper.setPayType(2);
|
}
|
if(payType == 1 && balance.compareTo(orderMoney) < 0){//使用余额抵扣部分
|
orderPriceWarpper.setPayType(4);
|
}
|
|
orderPriceWarpper.setPayMoney(orderMoney);
|
return orderPriceWarpper;
|
}
|
|
/**
|
* 获取订单支付页面优惠券列表
|
* @param uid
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<CouponWarpper> queryPayCouponList(Integer uid, Long orderId) throws Exception {
|
Order order = this.selectById(orderId);
|
return userToCouponService.queryPayCouponList(uid, order.getOrderMoney());
|
}
|
|
|
/**
|
* 支付订单操作
|
* @param uid
|
* @param orderPayment
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil orderPayment(Integer uid, OrderPayment orderPayment) throws Exception {
|
Order order = this.selectById(orderPayment.getOrderId());
|
AppUser appUser = appUserService.selectById(uid);
|
if(order.getState() != 107){
|
return ResultUtil.error("不允许支付");
|
}
|
if(orderPayment.getPayType() == 2){
|
Double payMoney = order.getOrderMoney() * (appUser.getHavDiscount() == 1 ? 0.9 : 1);
|
if(appUser.getAccountBalance() < payMoney){
|
return ResultUtil.error("账户余额不足");
|
}
|
}
|
//开始支付操作
|
if(orderPayment.getPayType() == 1){//微信支付
|
return weixinPay(order, appUser, orderPayment.getCouponId());
|
}
|
if(orderPayment.getPayType() == 2){//余额支付
|
return balancePayment(order, appUser, orderPayment.getCouponId());
|
}
|
if(orderPayment.getPayType() == 3){//线下支付(由司机端操作)
|
}
|
if(orderPayment.getPayType() == 4){//微信+余额
|
if(appUser.getAccountBalance() == 0){
|
return ResultUtil.error("账户余额不足");
|
}
|
return weixinAndBalancePayment(order, appUser, orderPayment.getCouponId());
|
}
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 微信支付
|
* @param order
|
* @param appUser
|
* @param couponId
|
* @return
|
* @throws Exception
|
*/
|
public ResultUtil weixinPay(Order order, AppUser appUser, Integer couponId) throws Exception{
|
Double payMoney = order.getOrderMoney();
|
if(null != couponId){
|
UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
|
if(userToCoupon.getValidCount() > 0){
|
userToCoupon.setValidCount(userToCoupon.getValidCount() - 1);
|
userToCouponService.updateById(userToCoupon);
|
Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
|
payMoney = payMoney - coupon.getCouponPreferentialAmount();
|
order.setCouponId(coupon.getId());
|
order.setDiscountedPrice(coupon.getCouponPreferentialAmount());
|
userToCouponService.updateById(userToCoupon);
|
}
|
}
|
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());
|
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);
|
|
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;
|
}
|
|
|
/**
|
* 账户余额支付
|
* @param order
|
* @param appUser
|
* @return
|
*/
|
public ResultUtil balancePayment(Order order, AppUser appUser, Integer couponId) throws Exception{
|
Double payMoney = order.getOrderMoney();
|
if(null != couponId){
|
UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
|
if(userToCoupon.getValidCount() > 0){
|
userToCoupon.setValidCount(userToCoupon.getValidCount() - 1);
|
userToCouponService.updateById(userToCoupon);
|
Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
|
payMoney = payMoney - coupon.getCouponPreferentialAmount();
|
order.setCouponId(coupon.getId());
|
order.setDiscountedPrice(coupon.getCouponPreferentialAmount());
|
|
Driver driver = driverService.selectById(order.getDriverId());
|
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);
|
}
|
}
|
|
if(appUser.getHavDiscount() == 1){//9折
|
order.setDiscount(9D);
|
order.setDiscountAmount(payMoney * 0.1);
|
payMoney = payMoney * 0.9;
|
}
|
|
order.setPayType(2);
|
order.setPayMoney(payMoney);
|
order.setPayTime(new Date());
|
order.setState(108);
|
this.updateById(order);
|
|
pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState());
|
if(null != order.getDriverId()) {
|
PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
|
pushOrderInfoWarpper.setId(order.getId());
|
pushOrderInfoWarpper.setState(order.getState());
|
pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
|
}
|
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(1);
|
accountChangeDetail.setUserId(appUser.getId());
|
accountChangeDetail.setCreateTime(new Date());
|
accountChangeDetail.setOldData(appUser.getAccountBalance());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(2);
|
accountChangeDetail.setOrderId(order.getId());
|
accountChangeDetail.setExplain("代驾服务费");
|
appUser.setAccountBalance(appUser.getAccountBalance() - payMoney);
|
accountChangeDetail.setNewData(appUser.getAccountBalance());
|
appUserService.updateById(appUser);
|
accountChangeDetailService.insert(accountChangeDetail);
|
|
//处理佣金和收入记录
|
saveCommission(order);
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 微信+账户余额支付
|
* @param order
|
* @param appUser
|
* @param couponId
|
* @return
|
* @throws Exception
|
*/
|
public ResultUtil weixinAndBalancePayment(Order order, AppUser appUser, Integer couponId) throws Exception{
|
Double payMoney = order.getOrderMoney();
|
if(null != couponId){
|
UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
|
if(userToCoupon.getValidCount() > 0){
|
userToCoupon.setValidCount(userToCoupon.getValidCount() - 1);
|
userToCouponService.updateById(userToCoupon);
|
Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
|
payMoney = payMoney - coupon.getCouponPreferentialAmount();
|
order.setCouponId(coupon.getId());
|
order.setDiscountedPrice(coupon.getCouponPreferentialAmount());
|
}
|
}
|
order.setPayType(1);
|
order.setPayMoney(payMoney);
|
|
payMoney = payMoney.compareTo(appUser.getAccountBalance()) > 0 ? payMoney - appUser.getAccountBalance() : 0D;
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(1);
|
accountChangeDetail.setUserId(appUser.getId());
|
accountChangeDetail.setCreateTime(new Date());
|
accountChangeDetail.setOldData(appUser.getAccountBalance());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(2);
|
accountChangeDetail.setOrderId(order.getId());
|
accountChangeDetail.setExplain("代驾服务费");
|
appUser.setAccountBalance(appUser.getAccountBalance().compareTo(payMoney) > 0 ? appUser.getAccountBalance() - payMoney : 0);
|
accountChangeDetail.setNewData(appUser.getAccountBalance());
|
appUserService.updateById(appUser);
|
accountChangeDetailService.insert(accountChangeDetail);
|
|
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());
|
|
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());
|
|
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);
|
|
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;
|
}
|
return ResultUtil.success();
|
|
}
|
|
/**
|
* 订单微信支付回调
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil orderPayCallback(String orderId, String transaction_id) throws Exception {
|
Order order = this.selectById(orderId);
|
if(order.getState() != 107){
|
return ResultUtil.success();
|
}
|
order.setState(108);
|
order.setPayTime(new Date());
|
order.setOrderNo(transaction_id);
|
this.updateById(order);
|
//添加收入明细
|
saveCommission(order);
|
|
pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState());
|
if(null != order.getDriverId()) {
|
PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
|
pushOrderInfoWarpper.setId(order.getId());
|
pushOrderInfoWarpper.setState(order.getState());
|
pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
|
}
|
return ResultUtil.success();
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
* 订单评价
|
* @param uid
|
* @param orderId
|
* @param score
|
* @param content
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil orderAppraise(Integer uid, Long orderId, Integer score, String content) throws Exception {
|
Order order = this.selectById(orderId);
|
if(order.getState() != 108){
|
return ResultUtil.error("不能进行评价");
|
}
|
order.setState(109);
|
this.updateById(order);
|
Evaluate evaluate = new Evaluate();
|
evaluate.setOrderId(orderId.intValue());
|
evaluate.setCreateTime(new Date());
|
evaluate.setScore(score);
|
evaluate.setEvaluate(content);
|
evaluate.setStatus(1);
|
evaluate.setUserId(uid);
|
evaluateService.insert(evaluate);
|
Driver driver = driverService.selectById(order.getDriverId());
|
driver.setScore(((null == driver.getScore() ? 0 : driver.getScore()) + score) / 2);
|
if(score == 5){//司机积分奖励
|
SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4));
|
if(null != systemConfig){
|
//{"num1":"10:00","num2":"14:00","num3":10,"num4":10,"num5":10,"num6":10,"num7":10,"num8":10,"num9":5,"num10":5}
|
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
|
Integer num5 = jsonObject.getInteger("num5");
|
|
//增加积分变动记录
|
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.getIntegral().doubleValue());
|
accountChangeDetail.setType(2);
|
accountChangeDetail.setExplain("代驾5星好评");
|
driver.setIntegral(driver.getIntegral() + num5);
|
accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
|
accountChangeDetailService.insert(accountChangeDetail);
|
}
|
}
|
if(score < 3){//差评扣减积分
|
SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4));
|
if(null != systemConfig){
|
//{"num1":"10:00","num2":"14:00","num3":10,"num4":10,"num5":10,"num6":10,"num7":10,"num8":10,"num9":5,"num10":5}
|
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
|
Integer num9 = jsonObject.getInteger("num9");
|
|
//增加积分变动记录
|
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.getIntegral().doubleValue());
|
accountChangeDetail.setType(2);
|
accountChangeDetail.setExplain("差评扣减积分");
|
driver.setIntegral(driver.getIntegral() - num9);
|
accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
|
accountChangeDetailService.insert(accountChangeDetail);
|
}
|
}
|
driverService.updateById(driver);
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 处理订单收入及分佣抽成
|
* @param order
|
* @return
|
* @throws Exception
|
*/
|
public void saveCommission(Order order) throws Exception{
|
//司机收入和代理商抽成(先分佣,后抽成)
|
//司机分佣和司机推荐用户首单奖励都在平台的抽佣中扣除,剩余的为平台抽佣。
|
Driver driver = driverService.selectById(order.getDriverId());
|
AppUser appUser = appUserService.selectById(order.getUserId());
|
Double payMoney = order.getPayMoney();
|
SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3));
|
if(null != systemConfig){
|
JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
|
Double num2 = jsonObject.getDouble("num2");
|
Double num3 = jsonObject.getDouble("num3");
|
if(order.getPayMoney() >= num2){
|
payMoney = payMoney - num3;//司机收入
|
SystemConfig systemConfig1 = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 2));
|
if(null != systemConfig1){
|
JSONObject jsonObject1 = JSON.parseObject(systemConfig1.getContent());
|
//司机推荐首单收入
|
List<Integer> state = Arrays.asList(108, 109);
|
int count = this.selectCount(new EntityWrapper<Order>().eq("userId", appUser.getId()).eq("status", 1).in("state", state));
|
if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && count == 1){
|
Double num1 = jsonObject1.getDouble("num1");
|
num1 = (num3 >= num1 ? num1 : num3);
|
|
if(num1 > 0){
|
Driver driver1 = driverService.selectById(appUser.getInviterId());
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver1.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(5);
|
accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
accountChangeDetail.setExplain("订单分佣收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver1.setCommission(driver1.getCommission() + num1);
|
accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
driverService.updateById(driver1);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
|
Revenue revenue = new Revenue();
|
revenue.setType(2);
|
revenue.setUserType(2);
|
revenue.setUserId(driver1.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num1);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
}
|
num3 = (num3 >= num1 ? num3 - num1 : 0);
|
}
|
|
//开始处理层级抽佣
|
if(null != driver & null != driver.getInviterType() && driver.getInviterType() == 2){
|
Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机
|
if(null != driver1 && null != driver1.getInviterType() && driver1.getInviterType() == 2){
|
Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机
|
if(null != driver2 && null != driver2.getInviterType() && driver2.getInviterType() == 2){
|
Driver driver3 = driverService.selectById(driver2.getInviterId());//三级级司机
|
Double num5 = jsonObject1.getDouble("num5");
|
Double num6 = jsonObject1.getDouble("num6");
|
Double num7 = jsonObject1.getDouble("num7");
|
num5 = (num3 >= num5 ? num5 : num3);
|
if(num5 > 0 && null != driver1){
|
Revenue revenue = new Revenue();
|
revenue.setType(2);
|
revenue.setUserType(2);
|
revenue.setUserId(driver1.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num5);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver1.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(5);
|
accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
accountChangeDetail.setExplain("订单分佣收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver1.setCommission(driver1.getCommission() + num5);
|
accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
driverService.updateById(driver1);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
num3 = (num3 >= num5 ? num3 - num5 : 0);
|
}
|
num6 = (num3 >= num6 ? num6 : num3);
|
if(num6 > 0 && null != driver2){
|
Revenue revenue = new Revenue();
|
revenue.setType(2);
|
revenue.setUserType(2);
|
revenue.setUserId(driver2.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num6);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver2.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(5);
|
accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
|
accountChangeDetail.setExplain("订单分佣收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver2.setCommission(driver2.getCommission() + num6);
|
accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
|
driverService.updateById(driver2);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
num3 = (num3 >= num6 ? num3 - num6 : 0);
|
}
|
num7 = (num3 >= num7 ? num7 : num3);
|
if(num7 > 0 && null != driver3){
|
Revenue revenue = new Revenue();
|
revenue.setType(2);
|
revenue.setUserType(2);
|
revenue.setUserId(driver3.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num7);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver3.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(5);
|
accountChangeDetail.setOldData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission());
|
accountChangeDetail.setExplain("订单分佣收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver3.setCommission(driver3.getCommission() + num7);
|
accountChangeDetail.setNewData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission());
|
driverService.updateById(driver3);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
num3 = (num3 >= num7 ? num3 - num7 : 0);
|
}
|
}else{
|
Double num3_ = jsonObject1.getDouble("num3");
|
Double num4 = jsonObject1.getDouble("num4");
|
num3_ = (num3 >= num3_ ? num3_ : num3);
|
if(num3_ > 0 && null != driver1){
|
Revenue revenue = new Revenue();
|
revenue.setType(2);
|
revenue.setUserType(2);
|
revenue.setUserId(driver1.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num3_);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver1.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(5);
|
accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
accountChangeDetail.setExplain("订单分佣收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver1.setCommission(driver1.getCommission() + num3_);
|
accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
driverService.updateById(driver1);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
num3 = (num3 >= num3_ ? num3 - num3_ : 0);
|
}
|
num4 = (num3 >= num4 ? num4 : num3);
|
if(num4 > 0 && null != driver2){
|
Revenue revenue = new Revenue();
|
revenue.setType(2);
|
revenue.setUserType(2);
|
revenue.setUserId(driver2.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num4);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver2.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(5);
|
accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
|
accountChangeDetail.setExplain("订单分佣收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver2.setCommission(driver2.getCommission() + num4);
|
accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission());
|
driverService.updateById(driver2);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
num3 = (num3 >= num4 ? num3 - num4 : 0);
|
}
|
}
|
}else{
|
Double num2_ = jsonObject1.getDouble("num2");
|
num2_ = (num3 >= num2_ ? num2_ : num3);
|
if(num2_ > 0 && null != driver1){
|
Revenue revenue = new Revenue();
|
revenue.setType(2);
|
revenue.setUserType(2);
|
revenue.setUserId(driver1.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num2_);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver1.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(5);
|
accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
accountChangeDetail.setExplain("订单分佣收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver1.setCommission(driver1.getCommission() + num2_);
|
accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
|
driverService.updateById(driver1);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
num3 = (num3 >= num2_ ? num3 - num2_ : 0);
|
}
|
}
|
}
|
//处理代理商抽佣
|
if(num3 > 0 && null != driver){
|
Revenue revenue = new Revenue();
|
revenue.setType(1);
|
revenue.setUserType(3);
|
revenue.setUserId(driver.getAgentId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(num3);
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
}
|
}
|
}
|
}
|
//司机订单收入
|
Revenue revenue = new Revenue();
|
revenue.setType(1);
|
revenue.setUserType(2);
|
revenue.setUserId(driver.getId());
|
revenue.setOrderId(order.getId());
|
revenue.setAmount(payMoney + order.getDiscountedPrice());
|
revenue.setCreateTime(new Date());
|
revenueService.insert(revenue);
|
|
AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
|
accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
|
accountChangeDetail.setUserType(2);
|
accountChangeDetail.setUserId(driver.getId());
|
accountChangeDetail.setType(1);
|
accountChangeDetail.setChangeType(1);
|
accountChangeDetail.setOrderId(order.getId());
|
accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
|
accountChangeDetail.setExplain("订单收入");
|
accountChangeDetail.setCreateTime(new Date());
|
driver.setBalance(driver.getBalance() + payMoney);
|
if(null != order.getCouponId()){
|
driver.setCouponBalance(driver.getCouponBalance() + order.getDiscountedPrice());
|
}
|
accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
|
driverService.updateById(driver);
|
accountChangeDetailService.saveData(accountChangeDetail);
|
}
|
|
|
/**
|
* 获取乘客行程
|
* @param uid
|
* @param pageNum
|
* @param pageSize
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<OrderListWarpper> queryMyOrder(Integer uid, Integer pageNum, Integer pageSize) throws Exception {
|
pageNum = (pageNum - 1) * pageSize;
|
return this.baseMapper.queryMyOrder(uid, pageNum, pageSize);
|
}
|
|
|
/**
|
* 获取未开票订单
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<OrderListWarpper> queryNotInvoiceOrder(Integer uid, NotInvoiceOrder notInvoiceOrder) throws Exception {
|
notInvoiceOrder.setPageNum((notInvoiceOrder.getPageNum() - 1) * notInvoiceOrder.getPageSize());;
|
return this.baseMapper.queryNotInvoiceOrder(uid, notInvoiceOrder);
|
}
|
|
|
}
|