| | |
| | | package com.supersavedriving.driver.modular.system.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | import com.supersavedriving.driver.core.util.JwtTokenUtil; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.dao.DriverMapper; |
| | | import com.supersavedriving.driver.modular.system.model.AppUser; |
| | | import com.supersavedriving.driver.modular.system.model.BranchOffice; |
| | | import com.supersavedriving.driver.modular.system.model.Driver; |
| | | import com.supersavedriving.driver.modular.system.model.DriverWork; |
| | | import com.supersavedriving.driver.modular.system.model.*; |
| | | import com.supersavedriving.driver.modular.system.service.*; |
| | | import com.supersavedriving.driver.modular.system.util.RedisUtil; |
| | | import com.supersavedriving.driver.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.driver.modular.system.util.UUIDUtil; |
| | | import com.supersavedriving.driver.modular.system.util.MallBook.model.*; |
| | | import com.supersavedriving.driver.modular.system.util.MallBook.util.TrhRequest; |
| | | import com.supersavedriving.driver.modular.system.util.*; |
| | | import com.supersavedriving.driver.modular.system.util.huawei.OBSUtil; |
| | | import com.supersavedriving.driver.modular.system.util.mongodb.model.Location; |
| | | import com.supersavedriving.driver.modular.system.warpper.DriverPositionWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.DriverRegisterWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.PromotionWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.TokenWarpper; |
| | | import com.supersavedriving.driver.modular.system.util.rongyun.RongYunUtil; |
| | | import com.supersavedriving.driver.modular.system.util.weChat.WeChatUtil; |
| | | import com.supersavedriving.driver.modular.system.util.weChat.model.Code2Session; |
| | | import com.supersavedriving.driver.modular.system.warpper.*; |
| | | import org.apache.shiro.authc.SimpleAuthenticationInfo; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.authc.credential.HashedCredentialsMatcher; |
| | | import org.apache.shiro.crypto.hash.Md5Hash; |
| | | import org.apache.shiro.util.ByteSource; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.geo.Circle; |
| | |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.io.PrintWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | import static org.bouncycastle.asn1.x500.style.RFC4519Style.c; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.net.InetAddress; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 司机 |
| | |
| | | |
| | | @Autowired |
| | | private IAppUserService appUserService; |
| | | |
| | | @Autowired |
| | | private ISystemConfigService systemConfigService; |
| | | |
| | | @Autowired |
| | | private IAccountChangeDetailService accountChangeDetailService; |
| | | |
| | | @Autowired |
| | | private IYouTuiDriverService youTuiDriverService; |
| | | |
| | | @Autowired |
| | | private IOrderService orderService; |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private IRechargeRecordService rechargeRecordService; |
| | | |
| | | @Autowired |
| | | private IAgentService agentService; |
| | | |
| | | @Autowired |
| | | private RongYunUtil rongYunUtil; |
| | | |
| | | @Autowired |
| | | private PushUtil pushUtil; |
| | | |
| | | @Autowired |
| | | private WeChatUtil weChatUtil; |
| | | |
| | | @Autowired |
| | | private IDriverOnlineTimeService driverOnlineTimeService; |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath; |
| | | |
| | | @Value("${wx.appletsAppid}") |
| | | private String appletsAppid; |
| | | |
| | | @Value("${alipay.appid}") |
| | | private String appid; |
| | | |
| | | |
| | | |
| | |
| | | //新账号 |
| | | if(null == driver){ |
| | | driver = new Driver(); |
| | | driver.setCode(UUIDUtil.getNumberRandom(16)); |
| | | driver.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | try { |
| | | driver = setDriverParamete(driver, driverRegisterWarpper); |
| | | }catch (Exception e){ |
| | |
| | | } |
| | | driver.setCreateTime(new Date()); |
| | | this.insert(driver); |
| | | String s = wechatMiniProgramORCode(driver.getId()); |
| | | driver.setReferralCode(s); |
| | | this.updateById(driver); |
| | | |
| | | |
| | | //司机邀请注册奖励 |
| | | if(null != driver.getInviterId()){ |
| | | Driver driver1 = this.selectById(driver.getInviterId()); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); |
| | | if(null != systemConfig){ |
| | | Integer num7 = JSON.parseObject(systemConfig.getContent()).getInteger("num7"); |
| | | if(num7 > 0){ |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getIntegral().doubleValue()); |
| | | driver1.setIntegral(driver1.getIntegral() + num7); |
| | | accountChangeDetail.setNewData(driver1.getIntegral().doubleValue()); |
| | | accountChangeDetail.setExplain("邀请司机注册奖励"); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | this.updateById(driver1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | //生成小程序二维码 |
| | | public String wechatMiniProgramORCode(Integer driverId) throws Exception{ |
| | | InputStream release = weChatUtil.getwxacodeunlimit("pages/index/index", "driverId=" + driverId, "release"); |
| | | String s = OBSUtil.putObjectToBucket(release, "driver_" + driverId + "_" + UUIDUtil.getNumberRandom(5) + ".jpg"); |
| | | return s; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | public Driver setDriverParamete(Driver driver, DriverRegisterWarpper driverRegisterWarpper) throws Exception{ |
| | | driver.setAvatar(driverRegisterWarpper.getAvatar()); |
| | | driver.setName(driverRegisterWarpper.getName()); |
| | | driver.setPhone(driverRegisterWarpper.getPhone()); |
| | | driver.setEmergencyContact(driverRegisterWarpper.getEmergencyContact()); |
| | | driver.setEmergencyPhone(driverRegisterWarpper.getEmergencyPhone()); |
| | | driver.setIdcardBack(driverRegisterWarpper.getIdcardBack()); |
| | | driver.setIdcardFront(driverRegisterWarpper.getIdcardFront()); |
| | | driver.setDriverLicense(driverRegisterWarpper.getDriverLicense()); |
| | | if(ToolUtil.isNotEmpty(driverRegisterWarpper.getFirstCertificateTime())){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | driver.setFirstCertificateTime(sdf.parse(driverRegisterWarpper.getFirstCertificateTime())); |
| | | } |
| | | //注册地 |
| | | String code = driverRegisterWarpper.getCode(); |
| | | BranchOffice branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("districtCode", code).eq("status", 1)); |
| | | if(null == branchOffice){ |
| | | throw new Exception("该区域无服务商"); |
| | | branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("cityCode", code).eq("status", 1)); |
| | | if(null == branchOffice){ |
| | | throw new Exception("该区域无服务商"); |
| | | } |
| | | } |
| | | driver.setBranchOfficeId(branchOffice.getId()); |
| | | driver.setAgentId(branchOffice.getAgentId()); |
| | |
| | | driver.setCityCode(branchOffice.getCityCode()); |
| | | driver.setAreaCode(branchOffice.getDistrictCode()); |
| | | driver.setAreaName(branchOffice.getDistrictName()); |
| | | driver.setInviterType(driverRegisterWarpper.getInviterType()); |
| | | driver.setInviterId(driverRegisterWarpper.getInviterId()); |
| | | if(null != driverRegisterWarpper.getInviterId()){ |
| | | driver.setInviterType(driverRegisterWarpper.getInviterType()); |
| | | driver.setInviterId(driverRegisterWarpper.getInviterId()); |
| | | } |
| | | driver.setApprovalStatus(1); |
| | | driver.setApprovalNotes(""); |
| | | driver.setApprovalTime(null); |
| | | driver.setApprovalUserId(null); |
| | | driver.setStatus(1); |
| | | driver.setSource(driverRegisterWarpper.getSource()); |
| | | driver.setName(driverRegisterWarpper.getName()); |
| | | driver.setIdcard(driverRegisterWarpper.getIdcard()); |
| | | driver.setCarAge(driverRegisterWarpper.getCarAge()); |
| | | return driver; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public ResultUtil<TokenWarpper> driverLogin(String receiver, String phone, String code) throws Exception { |
| | | if(ToolUtil.isEmpty(receiver)){ |
| | | receiver = "+86"; |
| | | } |
| | | String value = redisUtil.getValue(receiver + phone); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | if(!"12345".equals(code) && ToolUtil.isEmpty(value)){ |
| | | return ResultUtil.error("短信验证码无效"); |
| | | } |
| | | if(!value.equals(code)){ |
| | | if(!"12345".equals(code) && !value.equals(code)){ |
| | | return ResultUtil.error("短信验证码无效"); |
| | | } |
| | | Driver driver = this.selectOne(new EntityWrapper<Driver>().eq("phone", phone).ne("status", 3)); |
| | |
| | | tokenWarpper.setToken(token); |
| | | tokenWarpper.setValidTime(7200L); |
| | | tokenWarpper.setIsSetPassword(ToolUtil.isEmpty(driver.getPassword()) ? 0 : 1); |
| | | |
| | | String RYToken = rongYunUtil.getToken(driver.getId().toString(), driver.getName(), driver.getAvatar()); |
| | | if(ToolUtil.isNotEmpty(RYToken)){ |
| | | JSONObject jsonObject = JSON.parseObject(RYToken); |
| | | Integer code1 = jsonObject.getInteger("code"); |
| | | if(200 == code1){ |
| | | tokenWarpper.setRytoken(jsonObject.getString("token")); |
| | | } |
| | | } |
| | | |
| | | if(ToolUtil.isEmpty(driver.getReferralCode())){ |
| | | String s = wechatMiniProgramORCode(driver.getId()); |
| | | driver.setReferralCode(s); |
| | | this.updateById(driver); |
| | | } |
| | | return ResultUtil.success(tokenWarpper); |
| | | } |
| | | |
| | |
| | | if(driver.getApprovalStatus() == 3){ |
| | | return ResultUtil.error("账号审核不通过,请重新申请。"); |
| | | } |
| | | if(ToolUtil.isEmpty(password)){ |
| | | return ResultUtil.error("密码无效"); |
| | | } |
| | | if(ToolUtil.isEmpty(driver.getPassword())){ |
| | | return ResultUtil.error("请先配置密码"); |
| | | } |
| | | if(!driver.getPassword().equals(ShiroKit.md5(password, salt))){ |
| | | return ResultUtil.error("账号密码错误。"); |
| | | } |
| | |
| | | } |
| | | TokenWarpper tokenWarpper = new TokenWarpper(); |
| | | tokenWarpper.setToken(token); |
| | | tokenWarpper.setValidTime(7200L); |
| | | tokenWarpper.setValidTime(Integer.valueOf(7 * 24 * 60 * 60).longValue()); |
| | | tokenWarpper.setIsSetPassword(ToolUtil.isEmpty(driver.getPassword()) ? 0 : 1); |
| | | String RYToken = rongYunUtil.getToken(driver.getId().toString(), driver.getName(), driver.getAvatar()); |
| | | if(ToolUtil.isNotEmpty(RYToken)){ |
| | | JSONObject jsonObject = JSON.parseObject(RYToken); |
| | | Integer code1 = jsonObject.getInteger("code"); |
| | | if(200 == code1){ |
| | | tokenWarpper.setRytoken(jsonObject.getString("token")); |
| | | } |
| | | } |
| | | return ResultUtil.success(tokenWarpper); |
| | | } |
| | | |
| | |
| | | usernamePasswordToken, simpleAuthenticationInfo); |
| | | |
| | | if (passwordTrueFlag) { |
| | | String token = JwtTokenUtil.generateToken(phone); |
| | | String token = JwtTokenUtil.generateToken(phone + System.currentTimeMillis()); |
| | | String key = token; |
| | | if(token.length() > 16){ |
| | | key = token.substring(token.length() - 16); |
| | | } |
| | | redisUtil.setStrValue(key, driver.getId().toString(), 7200);//2小时 |
| | | redisUtil.setStrValue(key, driver.getId().toString(), 94608000);//7天 |
| | | redisUtil.setStrValue("DRIVER_" + phone, key, 94608000);//7天 |
| | | |
| | | //下线 |
| | | for (int i = 0; i < 5; i++) { |
| | | Integer code = pushUtil.pushOffline(driver.getId(), 2); |
| | | if(200 == code){ |
| | | break; |
| | | } |
| | | } |
| | | return token; |
| | | } |
| | | return ""; |
| | |
| | | |
| | | /** |
| | | * 校验token获取用户信息 |
| | | * @param request |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public Integer getUserByRequset(HttpServletRequest request) throws Exception { |
| | | public Integer getUserByRequest() throws Exception { |
| | | ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
| | | HttpServletRequest request = servletRequestAttributes.getRequest(); |
| | | String requestHeader = request.getHeader(JwtConstants.AUTH_HEADER); |
| | | if (ToolUtil.isNotEmpty(requestHeader) && requestHeader.startsWith("Bearer ")) { |
| | | requestHeader = requestHeader.substring(requestHeader.indexOf(" ") + 1); |
| | |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil<List<String>> queryDriverPosition(Integer uid) throws Exception { |
| | | public ResultUtil< HashMap<String, Object> > queryDriverPosition(Integer uid) throws Exception { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", uid).eq("status", 1)); |
| | | if(null == driverWork){ |
| | | return ResultUtil.error("请先上班"); |
| | |
| | | //找到中心点 |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(lon), Double.valueOf(lat)); |
| | | //构造半径 |
| | | Distance distanceR = new Distance(5D, Metrics.KILOMETERS); |
| | | Distance distanceR = new Distance(10D, Metrics.KILOMETERS); |
| | | //画圆 |
| | | Circle circle = new Circle(geoJsonPoint, distanceR); |
| | | // 构造query对象 |
| | | Query query = Query.query(Criteria.where("location").withinSphere(circle)); |
| | | List<Location> locations = mongoTemplate.find(query, Location.class); |
| | | locations.forEach(s -> { |
| | | list.add(s.getLocation().getX() + "," + s.getLocation().getY()); |
| | | int i=0; |
| | | Driver driver = this.baseMapper.selectById(s.getDriverId()); |
| | | if(null == driver){ |
| | | return; |
| | | } |
| | | i = driver.getServerStatus(); |
| | | if(driver.getServerStatus()==2){ |
| | | List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("driverId", s.getDriverId()).eq("state", 102)); |
| | | if(orders.size()>0){ |
| | | i = 3; |
| | | } |
| | | } |
| | | String value1 = redisUtil.getValue("DRIVER" + s.getDriverId()); |
| | | if(s.getDriverId().compareTo(uid) != 0 && ToolUtil.isNotEmpty(value1)){ |
| | | list.add(s.getLocation().getX() + "," + s.getLocation().getY()+","+i+","+driver.getName()); |
| | | } |
| | | }); |
| | | } |
| | | return ResultUtil.success(list); |
| | | |
| | | List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("hallOrder",1).eq("state",101)); |
| | | |
| | | map.put("driver",list); |
| | | ArrayList<String> blue = new ArrayList<>(); |
| | | orders.forEach(e-> blue.add(e.getStartLng()+","+e.getStartLat())); |
| | | |
| | | map.put("orderList",blue); |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(System.currentTimeMillis()); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -2); |
| | | Date time = calendar.getTime(); |
| | | List<Order> ordersOne = orderService.selectList(new EntityWrapper<Order>().eq("state",301).between("createTime",time,new Date())); |
| | | |
| | | ArrayList<String> red = new ArrayList<>(); |
| | | ordersOne.forEach(e-> red.add(e.getStartLng()+","+e.getStartLat())); |
| | | |
| | | map.put("cancelOrder",red); |
| | | return ResultUtil.success(map); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 添加司机定位 |
| | | * @param driverPositionWarpper |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void addDriverPosition(DriverPositionWarpper driverPositionWarpper) throws Exception { |
| | | //实时位置存入redis中 |
| | |
| | | .set("lastUpdated", System.currentTimeMillis()); |
| | | this.mongoTemplate.updateFirst(query, update, Location.class); |
| | | } |
| | | addDurationCredits(driverId); |
| | | |
| | | //存储订单轨迹 |
| | | if(null != orderId){ |
| | |
| | | @Override |
| | | public PromotionWarpper queryPromotionQRCode(Integer uid) throws Exception { |
| | | PromotionWarpper promotionWarpper = new PromotionWarpper(); |
| | | promotionWarpper.setUrl("http://127.0.0.1?uid=" + 2 + "utype=" + 2); |
| | | Driver driver1 = this.selectById(uid); |
| | | if(ToolUtil.isEmpty(driver1.getReferralCode())){ |
| | | String s = wechatMiniProgramORCode(driver1.getId()); |
| | | driver1.setReferralCode(s); |
| | | this.updateById(driver1); |
| | | } |
| | | // promotionWarpper.setUrl("https://chaoshengdaijia.com/share/driverShare/index.html?inviterId=" + uid); |
| | | promotionWarpper.setUrl(driver1.getReferralCode()); |
| | | int user = appUserService.selectCount(new EntityWrapper<AppUser>().eq("inviterType", 2).eq("inviterId", uid).eq("status", 1)); |
| | | int driver = this.selectCount(new EntityWrapper<Driver>().eq("inviterType", 2).eq("inviterId", uid).eq("approvalStatus", 2).eq("status", 1)); |
| | | promotionWarpper.setTotal(user + driver); |
| | | promotionWarpper.setUser(user); |
| | | promotionWarpper.setDriver(driver); |
| | | Driver driver1 = this.selectById(uid); |
| | | promotionWarpper.setAvatar(driver1.getAvatar()); |
| | | promotionWarpper.setName(driver1.getName()); |
| | | return promotionWarpper; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加司机时长积分 |
| | | */ |
| | | public void addDurationCredits(Integer driverId) throws Exception { |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); |
| | | if(null == systemConfig){ |
| | | return; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | String num1 = jsonObject.getString("num1");//12:00 |
| | | String num2 = jsonObject.getString("num2");//12:00 |
| | | Integer num3 = jsonObject.getInteger("num3");//每小时增加积分 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | long start = sdf.parse(sdf1.format(new Date()) + " " + num1 + ":00").getTime(); |
| | | Date e = sdf.parse(sdf1.format(new Date()) + " " + num2 + ":00"); |
| | | long end = e.getTime(); |
| | | if(start > end){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(e); |
| | | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); |
| | | end = calendar.getTimeInMillis(); |
| | | } |
| | | |
| | | long l = System.currentTimeMillis(); |
| | | if(start <= l && end > l){ |
| | | Driver driver = this.selectById(driverId); |
| | | String value = redisUtil.getValue("ONLINE" + driverId); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | redisUtil.setStrValue("ONLINE" + driverId, "0_" + sdf1.format(new Date()) + "_0", 25 * 60 * 60); |
| | | return; |
| | | } |
| | | String today = sdf1.format(new Date()); |
| | | String[] s = value.split("_"); |
| | | |
| | | //修改在线时长记录 |
| | | DriverOnlineTime driverOnlineTime = driverOnlineTimeService.selectOne(new EntityWrapper<DriverOnlineTime>().eq("driverId", driverId).last(" and DATE_FORMAT(`day`, '%Y-%m-%d') = DATE_FORMAT(now(), '%Y-%m-%d')")); |
| | | if(null != driverOnlineTime){ |
| | | driverOnlineTime.setOnlineTime(driverOnlineTime.getOnlineTime().add(new BigInteger("5"))); |
| | | driverOnlineTime.setOnlineTime(new BigInteger(s[0])); |
| | | driverOnlineTimeService.updateById(driverOnlineTime); |
| | | }else{ |
| | | driverOnlineTime = new DriverOnlineTime(); |
| | | driverOnlineTime.setDriverId(driverId); |
| | | driverOnlineTime.setDay(new Date()); |
| | | driverOnlineTime.setOnlineTime(new BigInteger("0")); |
| | | driverOnlineTimeService.insert(driverOnlineTime); |
| | | redisUtil.setStrValue("ONLINE" + driverId, "0_" + sdf1.format(new Date()) + "_0", 25 * 60 * 60); |
| | | return; |
| | | } |
| | | driver.setOnlineTime(driver.getOnlineTime().add(new BigInteger("5"))); |
| | | this.updateById(driver); |
| | | |
| | | Integer second = Integer.valueOf(s[0]) + 5; |
| | | Integer time = Integer.valueOf(s[2]); |
| | | |
| | | int h = Double.valueOf(second / 3600).intValue(); |
| | | if(h > 0 && h > time){ |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driverId); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); |
| | | driver.setIntegral(driver.getIntegral() + num3); |
| | | accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); |
| | | accountChangeDetail.setExplain("在线时长奖励"); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | driver.setOnlineTime(new BigInteger(s[0])); |
| | | this.updateById(driver); |
| | | time++; |
| | | } |
| | | redisUtil.setStrValue("ONLINE" + driverId, second + "_" + s[1] + "_" + time); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取司机个人信息 |
| | | * @param uid |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public DriverInfoWarpper queryDriverInfo(Integer uid) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | DriverInfoWarpper driverInfo = new DriverInfoWarpper(); |
| | | BeanUtils.copyProperties(driver, driverInfo); |
| | | driverInfo.setWithdrawBalance(driver.getBalance()); |
| | | driverInfo.setBalance(new BigDecimal(driver.getBalance()).add(new BigDecimal(driver.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue());//司机充值+平台充值 |
| | | driverInfo.setCommission(new BigDecimal(driver.getCommission()).add(new BigDecimal(driver.getCouponBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue());//司机订单收入+司机佣金收入+司机优惠券收入+司机折扣收入 |
| | | YouTuiDriver youTuiDriver = youTuiDriverService.selectOne(new EntityWrapper<YouTuiDriver>().eq("driverId", uid) |
| | | .eq("state", 2).last(" and failureTime > now() order by failureTime limit 0, 1")); |
| | | if(null != youTuiDriver){ |
| | | driverInfo.setYouTuiEnd(youTuiDriver.getType() == 1 ? youTuiDriver.getFailureTime().getTime() : youTuiDriver.getEndTime().getTime()); |
| | | } |
| | | List<Integer> state = Arrays.asList(107, 108, 109); |
| | | int count = orderService.selectCount(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1).in("state", state).last(" and DATE_FORMAT(createTime, '%Y-%m-%d') = DATE_FORMAT(now(), '%Y-%m-%d')")); |
| | | driverInfo.setTodayNum(count); |
| | | count = orderService.selectCount(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1).in("state", state).last(" and DATE_FORMAT(createTime, '%Y-%m') = DATE_FORMAT(now(), '%Y-%m')")); |
| | | driverInfo.setMonthNum(count); |
| | | DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", uid).eq("status", 1)); |
| | | driverInfo.setWork(null == driverWork ? 0 : 1); |
| | | driverInfo.setOnline(0); |
| | | String value = redisUtil.getValue("ONLINE" + uid); |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | Integer second = Integer.valueOf(value.split("_")[0]); |
| | | driverInfo.setOnline(second); |
| | | } |
| | | driverInfo.setWechatAuthorization(driver.getOpenid() == null ? 0 : 1); |
| | | Agent agent = agentService.selectById(driver.getAgentId()); |
| | | driverInfo.setServiceCalls(agent.getServiceCalls()); |
| | | return driverInfo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改司机个人信息 |
| | | * @param uid |
| | | * @param driverInfo |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil saveDriverInfo(Integer uid, DriverInfo driverInfo) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | if(ToolUtil.isNotEmpty(driverInfo.getAvatar())){ |
| | | driver.setAvatar(driverInfo.getAvatar()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driverInfo.getEmergencyContact())){ |
| | | driver.setEmergencyContact(driverInfo.getEmergencyContact()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driverInfo.getEmergencyPhone())){ |
| | | driver.setEmergencyPhone(driverInfo.getEmergencyPhone()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driverInfo.getWxCollectionCode())){ |
| | | driver.setWxCollectionCode(driverInfo.getWxCollectionCode()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driverInfo.getZfbCollectionCode())){ |
| | | driver.setZfbCollectionCode(driverInfo.getZfbCollectionCode()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driverInfo.getPhone()) && ToolUtil.isNotEmpty(driverInfo.getCode())){ |
| | | String value = redisUtil.getValue(driverInfo.getPhone()); |
| | | if(!"12345".equals(driverInfo.getCode())){ |
| | | if(ToolUtil.isEmpty(value)){ |
| | | return ResultUtil.error("验证码已过期"); |
| | | } |
| | | if(!value.equals(driverInfo.getCode())){ |
| | | return ResultUtil.error("验证码无效"); |
| | | } |
| | | } |
| | | driver.setPhone(driverInfo.getPhone()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driverInfo.getOpenid())){ |
| | | driver.setOpenid(driverInfo.getOpenid()); |
| | | } |
| | | this.updateById(driver); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | /** |
| | | * 清空司机积分 |
| | | */ |
| | | @Override |
| | | public void emptyIntegral() { |
| | | List<Driver> drivers = this.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("status", 1)); |
| | | List<AccountChangeDetail> list = new ArrayList<>(); |
| | | for (Driver driver : drivers) { |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver.getId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setExplain("定时清空积分"); |
| | | driver.setIntegral(0); |
| | | accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); |
| | | list.add(accountChangeDetail); |
| | | } |
| | | if(drivers.size() > 0){ |
| | | this.updateBatchById(drivers); |
| | | accountChangeDetailService.insertBatch(list); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil balanceRecharge(Integer uid, Double amount) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | //调起微信 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | RechargeRecord rechargeRecord = new RechargeRecord(); |
| | | rechargeRecord.setType(2); |
| | | rechargeRecord.setUserId(uid); |
| | | rechargeRecord.setCode(out_trade_no); |
| | | rechargeRecord.setAmount(amount); |
| | | rechargeRecord.setPayType(1); |
| | | rechargeRecord.setPayStatus(1); |
| | | rechargeRecord.setCreateTime(new Date()); |
| | | rechargeRecord.setAgentId(driver.getAgentId()); |
| | | rechargeRecordService.insert(rechargeRecord); |
| | | |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(new BigDecimal(amount).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | paymentOrder.setOrderName("账户充值"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |
| | | paymentOrder.setAsynSplitFlag("1"); |
| | | paymentOrder.setAppid(appletsAppid); |
| | | paymentOrder.setOpenid(driver.getOpenid()); |
| | | paymentOrder.setTerminalIp(InetAddress.getLocalHost().getHostAddress()); |
| | | List<PaymentOrderGood> goodsDetail = new ArrayList<>(); |
| | | PaymentOrderGood paymentOrderGood = new PaymentOrderGood(); |
| | | paymentOrderGood.setGoodsName("充值"); |
| | | goodsDetail.add(paymentOrderGood); |
| | | paymentOrder.setGoodsDetail(goodsDetail); |
| | | paymentOrder.setFrontUrl(callbackPath + "/base/driver/balanceRechargeCallback");//前端回调地址 |
| | | paymentOrder.setNotifyUrl(callbackPath + "/base/driver/balanceRechargeCallback"); |
| | | paymentOrder.setParameter1(out_trade_no); |
| | | |
| | | TrhRequest<PaymentOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(paymentOrder, PaymentOrder.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getCode())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | String merOrderId = jsonObject.getString("merOrderId"); |
| | | String payCode = jsonObject.getString("payCode"); |
| | | if(ToolUtil.isNotEmpty(payCode)){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10){ |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | RechargeRecord rechargeRecord1 = rechargeRecordService.selectOne(new EntityWrapper<RechargeRecord>().eq("code", out_trade_no)); |
| | | if(rechargeRecord1.getPayStatus() != 1){ |
| | | return; |
| | | } |
| | | QueryOrder queryOrder = new QueryOrder(); |
| | | queryOrder.setOriginalMerOrderId(merOrderId); |
| | | queryOrder.setQueryType("1"); |
| | | TrhRequest<QueryOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute1 = request.execute(queryOrder, QueryOrder.SERVICE_CODE); |
| | | if("0000".equals(execute1.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute1.getResult()); |
| | | String status1 = jsonObject1.getString("status"); |
| | | if("0".equals(status1)){//待处理 |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | if("1".equals(status1)){//成功 |
| | | String merOrderId = jsonObject1.getString("merOrderId"); |
| | | Driver driver1 = DriverServiceImpl.this.selectById(rechargeRecord1.getUserId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setChangeType(3); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setExplain("账户充值"); |
| | | accountChangeDetail.setOldData(new BigDecimal(driver1.getBalance()).add(new BigDecimal(driver1.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | driver1.setBalance(new BigDecimal(driver1.getBalance()).add(new BigDecimal(rechargeRecord1.getAmount())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | accountChangeDetail.setNewData(new BigDecimal(driver1.getBalance()).add(new BigDecimal(driver1.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | DriverServiceImpl.this.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | |
| | | rechargeRecord1.setPayTime(new Date()); |
| | | rechargeRecord1.setPayStatus(2); |
| | | rechargeRecord1.setOrderNumber(merOrderId); |
| | | rechargeRecord1.setSurplusDividedAmount(rechargeRecord1.getAmount()); |
| | | rechargeRecordService.updateById(rechargeRecord1); |
| | | break; |
| | | } |
| | | if("2".equals(status1) || 10 == num){//失败 |
| | | rechargeRecordService.deleteById(rechargeRecord1.getId()); |
| | | break; |
| | | } |
| | | }else{ |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | return ResultUtil.success(payCode); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 司机端跳小程序支付 |
| | | * @param driverId |
| | | * @param jscode |
| | | * @param amount |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil balanceRecharge1(Integer driverId, String jscode, Double amount) throws Exception { |
| | | Code2Session code2Session = weChatUtil.code2Session(jscode); |
| | | if(null != code2Session.getErrcode() && code2Session.getErrcode() != 0){ |
| | | return ResultUtil.error(code2Session.getErrmsg()); |
| | | } |
| | | String openid = code2Session.getOpenid(); |
| | | Driver driver = this.selectById(driverId); |
| | | driver.setOpenid(openid); |
| | | this.updateById(driver); |
| | | return balanceRecharge(driverId, amount); |
| | | } |
| | | |
| | | /** |
| | | * 充值回调通知逻辑处理 |
| | | * @param out_trade_no |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void balanceRechargeCallback(String out_trade_no, String transaction_id) throws Exception { |
| | | RechargeRecord rechargeRecord1 = rechargeRecordService.selectOne(new EntityWrapper<RechargeRecord>().eq("code", out_trade_no)); |
| | | if(rechargeRecord1.getPayStatus() != 1){ |
| | | return; |
| | | } |
| | | Driver driver1 = this.selectById(rechargeRecord1.getUserId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(rechargeRecord1.getUserId()); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setChangeType(3); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setExplain("账户充值"); |
| | | accountChangeDetail.setOldData(new BigDecimal(driver1.getBalance()).add(new BigDecimal(driver1.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | driver1.setBalance(new BigDecimal(driver1.getBalance()).add(new BigDecimal(rechargeRecord1.getAmount())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | accountChangeDetail.setNewData(new BigDecimal(driver1.getBalance()).add(new BigDecimal(driver1.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | this.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | |
| | | rechargeRecord1.setPayTime(new Date()); |
| | | rechargeRecord1.setPayStatus(2); |
| | | rechargeRecord1.setOrderNumber(transaction_id); |
| | | rechargeRecord1.setSurplusDividedAmount(rechargeRecord1.getAmount()); |
| | | rechargeRecordService.updateById(rechargeRecord1); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改密码 |
| | | * @param uid |
| | | * @param oldPass |
| | | * @param newPass |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil updatePassword(Integer uid, String oldPass, String newPass) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | if(!ShiroKit.md5(oldPass, salt).equals(driver.getPassword())){ |
| | | return ResultUtil.error("原密码错误"); |
| | | } |
| | | newPass = ShiroKit.md5(newPass, salt); |
| | | driver.setPassword(newPass); |
| | | this.updateById(driver); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | /** |
| | | * 设置密码 |
| | | * @param uid |
| | | * @param password |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil recoverPassword(Integer uid, String password) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | password = ShiroKit.md5(password, salt); |
| | | driver.setPassword(password); |
| | | this.updateById(driver); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 打开下单二维码 |
| | | * @param uid |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil openOrderQRCode(Integer uid) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | driver.setOpenOrderQRCode(1); |
| | | this.updateById(driver); |
| | | new Timer().schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | Driver driver = DriverServiceImpl.this.selectById(uid); |
| | | driver.setOpenOrderQRCode(0); |
| | | DriverServiceImpl.this.updateById(driver); |
| | | } |
| | | }, 120000); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 关闭下单二维码 |
| | | * @param uid |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil closeOrderQRCode(Integer uid) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | driver.setOpenOrderQRCode(0); |
| | | this.updateById(driver); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 开通小微商户 |
| | | * @param name |
| | | * @param number |
| | | * @param phone |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil microenterprise(Integer uid, String name, String number, String phone, String notifyUrl) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | Register registerVO = new Register(); |
| | | registerVO.setMerUserId(driver.getCode());//"driver_" + uid |
| | | registerVO.setPhone(phone); |
| | | registerVO.setUserType("0"); |
| | | registerVO.setUserName(name); |
| | | registerVO.setCertId(number); |
| | | registerVO.setNotifyUrl(callbackPath + notifyUrl); |
| | | registerVO.setParameter1(uid.toString()); |
| | | TrhRequest<Register> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(registerVO, Register.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getCode())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | driver.setMerchantIDCode(number); |
| | | driver.setMerchantName(name); |
| | | driver.setMerchantPhone(phone); |
| | | this.updateById(driver); |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | String userId = jsonObject.getString("userId"); |
| | | driver.setMerchantNumber(userId); |
| | | driver.setMerchantIDCode(number); |
| | | driver.setMerchantName(name); |
| | | driver.setMerchantPhone(phone); |
| | | this.updateById(driver); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | @Override |
| | | public ResultUtil<HashMap<String, Object>> queryDriverOrderNum(String time,Integer uid) { |
| | | String sTime = null; |
| | | String eTime =null; |
| | | EntityWrapper<Order> wrapper = new EntityWrapper<>(); |
| | | EntityWrapper<AppUser> wrapperOne = new EntityWrapper<>(); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | sTime = time.split(" - ")[0]+" 00:00:00"; |
| | | eTime = time.split(" - ")[1]+" 23:59:59"; |
| | | wrapper.between("orderTakingTime",sTime,eTime); |
| | | wrapperOne.between("createTime",sTime,eTime); |
| | | } |
| | | ArrayList<Integer> objects = new ArrayList<>(); |
| | | objects.add(101); |
| | | objects.add(201); |
| | | objects.add(301); |
| | | objects.add(401); |
| | | wrapper.eq("driverId",uid); |
| | | wrapper.notIn("state",objects); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | int orderNum = orderService.selectCount(wrapper); |
| | | map.put("orderNum",orderNum); |
| | | // 有效时长 |
| | | Integer okTime = this.baseMapper.getTime(sTime,eTime,uid); |
| | | map.put("okTime",okTime==null?0:okTime); |
| | | wrapperOne.eq("inviterType",2); |
| | | wrapperOne.eq("inviterId",uid); |
| | | int userNum = appUserService.selectCount(wrapperOne); |
| | | |
| | | |
| | | map.put("userNum",userNum); |
| | | |
| | | |
| | | return ResultUtil.success(map); |
| | | } |
| | | } |