user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java
@@ -112,7 +112,7 @@ @ResponseBody @PostMapping("/base/appUser/queryNearbyDrivers") // @ServiceLog(name = "获取附近的司机", url = "/base/appUser/queryNearbyDrivers") @ServiceLog(name = "获取附近的司机", url = "/base/appUser/queryNearbyDrivers") @ApiOperation(value = "获取附近的司机", tags = {"用户端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "string"), @@ -553,7 +553,7 @@ phone = phone.indexOf("+86") < 0 ? "+86" + phone : phone; String value = redisUtil.getValue(phone); if(ToolUtil.isEmpty(value) || !value.equals(code)){ resultUtil = ResultUtil.error("验证码无效"); return ResponseWarpper.success(ResultUtil.error("验证码无效")); } redisUtil.remove(phone); return ResponseWarpper.success(resultUtil); user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/BroadcastController.java
@@ -39,7 +39,9 @@ }) public ResponseWarpper<List<String>> queryBroadcast(){ try { List<Broadcast> broadcasts = broadcastService.selectList(new EntityWrapper<Broadcast>().eq("status", 1).orderBy("sort desc limit 0, 5")); List<Broadcast> broadcasts = broadcastService.selectList(new EntityWrapper<Broadcast>() .eq("`status`", 1).eq("`show`", 1) .eq("`upDown`", 1).orderBy("`sort` desc limit 0, 5")); List<String> list = new ArrayList<>(); for (Broadcast broadcast : broadcasts) { list.add(broadcast.getContent()); user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java
@@ -241,8 +241,8 @@ @ResponseBody @PostMapping("/api/order/queryOrderPrice") // @ServiceLog(name = "获取待支付页面订单费用明细", url = "/api/order/queryOrderPrice") @ApiOperation(value = "获取待支付页面订单费用明细", tags = {"用户端-首页"}, notes = "") // @ServiceLog(name = "获取订单费用明细", url = "/api/order/queryOrderPrice") @ApiOperation(value = "获取订单费用明细", tags = {"用户端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"), @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") @@ -611,4 +611,8 @@ return new ResponseWarpper(500, e.getMessage()); } } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/CommercialMapper.xml
@@ -30,7 +30,7 @@ jumpType, jumpUrl, html from t_commercial where status = 1 from t_commercial where status = 1 and onOffLine = 1 <if test="null != type"> and `type` = #{type} </if> user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/OrderMapper.xml
@@ -80,7 +80,7 @@ b.`name` as driverName, b.phone as driverPhone, b.`code` as driverCode, (DATE_FORMAT(now(), '%Y') - DATE_FORMAT(b.firstCertificateTime, '%Y')) as driverAge, ifnull(DATE_FORMAT(now(), '%Y') - DATE_FORMAT(b.firstCertificateTime, '%Y'), 0) as driverAge, (select count(1) from t_order where driverId = b.id and `status` = 1 and state in (107, 108, 109)) as driverNumber, b.score as driverScore, a.state, user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/IOrderService.java
@@ -149,4 +149,6 @@ * @throws Exception */ List<OrderListWarpper> queryNotInvoiceOrder(Integer uid, NotInvoiceOrder notInvoiceOrder) throws Exception; } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/IUserToCouponService.java
@@ -52,4 +52,10 @@ * @return */ Integer queryUsedCouponNum(Integer uid); /** * 删除优惠券数据 */ void delUserCoupon(); } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java
@@ -128,6 +128,7 @@ key = token.substring(token.length() - 16); } redisUtil.setStrValue(key, appUser.getId().toString(), 7 * 24 * 60 * 60); redisUtil.setStrValue("USER_" + appUser.getPhone(), key, 7 * 24 * 60 * 60); return token; } return null; @@ -204,7 +205,8 @@ * @param userId */ public List<CouponWarpper> pushCoupon(Integer userId){ List<Coupon> coupons = couponService.selectList(new EntityWrapper<Coupon>().eq("coupon_type", 2).eq("coupon_state", 1).gt("remaining_quantity", 0)); List<Coupon> coupons = couponService.selectList(new EntityWrapper<Coupon>().eq("coupon_type", 2) .eq("coupon_state", 1).eq("status", 1).gt("remaining_quantity", 0)); List<CouponWarpper> list = new ArrayList<>(); for (Coupon coupon : coupons) { UserToCoupon userToCoupon = new UserToCoupon(); user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/ComplaintServiceImpl.java
@@ -43,6 +43,6 @@ complaint.setState(1); complaint.setStatus(1); complaint.setCreateTime(new Date()); this.updateById(complaint); this.insert(complaint); } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java
@@ -1,5 +1,6 @@ package com.supersavedriving.user.modular.system.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.supersavedriving.user.core.util.ToolUtil; @@ -64,6 +65,7 @@ // 构造query对象 Query query = Query.query(Criteria.where("location").withinSphere(circle)); List<Location> locations = mongoTemplate.find(query, Location.class); // System.err.println("附近空闲司机" + JSON.toJSONString(locations)); List<Integer> collect = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); List<DriverWork> driverWorks = driverWorkService.selectList(new EntityWrapper<DriverWork>().in("driverId", collect).eq("status", 1)); for (DriverWork driverWork : driverWorks) { user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -431,6 +431,9 @@ return ResultUtil.error("司机还未上班"); } Driver driver = driverService.selectById(travelOrder.getDriverId()); if(driver.getServerStatus() == 2){ return ResultUtil.error("司机正在服务中"); } order.setAgentId(driver.getAgentId()); order.setBranchOfficeId(driver.getBranchOfficeId()); order.setOrderTakingTime(new Date()); @@ -439,6 +442,7 @@ driverService.updateById(driver); appUser.setCancelCount(0); appUser.setIsException(1); appUserService.updateById(appUser); } @@ -631,6 +635,9 @@ this.updateById(order); AppUser appUser = appUserService.selectById(uid); appUser.setCancelCount(appUser.getCancelCount() + 1); if(appUser.getCancelCount() >= 3){ appUser.setIsException(2); } appUserService.updateById(appUser); Driver driver = driverService.selectById(order.getDriverId()); if(null != driver){ @@ -710,6 +717,14 @@ Order orderPrice = getOrderPrice(1, d, 0, order1, city); order.setEstimatedPrice(orderPrice.getEstimatedPrice()); this.updateById(order); PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); pushOrderInfoWarpper.setId(order.getId()); pushOrderInfoWarpper.setState(order.getState()); pushOrderInfoWarpper.setEndAddress(order.getEndAddress()); pushOrderInfoWarpper.setEndLat(order.getEndLat()); pushOrderInfoWarpper.setEndLng(order.getEndLng()); pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); return ResultUtil.success(); } @@ -725,20 +740,24 @@ Order order = this.selectById(orderId); OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper(); BeanUtils.copyProperties(order, orderPriceWarpper); AppUser appUser = appUserService.selectById(uid); orderPriceWarpper.setBalance(appUser.getAccountBalance()); Double orderMoney = order.getOrderMoney(); //先算优惠券 Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); if(null != coupon){ orderMoney = orderMoney - coupon.getCouponPreferentialAmount(); orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); orderPriceWarpper.setCouponId(coupon.getId()); orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue()); if(null == order.getPayTime()){ AppUser appUser = appUserService.selectById(uid); orderPriceWarpper.setBalance(appUser.getAccountBalance()); Double orderMoney = order.getOrderMoney(); //先算优惠券 Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); if(null != coupon){ orderMoney = orderMoney - coupon.getCouponPreferentialAmount(); orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); orderPriceWarpper.setCouponId(coupon.getId()); } orderPriceWarpper.setDiscount(0D); orderPriceWarpper.setDiscountAmount(0D); orderPriceWarpper.setPayType(1);//微信支付 orderPriceWarpper.setPayMoney(orderMoney); } orderPriceWarpper.setDiscount(0D); orderPriceWarpper.setDiscountAmount(0D); orderPriceWarpper.setPayType(1);//微信支付 orderPriceWarpper.setPayMoney(orderMoney); return orderPriceWarpper; } @@ -758,6 +777,8 @@ OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper(); BeanUtils.copyProperties(order, orderPriceWarpper); AppUser appUser = appUserService.selectById(uid); orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue()); orderPriceWarpper.setBalance(appUser.getAccountBalance()); orderPriceWarpper.setDiscount(0D); orderPriceWarpper.setDiscountAmount(0D); @@ -766,7 +787,6 @@ //先算优惠券 Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); if(null != coupon && null == couponId){ orderMoney = orderMoney - coupon.getCouponPreferentialAmount(); orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); orderPriceWarpper.setCouponId(coupon.getId()); } @@ -777,10 +797,10 @@ orderPriceWarpper.setDiscountedPrice(coupon1.getCouponPreferentialAmount()); orderPriceWarpper.setCouponId(couponId); } if(payType == 1 && appUser.getHavDiscount() == 1){//使用余额抵扣 if(payType == 1 && appUser.getHavDiscount() == 1 && balance >= orderMoney){//使用余额抵扣 orderPriceWarpper.setDiscount(9D); orderPriceWarpper.setDiscountAmount(orderMoney * 0.1); orderMoney = orderMoney * 0.9; orderPriceWarpper.setDiscountAmount(new BigDecimal(orderMoney * 0.1).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); orderMoney = new BigDecimal(orderMoney * 0.9).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); } if(payType == 0){//不使用余额抵扣 orderPriceWarpper.setPayType(1); @@ -859,10 +879,12 @@ UserToCoupon userToCoupon = userToCouponService.selectById(couponId); if(userToCoupon.getValidCount() > 0){ userToCoupon.setValidCount(userToCoupon.getValidCount() - 1); userToCouponService.updateById(userToCoupon); Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); payMoney = payMoney - coupon.getCouponPreferentialAmount(); order.setCouponId(coupon.getId()); order.setDiscountedPrice(coupon.getCouponPreferentialAmount()); userToCouponService.updateById(userToCoupon); } } order.setPayType(1); @@ -924,10 +946,27 @@ UserToCoupon userToCoupon = userToCouponService.selectById(couponId); if(userToCoupon.getValidCount() > 0){ userToCoupon.setValidCount(userToCoupon.getValidCount() - 1); userToCouponService.updateById(userToCoupon); Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); payMoney = payMoney - coupon.getCouponPreferentialAmount(); order.setCouponId(coupon.getId()); order.setDiscountedPrice(coupon.getCouponPreferentialAmount()); Driver driver = driverService.selectById(order.getDriverId()); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(order.getDriverId()); accountChangeDetail.setCreateTime(new Date()); accountChangeDetail.setOldData(driver.getCouponBalance()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(7); accountChangeDetail.setOrderId(order.getId()); accountChangeDetail.setExplain("优惠券收入"); driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount()); accountChangeDetail.setNewData(driver.getCouponBalance()); driverService.updateById(driver); accountChangeDetailService.insert(accountChangeDetail); } } @@ -987,6 +1026,7 @@ UserToCoupon userToCoupon = userToCouponService.selectById(couponId); if(userToCoupon.getValidCount() > 0){ userToCoupon.setValidCount(userToCoupon.getValidCount() - 1); userToCouponService.updateById(userToCoupon); Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); payMoney = payMoney - coupon.getCouponPreferentialAmount(); order.setCouponId(coupon.getId()); @@ -1054,6 +1094,7 @@ this.updateById(order); return ResultUtil.success(payCode); // TODO: 2023/5/18 取消支付后需要处理优惠券数据回退 // // // new Thread(new Runnable() { @@ -1237,6 +1278,25 @@ List<PlatformRechargeRecord> platformRechargeRecords = platformRechargeRecordService.selectList(new EntityWrapper<PlatformRechargeRecord>().eq("state", 2).last(" and balance > 0 order by payTime")); Double discountedPrice = order.getDiscountedPrice(); Driver driver = driverService.selectById(order.getDriverId()); UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId()); Coupon coupon = couponService.selectById(userToCoupon.getCouponId()); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(order.getDriverId()); accountChangeDetail.setCreateTime(new Date()); accountChangeDetail.setOldData(driver.getCouponBalance()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(7); accountChangeDetail.setOrderId(order.getId()); accountChangeDetail.setExplain("优惠券收入"); driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount()); accountChangeDetail.setNewData(driver.getCouponBalance()); driverService.updateById(driver); accountChangeDetailService.insert(accountChangeDetail); for (PlatformRechargeRecord platformRechargeRecord : platformRechargeRecords) { if(discountedPrice == 0){ break; @@ -1661,4 +1721,6 @@ notInvoiceOrder.setPageNum((notInvoiceOrder.getPageNum() - 1) * notInvoiceOrder.getPageSize());; return this.baseMapper.queryNotInvoiceOrder(uid, notInvoiceOrder); } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/UserToCouponServiceImpl.java
@@ -1,5 +1,6 @@ package com.supersavedriving.user.modular.system.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.supersavedriving.user.modular.system.dao.UserToCouponMapper; import com.supersavedriving.user.modular.system.model.Coupon; @@ -62,4 +63,17 @@ public Integer queryUsedCouponNum(Integer uid) { return this.baseMapper.queryUsedCouponNum(uid); } /** * 删除优惠券 */ @Override public void delUserCoupon() { List<UserToCoupon> userToCoupons = this.selectList(new EntityWrapper<UserToCoupon>().eq("status", 1).last(" and UNIX_TIMESTAMP(expireTime) + 1296000 <= UNIX_TIMESTAMP(now())")); for (UserToCoupon userToCoupon : userToCoupons) { userToCoupon.setStatus(3); this.updateById(userToCoupon); } } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/TaskUtil.java
New file @@ -0,0 +1,71 @@ package com.supersavedriving.user.modular.system.util; import com.supersavedriving.user.modular.system.service.IUserToCouponService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; /** * 定时任务工具类 */ @Component public class TaskUtil { @Autowired private IUserToCouponService userToCouponService; /** * 每隔一分钟去处理的定时任务 */ @Scheduled(fixedRate = 1000 * 60) public void taskMinute(){ try { } catch (Exception e) { e.printStackTrace(); } } /** * 每天的凌晨执行的任务 */ @Scheduled(cron = "0 0 0 * * *") public void taskDay(){ try { userToCouponService.delUserCoupon(); }catch (Exception e){ e.printStackTrace(); } } /** * 每月1日凌晨执行的任务 */ @Scheduled(cron = "0 0 0 1 * *") public void taskMonth1(){ try { }catch (Exception e){ e.printStackTrace(); } } /** * 每月16日凌晨执行的任务 */ @Scheduled(cron = "0 0 0 16 * *") public void taskMonth16(){ try { }catch (Exception e){ e.printStackTrace(); } } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/warpper/PushOrderInfoWarpper.java
@@ -19,6 +19,12 @@ private Double actualMileage; @ApiModelProperty("行驶时间(分钟)") private Integer travelTime; @ApiModelProperty("终点地址") private String endAddress; @ApiModelProperty("终点纬度") private String endLat; @ApiModelProperty("终点经度") private String endLng; @ApiModelProperty("101=待接单,102=已接单,103=前往预约点,104=到达预约点,105=开始服务,106=到达目的地,107=待支付,108=待评价,109=已完成,201=转单中,301=已取消,401=等待中") private Integer state; } user/guns-admin/src/main/resources/redis.properties
@@ -1,14 +1,15 @@ #redisÅäÖÿªÊ¼ # RedisÊý¾Ý¿âË÷Òý£¨Ä¬ÈÏΪ0£© spring.redis.database=0 ## Redis·þÎñÆ÷µØÖ· #spring.redis.host=127.0.0.1 ### Redis·þÎñÆ÷Á¬½Ó¶Ë¿Ú #spring.redis.port=16379 ### Redis·þÎñÆ÷Á¬½ÓÃÜÂ루ĬÈÏΪ¿Õ£© #spring.redis.password=cKsEeyffDXG5PzNg8CIbrWxFluXrCprZ ## Redis·þÎñÆ÷µØÖ· #spring.redis.host=127.0.0.1 ## Redis·þÎñÆ÷Á¬½Ó¶Ë¿Ú #spring.redis.port=16379 ## Redis·þÎñÆ÷Á¬½ÓÃÜÂ루ĬÈÏΪ¿Õ£© #spring.redis.password=cKsEeyffDXG5PzNg8CIbrWxFluXrCprZ # Redis·þÎñÆ÷µØÖ· spring.redis.host=127.0.0.1 # Redis·þÎñÆ÷Á¬½Ó¶Ë¿Ú spring.redis.port=6379