| | |
| | | import com.agentdriving.driver.modular.system.warpper.AddOrderWarpper; |
| | | import com.agentdriving.driver.modular.system.warpper.HallOrderList; |
| | | import com.agentdriving.driver.modular.system.warpper.OrderInfoWarpper; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.Circle; |
| | |
| | | */ |
| | | @Service |
| | | public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService { |
| | | |
| | | Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class); |
| | | |
| | | @Autowired |
| | | private IDriverWorkService driverWorkService; |
| | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushOrder(finalOrder); |
| | | pushOrder(finalOrder.getId()); |
| | | } |
| | | }).start(); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 订单推送逻辑 |
| | | * @param order |
| | | */ |
| | | public void pushOrder(Order order){ |
| | | public void pushOrder(Long orderId){ |
| | | try { |
| | | Order order = this.selectById(orderId); |
| | | /** |
| | | * 1.先找最大推单范围内的优推司机 -》 距离最近 |
| | | * 没有1 - 》 |
| | |
| | | * 合适司:积分 > 评分 > 距离 |
| | | * 3.司机没有接单直接将订单置入大厅 |
| | | */ |
| | | try { |
| | | boolean lock = redisUtil.lock(5); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | |
| | | } |
| | | } |
| | | if(!lock){ |
| | | redisUtil.unlock(); |
| | | order.setHallOrder(1); |
| | | this.updateById(order); |
| | | ExtraPushOrder(order); |
| | | return; |
| | | redisUtil.unlock(); |
| | | } |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1)); |
| | | if(null == systemConfig){ |
| | |
| | | YouTuiDriver youTuiDriver1 = null; |
| | | if(driverIds.size() > 0){ |
| | | List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds) |
| | | .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime")); |
| | | .eq("state", 2).last(" and surplusQuantity > 0 and now() < endTime and now() < failureTime")); |
| | | Double d = null; |
| | | for (YouTuiDriver youTuiDriver : youTuiDrivers) { |
| | | String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId()); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | continue; |
| | | } |
| | | DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", youTuiDriver.getDriverId()).eq("status", 1)); |
| | | Driver driver1 = driverService.selectById(youTuiDriver.getDriverId()); |
| | | if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){ |
| | | continue; |
| | | } |
| | | DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId()).eq("status", 1)); |
| | | if(null == driverWork){ |
| | | continue; |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){ |
| | | youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1); |
| | | youTuiDriverService.updateById(youTuiDriver1); |
| | |
| | | |
| | | driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); |
| | | if(driverIds.size() > 0){ |
| | | List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("serverStatus", 1).eq("status", 1).in("id", driverIds)); |
| | | List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2) |
| | | .eq("serverStatus", 1).eq("openOrderQRCode", 0).eq("status", 1).in("id", driverIds)); |
| | | if(drivers.size() == 0){ |
| | | continue; |
| | | } |
| | | |
| | | Integer integral = null; |
| | | Double score = null; |
| | | Integer integral = null;//积分 |
| | | Double score = null;//评分 |
| | | Double d = null; |
| | | for (Driver driver1 : drivers) { |
| | | String value = redisUtil.getValue("DRIVER" + driver1.getId()); |
| | |
| | | if(null == driverWork){ |
| | | continue; |
| | | } |
| | | |
| | | if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大 |
| | | integral = driver1.getIntegral(); |
| | | score = driver1.getScore(); |
| | | driver = driver1.getId(); |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | d = wgs84; |
| | | continue; |
| | | } |
| | | if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分 |
| | | integral = driver1.getIntegral(); |
| | | score = driver1.getScore(); |
| | | driver = driver1.getId(); |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | d = wgs84; |
| | | continue; |
| | | } |
| | | if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离 |
| | | |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | if(d == null || d.compareTo(wgs84) > 0){ |
| | | if(d.compareTo(wgs84) > 0){ |
| | | d = wgs84; |
| | | integral = driver1.getIntegral(); |
| | | score = driver1.getScore(); |
| | | driver = driver1.getId(); |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | if(null != driver){ |
| | | //防止多笔订单推给一个司机 |
| | | Driver driver1 = driverService.selectById(driver); |
| | | driver1.setServerStatus(2); |
| | | driverService.updateById(driver1); |
| | | |
| | | pushUtil.pushGrabOrder(driver, 2, order.getId(), num4); |
| | | //创建定时任务处理订单到大厅 |
| | | new Timer().schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | Order order1 = OrderServiceImpl.this.selectById(order.getId()); |
| | | if(order1.getState() != 101 && order1.getState() != 201 && order1.getState() != 301 && order1.getDriverId().compareTo(driver1.getId()) != 0){ |
| | | driver1.setServerStatus(1); |
| | | driverService.updateById(driver1); |
| | | Order order1 = OrderServiceImpl.this.selectById(order.getId()); |
| | | if(order1.getState() == 101 || order1.getState() == 201){ |
| | | } |
| | | |
| | | if(order1.getState() == 201 || order1.getState() == 301 || (order1.getState() == 101 && null == order1.getDriverId())){ |
| | | driver1.setServerStatus(1); |
| | | driverService.updateById(driver1); |
| | | } |
| | | if(order1.getState() == 201 || (order1.getState() == 101 && null == order1.getDriverId())){ |
| | | order1.setHallOrder(1); |
| | | OrderServiceImpl.this.updateById(order1); |
| | | |
| | | ExtraPushOrder(order1); |
| | | ExtraPushOrder(order); |
| | | } |
| | | |
| | | |
| | | } |
| | | }, num4 * 1000); |
| | | }else{ |
| | |
| | | } |
| | | redisUtil.unlock(); |
| | | }catch (Exception e){ |
| | | redisUtil.unlock(); |
| | | e.printStackTrace(); |
| | | redisUtil.unlock(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushOrder(finalOrder); |
| | | pushOrder(finalOrder.getId()); |
| | | } |
| | | }).start(); |
| | | return ResultUtil.success(); |
| | |
| | | */ |
| | | @Override |
| | | public ResultUtil setOrderStatus(Integer uid, Long orderId, Integer payType, Integer state) throws Exception { |
| | | if(108 == state){ |
| | | String value = redisUtil.getValue("repeat_" + orderId.toString()); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | redisUtil.setStrValue("repeat_" + orderId, System.currentTimeMillis() + "", 10 * 60); |
| | | }else{ |
| | | Long s = System.currentTimeMillis() - Long.valueOf(value); |
| | | if(s < 60000){//1分钟 |
| | | return ResultUtil.error("数据处理中"); |
| | | } |
| | | } |
| | | } |
| | | List<Integer> s = Arrays.asList(107, 108); |
| | | if(!s.contains(state)){ |
| | | return ResultUtil.error("操作失败"); |
| | |
| | | if(null != order.getUserId()){ |
| | | pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState()); |
| | | } |
| | | if(108 == state){ |
| | | redisUtil.remove("repeat_" + orderId.toString()); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | AppUser appUser = appUserService.selectById(order.getUserId()); |
| | | |
| | | if(null != order.getUserId()){ |
| | | //司机推荐首单收入 |
| | | List<Integer> state = Arrays.asList(108, 109); |
| | | List<Integer> state = Arrays.asList(107, 108, 109); |
| | | int count = this.selectCount(new EntityWrapper<Order>().eq("userId", order.getUserId()).eq("status", 1).in("state", state)); |
| | | if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && count == 1){ |
| | | Driver driver1 = driverService.selectById(appUser.getInviterId()); |
| | |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | driverService.updateById(driver1); |
| | | } |
| | | } |
| | | |
| | | |
| | | Double payMoney = order.getPayMoney(); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3)); |
| | | Double n = 0D; |
| | | if(null != systemConfig){ |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | Double num3 = jsonObject.getDouble("num3"); |
| | | n = num3; |
| | | if(order.getPayMoney() >= num2){ |
| | | payMoney = payMoney - num3;//司机收入 |
| | | if(order.getOrderMoney() >= num2){//订单金额大于num2才有抽佣金 |
| | | driver = driverService.selectById(order.getDriverId()); |
| | | AccountChangeDetail accountChangeDetail1 = new AccountChangeDetail(); |
| | | accountChangeDetail1.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail1.setUserType(2); |
| | | accountChangeDetail1.setUserId(driver.getId()); |
| | | accountChangeDetail1.setType(1); |
| | | accountChangeDetail1.setChangeType(9); |
| | | accountChangeDetail1.setOrderId(order.getId()); |
| | | accountChangeDetail1.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail1.setExplain("订单信息费"); |
| | | accountChangeDetail1.setCreateTime(new Date()); |
| | | driver.setBalance(driver.getBalance() - num3); |
| | | accountChangeDetail1.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | driverService.updateById(driver); |
| | | accountChangeDetailService.saveData(accountChangeDetail1); |
| | | |
| | | |
| | | //有分佣的情况,分佣的金额从司机充值金额中扣除转给分佣对象 |
| | | SystemConfig systemConfig1 = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 2)); |
| | | if(null != systemConfig1){ |
| | | JSONObject jsonObject1 = JSON.parseObject(systemConfig1.getContent()); |
| | | //开始处理层级抽佣 |
| | | if(null != driver.getInviterType() && driver.getInviterType() == 2){ |
| | | Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机 |
| | | if(null != driver1 && null != driver1.getInviterType() && driver1.getInviterType() == 2){ |
| | | Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机 |
| | | if(null != driver2 && null != driver2.getInviterType() && driver2.getInviterType() == 2){ |
| | | Driver driver3 = driverService.selectById(driver2.getInviterId());//三级级司机 |
| | | Double num4 = jsonObject1.getDouble("num4"); |
| | | Double num5 = jsonObject1.getDouble("num5"); |
| | | Double num6 = jsonObject1.getDouble("num6"); |
| | | num4 = (num3 >= num4 ? num4 : num3); |
| | | if(num4 > 0){ |
| | | //司机推荐用户收入 |
| | | if(null != appUser && null != appUser.getInviterType() && appUser.getInviterType() == 2){ |
| | | Double num1 = jsonObject1.getDouble("num1"); |
| | | num1 = (num3 >= num1 ? num1 : num3); |
| | | |
| | | if(num1 > 0){ |
| | | Driver driver1 = driverService.selectById(appUser.getInviterId()); |
| | | //首单积分奖励 |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | accountChangeDetail.setExplain("邀请用户奖励"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num1); |
| | | accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | driverService.updateById(driver1); |
| | | |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num4); |
| | | revenue.setAmount(num1); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | } |
| | | num3 = (num3 >= num1 ? num3 - num1 : 0); |
| | | } |
| | | |
| | | //开始处理层级抽佣 |
| | | if(num3 > 0 && null != driver.getInviterType() && driver.getInviterType() == 2){ |
| | | Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机 |
| | | if(null != driver1 && null != driver1.getInviterType() && driver1.getInviterType() == 2){ |
| | | Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机 |
| | | if(null != driver2 && null != driver2.getInviterType() && driver2.getInviterType() == 2){ |
| | | Driver driver3 = driverService.selectById(driver2.getInviterId());//三级级司机 |
| | | Double num5 = jsonObject1.getDouble("num5"); |
| | | Double num6 = jsonObject1.getDouble("num6"); |
| | | Double num7 = jsonObject1.getDouble("num7"); |
| | | num5 = (num3 >= num5 ? num5 : num3); |
| | | if(num5 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num5); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | |
| | | accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num4); |
| | | driver1.setCommission(driver1.getCommission() + num5); |
| | | accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | driverService.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num4 ? num3 - num4 : 0); |
| | | num3 = (num3 >= num5 ? num3 - num5 : 0); |
| | | } |
| | | num5 = (num3 >= num5 ? num5 : num3); |
| | | if(num5 > 0){ |
| | | num6 = (num3 >= num6 ? num6 : num3); |
| | | if(num6 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver2.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num5); |
| | | revenue.setAmount(num6); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | |
| | | accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver2.setCommission(driver2.getCommission() + num5); |
| | | driver2.setCommission(driver2.getCommission() + num6); |
| | | accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission()); |
| | | driverService.updateById(driver2); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num5 ? num3 - num5 : 0); |
| | | |
| | | num3 = (num3 >= num6 ? num3 - num6 : 0); |
| | | } |
| | | num6 = (num3 >= num6 ? num6 : num3); |
| | | if(num6 > 0){ |
| | | num7 = (num3 >= num7 ? num7 : num3); |
| | | if(num7 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver3.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num6); |
| | | revenue.setAmount(num7); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | |
| | | accountChangeDetail.setOldData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver3.setCommission(driver3.getCommission() + num6); |
| | | driver3.setCommission(driver3.getCommission() + num7); |
| | | accountChangeDetail.setNewData(driver3.getBalance() + driver3.getBackgroundBalance() + driver3.getCouponBalance() + driver3.getCommission()); |
| | | driverService.updateById(driver3); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num6 ? num3 - num6 : 0); |
| | | |
| | | num3 = (num3 >= num7 ? num3 - num7 : 0); |
| | | } |
| | | }else{ |
| | | Double num3_ = jsonObject1.getDouble("num3"); |
| | | Double num4 = jsonObject1.getDouble("num4"); |
| | | num3_ = (num3 >= num3_ ? num3_ : num3); |
| | | if(num3_ > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num3_); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num3_); |
| | | accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | driverService.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | |
| | | num3 = (num3 >= num3_ ? num3 - num3_ : 0); |
| | | } |
| | | num4 = (num3 >= num4 ? num4 : num3); |
| | | if(num4 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver2.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num4); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver2.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver2.setCommission(driver2.getCommission() + num4); |
| | | accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission()); |
| | | driverService.updateById(driver2); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num4 ? num3 - num4 : 0); |
| | | } |
| | | } |
| | | }else{ |
| | | Double num2_ = jsonObject1.getDouble("num2"); |
| | | Double num3_ = jsonObject1.getDouble("num3"); |
| | | num2_ = (num3 >= num2_ ? num2_ : num3); |
| | | if(num2_ > 0){ |
| | | Revenue revenue = new Revenue(); |
| | |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num2_ ? num3 - num2_ : 0); |
| | | } |
| | | num3_ = (num3 >= num3_ ? num3_ : num3); |
| | | if(num3_ > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver2.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num3_); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver2.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver2.setCommission(driver2.getCommission() + num3_); |
| | | accountChangeDetail.setNewData(driver2.getBalance() + driver2.getBackgroundBalance() + driver2.getCouponBalance() + driver2.getCommission()); |
| | | driverService.updateById(driver2); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num3_ ? num3 - num3_ : 0); |
| | | } |
| | | } |
| | | }else{ |
| | | Double num1_ = jsonObject1.getDouble("num1"); |
| | | num1_ = (num3 >= num1_ ? num1_ : num3); |
| | | if(num1_ > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num1_); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num1_); |
| | | accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); |
| | | driverService.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num1_ ? num3 - num1_ : 0); |
| | | } |
| | | } |
| | | } |
| | | //处理代理商抽佣 |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //司机余额扣减抽佣金额 |
| | | if(n > 0){ |
| | | driver = driverService.selectById(order.getDriverId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(9); |
| | | accountChangeDetail.setOrderId(order.getId()); |
| | | accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail.setExplain("线下收款服务费支出"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver.setBalance(driver.getBalance() - n); |
| | | accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | driverService.updateById(driver); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | } |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void completeCollection() { |
| | | List<Order> orders = this.selectList(new EntityWrapper<Order>().eq("state", 107).eq("status", 1) |
| | | .eq("payType", 3).last(" and UNIX_TIMESTAMP(getoffTime) + 120 <= UNIX_TIMESTAMP(now())")); |
| | | .eq("payType", 3).last(" and UNIX_TIMESTAMP(getoffTime) + 600 <= UNIX_TIMESTAMP(now())")); |
| | | for (Order order : orders) { |
| | | order.setState(108); |
| | | order.setPayTime(new Date()); |
| | | if(null != order.getCouponId()){ |
| | | UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId()); |
| | | if(userToCoupon.getValidCount() > 0){ |
| | | userToCoupon.setValidCount(userToCoupon.getValidCount() - 1); |
| | | userToCouponService.updateById(userToCoupon); |
| | | Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); |
| | | |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order.getDriverId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail.setOldData(driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(7); |
| | | accountChangeDetail.setOrderId(order.getId()); |
| | | accountChangeDetail.setExplain("优惠券收入"); |
| | | driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount()); |
| | | accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); |
| | | driver.setCommission(driver.getCommission() + coupon.getCouponPreferentialAmount()); |
| | | accountChangeDetail.setNewData(driver.getCouponBalance() + driver.getCommission()); |
| | | driverService.updateById(driver); |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | } |
| | | } |
| | | |
| | | this.updateById(order); |
| | | |
| | | try { |