package com.stylefeng.guns.modular.taxi.service.impl;
|
|
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.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.account.controller.AppOrderController;
|
import com.stylefeng.guns.modular.crossCity.dao.OrderCrossCityMapper;
|
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
|
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
|
import com.stylefeng.guns.modular.crossCity.server.impl.OrderCrossCityServiceImpl;
|
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
|
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
|
import com.stylefeng.guns.modular.specialTrain.dao.OrderPrivateCarMapper;
|
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
|
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
|
import com.stylefeng.guns.modular.system.dao.*;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.*;
|
import com.stylefeng.guns.modular.system.warpper.*;
|
import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
|
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
|
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
|
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
|
import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
|
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
|
import org.bouncycastle.crypto.tls.MACAlgorithm;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.MediaType;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Isolation;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
import org.springframework.web.client.RestTemplate;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.MathContext;
|
import java.math.RoundingMode;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@Service
|
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
public class OrderTaxiServiceImpl extends ServiceImpl<OrderTaxiMapper, OrderTaxi> implements IOrderTaxiService {
|
|
@Resource
|
private OrderTaxiMapper orderTaxiMapper;
|
|
@Resource
|
private SensitiveWordsMapper sensitiveWordsMapper;
|
|
@Resource
|
private SysIntegralMapper sysIntegralMapper;
|
|
@Resource
|
private UserActivityDiscount1Mapper userActivityDiscount1Mapper;
|
|
@Resource
|
private OrderPrivateCarMapper orderPrivateCarMapper;
|
|
@Resource
|
private RegionMapper regionMapper;
|
|
@Autowired
|
private IOrderCancelService orderCancelService;
|
|
@Autowired
|
private GDMapElectricFenceUtil gdMapElectricFenceUtil;
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private DateUtil dateUtil;
|
|
@Autowired
|
private IUserInfoService userInfoService;
|
|
@Autowired
|
private IPushOrderService pushOrderService;
|
|
@Autowired
|
private ICancleOrderService cancleOrderService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
@Autowired
|
private ITransactionDetailsService transactionDetailsService;
|
|
@Autowired
|
private IPaymentRecordService paymentRecordService;
|
|
@Autowired
|
private IUserCouponRecordService userCouponRecordService;
|
|
@Autowired
|
private IUserRedPacketRecordService userRedPacketRecordService;
|
|
@Autowired
|
private GDMapGeocodingUtil gdMapGeocodingUtil;
|
|
@Autowired
|
private ICompanyCityService companyCityService;
|
|
@Autowired
|
private PushUtil pushUtil;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private RestTemplate internalRestTemplate;
|
|
@Autowired
|
private IUserActivityRedenvelopeService userActivityRedenvelopeService;
|
|
@Autowired
|
private IDriverOrdersService driverOrdersService;
|
|
@Autowired
|
private IIncomeService incomeService;
|
|
@Autowired
|
private ICompanyService companyService;
|
|
@Autowired
|
private ISystemNoticeService systemNoticeService;
|
|
@Autowired
|
private IOrderPositionService orderPositionService;
|
|
@Autowired
|
private ChinaMobileUtil chinaMobileUtil;
|
|
@Autowired
|
private IDriverServiceService driverServiceService;
|
|
@Autowired
|
private GDFalconUtil gdFalconUtil;
|
|
@Autowired
|
private IOrderPrivateCarService orderPrivateCarService;
|
|
@Autowired
|
private IOrderCrossCityService orderCrossCityService;
|
|
@Resource
|
private OrderCrossCityMapper orderCrossCityMapper;
|
|
@Autowired
|
private IOrderLogisticsService orderLogisticsService;
|
|
@Autowired
|
private IOpenCityService openCityService;
|
|
@Autowired
|
private ITaxiCardService taxiCardService;
|
|
@Autowired
|
private ITaxiCardPaymentService taxiCardPaymentService;
|
|
@Autowired
|
private IUserUserService userUserService;
|
|
@Autowired
|
private IUserTaxiCardService userTaxiCardService;
|
|
@Autowired
|
private IRegionService regionService;
|
|
public static List<Integer> orderIds = new ArrayList<>();
|
|
|
@Value("${callbackPath}")
|
private String callbackPath;
|
|
|
|
|
|
|
|
/**
|
* 出租车下单操作
|
* @param orderTaxi
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public synchronized ResultUtil<BaseWarpper> taxiOrder(OrderTaxi orderTaxi, Integer uid) throws Exception {
|
//定义用户所属公司
|
UserInfo userInfo1 = userInfoService.selectById(uid);
|
Company query = companyCityService.query(String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat()));
|
if(null == query){
|
return ResultUtil.error("出发点暂未开通");
|
}
|
if(null != userInfo1.getCompanyId() && 0 != userInfo1.getCompanyId()){
|
userInfo1.setCompanyId(query.getId());
|
userInfoService.updateById(userInfo1);
|
}
|
|
if(orderTaxi.getTravelTime().getTime() > (System.currentTimeMillis() + 600000)){
|
orderTaxi.setOrderType(2);
|
}
|
|
|
/**
|
* 1.出租车、专车、跨城有待支付的订单不能叫车
|
* 2.小件物流有未完成的订单可以下跨城、专车、出租车
|
* 3.出租车、专车、跨城有预约单可以下即时单
|
*/
|
List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12);
|
if(orderPrivateCars.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, null, 1, 7, 12);
|
if(list.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
List<OrderCrossCity> orderCrossCities1 = orderCrossCityMapper.queryByState(uid, 7, 12);
|
if(orderCrossCities1.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
if(orderTaxi.getOrderType() == 1){
|
orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12);
|
if(orderPrivateCars.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
list = orderTaxiMapper.queryByState_(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12);
|
if(list.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
}
|
|
List<OrderPrivateCar> orderPrivateCars1 = orderPrivateCarMapper.queryByState(uid, null, 3, 7, 12);
|
if(orderPrivateCars1.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
List<OrderTaxi> list1 = orderTaxiMapper.queryByState_(uid, null, 3, 7, 12);
|
if(list1.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
List<OrderCrossCity> orderCrossCities11 = orderCrossCityMapper.queryByState(uid, 7, 12);
|
if(orderCrossCities11.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
if(orderTaxi.getOrderType() == 1){
|
orderPrivateCars1 = orderPrivateCarMapper.queryByState(uid, 1, 3, 1, 2, 3, 4, 5, 6, 7, 11, 12);
|
if(orderPrivateCars1.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
list1 = orderTaxiMapper.queryByState_(uid, 1, 3, 1, 2, 3, 4, 5, 6, 7, 11, 12);
|
if(list1.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
}
|
|
orderTaxi.setOrderNum(this.getOrderNum());
|
if(ToolUtil.isEmpty(orderTaxi.getPlacementLon()) || ToolUtil.isEmpty(orderTaxi.getPlacementLat())) {
|
return ResultUtil.error("未开启定位");
|
}
|
Map<String, String> geocode = gdMapGeocodingUtil.geocode(String.valueOf(orderTaxi.getPlacementLon()), String.valueOf(orderTaxi.getPlacementLat()));
|
orderTaxi.setPlacementAddress(geocode.get("address"));
|
orderTaxi.setStartAddress(orderTaxi.getStartAddress().replaceAll("& #40;", "\\("));//特殊字符转义
|
orderTaxi.setStartAddress(orderTaxi.getStartAddress().replaceAll("& #41;", "\\)"));
|
orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #40;", "\\("));
|
orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #41;", "\\)"));
|
orderTaxi.setUserId(uid);
|
orderTaxi.setMileage(0D);
|
orderTaxi.setOrderMoney(0D);
|
orderTaxi.setTravelMoney(0D);
|
orderTaxi.setParkMoney(0D);
|
orderTaxi.setRoadTollMoney(0D);
|
orderTaxi.setRedPacketMoney(0D);
|
orderTaxi.setCouponMoney(0D);
|
orderTaxi.setInsertTime(new Date());
|
orderTaxi.setIsReassign(1);
|
if(orderTaxi.getSubstitute() == 0){//不是代下单
|
UserInfo userInfo = userInfoService.selectById(uid);
|
if(ToolUtil.isEmpty(userInfo.getPhone())){
|
return ResultUtil.error("请先绑定手机号码");
|
}
|
orderTaxi.setPassengers(userInfo.getName());
|
orderTaxi.setPassengersPhone(userInfo.getPhone());
|
}
|
orderTaxi.setState(1);//待接单
|
if(orderTaxi.getOrderSource() == 2 && null != orderTaxi.getDriverId()){//扫码下单,
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
if(null == driver){
|
return ResultUtil.error("扫码下单失败,司机信息有误");
|
}
|
if(driver.getAuthState() == 1){
|
return ResultUtil.error("司机信息还未完成审核,无法完成下单");
|
}
|
if(driver.getAuthState() == 3){
|
return ResultUtil.error("司机账户已被冻结,无法提供服务");
|
}
|
if(driver.getAuthState() == 4){
|
return ResultUtil.error("司机信息未通过审核,无法提供服务");
|
}
|
if(driver.getState() == 1){
|
return ResultUtil.error("司机还未上线,无法提供服务");
|
}
|
if(driver.getState() == 3){
|
return ResultUtil.error("司机正在服务中,无法提供服务");
|
}
|
List<DriverService> driverServices = driverServiceService.query(orderTaxi.getDriverId(), 2);
|
if(driverServices.size() == 0){
|
return ResultUtil.error("该司机不能服务此业务");
|
}
|
|
orderTaxi.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
|
driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
|
orderTaxi.setCarId(driver.getCarId());
|
orderTaxi.setState(2);//待出发
|
orderTaxi.setSnatchOrderTime(new Date());
|
|
// //调用高德创建轨迹
|
// String s = gdFalconUtil.selectTerminal(driver.getPhone());
|
// String track = gdFalconUtil.createTrack(s);
|
// orderTaxi.setTrackId(track);
|
//
|
//调用移动的小号接口
|
Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
|
if(String.valueOf(map.get("code")).equals("200")){
|
orderTaxi.setTelX(map.get("telX"));
|
orderTaxi.setBindId(map.get("bindId"));
|
}
|
|
driver.setState(3);
|
driverService.updateById(driver);
|
}
|
|
this.insert(orderTaxi);
|
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
if(orderTaxi.getState() == 2){
|
//推送司机订单状态
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
|
pushUtil.pushDriverPosition(orderTaxi.getId(), 2);
|
}
|
}
|
}).start();
|
|
if(orderTaxi.getState() == 1){
|
//推送司机抢单
|
this.pushOrder(orderTaxi, 1);
|
}
|
|
//添加消息
|
systemNoticeService.addSystemNotice(1, "您的出租车订单已下单成功,我们正在为您指派司机,请稍后!", orderTaxi.getUserId(), 1);
|
|
BaseWarpper baseWarpper = new BaseWarpper();
|
baseWarpper.setId(orderTaxi.getId());
|
return ResultUtil.success(baseWarpper);
|
}
|
|
|
/**
|
* 继续执行推动等待操作
|
* @param id
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil pushOrderTaxi(Integer id) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(id);
|
if(null == orderTaxi){
|
return ResultUtil.error("推送订单失败,订单信息有误");
|
}
|
if(orderTaxi.getState() != 1){
|
return ResultUtil.error("订单已被司机接单,不能重复推送");
|
}
|
|
//处理摆渡订单的继续推单操作
|
if(orderTaxi.getType() == 2){
|
OrderCrossCityServiceImpl.pushEndMap.put(orderTaxi.getCrossCityOrderId(), false);//还原标识数据
|
List<OrderPrivateCar> list = orderPrivateCarService.selectList(new EntityWrapper<OrderPrivateCar>().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace()));
|
List<Map<String, Integer>> orders = new ArrayList<>();
|
for(OrderPrivateCar orderPrivateCar1 : list){
|
if(orderPrivateCar1.getState() != 1){
|
return ResultUtil.error("订单已被司机接单,推单取消");
|
}
|
Map<String, Integer> map = new HashMap<>();
|
map.put("orderType", 1);
|
map.put("orderId", orderPrivateCar1.getId());
|
orders.add(map);
|
}
|
List<OrderTaxi> list1 = this.selectList(new EntityWrapper<OrderTaxi>().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace()));
|
for(OrderTaxi orderTaxi1 : list1){
|
if(orderTaxi1.getState() != 1){
|
return ResultUtil.error("订单已被司机接单,推单取消");
|
}
|
Map<String, Integer> map = new HashMap<>();
|
map.put("orderType", 2);
|
map.put("orderId", orderTaxi1.getId());
|
orders.add(map);
|
}
|
//开始重新推单
|
orderCrossCityService.pushOrder(orders);
|
|
}else{
|
this.pushOrder(orderTaxi, 1);
|
}
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 获取取消订单需要支付的金额(包含小费)
|
* @param id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil<BaseWarpper> queryCancleAmount(Integer id) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(id);
|
if(null == orderTaxi){
|
return ResultUtil.error("获取数据失败,订单信息有误");
|
}
|
double amount = 0;
|
CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, orderTaxi.getCompanyId());
|
if(null == query){
|
return ResultUtil.error("请先完善取消规则");
|
}
|
if(null != orderTaxi.getDriverId() &&
|
(orderTaxi.getSnatchOrderTime().getTime() + query.getMinuteNum() * 60 * 1000) < new Date().getTime()){//收费的情况
|
if(null != query){
|
amount += query.getMoney();
|
}
|
}
|
BaseWarpper baseWarpper = new BaseWarpper();
|
baseWarpper.setAmount(amount);
|
return ResultUtil.success(baseWarpper);
|
}
|
|
|
/**
|
* 添加订单取消
|
* @param id
|
* @param reason
|
* @param remark
|
* @param uid
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid) throws Exception {
|
if(ToolUtil.isNotEmpty(remark)){
|
if(ToolUtil.isNotEmpty(remark)){
|
List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
|
for(SensitiveWords s : sensitiveWords){
|
remark = remark.replaceAll(s.getContent(), "***");
|
}
|
}
|
}
|
|
OrderTaxi orderTaxi = this.selectById(id);
|
Integer integer = null;
|
if(null == orderTaxi){
|
return ResultUtil.error("取消订单失败,订单信息有误");
|
}
|
// if(orderTaxi.getState() == 4){
|
// return ResultUtil.error("司机已到达预约点,取消会产生一定的费用");
|
// }
|
if(orderTaxi.getState() >= 5 && orderTaxi.getState() != 11){
|
return ResultUtil.error("取消订单失败,不合法的操作");
|
}
|
if(null == orderTaxi.getDriverId()){//没有接单的情况
|
if(orderTaxi.getType() == 2){//摆渡车
|
OrderCrossCityServiceImpl.pushEndMap.remove(orderTaxi.getCrossCityOrderId());//删除标识数据
|
List<OrderPrivateCar> list = orderPrivateCarService.selectList(new EntityWrapper<OrderPrivateCar>().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace()));
|
for(OrderPrivateCar orderPrivateCar1 : list){
|
orderCancelService.saveData(orderPrivateCar1.getId(), 1, "无司机接单", "无司机接单", null, null, 2, 1, uid);
|
orderPrivateCar1.setState(10);
|
orderPrivateCarService.updateById(orderPrivateCar1);
|
}
|
List<OrderTaxi> list1 = this.selectList(new EntityWrapper<OrderTaxi>().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace()));
|
for(OrderTaxi orderTaxi1 : list1){
|
orderCancelService.saveData(orderTaxi1.getId(), 2, "无司机接单", "无司机接单", null, null, 2, 1, uid);
|
orderTaxi1.setState(10);
|
this.updateById(orderTaxi1);
|
}
|
}else{
|
integer = orderCancelService.saveData(id, 2, "无司机接单", "无司机接单", null, null, 2, 1, uid);
|
orderTaxi.setState(10);
|
this.updateById(orderTaxi);
|
}
|
}else {
|
CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, orderTaxi.getCompanyId());
|
if (null != query) {
|
if ((orderTaxi.getSnatchOrderTime().getTime() + query.getMinuteNum() * 60 * 1000) < System.currentTimeMillis() && query.getMoney().compareTo(0D) > 0) {//收费的情况
|
orderTaxi.setState(12);
|
this.updateById(orderTaxi);
|
integer = orderCancelService.saveData(id, 2, reason, remark, null, query.getMoney(), 1, 1, uid);
|
} else {
|
integer = orderCancelService.saveData(id, 2, reason, remark, null, null, 2, 1, uid);
|
|
orderTaxi.setState(10);
|
this.updateById(orderTaxi);
|
}
|
this.deleteTask(id);//删除定时任务
|
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
System.err.println("推送取消操作---------------------");
|
}
|
}).start();
|
|
//修改司机为空闲
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
driver.setState(2);
|
driverService.updateById(driver);
|
}else{
|
return ResultUtil.error("请完善后台取消规则设置");
|
}
|
|
}
|
|
//添加消息
|
systemNoticeService.addSystemNotice(1, "您已成功取消出行订单,谢谢使用!", orderTaxi.getUserId(), 1);
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", integer);
|
return ResultUtil.success(map);
|
}
|
|
|
/**
|
* 取消订单操作
|
* @param id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
public ResultUtil cancleOrderTaxi(Integer id, Integer payType, Integer cancleId, Integer type) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(id);
|
Integer uid = orderTaxi.getUserId();
|
UserInfo userInfo = userInfoService.selectById(uid);
|
ResultUtil resultUtil = ResultUtil.success(new Object());
|
|
if(null == orderTaxi){
|
return ResultUtil.error("取消订单失败,订单信息有误", "");
|
}
|
if(orderTaxi.getState() != 12){
|
return ResultUtil.error("取消订单失败,不合法的操作", "");
|
}
|
OrderCancel orderCancel = null;
|
if(null == cancleId){
|
orderCancel = orderCancelService.query(id, 2, null, null, 1);
|
}else{
|
orderCancel = orderCancelService.selectById(cancleId);
|
}
|
|
CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, orderTaxi.getCompanyId());
|
System.out.println("取消订单:"+query);
|
if(null != query){
|
if(payType == 1){//微信支付
|
String value = redisUtil.getValue("appletOpenId");
|
String appletsOpenId = null;
|
if(ToolUtil.isNotEmpty(value)){
|
JSONObject jsonObject = JSON.parseObject(value);
|
appletsOpenId = jsonObject.getString(uid.toString());
|
}else{
|
appletsOpenId = userInfo.getAppletsOpenId();
|
}
|
orderCancel.setPayType(1);
|
orderCancelService.updateById(orderCancel);
|
String app = type == 1 ? "APP" : "JSAPI";
|
resultUtil = payMoneyUtil.weixinpay("订单取消", "", id + "_2_" + UUIDUtil.getRandomCode(5), query.getMoney().toString(), "/base/wxCancelOrderTaxi", app, userInfo.getAppletsOpenId());
|
paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 1, query.getMoney(), "", 1);//添加预支付数据
|
|
// Map<String, String> map = icbcPayUtil.placeAnOrder(id + ",2", 9, 5, uid.toString(), "订单取消", query.getMoney(), callbackPath + "/base/wxCancelOrderTaxi", "", type, appletsOpenId);
|
// if(map.get("code").equals("200")){
|
// paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 1, query.getMoney(), map.get("order_id"), 1);//添加预支付数据
|
// resultUtil = ResultUtil.success(map.get("data"));
|
// }else{
|
// resultUtil = ResultUtil.error(map.get("msg"), "");
|
// }
|
}
|
if(payType == 2){//支付宝支付
|
orderCancel.setPayType(2);
|
orderCancelService.updateById(orderCancel);
|
resultUtil = payMoneyUtil.alipay("订单取消", "订单取消", "", id + "_2_" + UUIDUtil.getRandomCode(5), query.getMoney().toString(), "/base/aliCancelOrderTaxi");
|
paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 2, query.getMoney(), "", 1);//添加预支付数据
|
|
// Map<String, String> map = icbcPayUtil.placeAnOrder(id + ",2", 10, 5, uid.toString(), "订单取消", query.getMoney(), callbackPath + "/base/aliCancelOrderTaxi", "", type, null);
|
// if(map.get("code").equals("200")){
|
// paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 2, query.getMoney(), map.get("order_id"), 1);//添加预支付数据
|
// resultUtil = ResultUtil.success(map.get("data"));
|
// }else{
|
// resultUtil = ResultUtil.error(map.get("msg"), "");
|
// }
|
}
|
if(payType == 3){//余额支付
|
if(userInfo.getBalance() != null && userInfo.getBalance() < query.getMoney()){
|
return ResultUtil.error("余额不足,无法完成支付");
|
}
|
// resultUtil= appOrderController.moneyPay(id,userInfo.getId(),query.getMoney());
|
// if(resultUtil.getCode()==500){
|
// return ResultUtil.error("电子余额不足,无法完成支付");
|
// }
|
|
userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(query.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "出租车取消订单", query.getMoney(), 2, 1, 1, 2, id);
|
userInfoService.updateById(userInfo);
|
|
//解除小号绑定
|
if(orderTaxi.getBindId() != null){
|
chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId(), orderTaxi.getTelX(), (System.currentTimeMillis() + 600000));
|
}
|
|
orderTaxi.setState(10);
|
orderTaxi.setTelX("");
|
orderTaxi.setBindId("");
|
this.updateById(orderTaxi);
|
|
orderCancel.setState(2);
|
orderCancel.setPayType(3);
|
orderCancelService.updateById(orderCancel);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderTaxi.getCompanyId(), 3, orderTaxi.getId(), 2, query.getMoney());
|
|
this.deleteTask(id);//删除定时任务
|
|
// new Thread(new Runnable() {
|
// @Override
|
// public void run() {
|
// pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
// }
|
// }).start();
|
|
//添加消息
|
systemNoticeService.addSystemNotice(1, "您已使用余额成功支付取消订单费用,谢谢使用!", orderTaxi.getUserId(), 1);
|
}
|
if(payType == 4){
|
Double payMoney = orderTaxi.getOrderMoney();
|
Integer integer = paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 4, query.getMoney(), "", 1);
|
resultUtil = appOrderController.placeAnOrder(new BigDecimal(query.getMoney()), 4,id,8,integer);
|
|
}
|
}
|
return resultUtil;
|
}
|
|
|
/**
|
* 删除定时任务
|
* @param orderId
|
*/
|
@Override
|
public void deleteTask(Integer orderId){
|
//发送验证码短信
|
HttpHeaders headers = new HttpHeaders();
|
// 以表单的方式提交
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
//将请求头部和参数合成一个请求
|
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
params.add("orderId", orderId + "");
|
params.add("orderType", "2");
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
|
String s = internalRestTemplate.postForObject("http://driver-server/base/netty/deleteTask", requestEntity, String.class);
|
JSONObject jsonObject = JSON.parseObject(s, JSONObject.class);
|
if(jsonObject.getIntValue("code") != 200){
|
System.err.println("调用driver-server出错了");
|
}
|
}
|
|
|
/**
|
* 获取用户余额和可用优惠券数量
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public Map<String, Object> queryBalance(Integer orderId, Integer uid) throws Exception {
|
Map<String, Object> map = new HashMap<>();
|
UserInfo userInfo = userInfoService.selectById(uid);
|
map.put("balance", userInfo.getBalance());
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
int i = userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 2, orderTaxi.getOrderMoney());
|
i = i + userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 0, orderTaxi.getOrderMoney());
|
map.put("coupon", i);
|
return map;
|
}
|
|
@Override
|
public PreferentialDataVo queryBalance1(Integer orderId, Integer uid) throws Exception {
|
UserInfo userInfo = userInfoService.selectById(uid);
|
PreferentialDataVo preferentialDataVo = new PreferentialDataVo();
|
preferentialDataVo.setBalance(userInfo.getBalance());
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
Integer ids = userInfoService.getDiscount();
|
if(ids!=null){
|
List<UserActivityDiscount1> userActivityId = userActivityDiscount1Mapper.selectList(new EntityWrapper<UserActivityDiscount1>().eq("userActivityId", ids));
|
if(userActivityId.size()>0){
|
preferentialDataVo.setDiscount(userActivityId.get(0).getTaxi());
|
}
|
}
|
// 查出当前用户的红包 并将订单的修改
|
List<UserRedPacketRecord> userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper<UserRedPacketRecord>().eq("userId", uid).eq("state", 1).le("money",orderTaxi.getOrderMoney()).gt("expirationTime", new Date()).gt("endTime", new Date()));
|
if(userRedPacketRecords.size()>0){
|
|
preferentialDataVo.setRedPacket(userRedPacketRecords.get(0).getMoney());
|
orderTaxi.setRedPacketId(userRedPacketRecords.get(0).getId());
|
orderTaxi.setRedPacketMoney(userRedPacketRecords.get(0).getMoney());
|
this.updateById(orderTaxi);
|
}
|
|
//获取优惠券中最优数据
|
List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("companyId", orderTaxi.getCompanyId()).eq("state", 1).le("money",orderTaxi.getOrderMoney()).in("couponUseType", Arrays.asList(0, 2)).eq("userId", uid).where("now() < expirationTime"));
|
Integer id = null;
|
Double price = 0d;
|
Integer type = 0;
|
for (UserCouponRecord userCouponRecord : list){
|
if(userCouponRecord.getCouponType() == 1){//抵扣券
|
if(price.compareTo(userCouponRecord.getMoney()) < 0){
|
price = userCouponRecord.getMoney();
|
id = userCouponRecord.getId();
|
type = 1;
|
}
|
}else{//满减券
|
if(orderTaxi.getOrderMoney().compareTo(userCouponRecord.getFullMoney()) >= 0 && price.compareTo(userCouponRecord.getMoney()) < 0){
|
price = userCouponRecord.getMoney();
|
id = userCouponRecord.getId();
|
type = 1;
|
}
|
}
|
}
|
|
//获取打车卡中最优数
|
Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
|
CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1));
|
if(null == companyCity){
|
companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1));
|
}
|
if(null == companyCity){
|
companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1));
|
}
|
List<UserTaxiCard> userTaxiCards;
|
if(null!=companyCity){
|
userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().like("companyCityId", "%" + companyCity.getId() + "%")
|
.in("type", Arrays.asList(1, 2, 3, 4)).eq("userId", uid).where("now() between startTime and endTime"));
|
|
}else {
|
userTaxiCards=new ArrayList<>();
|
}
|
|
//全国卡
|
List<TaxiCard> taxiCards = taxiCardService.selectList(new EntityWrapper<TaxiCard>().eq("taxiCardType", 2).in("type", Arrays.asList(1, 2, 3, 4)).eq("state", 1));
|
if(taxiCards.size() > 0) {
|
List<UserTaxiCard> userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid)
|
.in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime"));
|
userTaxiCards.addAll(userTaxiCards2);
|
}
|
Map<String, Object> map = getOptimalTaxiCards(orderTaxi, price, id, type, userTaxiCards);
|
price = Double.valueOf(map.get("price").toString());
|
id = null != map.get("id") ? Integer.valueOf(map.get("id").toString()) : null;
|
type = Integer.valueOf(map.get("type").toString());
|
|
|
//亲密账户
|
List<UserTaxiCard> userTaxiCards_ = new ArrayList<>();
|
List<UserUser> bindUserId = userUserService.selectList(new EntityWrapper<UserUser>().eq("bindUserId", uid));
|
CompanyCity finalCompanyCity = companyCity;
|
bindUserId.forEach(userUser -> {
|
if(finalCompanyCity!=null) {
|
List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().in("type", Arrays.asList(1, 2, 3, 4))
|
.like("companyCityId", "%" + finalCompanyCity.getId() + "%").eq("userId", userUser.getUserId()).where("now() between startTime and endTime"));
|
userTaxiCards_.addAll(userTaxiCards1);
|
}
|
|
//全国卡
|
if(taxiCards.size() > 0) {
|
List<UserTaxiCard> userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", userUser.getUserId())
|
.in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime"));
|
userTaxiCards_.addAll(userTaxiCards2);
|
}
|
});
|
map = getOptimalTaxiCards(orderTaxi, price, id, type, userTaxiCards_);
|
price = Double.valueOf(map.get("price").toString());
|
id = null != map.get("id") ? Integer.valueOf(map.get("id").toString()) : null;
|
type = Integer.valueOf(map.get("type").toString());
|
|
if(price<=orderTaxi.getOrderMoney() || type==2 ){
|
preferentialDataVo.setObjectId(id);
|
preferentialDataVo.setDiscountAmount(price);
|
preferentialDataVo.setType(type);
|
}
|
return preferentialDataVo;
|
}
|
|
|
/**
|
* 获取最优数据
|
* @param orderTaxi
|
* @param price
|
* @param id
|
* @param type
|
* @param userTaxiCards
|
* @return
|
*/
|
public Map<String, Object> getOptimalTaxiCards(OrderTaxi orderTaxi, Double price, Integer id, Integer type, List<UserTaxiCard> userTaxiCards) throws Exception{
|
Map<String, Object> map = new HashMap<>();
|
for(UserTaxiCard t : userTaxiCards){
|
JSONObject jsonObject = JSON.parseObject(t.getContent());
|
List<Integer> integers = jsonObject.getJSONArray("businessTypes").toJavaList(Integer.class);
|
if(!integers.contains(2)){
|
continue;
|
}
|
if(t.getType() == 1){//打折次数卡{"businessTypes":[1,2,3],"time":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"discount":5}
|
Integer time = jsonObject.getInteger("time");
|
if(time == 0){
|
continue;
|
}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
Double discount = jsonObject.getDouble("discount");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
double v = new BigDecimal(orderTaxi.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
|
if(price.compareTo(v) < 0){
|
price = v;
|
id = t.getId();
|
type = 2;
|
}
|
|
}
|
}
|
|
}
|
if(t.getType() == 2){//优惠卡{"businessTypes":[1,2,3],"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"fullReduction":[[50,3],[100,5],[150,10]]}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
JSONArray fullReduction = jsonObject.getJSONArray("fullReduction");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
for(int j = fullReduction.size() - 1; j >= 0; j--){
|
JSONArray jsonArray = fullReduction.getJSONArray(j);
|
Double p = jsonArray.getDouble(0);//满金额
|
Double y = jsonArray.getDouble(1);//优惠金额
|
if(orderTaxi.getOrderMoney().compareTo(p) >= 0 && price.compareTo(y) < 0){
|
price = y;
|
id = t.getId();
|
type = 2;
|
}
|
}
|
}
|
}
|
}
|
if(t.getType() == 3){//次数卡{"businessTypes":[1,2,3],"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"time":1,"discountAmount":10}
|
Integer time = jsonObject.getInteger("time");
|
if(time == 0){
|
continue;
|
}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
Double discountAmount = jsonObject.getDouble("discountAmount");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
if(price.compareTo(discountAmount) < 0){
|
price = discountAmount;
|
id = t.getId();
|
type = 2;
|
}
|
}
|
}
|
|
}
|
if(t.getType() == 4){//打折天数卡{"businessTypes":[1,2,3],"discount":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"]}
|
Double discount = jsonObject.getDouble("discount");//折扣
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");//使用时间段
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
double v = new BigDecimal(orderTaxi.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
|
if(price.compareTo(v) < 0){
|
price = v;
|
id = t.getId();
|
type = 2;
|
}
|
}
|
}
|
}
|
}
|
map.put("price", price);
|
map.put("id", id);
|
map.put("type", type);
|
return map;
|
}
|
|
|
|
/**
|
* 获取优惠券列表
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryCoupon(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
List<Map<String, Object>> list = userCouponRecordService.queryCoupon(uid, orderTaxi.getCompanyId(), 1, 2, orderTaxi.getOrderMoney(), pageNum, size);
|
List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(uid, orderTaxi.getCompanyId(), 1, 0, orderTaxi.getOrderMoney(), pageNum, size);
|
list.addAll(list1);
|
return list;
|
}
|
|
|
@Override
|
public List<CouponsListVo> queryCouponList(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
|
pageNum = (pageNum - 1) * size;
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
List<CouponsListVo> rows = new ArrayList<>();
|
List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("companyId", orderTaxi.getCompanyId())
|
.eq("state", 1).in("couponUseType", Arrays.asList(0, 2)).eq("userId", uid).where("expirationTime >= now()"));
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
for (UserCouponRecord userCouponRecord : list){
|
if(userCouponRecord.getCouponType() == 2){//满减券
|
if(orderTaxi.getOrderMoney().compareTo(userCouponRecord.getFullMoney()) < 0){
|
continue;
|
}
|
}
|
CouponsListVo couponsListVo = new CouponsListVo();
|
couponsListVo.setId(userCouponRecord.getId());
|
couponsListVo.setDataType(1);
|
couponsListVo.setMoney(userCouponRecord.getMoney());
|
couponsListVo.setUserType(userCouponRecord.getCouponUseType());
|
couponsListVo.setTime(sdf.format(userCouponRecord.getExpirationTime()));
|
couponsListVo.setType(userCouponRecord.getCouponType());
|
couponsListVo.setFullMoney(userCouponRecord.getFullMoney());
|
couponsListVo.setState(userCouponRecord.getState());
|
Company company = companyService.selectById(userCouponRecord.getCompanyId());
|
couponsListVo.setCompany(company.getName());
|
rows.add(couponsListVo);
|
}
|
|
Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
|
System.out.println(geocode);
|
CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1));
|
if(null == companyCity){
|
companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1));
|
}
|
if(null == companyCity){
|
companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1));
|
}
|
List<UserTaxiCard> userTaxiCards=new ArrayList<>();
|
if(null !=companyCity){
|
userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid)
|
.in("type", Arrays.asList(1, 2, 3, 4)).like("companyCityId", "%" + companyCity.getId() + "%").where("now() between startTime and endTime"));
|
}
|
|
//全国卡
|
List<TaxiCard> taxiCards = taxiCardService.selectList(new EntityWrapper<TaxiCard>().eq("taxiCardType", 2).in("type", Arrays.asList(1, 2, 3, 4)).eq("state", 1));
|
if(taxiCards.size() > 0) {
|
List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid)
|
.in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime"));
|
userTaxiCards.addAll(userTaxiCards1);
|
}
|
|
|
//亲密账户
|
List<UserUser> bindUserId = userUserService.selectList(new EntityWrapper<UserUser>().eq("bindUserId", uid));
|
CompanyCity finalCompanyCity = companyCity;
|
List<UserTaxiCard> finalUserTaxiCards = userTaxiCards;
|
bindUserId.forEach(userUser -> {
|
if(finalCompanyCity!=null) {
|
List<UserTaxiCard> taxiCardPayments1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().in("type", Arrays.asList(1, 2, 3, 4))
|
.like("companyCityId", "%" + finalCompanyCity.getId() + "%").eq("userId", userUser.getUserId()).where("now() between startTime and endTime"));
|
finalUserTaxiCards.addAll(taxiCardPayments1);
|
}
|
|
//全国卡
|
if(taxiCards.size() > 0) {
|
List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", userUser.getUserId())
|
.in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime"));
|
finalUserTaxiCards.addAll(userTaxiCards1);
|
}
|
});
|
|
for(UserTaxiCard t : finalUserTaxiCards){
|
try {
|
CouponsListVo couponsListVo = new CouponsListVo();
|
couponsListVo.setId(t.getId());
|
couponsListVo.setDataType(2);
|
couponsListVo.setUserType(1);
|
couponsListVo.setTaxiCardType(t.getType());
|
couponsListVo.setTime(sdf.format(t.getEndTime()));
|
couponsListVo.setState(1);
|
Company company = companyService.selectById(t.getCompanyId());
|
couponsListVo.setCompany(company.getName());
|
couponsListVo.setName(taxiCardService.selectById(t.getTaxiCardId()).getName());
|
|
|
JSONObject jsonObject = JSON.parseObject(t.getContent());
|
JSONArray businessTypes = jsonObject.getJSONArray("businessTypes");
|
if(!businessTypes.toJavaList(Integer.class).contains(2)){
|
continue;
|
}
|
if(t.getType() == 1){//{"businessTypes":[1,2,3],"time":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"discount":5}
|
Integer time = jsonObject.getInteger("time");
|
if(time == 0){
|
continue;
|
}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
boolean b = true;
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]);
|
Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
b = false;
|
break;
|
}
|
}
|
if(b){
|
continue;
|
}
|
couponsListVo.setMoney(jsonObject.getDouble("discount"));
|
couponsListVo.setType(1);
|
}
|
if(t.getType() == 2){//{"businessTypes":[1,2,3],"fullReduction":[[50,3],[100,5],[150,10]]}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
boolean b = true;
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]);
|
Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
b = false;
|
break;
|
}
|
}
|
if(b){
|
continue;
|
}
|
JSONArray fullReduction = jsonObject.getJSONArray("fullReduction");
|
b = true;
|
for(int i = fullReduction.size() - 1; i >= 0 ; i--){
|
JSONArray jsonArray = fullReduction.getJSONArray(i);
|
Double m = jsonArray.getDouble(0);
|
Double j = jsonArray.getDouble(1);
|
if(orderTaxi.getOrderMoney().compareTo(m) >= 0){
|
couponsListVo.setMoney(j);
|
couponsListVo.setFullMoney(m);
|
b = false;
|
break;
|
}
|
}
|
if(b){
|
continue;
|
}
|
couponsListVo.setType(2);
|
}
|
if(t.getType() == 3){//{"businessTypes":[1,2,3],"time":1,"discountAmount":10}
|
Integer time = jsonObject.getInteger("time");
|
if(time == 0){
|
continue;
|
}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
boolean b = true;
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]);
|
Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
b = false;
|
break;
|
}
|
}
|
if(b){
|
continue;
|
}
|
couponsListVo.setMoney(jsonObject.getDouble("discountAmount"));
|
couponsListVo.setType(2);
|
}
|
if(t.getType() == 4){//{"businessTypes":[1,2,3],"discount":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"]}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
boolean b = true;
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]);
|
Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
b = false;
|
break;
|
}
|
}
|
if(b){
|
continue;
|
}
|
couponsListVo.setMoney(jsonObject.getDouble("discount"));
|
couponsListVo.setType(1);
|
}
|
|
|
String str = "";
|
TaxiCard taxiCard = taxiCardService.selectById(t.getTaxiCardId());
|
if(taxiCard.getTaxiCardType() == 1){
|
String[] split = taxiCard.getCompanyCityId().split(";");
|
for(String c : split){
|
CompanyCity companyCity1 = companyCityService.selectById(c);
|
if(ToolUtil.isNotEmpty(companyCity1.getAreaCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity1.getAreaCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity1.getCityCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity1.getCityCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
if(ToolUtil.isNotEmpty(companyCity1.getProvinceCode())){
|
Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity1.getProvinceCode()));
|
str += region.getName() + ";";
|
continue;
|
}
|
}
|
}else{
|
str = "全国;";
|
}
|
couponsListVo.setCity(str.substring(0, str.length() - 1));
|
|
rows.add(couponsListVo);
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
Collections.sort(rows, new Comparator<CouponsListVo>() {
|
public int compare(CouponsListVo s1, CouponsListVo s2) {
|
return Integer.compare(s1.getId(), s2.getId());
|
}
|
});
|
|
if(rows.size() >= (pageNum + 1) * size){
|
rows = rows.subList(pageNum, pageNum + size);
|
}else if(pageNum < rows.size() && rows.size() < (pageNum + 1) * size){
|
rows = rows.subList(pageNum, rows.size());
|
}else{
|
rows = new ArrayList<>();
|
}
|
|
rows = rows.stream().filter(e->e.getMoney()<=orderTaxi.getOrderMoney()|| e.getDataType()==2).collect(Collectors.toList());
|
return rows;
|
}
|
|
/**
|
* 订单完成支付订单操作
|
* @param payType 1=微信,2=支付宝,3=余额
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil payTaxiOrder(Integer payType, Integer orderId, Integer couponId, Integer type) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(orderTaxi.getState() == 8 || orderTaxi.getState() == 9){
|
return ResultUtil.error("订单已完成支付,不允许重复支付", "");
|
}
|
if(orderTaxi.getState() != 7){
|
return ResultUtil.error("订单不在待支付状态,不允许支付", "");
|
}
|
Integer uid = orderTaxi.getUserId();
|
Double orderMoney = orderTaxi.getOrderMoney();
|
UserInfo userInfo = userInfoService.selectById(uid);
|
ResultUtil resultUtil = ResultUtil.success(new Object());
|
orderTaxi.setCouponMoney(0D);//初始化历史数据
|
orderTaxi.setCouponId(null);
|
|
//计算优惠券
|
UserCouponRecord userCouponRecord = null;
|
if(null != couponId){
|
userCouponRecord = userCouponRecordService.selectById(couponId);
|
if(userCouponRecord.getCompanyId() != orderTaxi.getCompanyId()){
|
return ResultUtil.error("优惠券不能用于此订单", "");
|
}
|
if(userCouponRecord.getState() == 2){
|
return ResultUtil.error("优惠券已使用", "");
|
}
|
if(userCouponRecord.getState() == 3){
|
return ResultUtil.error("优惠券已过期", "");
|
}
|
if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 2){
|
return ResultUtil.error("优惠券不能用于此类型订单", "");
|
}
|
if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){
|
return ResultUtil.error("优惠券不能用于此订单", "");
|
}
|
orderMoney = orderMoney - userCouponRecord.getMoney();
|
orderTaxi.setCouponMoney(userCouponRecord.getMoney());
|
orderTaxi.setCouponId(couponId);
|
}
|
|
//计算红包
|
UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderTaxi.getCompanyId(), 1, 2, orderMoney);
|
if(null != query && orderMoney.compareTo(query.getMoney()) > 0){
|
orderMoney = orderMoney - query.getMoney();
|
orderTaxi.setRedPacketMoney(query.getMoney());
|
orderTaxi.setRedPacketId(query.getId());
|
}
|
|
//计算折扣
|
UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderTaxi.getCompanyId());
|
if(null != query2){
|
Double taxi = query2.getTaxi();
|
orderTaxi.setDiscount(taxi);
|
double v = new BigDecimal(orderMoney).multiply(new BigDecimal(taxi / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
if(orderMoney.compareTo(v) > 0){
|
orderTaxi.setDiscountMoney(orderMoney - v);
|
orderTaxi.setActivityId(query2.getId());
|
orderMoney = v;
|
}
|
}
|
|
if(payType == 1){//微信支付
|
String app = type == 1 ? "APP" : "JSAPI";
|
resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
|
paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, "", 1);//添加预支付数据
|
}
|
if(payType == 2){//支付宝支付
|
resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi");
|
paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 2, orderMoney, "", 1);//添加预支付数据
|
}
|
if(payType == 3){//余额支付
|
if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){
|
return ResultUtil.error("余额不足,无法完成支付", "");
|
}
|
|
userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
|
SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
|
userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
|
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "出租车", orderMoney, 2, 1, 1, 2, orderId);
|
userInfoService.updateById(userInfo);
|
|
orderTaxi.setState(8);
|
orderTaxi.setPayType(3);
|
orderTaxi.setPayMoney(orderMoney);
|
|
//处理优惠券和红包
|
if(null != userCouponRecord){
|
userCouponRecord.setState(2);
|
userCouponRecord.setEndTime(new Date());
|
userCouponRecordService.updateById(userCouponRecord);
|
}
|
if(null != query){
|
query.setState(2);
|
query.setEndTime(new Date());
|
userRedPacketRecordService.updateById(query);
|
}
|
//添加收入
|
Map<String, Object> map = incomeService.saveIncome(orderTaxi.getId(), 2, orderTaxi.getOrderMoney());
|
orderTaxi.setSplitAllocation(JSON.toJSONString(map));
|
|
// TODO: 2020/5/24 这里需要给司机和用户推送订单状态
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
}
|
}).start();
|
|
//用户付款后,删除限制司机6分钟不能接单的标识
|
String vehicle = redisUtil.getValue("VEHICLE");
|
if(ToolUtil.isNotEmpty(vehicle)){
|
JSONArray jsonArray = JSON.parseArray(vehicle);
|
for(int i = 0; i < jsonArray.size(); i++){
|
if(jsonArray.getInteger(i).compareTo(orderTaxi.getDriverId()) == 0){
|
jsonArray.remove(i);
|
break;
|
}
|
}
|
redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
|
}
|
systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行订单支付,谢谢使用!", uid, 1);
|
}
|
|
this.updateAllColumnById(orderTaxi);
|
return resultUtil;
|
}
|
|
@Override
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
public ResultUtil payTaxiOrder1(Integer payType, Integer orderId, Integer objectId, Integer objectType, Integer type) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(orderTaxi.getState() == 8 || orderTaxi.getState() == 9){
|
return ResultUtil.error("订单已完成支付,不允许重复支付", "");
|
}
|
if(orderTaxi.getState() != 7){
|
return ResultUtil.error("订单不在待支付状态,不允许支付", "");
|
}
|
Integer uid = orderTaxi.getUserId();
|
Double orderMoney = orderTaxi.getOrderMoney();
|
UserInfo userInfo = userInfoService.selectById(uid);
|
ResultUtil resultUtil = ResultUtil.success(new Object());
|
orderTaxi.setCouponMoney(0D);//初始化历史数据
|
orderTaxi.setCouponId(null);
|
|
//计算优惠券
|
UserCouponRecord userCouponRecord = null;
|
if(null != objectId && 1 == objectType){
|
userCouponRecord = userCouponRecordService.selectById(objectId);
|
if(userCouponRecord.getCompanyId() != orderTaxi.getCompanyId()){
|
return ResultUtil.error("优惠券不能用于此订单", "");
|
}
|
if(userCouponRecord.getState() == 2){
|
return ResultUtil.error("优惠券已使用", "");
|
}
|
if(userCouponRecord.getState() == 3){
|
return ResultUtil.error("优惠券已过期", "");
|
}
|
if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 2){
|
return ResultUtil.error("优惠券不能用于此类型订单", "");
|
}
|
if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){
|
return ResultUtil.error("优惠券不能用于此订单", "");
|
}
|
orderMoney = orderMoney - userCouponRecord.getMoney();
|
orderTaxi.setCouponMoney(userCouponRecord.getMoney());
|
orderTaxi.setCouponId(objectId);
|
}
|
|
//计算打车卡
|
UserTaxiCard userTaxiCard = null;
|
if(null != objectId && objectType == 2){
|
userTaxiCard = userTaxiCardService.selectById(objectId);
|
TaxiCard taxiCard = taxiCardService.selectById(userTaxiCard.getTaxiCardId());
|
if(taxiCard.getTaxiCardType() == 1 && userTaxiCard.getCompanyId() != orderTaxi.getCompanyId()){
|
return ResultUtil.error("打车卡不能用于此订单", "");
|
}
|
if(System.currentTimeMillis() > userTaxiCard.getEndTime().getTime()){
|
return ResultUtil.error("打车卡已过期", "");
|
}
|
if(userTaxiCard.getType() == 1 || userTaxiCard.getType() == 3){
|
Integer time = JSON.parseObject(userTaxiCard.getContent()).getInteger("time");
|
if(0 == time){
|
return ResultUtil.error("打车卡已使用完", "");
|
}
|
}
|
List<Integer> integers = JSON.parseObject(userTaxiCard.getContent()).getJSONArray("businessTypes").toJavaList(Integer.class);
|
if(!integers.contains(2)){
|
return ResultUtil.error("打车卡不能用于此类型订单", "");
|
}
|
|
Double yh = 0D;
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent());
|
if(userTaxiCard.getType() == 1){//打折次数卡{"businessTypes":[1,2,3],"time":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"discount":5}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
Double discount = jsonObject.getDouble("discount");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
yh = new BigDecimal(orderTaxi.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
|
jsonObject.put("time", jsonObject.getInteger("time") - 1);
|
userTaxiCard.setContent(jsonObject.toJSONString());
|
break;
|
}
|
}
|
|
}
|
if(userTaxiCard.getType() == 2){//优惠卡{"businessTypes":[1,2,3],"fullReduction":[[50,3],[100,5],[150,10]]}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
JSONArray fullReduction = jsonObject.getJSONArray("fullReduction");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
for(int j = fullReduction.size() - 1; j >= 0 ; j--){
|
JSONArray jsonArray = fullReduction.getJSONArray(j);
|
Double p = jsonArray.getDouble(0);//满金额
|
if(orderTaxi.getOrderMoney().compareTo(p) >= 0){
|
yh = jsonArray.getDouble(1);//优惠金额
|
break;
|
}
|
}
|
}
|
}
|
|
}
|
if(userTaxiCard.getType() == 3){//次数卡{"businessTypes":[1,2,3],"time":1,"discountAmount":10}
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
yh = jsonObject.getDouble("discountAmount");
|
jsonObject.put("time", jsonObject.getInteger("time") - 1);
|
userTaxiCard.setContent(jsonObject.toJSONString());
|
}
|
}
|
}
|
if(userTaxiCard.getType() == 4){//打折天数卡{"businessTypes":[1,2,3],"discount":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"]}
|
Double discount = jsonObject.getDouble("discount");//折扣
|
JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");//使用时间段
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date date = new Date();
|
for(int i = 0; i < timeQuantum.size(); i++){
|
String[] split = timeQuantum.getString(i).split(" - ");
|
Date s = sdf1.parse(sdf.format(date) + " " + split[0]);
|
Date e = sdf1.parse(sdf.format(date) + " " + split[1]);
|
if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){
|
yh = new BigDecimal(orderTaxi.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
|
break;
|
}
|
}
|
}
|
|
orderMoney = orderMoney - yh;
|
orderTaxi.setTaxiCardId(userTaxiCard.getTaxiCardId());
|
orderTaxi.setUserTaxiCardId(objectId);
|
orderTaxi.setDiscountAmount(yh);
|
}
|
|
//计算红包
|
UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderTaxi.getCompanyId(), 1, 2, orderMoney);
|
if(null != query && orderMoney.compareTo(query.getMoney()) > 0){
|
orderMoney = orderMoney - query.getMoney();
|
orderTaxi.setRedPacketMoney(query.getMoney());
|
orderTaxi.setRedPacketId(query.getId());
|
}
|
|
//计算折扣
|
UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderTaxi.getCompanyId());
|
if(null != query2){
|
Double taxi = query2.getTaxi();
|
orderTaxi.setDiscount(taxi);
|
double v = new BigDecimal(orderMoney).multiply(new BigDecimal(taxi / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
if(orderMoney.compareTo(v) > 0){
|
orderTaxi.setDiscountMoney(orderMoney - v);
|
orderTaxi.setActivityId(query2.getId());
|
orderMoney = v;
|
}
|
}
|
orderMoney = orderMoney < 0 ? 0 : orderMoney;
|
orderMoney = new BigDecimal(orderMoney).setScale(2,RoundingMode.HALF_UP).doubleValue();
|
System.out.println("!!!"+orderMoney+"!!!!");
|
if(payType == 1){//微信支付
|
if(orderMoney == 0){
|
return ResultUtil.error("请使用余额支付");
|
}
|
String app = type == 1 ? "APP" : "JSAPI";
|
resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
|
paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, "", 1);//添加预支付数据
|
}
|
if(payType == 2){//支付宝支付
|
if(orderMoney == 0){
|
return ResultUtil.error("请使用余额支付");
|
}
|
resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi");
|
paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 2, orderMoney, "", 1);//添加预支付数据
|
}
|
if(payType == 3){//余额支付
|
if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){
|
return ResultUtil.error("余额不足,无法完成支付");
|
}
|
// if(orderMoney>0) {
|
// resultUtil = appOrderController.moneyPay(orderId, userInfo.getId(), orderMoney);
|
// if (resultUtil.getCode() == 500) {
|
// return ResultUtil.error("电子余额不足,无法完成支付");
|
// }
|
// }
|
|
userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
|
SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
|
if(null != query1){
|
userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
|
}
|
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "出租车", orderMoney, 2, 1, 1, 2, orderId);
|
userInfoService.updateById(userInfo);
|
|
orderTaxi.setState(8);
|
orderTaxi.setPayType(3);
|
orderTaxi.setPayMoney(orderMoney);
|
|
//处理优惠券和红包
|
if(null != userCouponRecord){
|
userCouponRecord.setState(2);
|
userCouponRecord.setEndTime(new Date());
|
userCouponRecordService.updateById(userCouponRecord);
|
}
|
//处理打车卡
|
if(null != userTaxiCard){
|
userTaxiCardService.updateById(userTaxiCard);
|
}
|
if(null != query){
|
query.setState(2);
|
query.setEndTime(new Date());
|
userRedPacketRecordService.updateById(query);
|
}
|
|
//添加收入
|
Map<String, Object> map = incomeService.saveIncome(orderTaxi.getId(), 2, orderTaxi.getOrderMoney());
|
orderTaxi.setSplitAllocation(JSON.toJSONString(map));
|
|
// TODO: 2020/5/24 这里需要给司机和用户推送订单状态
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
}
|
}).start();
|
|
//用户付款后,删除限制司机6分钟不能接单的标识
|
String vehicle = redisUtil.getValue("VEHICLE");
|
if(ToolUtil.isNotEmpty(vehicle)){
|
JSONArray jsonArray = JSON.parseArray(vehicle);
|
for(int i = 0; i < jsonArray.size(); i++){
|
if(jsonArray.getInteger(i).compareTo(orderTaxi.getDriverId()) == 0){
|
jsonArray.remove(i);
|
break;
|
}
|
}
|
redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
|
}
|
systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行订单支付,谢谢使用!", uid, 1);
|
|
}else if(payType == 4){
|
if(orderMoney == 0){
|
return ResultUtil.error("请使用余额支付");
|
}
|
Double payMoney = orderTaxi.getOrderMoney();
|
Integer integer = paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 4, orderMoney, "", 1);
|
resultUtil = appOrderController.placeAnOrder(new BigDecimal(orderMoney), 4,orderId,9,integer);
|
|
}
|
|
this.updateAllColumnById(orderTaxi);
|
return resultUtil;
|
}
|
@Autowired
|
private AppOrderController appOrderController;
|
/**
|
* 手动完成订单操作
|
* @param orderId
|
* @param orderType
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil completeOrder(Integer orderId, Integer orderType) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(orderTaxi.getState() != 7){
|
return ResultUtil.error("订单不在待支付,无法完成订单");
|
}
|
orderTaxi.setPayManner(2);//其他方式支付
|
// orderTaxi.setOrderMoney(0D);
|
// orderTaxi.setTravelMoney(0D);
|
// orderTaxi.setParkMoney(0D);
|
// orderTaxi.setRoadTollMoney(0D);
|
orderTaxi.setRedPacketMoney(0D);
|
orderTaxi.setCouponMoney(0D);
|
orderTaxi.setDiscount(0D);
|
orderTaxi.setDiscountMoney(0D);
|
orderTaxi.setPayMoney(orderTaxi.getOrderMoney());
|
orderTaxi.setState(8);
|
this.updateById(orderTaxi);
|
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
}
|
}).start();
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 获取用户的订单列表
|
* @param uid
|
* @param pageNum
|
* @param size
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryMyOrderList(Integer uid, Integer pageNum, Integer size) throws Exception {
|
pageNum = (pageNum - 1) * size;
|
List<Map<String, Object>> maps = orderTaxiMapper.queryMyOrderList(uid, pageNum, size);
|
for(Map<String, Object> map : maps){
|
if(Integer.valueOf(String.valueOf(map.get("state"))) == 11){
|
map.put("state", map.get("oldState"));
|
}
|
}
|
return maps;
|
}
|
|
|
/**
|
* 获取历史消费记录
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryMyTravelRecord(Integer uid) throws Exception {
|
return orderTaxiMapper.queryMyTravelRecord(uid);
|
}
|
|
|
/**
|
* 获取红包使用记录
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryRedEnvelope(Integer uid) throws Exception {
|
return orderTaxiMapper.queryRedEnvelope(uid);
|
}
|
|
|
/**
|
* 获取用户单发票页面的订单列表
|
* @param type 开票状态(1=未开票,2=已开票)
|
* @param startTime 订单开始时间
|
* @param endTime 订单结束时间
|
* @param startMoney 订单金额范围
|
* @param endMoney
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryInvoiceOrder(Integer type, Date startTime, Date endTime, Double startMoney,
|
Double endMoney, Integer uid) throws Exception {
|
startTime = dateUtil.getStartOrEndDate(startTime, "start");
|
endTime = dateUtil.getStartOrEndDate(endTime, "end");
|
return orderTaxiMapper.queryInvoiceOrder(type, startTime, endTime, startMoney, endMoney, uid);
|
}
|
|
|
/**
|
* 获取订单详情
|
* @param orderId
|
* @return
|
*/
|
@Override
|
public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception{
|
Map<String, Object> map = orderTaxiMapper.queryOrderInfo(orderId);
|
if(null != map && null != map.get("reassignNotice") && Integer.valueOf(String.valueOf(map.get("reassignNotice"))) == 2){//改派完成,重新获取了新的司机数据,开始修改数据防止继续调用
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
orderTaxi.setReassignNotice(0);
|
this.updateById(orderTaxi);
|
}
|
if(Integer.valueOf(String.valueOf(map.get("state"))) == 11){
|
map.put("state", map.get("oldState"));
|
}
|
String driverId = redisUtil.getValue("DEVICE_" + map.get("driverId"));
|
map.put("device", ToolUtil.isNotEmpty(driverId) ? 2 : 1);
|
map.put("orderType", 2);
|
return map;
|
}
|
|
|
/**
|
* 获取下单推送完后没有司机下单的提醒
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public EndPushWarpper queryEndPush(Integer uid) throws Exception {
|
List<OrderTaxi> list = orderTaxiMapper.queryByState(uid, 1);
|
EndPushWarpper endPushWarpper = new EndPushWarpper();
|
if(list.size() > 0){
|
OrderTaxi orderTaxi = list.get(0);
|
if(!orderIds.contains(orderTaxi.getId())){
|
endPushWarpper.setOrderId(orderTaxi.getId());
|
endPushWarpper.setOrderType(2);
|
endPushWarpper.setState(1);
|
List<PushOrder> querys = pushOrderService.querys(null, 2, orderTaxi.getCompanyId());//获取需要推送的次数
|
int time = 0;
|
for(int i = 1; i <= querys.size(); i++){
|
PushOrder pushOrder = pushOrderService.querys(i, 2, orderTaxi.getCompanyId()).get(0);
|
time += pushOrder.getPushTime() * 1000;
|
}
|
//当前时间减去推单总时间大于下单时间
|
if((System.currentTimeMillis() - time) > orderTaxi.getInsertTime().getTime()){
|
endPushWarpper.setState(2);
|
}
|
}
|
|
}
|
return endPushWarpper;
|
}
|
|
|
|
|
/**
|
* 获取服务中的订单数据
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public OrderServerWarpper queryOrderServer(Integer orderId, Integer uid) throws Exception {
|
OrderServerWarpper orderServerWarpper = new OrderServerWarpper();
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(null == orderTaxi){
|
return orderServerWarpper;
|
}
|
//计算预计距离和剩余时间
|
String value = redisUtil.getValue("DRIVER" + String.valueOf(orderTaxi.getDriverId()));
|
if(null == value || "".equals(value)){
|
System.err.println("司机没有上传位置信息");
|
|
//调用获取轨迹中的数据
|
List<Map<String, Object>> list = orderPositionService.queryTrack(orderId, 2);
|
if(list.size() > 0){
|
Map<String, Object> map = list.get(list.size() - 1);
|
value = map.get("lon") + "," + map.get("lat");
|
}
|
}
|
|
orderServerWarpper.setOrderId(orderTaxi.getId());
|
orderServerWarpper.setOrderType(2);
|
orderServerWarpper.setState(orderTaxi.getState());
|
orderServerWarpper.setLon(null != value ? value.split(",")[0] : "0.0");
|
orderServerWarpper.setLat(null != value ? value.split(",")[1] : "0.0");
|
orderServerWarpper.setReassignNotice(orderTaxi.getReassignNotice());
|
if(orderTaxi.getState() == 2 || orderTaxi.getState() == 3){//前往预约地
|
// TODO: 2023/11/4 无法修改
|
Map<String, String> distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getStartLon() + "," + orderTaxi.getStartLat(), 1);
|
String d = "0";
|
String t = "0";
|
if(null == distance){
|
System.err.println("查询距离出错了");
|
}else{
|
d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
|
t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
|
}
|
orderServerWarpper.setReservationMileage(d);
|
orderServerWarpper.setReservationTime(t);
|
orderServerWarpper.setServedMileage("0");
|
orderServerWarpper.setServedTime("0");
|
orderServerWarpper.setLaveMileage("0");
|
orderServerWarpper.setLaveTime("0");
|
}
|
if(orderTaxi.getState() == 5 || orderTaxi.getState() == 6){//服务中
|
// TODO: 2023/11/4 无法修改
|
Map<String, String> distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getEndLon() + "," + orderTaxi.getEndLat(), 1);
|
String d = "0";
|
String t = "0";
|
if(null == distance){
|
System.err.println("查询距离出错了");
|
}else{
|
d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
|
t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
|
}
|
orderServerWarpper.setReservationMileage("0");
|
orderServerWarpper.setReservationTime("0");
|
orderServerWarpper.setServedMileage(String.valueOf(orderTaxi.getMileage() / 1000));
|
orderServerWarpper.setServedTime(Long.valueOf((new Date().getTime() - orderTaxi.getStartServiceTime().getTime()) / 60000).intValue() + "");
|
orderServerWarpper.setLaveMileage(d);
|
orderServerWarpper.setLaveTime(t);
|
}
|
|
return orderServerWarpper;
|
}
|
|
|
/**
|
* 评论成功后获取红包金额
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public synchronized ResultUtil<BaseWarpper> queryRedMoney(Integer orderId) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
Integer companyId = orderTaxi.getCompanyId();
|
|
Map<String, Object> query = userActivityRedenvelopeService.query(companyId, orderTaxi.getTravelTime());
|
Double money = 0D;
|
BaseWarpper baseWarpper = new BaseWarpper();
|
if(null != query){
|
Integer type = Integer.valueOf(String.valueOf(query.get("type")));
|
if(type == 1){//固定金额
|
money = Double.valueOf(String.valueOf(query.get("money")));
|
}else{//随机金额
|
Double startMoney = Double.valueOf(String.valueOf(query.get("startMoney")));
|
Double endMoney = Double.valueOf(String.valueOf(query.get("endMoney")));
|
int i = new BigDecimal(endMoney).subtract(new BigDecimal(startMoney)).intValue();
|
Random random = new Random();
|
int num = random.nextInt(i);
|
money = new BigDecimal(startMoney).add(new BigDecimal(num)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
}
|
|
//判断当前红包是否大于剩余可领取总金额
|
if(money.compareTo(Double.valueOf(query.get("lavePrice").toString())) > 0){
|
baseWarpper.setAmount(0D);
|
return ResultUtil.success(baseWarpper);
|
}
|
}
|
baseWarpper.setAmount(money);
|
|
if(money > 0){
|
//添加临时红包数据
|
UserRedPacketRecord userRedPacketRecord = new UserRedPacketRecord();
|
userRedPacketRecord.setMoney(money);
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(new Date());
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + Integer.valueOf(String.valueOf(query.get("effective"))));
|
userRedPacketRecord.setExpirationTime(calendar.getTime());
|
userRedPacketRecord.setInsertTime(new Date());
|
userRedPacketRecord.setCompanyId(Integer.valueOf(String.valueOf(query.get("companyId"))));
|
userRedPacketRecord.setState(0);
|
userRedPacketRecord.setOrderId(orderTaxi.getId());
|
userRedPacketRecord.setOrderType(2);
|
userRedPacketRecord.setUserId(orderTaxi.getUserId());
|
userRedPacketRecordService.insert(userRedPacketRecord);
|
}
|
appOrderController.moneyPay(orderTaxi.getId(),orderTaxi.getUserId(),money);
|
return ResultUtil.success(baseWarpper);
|
}
|
|
/**
|
* 分享成功后添加红包
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public synchronized ResultUtil shareRedEnvelope(Integer orderId) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
UserRedPacketRecord query = userRedPacketRecordService.query_(orderTaxi.getUserId(), orderTaxi.getCompanyId(), 0, 2, null);
|
if(null != query){
|
Double money = query.getMoney();
|
Map<String, Object> map = userActivityRedenvelopeService.query(orderTaxi.getCompanyId(), orderTaxi.getTravelTime());
|
Double laveMoney = Double.valueOf(String.valueOf(map.get("laveMoney")));
|
if(money.compareTo(laveMoney) > 0){
|
return ResultUtil.error("手速太慢了,红包已派发完啦!");
|
}
|
//判断当前红包是否大于剩余可领取总金额
|
if(money.compareTo(Double.valueOf(map.get("lavePrice").toString())) > 0){
|
return ResultUtil.error("手速太慢了,红包已派发完啦!");
|
}
|
double v = new BigDecimal(laveMoney).subtract(new BigDecimal(money)).doubleValue();
|
|
UserActivityRedenvelope id = userActivityRedenvelopeService.selectById(String.valueOf(map.get("id")));
|
id.setLaveMoney(v);
|
id.setLavePrice(new BigDecimal(id.getLavePrice() - money).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
userActivityRedenvelopeService.updateById(id);
|
|
query.setState(1);
|
query.setRedPacketActivityId(id.getId());
|
userRedPacketRecordService.updateById(query);
|
}
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 获取订单数据
|
* @param uid
|
* @param state
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<OrderTaxi> queryOrder(Integer uid, Integer... state) throws Exception {
|
List<OrderTaxi> list = orderTaxiMapper.queryByState(uid, state);
|
return list;
|
}
|
|
|
/**
|
* 订单支付完成后的处理
|
* @param id 订单=id
|
* @param order_id 工行支付单号
|
* @param type 1=微信,2=支付宝
|
* @throws Exception
|
*/
|
@Override
|
public void payOrderTaxiCallback(Integer id, String order_id, Integer type,Integer paymentId) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(id);
|
PaymentRecord query = paymentRecordService.query(1, orderTaxi.getUserId(), 1, Integer.valueOf(id), 2, type, 1);
|
if(null != query && query.getState() == 1){
|
//添加交易明细
|
transactionDetailsService.saveData(orderTaxi.getUserId(), "出租车", query.getAmount(), 2, 1, 1, 2, query.getOrderId());
|
orderTaxi.setState(8);
|
orderTaxi.setPayType(type);
|
orderTaxi.setPayMoney(query.getAmount());
|
|
UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId());
|
SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
|
userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
|
userInfoService.updateById(userInfo);
|
|
//处理优惠券和红包
|
if(null != orderTaxi.getCouponId()){
|
UserCouponRecord userCouponRecord = userCouponRecordService.selectById(orderTaxi.getCouponId());
|
userCouponRecord.setState(2);
|
userCouponRecord.setEndTime(new Date());
|
userCouponRecordService.updateById(userCouponRecord);
|
}
|
if(null != orderTaxi.getUserTaxiCardId()){
|
UserTaxiCard userTaxiCard = userTaxiCardService.selectById(orderTaxi.getUserTaxiCardId());
|
if(userTaxiCard.getType() == 1 || userTaxiCard.getType() == 3){
|
JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent());
|
jsonObject.put("time", jsonObject.getInteger("time") - 1);
|
userTaxiCard.setContent(jsonObject.toJSONString());
|
userTaxiCardService.updateById(userTaxiCard);
|
}
|
}
|
if(null != orderTaxi.getRedPacketId()){
|
UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(orderTaxi.getRedPacketId());
|
userRedPacketRecord.setState(2);
|
userRedPacketRecord.setEndTime(new Date());
|
userRedPacketRecordService.updateById(userRedPacketRecord);
|
}
|
|
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
|
//添加收入
|
Map<String, Object> map = incomeService.saveIncome(orderTaxi.getId(), 2, orderTaxi.getOrderMoney());
|
orderTaxi.setSplitAllocation(JSON.toJSONString(map));
|
this.updateById(orderTaxi);
|
|
// TODO: 2020/5/24 这里需要给司机和用户推送订单状态
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
}
|
}).start();
|
|
//用户付款后,删除限制司机6分钟不能接单的标识
|
String vehicle = redisUtil.getValue("VEHICLE");
|
if(ToolUtil.isNotEmpty(vehicle)){
|
JSONArray jsonArray = JSON.parseArray(vehicle);
|
for(int i = 0; i < jsonArray.size(); i++){
|
if(jsonArray.getInteger(i).compareTo(orderTaxi.getDriverId()) == 0){
|
jsonArray.remove(i);
|
break;
|
}
|
}
|
redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
|
}
|
|
|
systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : (type==2?"支付宝":"云闪付")) + "成功完成出行订单支付,谢谢使用!", orderTaxi.getUserId(), 1);
|
}else{
|
System.err.println("预支付数据异常(orderId = " + id + ")");
|
}
|
}
|
|
|
/**
|
* 取消订单支付后的处理
|
* @param id 订单=id
|
* @param order_id 工行支付单号
|
* @param type 1=微信,2=支付宝
|
* @throws Exception
|
*/
|
@Override
|
public void payCancelOrderTaxi(Integer id, String order_id, Integer type) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(id);
|
PaymentRecord query = paymentRecordService.query(1, orderTaxi.getUserId(), 1, Integer.valueOf(id), 2, type, 1);
|
if(null != query){
|
//添加交易明细
|
transactionDetailsService.saveData(orderTaxi.getUserId(), "出租车取消订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId());
|
orderTaxi.setState(10);
|
//解除小号绑定
|
if(orderTaxi.getBindId() != null){
|
chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId(), orderTaxi.getTelX(), (System.currentTimeMillis() + 600000));
|
}
|
orderTaxi.setBindId("");
|
orderTaxi.setTelX("");
|
this.updateById(orderTaxi);
|
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
|
OrderCancel query1 = orderCancelService.query(query.getOrderId(), query.getOrderType(), query.getAmount(), query.getPayType(), 1);
|
if (null != query1){
|
query1.setState(2);
|
orderCancelService.updateById(query1);
|
}
|
|
//添加已收入明细
|
incomeService.saveData(1, orderTaxi.getCompanyId(), 3, orderTaxi.getId(), 2, query.getAmount());
|
|
this.deleteTask(orderTaxi.getId());//删除定时任务
|
|
// TODO: 2020/5/24 这里需要给司机和用户推送订单状态
|
// new Thread(new Runnable() {
|
// @Override
|
// public void run() {
|
// pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
|
// }
|
// }).start();
|
|
//添加消息
|
systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信": (type==2?"支付宝":"云闪付")) + "成功支付取消订单费用,谢谢使用!", orderTaxi.getUserId(), 1);
|
}else{
|
System.err.println("预支付数据异常(orderId = " + id + ")");
|
}
|
}
|
|
|
/**
|
* 推送订单给司机抢单
|
* @param orderTaxi
|
* @throws Exception
|
*/
|
@Override
|
public void pushOrder(OrderTaxi orderTaxi, Integer type) throws Exception{
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
try {
|
orderIds.add(orderTaxi.getId());//添加记录,防止调用接口重复提醒无人接单
|
String vehicle = redisUtil.getValue("VEHICLE");
|
List<Integer> integers = new ArrayList<>();
|
if(ToolUtil.isNotEmpty(vehicle)){
|
integers = JSON.parseArray(vehicle).toJavaList(Integer.class);
|
}
|
Company query = companyCityService.query(String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat()));//获取起点所属分公司
|
List<PushOrder> querys = pushOrderService.querys(null, 2, query.getId());//获取需要推送的次数
|
boolean b = false;
|
for(int i = 1; i <= querys.size(); i++){
|
if(b){
|
break;
|
}
|
PushOrder pushOrder = pushOrderService.querys(i, 2, query.getId()).get(0);
|
System.out.println("pushOrder:"+pushOrder);
|
int i2 = pushOrder.getPushTime() / 10;
|
if(i2==0){
|
i2=1;
|
}
|
System.out.println(i2);
|
for (int i1 = 0; i1 < i2 ; i1++) {
|
Integer state = 0;
|
//批量订单
|
if(type == 3){
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderTaxi.getId());
|
if(null == orderPrivateCar || orderPrivateCar.getState() != 1){
|
b = true;
|
break;
|
}
|
}else{
|
state = orderTaxiMapper.selectById(orderTaxi.getId()).getState();
|
if(state != 1){
|
b = true;
|
break;
|
}
|
}
|
//获取空闲司机
|
List<Driver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
|
if(list.size() > 0){
|
double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
|
int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
|
lastIndex = lastIndex == 0 ? list.size() : lastIndex;
|
list = list.subList(0, lastIndex);//获取空闲司机中占比数据
|
for(Driver driver : list){//开始进行推送
|
//查询是否在限制推单范围内
|
boolean bo = false;
|
for(Integer integer : integers){
|
if(integer.compareTo(driver.getId()) == 0){
|
bo = true;
|
break;
|
}
|
}
|
if(bo){
|
continue;
|
}
|
pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime());
|
}
|
}
|
Thread.sleep( 10000);//设置等待时间
|
if(i == querys.size() && state == 1){
|
pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2);
|
orderIds.remove(orderTaxi.getId());
|
}
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}).start();
|
}
|
|
|
|
@Override
|
public synchronized String getOrderNum() throws Exception{
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
return "TA" + sdf.format(new Date()) + UUIDUtil.getRandomCode(5);
|
}
|
|
@Override
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
public ResultUtil payThankYouFee(Integer uid, Integer orderId, Double money, Integer payType, Integer type) throws Exception {
|
UserInfo userInfo = userInfoService.selectById(uid);
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
ResultUtil resultUtil = ResultUtil.success();
|
if(payType == 1){//微信支付
|
String app = type == 1 ? "APP" : "JSAPI";
|
resultUtil = payMoneyUtil.weixinpay("感谢费", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/wxPayThankYouFee", app, userInfo.getAppletsOpenId());
|
paymentRecordService.saveData(3, uid, 1, orderId, 2, 1, money, "", 1);//添加预支付数据
|
}
|
if(payType == 2){//支付宝支付
|
resultUtil = payMoneyUtil.alipay("感谢费", "感谢费", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/aliPayThankYouFee");
|
paymentRecordService.saveData(1, uid, 1, orderId, 2, 2, money, "", 1);//添加预支付数据
|
}
|
if(payType == 3){//余额支付
|
if(userInfo.getBalance() == null || userInfo.getBalance() < money){
|
return ResultUtil.error("余额不足,无法完成支付");
|
}
|
// resultUtil= appOrderController.moneyPay(orderId,userInfo.getId(),money);
|
// if(resultUtil.getCode()==500){
|
// return ResultUtil.error("电子余额不足,无法完成支付");
|
// }
|
userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
|
SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
|
userInfo.setIntegral(userInfo.getIntegral() + (money.intValue() * query1.getIntegral()));//积分
|
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "出租车-感谢费", money, 2, 1, 1, 2, orderId);
|
userInfoService.updateById(userInfo);
|
|
orderTaxi.setThankYouFee(money);
|
this.updateById(orderTaxi);
|
|
//添加已收入明细
|
incomeService.saveData(2, orderTaxi.getDriverId(), 6, orderTaxi.getId(), 2, money);
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driverService.updateById(driver);
|
systemNoticeService.addSystemNotice(1, "您已使用余额成功完成感谢费支付,谢谢使用!", uid, 1);
|
|
}
|
if(payType==4){
|
Double payMoney = orderTaxi.getThankYouFee();
|
Integer integer = paymentRecordService.saveData(3, uid, 1, orderId, 2, 4, money, "", 1);
|
resultUtil = appOrderController.placeAnOrder(new BigDecimal(money), 4,orderId,12,integer);
|
}
|
return resultUtil;
|
}
|
|
@Override
|
public void payThankYouFeeCallback(Integer orderId, String order_id, Integer payType) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId());
|
PaymentRecord query = paymentRecordService.query(3, userInfo.getId(), 1, orderId, 2, payType, 1);
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
|
SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
|
userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
|
|
//添加交易明细
|
transactionDetailsService.saveData(userInfo.getId(), "出租车-感谢费", query.getAmount(), 2, 1, 1, 2, orderId);
|
userInfoService.updateById(userInfo);
|
|
orderTaxi.setThankYouFee(query.getAmount());
|
this.updateById(orderTaxi);
|
|
//添加已收入明细
|
incomeService.saveData(2, orderTaxi.getDriverId(), 6, orderTaxi.getId(), 2, query.getAmount());
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driverService.updateById(driver);
|
systemNoticeService.addSystemNotice(1, "您已使用" + (payType == 1 ? "微信" : (payType==2?"支付宝":"云闪付")) + "成功完成感谢费支付,谢谢使用!", userInfo.getId(), 1);
|
}
|
}
|