package com.stylefeng.guns.modular.shunfeng.controller; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.core.common.constant.state.BalanceChangeType; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.shunfeng.model.*; import com.stylefeng.guns.modular.shunfeng.model.vo.ApiJson; import com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideInfoVo; import com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideVo; import com.stylefeng.guns.modular.shunfeng.service.*; import com.stylefeng.guns.modular.shunfeng.task.base.QuartzManager; import com.stylefeng.guns.modular.shunfeng.task.base.TimeJobType; import com.stylefeng.guns.modular.shunfeng.task.jobs.CourseExamineRide; import com.stylefeng.guns.modular.shunfeng.util.OrdersUtil; import com.stylefeng.guns.modular.shunfeng.util.SensitiveWordUtil; import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper; import com.stylefeng.guns.modular.system.model.SensitiveWords; import com.stylefeng.guns.modular.system.model.TCarBrand; import com.stylefeng.guns.modular.system.model.UserInfo; import com.stylefeng.guns.modular.system.service.ICompanyService; import com.stylefeng.guns.modular.system.service.ISystemNoticeService; import com.stylefeng.guns.modular.system.service.ITCarBrandService; import com.stylefeng.guns.modular.system.service.IUserInfoService; import com.stylefeng.guns.modular.system.util.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import net.sf.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; /** * 顺风车相关接口 */ @Slf4j @Api(tags = "顺风车相关接口") @Controller @RequestMapping("/api/rideComment") public class rideCommentController { /*顺风车订单*/ @Autowired private IOrderRideService orderRideService; /*顺风车行程*/ @Autowired private IOrderTravelService orderTravelService; /*顺风车设置*/ @Autowired private IParamRideService paramRideService; /*定时任务*/ @Autowired private ITimeTaskService timeTaskService; /*顺风车司机*/ @Autowired private IDriverRideService driverRideService; /*顺风车品牌*/ @Autowired private ITCarBrandService carBrandService; /*评价*/ @Autowired private IEvaluateService evaluateService; /*投诉*/ @Autowired private IComplaintsService complaintsService; /*实名认证*/ @Autowired private IUserApplyService applyService; @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; @Autowired private IUserInfoService userInfoService; @Autowired private PushUtil pushUtil; @Autowired private ISystemNoticeService systemNoticeService; @Resource private SensitiveWordsMapper sensitiveWordsMapper; @Autowired private IFinancialService financialService; @Autowired private ICompanyService companyService; @Autowired private IOrderInvitationService orderInvitationService; /** * 发布顺风车行程实名认证 * @param userId * @param type:1用户身份申请,2司机身份申请 * * @param * @return */ @ResponseBody @PostMapping("/authentication") @ApiOperation(value = "发布顺风车行程实名认证", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "name", value = "姓名", dataType = "string"), @ApiImplicitParam(name = "identity", value = "身份证", dataType = "string"), @ApiImplicitParam(name = "type", value = "1用户,2司机", dataType = "int"), }) public Object authentication(Integer userId,String name,String identity,Integer type) { try { if (userId == null || userId == 0) { return ResultUtil.paranErr("userId不能为空"); } /*发布顺风车行程实名认证*/ UserApply apply=new UserApply(); apply.setUserId(userId); apply.setApplyTime(new Date()); apply.setApplyState(1); apply.setType(type);//司机申请 apply.setApplyType(3);//3发布顺风车行程实名认证 apply.setName(name); apply.setIdentity(identity); apply.setApplyState(1); Boolean aBoolean = UserUtil.idCardAuth(name, identity); if(aBoolean){ apply.setApplyState(2); /*修改用户实名认证通过*/ UserInfo userInfo=new UserInfo(); userInfo.setId(userId); userInfo.setIsAuth(2); String sex = identity.substring(16, 17); //取指定位置的值(16位之后,17位结束;) int b = Integer.parseInt(sex);//强制类型转换 if (b % 2 == 0) { userInfo.setSex(2); } else { userInfo.setSex(1); } userInfo.setName(name); userInfo.setIdCard(identity); userInfoService.updateById(userInfo); }else { apply.setApplyState(3); } applyService.insert(apply); Map reMap=new HashMap<>(); reMap.put("auditState", true); return ResultUtil.success(reMap); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 人脸识别 * @param userId * @param headImg * @return */ @ResponseBody @PostMapping("/faceAuthentication") @ApiOperation(value = "人脸识别", httpMethod = "POST") public Object authentication(Integer userId,String headImg) { // try { // if (userId == null || userId == 0) { // return ResultUtil.paranErr("userId不能为空"); // } // /*查询实名认证信息*/ // UserApply apply=applyService.selectOne(new EntityWrapper().eq("userId",userId) // .eq("applyState",2) // .eq("applyType",3)); // /*是否验证成功*/ // Integer auditState=0; // if(apply!=null){ // String name=apply.getName(); // String identity=apply.getIdentity(); // apply.setHeadImg(headImg); // applyService.updateById(apply); // /*todo 第三方实名认证*/ // String urlBase64=RealNameAuthenticationUtil.NetImageToBase64(headImg); // Map bodys = new HashMap(); // bodys.put("base64Str", urlBase64); // bodys.put("liveChk", "0"); // bodys.put("name", name); // bodys.put("number", identity); // Boolean result=RealNameAuthenticationUtil.faceAuthentication(bodys); // if(result){//认证通过 // auditState=1; // } // if(auditState==1){//审核通过 // UserInfo userInfo=new UserInfo(); // userInfo.setId(userId); // userInfo.setIsFaceAuthenticationRide(1); // userInfo.setCertificationImg(headImg); // userInfoService.updateById(userInfo); // } // } // Map reMap=new HashMap<>(); // reMap.put("auditState",auditState); // return ApiJson.returnOK(reMap); // } catch (Exception e) { // e.printStackTrace(); // } return ResultUtil.paranErr("异常"); } /** * 获取车辆品牌列表 * @return */ @ResponseBody @GetMapping("/getBrandList") @ApiOperation(value = "获取车辆品牌列表", httpMethod = "GET") public Object getBrandList(){ try { List tCarBrands = carBrandService.selectList(null); return ApiJson.returnOK(tCarBrands); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 顺风车首页(待处理订单数) * @param userId 用户id * @param type 1= 用户,2顺风车司机 * @return */ @ResponseBody @GetMapping("/homeOrderCount") @ApiOperation(value = "顺风车首页(待处理订单数)", httpMethod = "GET") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "type", value = "1用户,2司机", dataType = "int"), }) public Object homeOrderCount(Integer userId,Integer type){ try { if(ToolUtil.isEmpty(userId)){ return ResultUtil.paranErr("userId不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } Integer count=0; if(type==1){//用户待处理订单:进行中的订单 EntityWrapper entityWrapper=new EntityWrapper(); entityWrapper.eq("userId",userId); entityWrapper.in("state","1,2,3,4"); count=orderRideService.selectCount(entityWrapper); }else if(type==2){//司机待处理订单:进行中的订单 EntityWrapper entityWrapper=new EntityWrapper(); entityWrapper.eq("driverId",userId); entityWrapper.in("state","2,3,4"); count=orderTravelService.selectCount(entityWrapper); } return ApiJson.returnOK(count); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("获取异常"); } /** * 顺风车首页(待处理订单列表) * @param userId * @param type 1用户待处理订单:进行中的订单 2司机待处理订单:进行中的订单 3我的顺风车行程 * @return */ @ResponseBody @GetMapping("/homeOrderList") @ApiOperation(value = "顺风车首页(待处理订单列表)", httpMethod = "GET") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "type", value = "1用户待处理订单:进行中的订单 2司机待处理订单:进行中的订单 3我的顺风车行程", dataType = "int"), }) public Object homeOrderList(Integer userId,Integer type,Integer current,Integer size){ try { if(ToolUtil.isEmpty(userId)){ return ResultUtil.paranErr("userId不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } List rideVoList=new ArrayList<>(); OrderRideVo orderRideVo=new OrderRideVo(); orderRideVo.setCurrent(current > 0 ? (current - 1) * size : 0); orderRideVo.setSize(size); orderRideVo.setUserId(userId); orderRideVo.setDriverId(userId); if(type==1){//用户待处理订单:进行中的订单 orderRideVo.setType(1);//待处理订单 rideVoList=orderRideService.getOrderRide(orderRideVo); }else if(type==2){//司机待处理订单:进行中的订单 orderRideVo.setType(1);//待处理订单 rideVoList=orderTravelService.getOrderTravel(orderRideVo); }else if(type==3){//我的行程 UserInfo userInfo=userInfoService.selectById(userId); orderRideVo.setDriverId(userInfo.getDriverId()); rideVoList=orderRideService.getOrderRideAndTravel(orderRideVo); } return ApiJson.returnOK(rideVoList); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("获取异常"); } /** * 根据输入的开始结束经纬度和人数获取订单价格 * @param num * @return */ @ResponseBody @PostMapping("/orderPrice") @ApiOperation(value = "根据输入的开始结束经纬度和人数获取订单价格", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "num", value = "人数", dataType = "int"), @ApiImplicitParam(name = "startLat", value = "起点纬度", dataType = "double"), @ApiImplicitParam(name = "startLon", value = "起点经度", dataType = "double"), @ApiImplicitParam(name = "endLat", value = "终点纬度", dataType = "double"), @ApiImplicitParam(name = "endLon", value = "终点经度", dataType = "double"), }) public Object orderPrice(Integer num,Double startLat,Double startLon,Double endLat,Double endLon){ try { String locationS=startLon+","+startLat; String locationE=endLon+","+endLat; if(locationE==null){ return ApiJson.returnOK(null); } /*计算两个地址的距离*/ String strS=locationS; String strE=locationE; Map map1= null; try { map1 = gdMapElectricFenceUtil.getDistance(strS,strE, 1); } catch (Exception e1) { e1.printStackTrace(); } log.info("顺风车预估里程:{}", JSON.toJSONString(map1)); Double distance = new BigDecimal(map1.get("distance")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();//距离公里 Integer distanceType=1; //距离类型(1-100==1,100-200==2,200-500==3,500-800==4,800以上==5) if(distance<100){ distanceType=1; }else if(distance>=100 && distance<200){ distanceType=2; }else if(distance>=200 && distance<500){ distanceType=3; }else if(distance>=500 && distance<800){ distanceType=4; }else { distanceType=5; } ParamRide paramRide=paramRideService.selectOne(new EntityWrapper().eq("type",1).eq("distanceType",distanceType)); Double price=0d; if(paramRide!=null){ log.info("获取的价格配置规则:{}", JSON.toJSONString(paramRide)); JSONObject jsonObject =JSONObject.fromObject(paramRide.getContext()); String priceStr=jsonObject.getString("person"+num); if(priceStr!=null){ price=Double.valueOf(priceStr)*distance; } } return ApiJson.returnOK(price); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("获取异常"); } /** * 用户下单 * @param userId * @param startTime * @param num * @param startName * @param endName * @param isDai * @param lxPhone * @return */ @ResponseBody @PostMapping("/userAddOrder") @ApiOperation(value = "用户下单", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "startTime", value = "出行时间", dataType = "string"), @ApiImplicitParam(name = "num", value = "出行人数", dataType = "int"), @ApiImplicitParam(name = "startName", value = "起点名称", dataType = "string"), @ApiImplicitParam(name = "startLat", value = "起点纬度", dataType = "double"), @ApiImplicitParam(name = "startLon", value = "起点经度", dataType = "double"), @ApiImplicitParam(name = "endName", value = "终点名称", dataType = "string"), @ApiImplicitParam(name = "endLat", value = "终点纬度", dataType = "double"), @ApiImplicitParam(name = "endLon", value = "终点经度", dataType = "double"), @ApiImplicitParam(name = "money", value = "金额", dataType = "double"), @ApiImplicitParam(name = "isDai 1=是 2=否", value = "是否代喊 1=是 2=否", dataType = "int"), @ApiImplicitParam(name = "lxPhone", value = "联系电话", dataType = "string"), }) public Object addOrder(Integer userId,String startTime,Integer num,String startName,Double startLat,Double startLon,Double endLat,Double endLon, String endName,Double money,Integer isDai,String lxPhone){ try { if(ToolUtil.isEmpty(userId)){ return ResultUtil.paranErr("userId不能为空"); } if(ToolUtil.isEmpty(startTime)){ return ResultUtil.paranErr("startTime不能为空"); } if(ToolUtil.isEmpty(num)){ return ResultUtil.paranErr("num不能为空"); } if(ToolUtil.isEmpty(startName)){ return ResultUtil.paranErr("startName不能为空"); } if(ToolUtil.isEmpty(endName)){ return ResultUtil.paranErr("endName不能为空"); } if(ToolUtil.isEmpty(money)){ return ResultUtil.paranErr("money不能为空"); } /*用户只能发布一个进行中的行程*/ /*EntityWrapper entityWrapper=new EntityWrapper(); entityWrapper.eq("userId",userId); entityWrapper.in("state","1,2,3,4"); Integer count=orderRideService.selectCount(entityWrapper); if(count>0){ return ResultUtil.paranErr("还有进行中的订单"); }*/ /*用户可以发布多个订单*/ ParamRide paramRide=paramRideService.selectOne(new EntityWrapper().eq("type",2)); Double platformMoney=0d; if(paramRide!=null){ JSONObject jsonObject =JSONObject.fromObject(paramRide.getContext()); String priceStr=jsonObject.getString("commission"+num+""); if(priceStr!=null){ platformMoney=Double.valueOf(priceStr); } } OrderRide orderRide=new OrderRide(); orderRide.setOrderNum(OrdersUtil.getOrderNoForPrefix("ride")); orderRide.setPlatformMoney(platformMoney); orderRide.setAddTime(new Date()); orderRide.setUserId(userId); orderRide.setStartTime(DateUtil.getDate(startTime,"yyyy-MM-dd HH:mm")); orderRide.setNum(num);//乘车人数 orderRide.setStartName(startName);//出发地 orderRide.setStartLon(startLon); orderRide.setStartLat(startLat); orderRide.setEndName(endName);//目的地 orderRide.setEndLon(endLon); orderRide.setEndLat(endLat); orderRide.setIsDai(isDai); orderRide.setLxPhone(lxPhone); orderRide.setMoney(money); orderRide.setState(1);//未支付状态 orderRideService.insert(orderRide); //todo 定时人数 自动取消订单 Integer time =10; Map reMap=new HashMap<>(); reMap.put("djs",time); reMap.put("orderId",orderRide.getId()); reMap.put("addTime",orderRide.getAddTime()); // 添加定时任务信息 TimeTask timeTask=new TimeTask(); timeTask.setCreateDate(new Date()); timeTask.setExcuteDate(DateUtil.getDate_strYMdHms(System.currentTimeMillis() + 1000*60*time)); timeTask.setTaskName((CourseExamineRide.DSCE+orderRide.getId()).toUpperCase()); timeTask.setTypeName(CourseExamineRide.DSCE); timeTask.setMap(orderRide.getId()+""); timeTaskService.insert(timeTask); //倒计时 Map maps=new HashMap<>(); maps.put("orderId",orderRide.getId()); maps.put("timeTaskId",timeTask.getId()); QuartzManager.addJob(CourseExamineRide.class,(CourseExamineRide.DSCE+orderRide.getId()).toUpperCase(), TimeJobType.UNLOCK, DateUtil.getDate_strYMdHms(System.currentTimeMillis() + 1000*60*time) , maps); return ResultUtil.success(orderRide.getId()); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 司机创建行程 * @param driverId * @param startTime * @param num * @param startName * @param endName * @return */ @ResponseBody @PostMapping("/driverAddTravel") @ApiOperation(value = "司机创建行程", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"), @ApiImplicitParam(name = "startTime", value = "出行时间", dataType = "string"), @ApiImplicitParam(name = "num", value = "出行人数", dataType = "int"), @ApiImplicitParam(name = "startName", value = "起点名称", dataType = "string"), @ApiImplicitParam(name = "startLat", value = "起点纬度", dataType = "double"), @ApiImplicitParam(name = "startLon", value = "起点经度", dataType = "double"), @ApiImplicitParam(name = "endName", value = "终点名称", dataType = "string"), @ApiImplicitParam(name = "endLat", value = "终点纬度", dataType = "double"), @ApiImplicitParam(name = "endLon", value = "终点经度", dataType = "double"), }) public Object driverAddTravel(Integer driverId,String startTime,Integer num,String startName,String endName,Double startLat,Double startLon,Double endLat,Double endLon){ try { if(ToolUtil.isEmpty(driverId)){ return ResultUtil.paranErr("driverId不能为空"); } if(ToolUtil.isEmpty(startTime)){ return ResultUtil.paranErr("startTime不能为空"); } if(ToolUtil.isEmpty(num)){ return ResultUtil.paranErr("num不能为空"); } if(ToolUtil.isEmpty(startName)){ return ResultUtil.paranErr("startName不能为空"); } if(ToolUtil.isEmpty(endName)){ return ResultUtil.paranErr("endName不能为空"); } /*用户的资料过期了不可以发布行程*/ DriverRide driverRide=driverRideService.selectById(driverId); if(driverRide!=null){ if(driverRide!=null){ if(DateUtil.getDate(driverRide.getComInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getBusinessInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getDutyInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getAnnualInspectionTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 ){ return ResultUtil.error("您的证件已过期,请重新上传资料"); } } /*1一个司机可以创建多个行程*/ OrderTravel orderTravel=new OrderTravel(); orderTravel.setOrderNum(OrdersUtil.getOrderNoForPrefix("travel")); orderTravel.setAddTime(new Date()); orderTravel.setDriverId(driverId); orderTravel.setStartTime(DateUtil.getDate(startTime,"yyyy-MM-dd HH:mm")); orderTravel.setNum(num);//乘车人数 orderTravel.setStartName(startName);//出发地 orderTravel.setEndName(endName);//目的地 orderTravel.setState(2);//待出行 orderTravel.setStartLon(startLon); orderTravel.setStartLat(startLat); orderTravel.setEndLon(endLon); orderTravel.setEndLat(endLat); orderTravelService.insert(orderTravel); return ApiJson.returnOK(orderTravel.getId()); } return ApiJson.returnOK(""); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 用户申请顺风车司机/修改司机资料 * @param userId * @param carType * @param carNum * @param inviteCodeRide * @param license * @param licenseImg * @param comInsuranceTime * @param comInsuranceImg * @param businessInsuranceTime * @param businessInsuranceImg * @param dutyInsuranceTime * @param dutyInsuranceImg * @param annualInspectionTime * @param annualInspectionImg * @return */ @ResponseBody @PostMapping("/driverAudit") @ApiOperation(value = "用户申请顺风车司机/修改司机资料", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "brandId", value = "品牌id", dataType = "int"), @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"), @ApiImplicitParam(name = "carType", value = "车辆品牌", dataType = "string"), @ApiImplicitParam(name = "carNum", value = "车牌", dataType = "string"), @ApiImplicitParam(name = "inviteCodeRide", value = "别人的邀请码", dataType = "string"), @ApiImplicitParam(name = "license", value = "驾驶证号", dataType = "string"), @ApiImplicitParam(name = "licenseImg", value = "驾驶证图片", dataType = "string"), @ApiImplicitParam(name = "comInsuranceTime", value = "交强险到期时间", dataType = "string"), @ApiImplicitParam(name = "comInsuranceImg", value = "交强险照片", dataType = "string"), @ApiImplicitParam(name = "businessInsuranceTime", value = "商业险到期时间", dataType = "string"), @ApiImplicitParam(name = "businessInsuranceImg", value = "商业险图片", dataType = "string"), @ApiImplicitParam(name = "dutyInsuranceTime", value = "驾乘人员责任险到期时间", dataType = "string"), @ApiImplicitParam(name = "dutyInsuranceImg", value = "驾乘人员责任险照片", dataType = "string"), @ApiImplicitParam(name = "annualInspectionTime", value = "年检到期时间", dataType = "string"), @ApiImplicitParam(name = "annualInspectionImg", value = "年检图片", dataType = "string"), }) public Object driverAudit(Integer userId,Integer brandId,Integer driverId,String carType,String carNum,String inviteCodeRide,String license,String licenseImg,String comInsuranceTime,String comInsuranceImg, String businessInsuranceTime,String businessInsuranceImg,String dutyInsuranceTime,String dutyInsuranceImg,String annualInspectionTime,String annualInspectionImg){ try { if(ToolUtil.isEmpty(userId)){ return ResultUtil.paranErr("userId不能为空"); } if(ToolUtil.isEmpty(carType)){ return ResultUtil.paranErr("carType不能为空"); } if(ToolUtil.isEmpty(brandId)){ return ResultUtil.paranErr("brandId不能为空"); } if(ToolUtil.isEmpty(carNum)){ return ResultUtil.paranErr("carNum不能为空"); } if(ToolUtil.isEmpty(license)){ return ResultUtil.paranErr("license不能为空"); } if(ToolUtil.isEmpty(licenseImg)){ return ResultUtil.paranErr("licenseImg不能为空"); } if(ToolUtil.isEmpty(comInsuranceTime)){ return ResultUtil.paranErr("comInsuranceTime不能为空"); } if(ToolUtil.isEmpty(comInsuranceImg)){ return ResultUtil.paranErr("comInsuranceImg不能为空"); } if(ToolUtil.isEmpty(businessInsuranceTime)){ return ResultUtil.paranErr("businessInsuranceTime不能为空"); } if(ToolUtil.isEmpty(businessInsuranceImg)){ return ResultUtil.paranErr("businessInsuranceImg不能为空"); } if(ToolUtil.isEmpty(dutyInsuranceTime)){ return ResultUtil.paranErr("dutyInsuranceTime不能为空"); } if(ToolUtil.isEmpty(dutyInsuranceImg)){ return ResultUtil.paranErr("dutyInsuranceImg不能为空"); } if(ToolUtil.isEmpty(annualInspectionTime)){ return ResultUtil.paranErr("annualInspectionTime不能为空"); } if(ToolUtil.isEmpty(annualInspectionImg)){ return ResultUtil.paranErr("annualInspectionImg不能为空"); } DriverRide driverRide=new DriverRide(); driverRide.setBrandId(brandId); driverRide.setUserId(userId); driverRide.setByInviteCode(inviteCodeRide); driverRide.setCompanyId(1); driverRide.setCarType(carType); driverRide.setCarNum(carNum); driverRide.setLicense(license); driverRide.setLicenseImg(licenseImg); if(ToolUtil.isNotEmpty(driverId)){ driverRide.setId(driverId); driverRide.setState(1);//待审核状态 if(ToolUtil.isNotEmpty(comInsuranceTime)){ driverRide.setComInsuranceTime(comInsuranceTime); } if(ToolUtil.isNotEmpty(comInsuranceImg)) { driverRide.setComInsuranceImg(comInsuranceImg); } if(ToolUtil.isNotEmpty(businessInsuranceTime)) { driverRide.setBusinessInsuranceTime(businessInsuranceTime); } if(ToolUtil.isNotEmpty(businessInsuranceImg)) { driverRide.setBusinessInsuranceImg(businessInsuranceImg); } if(ToolUtil.isNotEmpty(dutyInsuranceTime)) { driverRide.setDutyInsuranceTime(dutyInsuranceTime); } if(ToolUtil.isNotEmpty(dutyInsuranceImg)) { driverRide.setDutyInsuranceImg(dutyInsuranceImg); } if(ToolUtil.isNotEmpty(annualInspectionTime)) { driverRide.setAnnualInspectionTime(annualInspectionTime); } if(ToolUtil.isNotEmpty(annualInspectionImg)) { driverRide.setAnnualInspectionImg(annualInspectionImg); } driverRideService.updateById(driverRide); }else { driverRide.setAddTime(new Date()); /*获取司机品牌id*/ /*Brand b=brandService.selectById(driverRide.getBrandId()); if(b!=null){ driverRide.setCarType(b.getName()); }*/ driverRide.setComInsuranceTime(comInsuranceTime); driverRide.setComInsuranceImg(comInsuranceImg); driverRide.setBusinessInsuranceTime(businessInsuranceTime); driverRide.setBusinessInsuranceImg(businessInsuranceImg); driverRide.setDutyInsuranceTime(dutyInsuranceTime); driverRide.setDutyInsuranceImg(dutyInsuranceImg); driverRide.setAnnualInspectionTime(annualInspectionTime); driverRide.setAnnualInspectionImg(annualInspectionImg); driverRideService.insert(driverRide); /*绑定司机和用户的关系*/ UserInfo userInfo_=new UserInfo(); userInfo_.setId(userId); userInfo_.setDriverId(driverRide.getId()); userInfoService.updateById(userInfo_); } return ApiJson.returnOK(driverRide); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 获取司机资料 * @param driverId * @return */ @ResponseBody @GetMapping("/driverInfo") @ApiOperation(value = "获取司机资料", httpMethod = "GET") public Object driverInfo(Integer driverId){ try { if(ToolUtil.isEmpty(driverId)){ return ResultUtil.paranErr("driverId不能为空"); } DriverRide driverRide=driverRideService.selectById(driverId); /*获取司机品牌id*/ TCarBrand tCarBrand = carBrandService.selectById(driverRide.getBrandId()); if(tCarBrand!=null){ driverRide.setCarType(tCarBrand.getName()); } return ApiJson.returnOK(driverRide); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 司机用户获取取消的服务费(同时计算退款金额) * @param orderId 订单id * @param type 1用户,2司机 * @return */ @ResponseBody @GetMapping("/cancelServiceMoney") @ApiOperation(value = "司机用户获取取消的服务费(同时计算退款金额)", httpMethod = "GET") @ApiImplicitParams({ @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"), @ApiImplicitParam(name = "type", value = "1用户,2司机", dataType = "int") }) public Object cancelServiceMoney(Integer orderId,Integer type){ try { if(ToolUtil.isEmpty(orderId)){ return ResultUtil.paranErr("orderId不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } Double serviceMoney=0d; if(type==1){//用户 OrderRide orderRide=orderRideService.selectById(orderId); if(orderRide.getState()>=3){//待出行状态取消才会有服务费 EntityWrapper rideEntityWrapper=new EntityWrapper<>(); rideEntityWrapper.eq("type",3);//用户 ParamRide paramRide=paramRideService.selectOne(rideEntityWrapper);//退单比例 serviceMoney=Double.valueOf(paramRide.getContext())*orderRide.getPlatformMoney();//退单金额:退单比例*平台抽成 orderRide.setServiceMoney(serviceMoney);//设置取消服务费 /*计算退款金额*/ if(orderRide.getState()==2){//已支付: 需要退款 orderRide.setTuiMoney(orderRide.getMoney()); }else if(orderRide.getState()>=3){//待出行,需要计算 然后 需要退款 if(serviceMoney>orderRide.getMoney()){//退款金额大于了取消服务费,就直接全部扣完 orderRide.setTuiMoney(0d); }else { orderRide.setTuiMoney(orderRide.getMoney()-serviceMoney); } } }else{ orderRide.setTuiMoney(orderRide.getMoney()); } orderRideService.updateById(orderRide);//更新退款金额和取消服务器 }else if(type==2){//司机 OrderTravel orderTravel=orderTravelService.selectById(orderId); if(orderTravel.getState()>=3){//待出行的状态取消才有服务费 EntityWrapper rideEntityWrapper=new EntityWrapper<>(); rideEntityWrapper.eq("type",4);//司机 ParamRide paramRide=paramRideService.selectOne(rideEntityWrapper);//司机退单比例 /*查询订单(现在订单和行程时一对一关系)*/ OrderRide orderRide=orderRideService.selectOne(new EntityWrapper().eq("travelId",orderId)); if(orderRide!=null){ serviceMoney=Double.valueOf(paramRide.getContext())*orderRide.getPlatformMoney(); orderTravel.setServiceMoney(serviceMoney);//司机退单比例*订单提成比例 orderRide.setTuiMoney(orderRide.getMoney()); orderRideService.updateById(orderRide); } } orderTravelService.updateById(orderTravel);//更新取消服务费 } return ResultUtil.success(serviceMoney); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 用户订单取消 待出行之前才可以取消 * @param orderId * * @return */ @ResponseBody @PostMapping("/userCancel") @ApiOperation(value = "用户订单取消 待出行之前才可以取消", httpMethod = "POST") public Object userCancel(Integer orderId){ try { if(ToolUtil.isEmpty(orderId)){ return ResultUtil.paranErr("orderId不能为空"); } /*查看这个订单是否在进行中*/ OrderRide orderRide=orderRideService.selectById(orderId); if(orderRide!=null){ if(orderRide.getState() == 4){ return ResultUtil.error("订单行程中,不能取消订单"); } if(orderRide.getState() == 6){ return ResultUtil.error("订单已取消,不能重复操作"); } //用户取消给司机推送 if(orderRide.getDriverId()!=null) { UserInfo userInfo1=userInfoService.selectOne(new EntityWrapper().eq("driverId",orderRide.getDriverId())); pushUtil.pushOrderState(1, userInfo1.getDriverId(), orderRide.getId(), 8, 6, null); } //用户取消退款 userCancelTuik(orderRide); } //取消司机行程 if(orderRide.getTravelId()!=null){ OrderTravel orderTravel=orderTravelService.selectById(orderRide.getTravelId()); orderTravel.setState(2); orderTravelService.updateById(orderTravel); } return ResultUtil.success(""); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } private Integer getState(Integer state){ switch (state){ case 1: return 7; case 2: return 1; case 3: return 4; case 4: return 5; case 5: return 8; case 6: return 10; } return null; } //用户取消退款 public void userCancelTuik(OrderRide orderRide){ UserInfo userInfo=userInfoService.selectById(orderRide.getUserId()); if(orderRide.getState()==2){//用户已经支付了订单但司机没有接单 orderRide.setTuiMoney(orderRide.getMoney()); } if(null != orderRide.getTuiMoney() && orderRide.getTuiMoney()>0){ Financial financial= financialService.selectOne(new EntityWrapper().eq("orderNum",orderRide.getOrderNum())); String finNum=OrdersUtil.getOrderNoForPrefix("fin"); //todo 退款金额大于0需要退款 if(orderRide.getPayType()==1){//余额 userInfo.setBalanceChangeType(BalanceChangeType.REFUND.getCode()); userInfo.setBalance(userInfo.getBalance()+orderRide.getTuiMoney()); userInfoService.updateById(userInfo); }else if(orderRide.getPayType()==2){ //微信 // Integer money = new Double(orderRide.getMoney() * 100).intValue(); // Integer tMoney_ = new Double(orderRide.getTuiMoney()* 100).intValue(); // PayUtil.refundForWxpay(1, financial.getLsType(), orderRide.getOrderNum(), finNum, money,tMoney_ , "2"); CbyzxPayUtil.ClosePayOrderRequest request = new CbyzxPayUtil.ClosePayOrderRequest(); request.setOutRequestNo(orderRide.getOutNum()); request.setRefundOutRequestNo(buildPrepayRefundOutNo(orderRide.getId())); request.setRefundAmount(toFen(orderRide.getTuiMoney())); request.setRefundDesc("顺风车订单取消退款"); com.alibaba.fastjson.JSONObject response = CbyzxPayUtil.closePayOrder(request); if (!isPrivateCarPrepayRefundSuccess(response)) { throw new RuntimeException(extractPrivateCarRefundMessage(response)); } }else if(orderRide.getPayType()==3){ } /*财务明细*/ Financial f=new Financial(); f.setAddTime(new Date()); f.setType(2);//类型 1=收入 2=支出 f.setMoney(orderRide.getTuiMoney()); f.setPwType(9);//9=顺风车取消服务费 f.setOrderNum(orderRide.getOrderNum()); f.setLsType(finNum); f.setUserId(orderRide.getUserId()); f.setOrderType(4); f.setLx(1); financialService.insert(f); }else{ } /*添加系统消息*/ try { systemNoticeService.addSystemNotice(1, "您从"+orderRide.getStartName()+"到"+orderRide.getEndName()+"的顺风车订单已取消", orderRide.getUserId(), 1); } catch (Exception e) { throw new RuntimeException(e); } orderRide.setState(6);//取消状态 orderRide.setTravelId(null); orderRideService.updateAllColumnById(orderRide); } private String buildPrepayRefundOutNo(Integer orderId) { return "PREPAY_REFUND_8_" + orderId+ToolUtil.getRandomString(5); } private Integer toFen(Double amount) { return new BigDecimal(String.valueOf(amount)).multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).intValue(); } private boolean isPrivateCarPrepayRefundSuccess(com.alibaba.fastjson.JSONObject response) { if (response == null) { return false; } Object code = response.get("code"); if (code == null || !"0".equals(String.valueOf(code))) { return false; } com.alibaba.fastjson.JSONObject data = response.getJSONObject("data"); return data != null && Boolean.TRUE.equals(data.getBoolean("isSuccess")); } private String extractPrivateCarRefundMessage(com.alibaba.fastjson.JSONObject response) { if (response == null) { return "微信退款失败"; } com.alibaba.fastjson.JSONObject data = response.getJSONObject("data"); if (data != null && ToolUtil.isNotEmpty(data.getString("failReason"))) { return data.getString("failReason"); } String msg = response.getString("msg"); return ToolUtil.isNotEmpty(msg) ? msg : "微信退款失败"; } /** * 司机行程取消 * @param orderId * * @return */ @ResponseBody @PostMapping("/driverCancel") @ApiOperation(value = "司机行程取消", httpMethod = "POST") public Object driverCancel(Integer orderId){ try { if(ToolUtil.isEmpty(orderId)){ return ResultUtil.paranErr("orderId不能为空"); } OrderTravel orderTravel=orderTravelService.selectById(orderId); if(null == orderTravel){ return ResultUtil.error("无效的订单ID"); } if(orderTravel.getState()==6){ return ResultUtil.error("该订单已取消"); } if(orderTravel.getState()==4){ return ResultUtil.error("出行中不能取消订单"); } DriverRide driverRide=driverRideService.selectById(orderTravel.getDriverId()); if(orderTravel.getServiceMoney()!=null && orderTravel.getServiceMoney()>0){ /*todo 更新司机余额*/ driverRide.setBalance(driverRide.getBalance()-orderTravel.getServiceMoney()); driverRideService.updateById(driverRide); /* 更新司机用户余额(用户和司机用户一个账号余额)*/ UserInfo userInfo=userInfoService.selectOne(new EntityWrapper().eq("driverId",orderTravel.getDriverId())); if(userInfo!=null){ //用户余额可以为负数 userInfo.setBalanceChangeType(BalanceChangeType.CONSUME.getCode()); userInfo.setBalance(userInfo.getBalance()-orderTravel.getServiceMoney()); userInfoService.updateById(userInfo); } /*财务明细*/ Financial f=new Financial(); f.setAddTime(new Date()); f.setType(1);//类型 1=收入 2=支出 f.setMoney(orderTravel.getServiceMoney()); f.setPwType(9);//9=顺风车取消服务费 f.setOrderNum(orderTravel.getOrderNum()); String finNum=OrdersUtil.getOrderNoForPrefix("fin"); f.setLsType(finNum); f.setUserId(driverRide.getUserId()); f.setOrderType(4); f.setLx(1); financialService.insert(f); //司机取消给用户推送 } /*添加系统消息*/ try { systemNoticeService.addSystemNotice(1, "您从"+orderTravel.getStartName()+"到"+orderTravel.getEndName()+"的顺风车行程已取消", driverRide.getUserId(), 1); } catch (Exception e) { throw new RuntimeException(e); } orderTravel.setState(6);//取消状态 orderTravelService.updateById(orderTravel); //todo 推送 /*司机接单给用户发送消息*/ OrderRide orderRide=orderRideService.selectOne(new EntityWrapper().eq("travelId",orderId)); // if(orderRide!=null) { // pushUtil.pushOrderState(1, orderRide.getUserId(), orderRide.getId(), 8, 6, null); // } //取消乘客订单 if(orderRide!=null && orderRide.getState()!=6){ // orderRide.setTuiMoney(orderRide.getMoney()); // orderRideService.updateById(orderRide); // userCancelTuik(orderRide); orderRide.setState(2); orderRide.setTravelId(null); orderRide.setDriverId(null); orderRideService.updateAllColumnById(orderRide); } return ResultUtil.success(""); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 司机确认同行,接到乘客,送达乘客 * @param driverOrderId * @param type 1确认同行 2接到乘客,3送达乘客 * @return */ @ResponseBody @PostMapping("/driverOperation") @ApiOperation(value = "司机确认同行,接到乘客,送达乘客", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "userOrderId", value = "用户订单id", dataType = "int"), @ApiImplicitParam(name = "type", value = "1确认同行 2接到乘客,3送达乘客", dataType = "int"), @ApiImplicitParam(name = "driverOrderId", value = "司机订单id", dataType = "int") }) @Transactional public Object driverOperation(Integer userOrderId,Integer type,Integer driverOrderId){ try { if(ToolUtil.isEmpty(driverOrderId)){ return ResultUtil.paranErr("driverOrderId不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } OrderTravel orderTravel=orderTravelService.selectById(driverOrderId);//司机行程 /*用户的资料过期了不可以发布行程*/ DriverRide driverRide=driverRideService.selectById(orderTravel.getDriverId()); if(driverRide!=null){ if(DateUtil.getDate(driverRide.getComInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getBusinessInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getDutyInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getAnnualInspectionTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 ){ return ResultUtil.error("您的证件已过期,请重新上传资料"); } } OrderRide orderRide=orderRideService.selectById(userOrderId); if(orderRide!=null && orderRide.getState()==6){ return ResultUtil.error("用户已取消该行程"); } UserInfo userInfo=userInfoService.selectById(driverRide.getUserId()); if(orderTravel!=null){ if(type==1){//1确认同行 一个行程只能匹配一个订单 if(orderTravel.getState()==3){ return ResultUtil.error("该行程已经绑定了用户订单"); } orderTravel.setState(3); //绑定司机行程、设置用户订单状态 orderRide.setTravelId(driverOrderId); orderRide.setDriverId(orderTravel.getDriverId()); orderRide.setState(3); }else if(type==2){//2接到乘客 orderTravel.setState(4); orderRide.setState(4); }else if(type==3){//3送达乘客 orderTravel.setState(5); orderRide.setState(5); /*修改司机的总接单数*/ driverRide.setTotalOrders(driverRide.getTotalOrders()+1); driverRideService.updateById(driverRide); /*修改用户接单数和司机提成*/ userInfo.setBalanceChangeType(BalanceChangeType.REFUND.getCode()); userInfo.setBalance(userInfo.getBalance()+(orderRide.getMoney()-orderRide.getPlatformMoney())); userInfo.setTotalOrders(userInfo.getTotalOrders() + 1); userInfoService.updateById(userInfo); Financial f=new Financial(); f.setAddTime(new Date()); f.setType(2); f.setPayType("1");//余额 f.setMoney(orderRide.getMoney()-orderRide.getPlatformMoney());//司机提成 f.setPwType(11);//顺风车司机提成 f.setLsType(OrdersUtil.getOrderNoForPrefix("finan")); f.setUserId(userInfo.getId()); f.setOrderType(4); f.setLx(1); financialService.insert(f); /*如果司机有推荐人就需要算用户的提成*/ if(ToolUtil.isNotEmpty(driverRide.getByInviteCode())){ /*计算推广用户的提成*/ UserInfo userInfo1=userInfoService.selectOne(new EntityWrapper().eq("inviteCodeRide",driverRide.getByInviteCode())); Double discount=100d; Double money=orderRide.getMoney()*discount/100;//提成金额 userInfoService.updateById(userInfo1); f.setAddTime(new Date()); f.setType(2); f.setPayType("1");//余额 f.setMoney(money);//邀请金额 f.setPwType(10);//分享收益 f.setLsType(OrdersUtil.getOrderNoForPrefix("finan")); f.setUserId(userInfo1.getId()); f.setOrderType(4); f.setLx(1); financialService.insert(f); } } } orderRideService.updateById(orderRide); orderTravelService.updateById(orderTravel); if(type==1){//确认同行 String message="您发布的"+DateUtil.getDateToString(orderRide.getStartTime(),"MM月dd日")+"的行程有司机接单"; /*添加系统消息*/ try { systemNoticeService.addSystemNotice(1, message, driverRide.getUserId(), 1); } catch (Exception e) { throw new RuntimeException(e); } } pushUtil.pushOrderState(1, orderRide.getUserId(), orderRide.getId(), 8, orderRide.getState(), null); return ResultUtil.success(""); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 用户评价 * @param orderId * @param driverId * @param userId * @param score * @param content * @return */ @ResponseBody @PostMapping("/evaluate") @ApiOperation(value = "用户评价", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"), @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"), @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "score", value = "评分", dataType = "int"), @ApiImplicitParam(name = "content", value = "评价内容", dataType = "string") }) public Object evaluate(Integer orderId,Integer driverId,Integer userId,Integer score,String content){ try { if(userId == null || userId == 0){ return ResultUtil.paranErr("userId不能为空"); } if(driverId == null || driverId == 0){ return ResultUtil.paranErr("driverId不能为空"); } if(orderId == null || orderId == 0){ return ResultUtil.paranErr("orderId不能为空"); } if(score == null || score == 0){ return ResultUtil.paranErr("score不能为空"); } Evaluate evaluate=new Evaluate(); evaluate.setAddTime(new Date()); evaluate.setType(8); evaluate.setOrderId(orderId); evaluate.setScore(score); evaluate.setUserId(userId); if(ToolUtil.isNotEmpty(content)){ /*判断评价内容是否包含敏感词*/ List list = sensitiveWordsMapper.selectList(null); Set sensitiveWordSet = new HashSet<>(); for(SensitiveWords gs:list){ sensitiveWordSet.add(gs.getContent()); } SensitiveWordUtil.init(sensitiveWordSet); boolean result = SensitiveWordUtil.contains(content); if(result){ return ResultUtil.error("评价内容包含敏感词"); } } evaluate.setContent(content); evaluate.setDriverId(driverId); /*查询用户手机号*/ UserInfo userInfo=userInfoService.selectById(userId); if(userInfo!=null){ evaluate.setUserPhone(userInfo.getPhone()); } /*查询司机电话*/ DriverRide driverRide=driverRideService.selectById(driverId); if(driverRide!=null){ /*计算司机的评分*/ driverRide.setEvaluateNum((null != driverRide.getEvaluateNum() ? driverRide.getEvaluateNum() : 0 )+1); driverRide.setEvaluateScore((null == driverRide.getEvaluateScore() ? 0 : driverRide.getEvaluateScore())+score); driverRideService.updateById(driverRide); } /*标记订单已评价*/ OrderRide orderTaxi=new OrderRide(); orderTaxi.setId(orderId); orderTaxi.setIsEvaluate(2); orderTaxi.setEvaluateScoreUser(score); orderTaxi.setContent(content); orderRideService.updateById(orderTaxi); evaluateService.insert(evaluate); /*需要反订单数据*/ return ResultUtil.success(orderId); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error(""); } /** * 投诉 * @param type 1:用户投诉司机,2司机投诉用户 * @param driverId * @param userId * @param content * @param reMark * @return */ @ResponseBody @PostMapping("/complaints") @ApiOperation(value = "投诉", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"), @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "content", value = "投诉内容", dataType = "string"), @ApiImplicitParam(name = "reMark", value = "备注", dataType = "string"), @ApiImplicitParam(name = "type", value = "1=顺风车用户,2=顺风车司机", dataType = "int"), @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int") }) public Object complaints(Integer driverId,Integer userId,String content,String reMark,Integer type,Integer orderId) { try { if (userId == null || userId == 0) { return ResultUtil.paranErr("userId不能为空"); } if (driverId == null || driverId == 0) { return ResultUtil.paranErr("driverId不能为空"); } if (orderId == null || orderId == 0) { return ResultUtil.paranErr("orderId不能为空"); } Complaints complaints=new Complaints(); complaints.setAddTime(new Date()); complaints.setUserId(userId); complaints.setDriverId(driverId); /*判断投诉内容是否包含敏感词*/ List list = sensitiveWordsMapper.selectList(null); Set sensitiveWordSet = new HashSet<>(); for(SensitiveWords gs:list){ sensitiveWordSet.add(gs.getContent()); } SensitiveWordUtil.init(sensitiveWordSet); boolean result = SensitiveWordUtil.contains(content); if(result){ return ResultUtil.error("投诉内容包含敏感词"); } complaints.setContent(content); complaints.setReMark(reMark); if(type==1){ complaints.setType(4);//顺风车用户 }else if(type==2){ complaints.setType(3);//顺风车司机 } /*查询用户手机号*/ UserInfo userInfo=userInfoService.selectById(userId); if(userInfo!=null){ complaints.setPhone(userInfo.getPhone()); } complaints.setState(1); complaintsService.insert(complaints); /*标记订单已投诉*/ if(type==2){//司机投诉 OrderRide orderTaxi=new OrderRide(); orderTaxi.setId(orderId); orderTaxi.setIsComplaint(2); orderRideService.updateById(orderTaxi); }else{//用户投诉 OrderTravel orderTravel=new OrderTravel(); orderTravel.setId(orderId); orderTravel.setIsComplaint(2); orderTravelService.updateById(orderTravel); } return ResultUtil.success("投诉成功"); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error(""); } /** * 用户邀请司机接单(需要发送消息) * @param orderId 司机订单 * @param userId * @return */ @ResponseBody @PostMapping("/userInvite") @ApiOperation(value = "用户邀请司机接单(需要发送消息)", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"), @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int") }) public Object myOrders(Integer orderId,Integer userId){ try { if(ToolUtil.isEmpty(orderId)){ return ResultUtil.paranErr("orderId不能为空"); } if(ToolUtil.isEmpty(userId)){ return ResultUtil.paranErr("userId不能为空"); } OrderTravel orderTravel=orderTravelService.selectById(orderId); UserInfo userInfo_=userInfoService.selectOne(new EntityWrapper().eq("driverId",orderTravel.getDriverId()));//司机用户 OrderRide orderRide=orderRideService.selectOne(new EntityWrapper().eq("userId",userId) .eq("state",2)); if(orderRide!=null){ OrderInvitation orderInvitation = new OrderInvitation(); orderInvitation.setOrderRideId(orderRide.getId()); orderInvitation.setOrderTravelId(orderTravel.getId()); orderInvitation.setInsertTime(new Date()); orderInvitationService.insert(orderInvitation); String message="您发布的"+DateUtil.getDateToString(orderTravel.getStartTime(),"MM月dd日")+"的行程有乘客邀请您同行"; /*添加系统消息*/ try { systemNoticeService.addSystemNotice(1, message, userInfo_.getId(), 1); } catch (Exception e) { throw new RuntimeException(e); } } return ResultUtil.success("邀请成功"); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 用户订单匹配列表页面,用户订单去匹配司机的行程 * @param type 搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近 * @param orderId * @param current 司机当前经度 * @param size 司机当前纬度 * @return */ @ResponseBody @PostMapping("/userMatchingOrderList") @ApiOperation(value = "用户订单匹配列表页面,用户订单去匹配司机的行程", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"), @ApiImplicitParam(name = "type", value = "1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近", dataType = "int") }) public Object userMatchingOrderList(Integer orderId,Integer current,Integer size,Integer type){ try { if(ToolUtil.isEmpty(orderId)){ return ResultUtil.paranErr("orderId不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } OrderRide orderRide=orderRideService.selectById(orderId); current=current==null?1:current; size=size==null?10:size; size=current*size; current=(current-1)*size; OrderRideVo orderRideVo=new OrderRideVo(); orderRideVo.setCurrent(current); orderRideVo.setSize(size); orderRideVo.setLon(orderRide.getStartLon()); orderRideVo.setLat(orderRide.getStartLat()); orderRideVo.setNum(orderRide.getNum()); orderRideVo.setId(orderId); orderRideVo.setType(type+1);//搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近 List orderRides=orderTravelService.getOrderTravel(orderRideVo); return ResultUtil.success(orderRides); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 司机订单匹配列表页面(司机的订单去匹配乘客订单) * @param orderId * @param current * @param size * @param type 搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近,4价格最低 * @return */ @ResponseBody @PostMapping("/driverMatchingOrderList") @ApiOperation(value = "司机订单匹配列表页面(司机的订单去匹配乘客订单)", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"), @ApiImplicitParam(name = "type", value = "1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近,4价格最低", dataType = "int") }) public Object driverMatchingOrderList(Integer orderId,Integer current,Integer size,Integer type){ try { try { if(ToolUtil.isEmpty(orderId)){ return ResultUtil.paranErr("orderId不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } OrderTravel orderTravel=orderTravelService.selectById(orderId); current=current==null?1:current; size=size==null?10:size; size=current*size; current=(current-1)*size; OrderRideVo orderRideVo=new OrderRideVo(); orderRideVo.setCurrent(current); orderRideVo.setSize(size); orderRideVo.setNum(orderTravel.getNum()); orderRideVo.setLon(orderTravel.getStartLon()); orderRideVo.setLat(orderTravel.getStartLat()); orderRideVo.setType(type+1);//搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近,4价格最低 List orderRides=orderRideService.getOrderRide(orderRideVo); return ResultUtil.success(orderRides); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 订单详情 * @type 1用户订单,2司机端订单 * @param orderId * @return */ @ResponseBody @GetMapping("/orderInfo") @ApiOperation(value = "订单详情", httpMethod = "GET") @ApiImplicitParams({ @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"), @ApiImplicitParam(name = "type", value = "1=用户订单,2=司机订单", dataType = "int"), @ApiImplicitParam(name = "lon", value = "经度", dataType = "double"), @ApiImplicitParam(name = "lat", value = "纬度", dataType = "double"), }) public Object orderInfo(Integer orderId,Integer type,Double lon,Double lat) { try { if(ToolUtil.isEmpty(orderId)){ return ResultUtil.paranErr("orderId不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } //取司机的经纬度 OrderRideInfoVo orderRideInfoVo=new OrderRideInfoVo(); orderRideInfoVo.setLon(lon); orderRideInfoVo.setLat(lat); if(type==1){//用户端订单详情 用户端看到的就是自己的订单信息 orderRideInfoVo.setUserOrderId(orderId); orderRideInfoVo=orderRideService.getOrderInfo(orderRideInfoVo); }else if(type==2){//司机端订单详情 司机端看到的就是用户端的订单信息 orderRideInfoVo.setDriverOrderId(orderId); orderRideInfoVo=orderTravelService.getOrderInfo(orderRideInfoVo); } /*获取顺风车订单支付倒计时*/ Integer time =10; orderRideInfoVo.setDjs(time); return ResultUtil.success(orderRideInfoVo); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 验证输入的邀请码是否正确 * @param type 1:普通邀请码,2顺风车邀请码 * @param inviteCode * @return */ @ResponseBody @PostMapping("/checkInviteCode") @ApiOperation(value = "验证输入的邀请码是否正确", httpMethod = "POST") public Object orderInfo(String inviteCode,Integer type) { try { if(ToolUtil.isEmpty(inviteCode)){ return ResultUtil.paranErr("inviteCode不能为空"); } if(ToolUtil.isEmpty(type)){ return ResultUtil.paranErr("type不能为空"); } Integer count=0; if(type==1){ count=userInfoService.selectCount(new EntityWrapper().eq("inviteCode",inviteCode)); }else { count=userInfoService.selectCount(new EntityWrapper().eq("inviteCodeRide",inviteCode)); } return ResultUtil.success(count); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } /** * 验证司机证件是否过期 * * @param driverId * @return */ @ResponseBody @PostMapping("/checkInsuranceTime") @ApiOperation(value = "验证司机证件是否过期", httpMethod = "POST") public Object orderInfo(Integer driverId) { try { if(ToolUtil.isEmpty(driverId)){ return ResultUtil.paranErr("driverId不能为空"); } DriverRide driverRide=driverRideService.selectById(driverId); Integer count=0; if(driverRide!=null){ if(DateUtil.getDate(driverRide.getComInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getBusinessInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getDutyInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 || DateUtil.getDate(driverRide.getAnnualInspectionTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0 ){ count=1; } } return ResultUtil.success(count); } catch (Exception e) { e.printStackTrace(); } return ResultUtil.error("异常"); } }