From 03552ae04973a224b5ccfce34e64999ea6a13d44 Mon Sep 17 00:00:00 2001 From: liujie <liujie> Date: 星期四, 10 八月 2023 09:31:53 +0800 Subject: [PATCH] 超省2.0 --- driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java | 437 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 419 insertions(+), 18 deletions(-) diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java index f601368..957c73a 100644 --- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java +++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java @@ -12,10 +12,12 @@ import com.supersavedriving.driver.modular.system.model.*; import com.supersavedriving.driver.modular.system.service.*; import com.supersavedriving.driver.modular.system.dao.DriverMapper; -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.*; +import com.supersavedriving.driver.modular.system.util.MallBook.model.InterfaceResponse; +import com.supersavedriving.driver.modular.system.util.MallBook.model.Register; +import com.supersavedriving.driver.modular.system.util.MallBook.util.TrhRequest; import com.supersavedriving.driver.modular.system.util.mongodb.model.Location; +import com.supersavedriving.driver.modular.system.util.rongyun.RongYunUtil; import com.supersavedriving.driver.modular.system.warpper.*; import org.apache.shiro.authc.SimpleAuthenticationInfo; import org.apache.shiro.authc.UsernamePasswordToken; @@ -84,6 +86,21 @@ @Autowired private IOrderService orderService; + @Autowired + private PayMoneyUtil payMoneyUtil; + + @Autowired + private IRechargeRecordService rechargeRecordService; + + @Autowired + private IAgentService agentService; + + @Autowired + private RongYunUtil rongYunUtil; + + @Autowired + private PushUtil pushUtil; + /** @@ -148,7 +165,10 @@ 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()); @@ -165,6 +185,10 @@ 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; } @@ -207,6 +231,16 @@ 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")); + } + } + return ResultUtil.success(tokenWarpper); } @@ -251,6 +285,14 @@ tokenWarpper.setToken(token); 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); } @@ -280,12 +322,21 @@ 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(), 7 * 24 * 60 * 60);//7天 + redisUtil.setStrValue("DRIVER_" + phone, key, 7 * 24 * 60 * 60);//7天 + + //下线 + for (int i = 0; i < 5; i++) { + Integer code = pushUtil.pushOffline(driver.getId(), 2); + if(200 == code){ + break; + } + } return token; } return ""; @@ -354,7 +405,8 @@ @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("请先上班"); @@ -375,13 +427,36 @@ Query query = Query.query(Criteria.where("location").withinSphere(circle)); List<Location> locations = mongoTemplate.find(query, Location.class); locations.forEach(s -> { + int i=0; + Driver driver = this.baseMapper.selectById(s.getDriverId()); + 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()); + list.add(s.getLocation().getX() + "," + s.getLocation().getY()+","+i); } }); } - 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); + List<Order> ordersOne = orderService.selectList(new EntityWrapper<Order>().eq("state",301)); + + ArrayList<String> red = new ArrayList<>(); + ordersOne.forEach(e-> red.add(e.getStartLng()+","+e.getStartLat())); + + map.put("cancelOrder",red); + return ResultUtil.success(map); } @@ -434,7 +509,7 @@ @Override public PromotionWarpper queryPromotionQRCode(Integer uid) throws Exception { PromotionWarpper promotionWarpper = new PromotionWarpper(); - promotionWarpper.setUrl("http://127.0.0.1?uid=" + 2 + "utype=" + 2); + promotionWarpper.setUrl("http://121.37.15.157/share/driverShare/index.html?inviterId=" + uid); 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); @@ -483,6 +558,7 @@ if(h > 0 && h > time){ Driver driver = this.selectById(driverId); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); + accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(driverId); accountChangeDetail.setType(2); @@ -510,14 +586,17 @@ Driver driver = this.selectById(uid); DriverInfoWarpper driverInfo = new DriverInfoWarpper(); BeanUtils.copyProperties(driver, driverInfo); - YouTuiDriver youTuiDriver = youTuiDriverService.selectOne(new EntityWrapper<YouTuiDriver>().eq("driverId", uid).last(" and failureTime > now() order by failureTime limit 0, 1")); + driverInfo.setWithdrawBalance(driver.getBalance()); + driverInfo.setBalance(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); + 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.setYouTuiStart(youTuiDriver.getCreateTime().getTime()); + 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('%Y-%m-%d', createTime) = DATE_FORMAT('%Y-%m-%d', now())")); + 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('%Y-%m', createTime) = DATE_FORMAT('%Y-%m', now())")); + 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); @@ -527,6 +606,9 @@ 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; } @@ -550,17 +632,336 @@ 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(ToolUtil.isEmpty(value)){ - return ResultUtil.error("验证码已过期"); - } - if(!value.equals(driverInfo.getPhone())){ - return ResultUtil.error("验证码无效"); + 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(3)); + 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(3); + 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); + + + ResultUtil weixinpay = payMoneyUtil.weixinpay("余额充值", "", out_trade_no, amount.toString(), "/base/driver/balanceRechargeCallback", "APP"); + 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; + } + + /** + * SUCCESS--支付成功 + * REFUND--转入退款 + * NOTPAY--未支付 + * CLOSED--已关闭 + * REVOKED--已撤销(刷卡支付) + * USERPAYING--用户支付中 + * PAYERROR--支付失败(其他原因,如银行返回失败) + * ACCEPT--已接收,等待扣款 + */ + ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, ""); + if(resultUtil.getCode() == 200){ + Map<String, String> map = resultUtil.getData(); + String trade_type = map.get("trade_type"); + String trade_state = map.get("trade_state"); + String transaction_id = map.get("transaction_id"); + if("REFUND".equals(trade_state) || "NOTPAY".equals(trade_state) || "CLOSED".equals(trade_state) || "REVOKED".equals(trade_state) || "PAYERROR".equals(trade_state)){ + rechargeRecordService.deleteById(rechargeRecord1.getId()); + return; + } + if("SUCCESS".equals(trade_state)){ + Driver driver1 = DriverServiceImpl.this.selectById(uid); + AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); + accountChangeDetail.setUserType(2); + accountChangeDetail.setUserId(uid); + accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); + accountChangeDetail.setChangeType(3); + accountChangeDetail.setType(1); + accountChangeDetail.setCreateTime(new Date()); + accountChangeDetail.setExplain("余额充值"); + accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); + driver1.setBalance(driver1.getBalance() + amount); + accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); + DriverServiceImpl.this.updateById(driver1); + accountChangeDetailService.saveData(accountChangeDetail); + + rechargeRecord1.setPayTime(new Date()); + rechargeRecord1.setPayStatus(2); + rechargeRecord1.setOrderNumber(transaction_id); + rechargeRecordService.updateById(rechargeRecord1); + return; + } + if("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)){ + Thread.sleep(wait); + num++; + } + }else{ + Thread.sleep(wait); + num++; + } + if(10 == num){ + rechargeRecordService.deleteById(rechargeRecord1.getId()); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + }).start(); + return weixinpay; + } + + + /** + * 充值回调通知逻辑处理 + * @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(3)); + accountChangeDetail.setChangeType(3); + accountChangeDetail.setType(1); + accountChangeDetail.setCreateTime(new Date()); + accountChangeDetail.setExplain("余额充值"); + accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); + driver1.setBalance(driver1.getBalance() + rechargeRecord1.getAmount()); + accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission()); + this.updateById(driver1); + accountChangeDetailService.saveData(accountChangeDetail); + + rechargeRecord1.setPayTime(new Date()); + rechargeRecord1.setPayStatus(2); + rechargeRecord1.setOrderNumber(transaction_id); + 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) throws Exception { + Driver driver = this.selectById(uid); + Register registerVO = new Register(); + registerVO.setMerUserId("driver_" + uid); + registerVO.setPhone(phone); + registerVO.setUserType("0"); + registerVO.setUserName(name); + registerVO.setCertId(number); + registerVO.setNotifyUrl(""); + TrhRequest<Register> request = new TrhRequest(); + InterfaceResponse execute = request.execute(registerVO, Register.SERVICE_CODE); + if(!"0000".equals(execute.getResult())){ + 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)){ + 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); + // 有效时长 + int okTime = this.baseMapper.getTime(sTime,eTime,uid); + map.put("okTime",okTime); + wrapperOne.eq("inviterType",2); + wrapperOne.eq("inviterId",uid); + int userNum = appUserService.selectCount(wrapperOne); + + + map.put("userNum",userNum); + + + return ResultUtil.success(map); + } } -- Gitblit v1.7.1