| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.dao.OrderMapper; |
| | | import com.supersavedriving.driver.modular.system.model.*; |
| | | import com.supersavedriving.driver.modular.system.service.*; |
| | | import com.supersavedriving.driver.modular.system.util.*; |
| | | import com.supersavedriving.driver.modular.system.util.GaoDe.MapUtil; |
| | | import com.supersavedriving.driver.modular.system.util.GaoDe.model.District; |
| | | import com.supersavedriving.driver.modular.system.util.juhe.WeatherUtil; |
| | | import com.supersavedriving.driver.modular.system.util.mongodb.model.Location; |
| | | import com.supersavedriving.driver.modular.system.warpper.*; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.util.*; |
| | | import com.supersavedriving.driver.modular.system.util.GaoDe.model.District; |
| | | import com.supersavedriving.driver.modular.system.util.juhe.WeatherUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.*; |
| | | import com.supersavedriving.driver.modular.system.model.*; |
| | | import com.supersavedriving.driver.modular.system.service.*; |
| | | import com.supersavedriving.driver.modular.system.util.PushUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.AddOrderWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.HallOrderList; |
| | | import com.supersavedriving.driver.modular.system.warpper.OrderInfoWarpper; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.Circle; |
| | |
| | | private ICancelOrderService cancelOrderService; |
| | | |
| | | @Autowired |
| | | private IRevenueService revenueService; |
| | | private IAccountChangeDetailService accountChangeDetailService; |
| | | |
| | | private Map<String, Timer> timerMap = new HashMap<>(); |
| | | |
| | |
| | | String city = ""; |
| | | District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat()); |
| | | if(null != geocode){ |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getProvince() + "' like district")); |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district")); |
| | | city = null != weatherCity ? weatherCity.getId().toString() : ""; |
| | | } |
| | | order = getOrderPrice(1, d, 0, order, city); |
| | |
| | | pushUtil.pushOrderStatus(uid, 2, order.getId(), order.getStatus()); |
| | | }else{ |
| | | //开始推单 |
| | | pushOrder(order); |
| | | // pushOrder(order); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | orderRefusal.setStartAddress(order.getStartAddress()); |
| | | orderRefusal.setOrderId(orderId); |
| | | orderRefusalService.insert(orderRefusal); |
| | | |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | //扣除积分 |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); |
| | | if(null != systemConfig) { |
| | | //{"num1":"10:00","num2":"14:00","num3":10,"num4":10,"num5":10,"num6":10,"num7":10,"num8":10,"num9":5,"num10":5} |
| | | //拒绝订单扣除积分 |
| | | Integer num10 = JSON.parseObject(systemConfig.getContent()).getInteger("num10"); |
| | | if (num10 > 0) { |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order.getDriverId()); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); |
| | | driver.setIntegral(driver.getIntegral() - num10); |
| | | accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); |
| | | accountChangeDetail.setExplain("拒绝订单扣除积分"); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | driverService.updateById(driver); |
| | | } |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | if(null == driverWork){ |
| | | return ResultUtil.error("请先上班"); |
| | | } |
| | | boolean lock = redisUtil.lock(5); |
| | | boolean lock = redisUtil.lock(); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock(5); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | } |
| | | return ResultUtil.error("请重试"); |
| | | } |
| | | Order order = this.selectById(orderId); |
| | | Integer state = order.getState(); |
| | | Integer oldDriverId = order.getDriverId(); |
| | | if(state != 301){ |
| | | if(state == 301){ |
| | | redisUtil.unlock(); |
| | | return ResultUtil.error("订单已被取消"); |
| | | } |
| | |
| | | order.setOrderTakingTime(new Date()); |
| | | this.updateById(order); |
| | | redisUtil.unlock(); |
| | | |
| | | if(null != order.getUserId()){ |
| | | AppUser appUser = appUserService.selectById(order.getUserId()); |
| | | appUser.setCancelCount(0); |
| | | appUserService.updateById(appUser); |
| | | } |
| | | |
| | | driver.setServerStatus(2); |
| | | driverService.updateById(driver); |
| | |
| | | } |
| | | |
| | | //推动订单数据 |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //发送系统消息 |
| | | systemMessageService.addSystemMessage(uid, 2, "接单成功", "您已成功接到用户订单,请尽快联系客户!"); |
| | | pushUtil.pushOrderStatus(order.getDriverId(), 2, order.getId(), order.getState()); |
| | | if(null != order.getUserId()){ |
| | | systemMessageService.addSystemMessage(order.getUserId(), 1, "接单成功", driver.getName() + "师傅已成功接到您的订单,请保持电话畅通!"); |
| | | pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState()); |
| | | } |
| | | } |
| | | }).start(); |
| | | //发送系统消息 |
| | | systemMessageService.addSystemMessage(uid, 2, "接单成功", "您已成功接到用户订单,请尽快联系客户!"); |
| | | pushUtil.pushOrderStatus(order.getDriverId(), 2, order.getId(), order.getState()); |
| | | if(null != order.getUserId()){ |
| | | systemMessageService.addSystemMessage(order.getUserId(), 1, "接单成功", driver.getName() + "师傅已成功接到您的订单,请保持电话畅通!"); |
| | | pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState()); |
| | | } |
| | | }catch (Exception e){ |
| | | redisUtil.unlock(); |
| | | e.printStackTrace(); |
| | |
| | | String city = ""; |
| | | District geocode = MapUtil.geocode(order.getEndLng(), order.getEndLat()); |
| | | if(null != geocode){ |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getProvince() + "' like district")); |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district")); |
| | | city = null != weatherCity ? weatherCity.getId().toString() : ""; |
| | | } |
| | | order = getOrderPrice(2, Double.valueOf(order.getActualMileage() / 1000), order.getWaitTime(), order, city); |
| | | |
| | | //修改司机状态 |
| | | //修改司机状态和积分 |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | driver.setServerStatus(1); |
| | | driverService.updateById(driver); |
| | | saveIntegral(order); |
| | | break; |
| | | case 401: |
| | | order.setStartWaitTime(new Date()); |
| | |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加订单积分奖励 |
| | | * @param order |
| | | * @throws Exception |
| | | */ |
| | | public void saveIntegral(Order order) throws Exception{ |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); |
| | | if(null != systemConfig){ |
| | | //{"num1":"10:00","num2":"14:00","num3":10,"num4":10,"num5":10,"num6":10,"num7":10,"num8":10,"num9":5,"num10":5} |
| | | //完成订单奖励 |
| | | Integer num5 = JSON.parseObject(systemConfig.getContent()).getInteger("num5"); |
| | | if(num5 > 0){ |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order.getDriverId()); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); |
| | | driver.setIntegral(driver.getIntegral() + num5); |
| | | accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); |
| | | accountChangeDetail.setExplain("完成订单奖励"); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | } |
| | | //恶劣天气完成订单奖励 |
| | | Integer num8 = JSON.parseObject(systemConfig.getContent()).getInteger("num8"); |
| | | if(num8 > 0){ |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order.getDriverId()); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); |
| | | driver.setIntegral(driver.getIntegral() + num8); |
| | | accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); |
| | | accountChangeDetail.setExplain("恶劣天气完成订单奖励"); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | } |
| | | driverService.updateById(driver); |
| | | |
| | | if(null == order.getUserId()){ |
| | | return; |
| | | } |
| | | //推荐用户首单完成奖励 |
| | | Integer num4 = JSON.parseObject(systemConfig.getContent()).getInteger("num4"); |
| | | if(num4 > 0){ |
| | | List<Integer> state = Arrays.asList(105); |
| | | int count = this.selectCount(new EntityWrapper<Order>().eq("userId", order.getUserId()).eq("status", 1).in("state", state)); |
| | | if(count > 1){ |
| | | return; |
| | | } |
| | | AppUser appUser = appUserService.selectById(order.getUserId()); |
| | | if(appUser.getInviterType() == 1){ |
| | | return; |
| | | } |
| | | Driver driver1 = driverService.selectById(appUser.getInviterId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setOldData(driver1.getIntegral().doubleValue()); |
| | | driver1.setIntegral(driver1.getIntegral() + num4); |
| | | accountChangeDetail.setNewData(driver1.getIntegral().doubleValue()); |
| | | accountChangeDetail.setExplain("推荐用户完成首单奖励"); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | driverService.updateById(driver1); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | String city = ""; |
| | | District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat()); |
| | | if(null != geocode){ |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getProvince() + "' like district")); |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district")); |
| | | city = null != weatherCity ? weatherCity.getId().toString() : ""; |
| | | } |
| | | order = getOrderPrice(1, d, 0, order, city); |