user/guns-admin/pom.xml
@@ -163,11 +163,11 @@ <artifactId>alipay-sdk-java</artifactId> <version>4.8.10.ALL</version> </dependency> <!-- oos对象存储 --> <!-- obs对象存储 --> <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> <version>3.8.0</version> <groupId>com.huaweicloud</groupId> <artifactId>esdk-obs-java-bundle</artifactId> <version>[3.21.11,)</version> </dependency> <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core --> <dependency> user/guns-admin/src/main/java/com/supersavedriving/user/core/intercept/RestApiInteceptor.java
@@ -5,6 +5,8 @@ import com.supersavedriving.user.core.common.exception.BizExceptionEnum; import com.supersavedriving.user.core.util.JwtTokenUtil; import com.supersavedriving.user.core.util.RenderUtil; import com.supersavedriving.user.modular.system.util.ResultUtil; import com.supersavedriving.user.modular.system.warpper.ResponseWarpper; import io.jsonwebtoken.JwtException; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; @@ -48,12 +50,14 @@ } } catch (JwtException e) { //有异常就是token解析失败 RenderUtil.renderJson(response, new ErrorTip(BizExceptionEnum.TOKEN_ERROR.getCode(), BizExceptionEnum.TOKEN_ERROR.getMessage())); // RenderUtil.renderJson(response, new ErrorTip(BizExceptionEnum.TOKEN_ERROR.getCode(), BizExceptionEnum.TOKEN_ERROR.getMessage())); RenderUtil.renderJson(response, ResponseWarpper.success(ResultUtil.tokenErr())); return false; } } else { //header没有带Bearer字段 RenderUtil.renderJson(response, new ErrorTip(BizExceptionEnum.TOKEN_ERROR.getCode(), BizExceptionEnum.TOKEN_ERROR.getMessage())); // RenderUtil.renderJson(response, new ErrorTip(BizExceptionEnum.TOKEN_ERROR.getCode(), BizExceptionEnum.TOKEN_ERROR.getMessage())); RenderUtil.renderJson(response, ResponseWarpper.success(ResultUtil.tokenErr())); return false; } return true; user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java
@@ -6,6 +6,8 @@ import com.supersavedriving.user.modular.system.service.IAppUserService; import com.supersavedriving.user.modular.system.service.IDriverService; import com.supersavedriving.user.modular.system.util.ResultUtil; import com.supersavedriving.user.modular.system.util.UUIDUtil; import com.supersavedriving.user.modular.system.util.huawei.OBSUtil; import com.supersavedriving.user.modular.system.warpper.*; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -16,8 +18,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import java.io.InputStream; import java.util.List; /** @@ -157,4 +161,26 @@ return new ResponseWarpper(500, e.getMessage()); } } @ResponseBody @PostMapping("/api/appUser/uploadImg") // @ServiceLog(name = "上传头像图片", url = "/api/appUser/uploadImg") @ApiOperation(value = "上传头像图片", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "图片文件", name = "file", required = true, dataType = "file"), @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResponseWarpper<String> uploadImg(MultipartFile file){ try { InputStream inputStream = file.getInputStream(); String name = file.getName(); name = UUIDUtil.getRandomCode() + name.substring(name.lastIndexOf(".")); String s = OBSUtil.putObjectToBucket(inputStream, name); return ResponseWarpper.success(s); }catch (Exception e){ e.printStackTrace(); return new ResponseWarpper(500, e.getMessage()); } } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java
@@ -204,14 +204,43 @@ @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(value = "是否余额抵扣(0=否,1=是)", name = "payType", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResponseWarpper<OrderPriceWarpper> queryOrderPrice(Long orderId, Integer payType){ public ResponseWarpper<OrderPriceWarpper> queryOrderPrice(Long orderId){ if(null == orderId){ return ResponseWarpper.success(ResultUtil.paranErr("orderId")); } try { Integer uid = appUserService.getUserByRequest(); if(null == uid){ return ResponseWarpper.success(ResultUtil.tokenErr()); } OrderPriceWarpper orderPriceWarpper = orderService.queryOrderPrice(uid, orderId); return ResponseWarpper.success(orderPriceWarpper); }catch (Exception e){ e.printStackTrace(); return new ResponseWarpper(500, e.getMessage()); } } @ResponseBody @PostMapping("/api/order/calculationOfExpenses") // @ServiceLog(name = "重新计算待支付页面订单费用明细", url = "/api/order/calculationOfExpenses") @ApiOperation(value = "重新计算待支付页面订单费用明细", tags = {"用户端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"), @ApiImplicitParam(value = "优惠券id", name = "couponId", required = true, dataType = "int"), @ApiImplicitParam(value = "是否使用余额抵扣(0=否,1=是)", name = "payType", required = true, dataType = "int"), @ApiImplicitParam(value = "抵扣金额", name = "balance", required = true, dataType = "double"), @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResponseWarpper<OrderPriceWarpper> calculationOfExpenses(Long orderId, Integer couponId, Integer payType, Double balance){ if(null == orderId){ return ResponseWarpper.success(ResultUtil.paranErr("orderId")); } @@ -223,7 +252,7 @@ if(null == uid){ return ResponseWarpper.success(ResultUtil.tokenErr()); } OrderPriceWarpper orderPriceWarpper = orderService.queryOrderPrice(uid, orderId, payType); OrderPriceWarpper orderPriceWarpper = orderService.calculationOfExpenses(uid, orderId, couponId, payType, balance); return ResponseWarpper.success(orderPriceWarpper); }catch (Exception e){ e.printStackTrace(); user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/RevenueMapper.java
New file @@ -0,0 +1,11 @@ package com.supersavedriving.user.modular.system.dao; import com.baomidou.mybatisplus.mapper.BaseMapper; import com.supersavedriving.user.modular.system.model.Revenue; /** * @author zhibing.pu * @date 2023/3/13 10:03 */ public interface RevenueMapper extends BaseMapper<Revenue> { } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/AccountChangeDetailMapper.xml
@@ -8,6 +8,7 @@ <result column="userType" property="userType"/> <result column="userId" property="userId"/> <result column="type" property="type"/> <result column="changeType" property="changeType"/> <result column="oldData" property="oldData"/> <result column="newData" property="newData"/> <result column="explain" property="explain"/> user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/DriverMapper.xml
@@ -26,6 +26,7 @@ <result column="branchOfficeId" property="branchOfficeId"/> <result column="balance" property="balance"/> <result column="backgroundBalance" property="backgroundBalance"/> <result column="couponBalance" property="couponBalance"/> <result column="approvalStatus" property="approvalStatus"/> <result column="approvalNotes" property="approvalNotes"/> <result column="approvalUserId" property="approvalUserId"/> user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/RevenueMapper.xml
New file @@ -0,0 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.supersavedriving.user.modular.system.dao.RevenueMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.supersavedriving.user.modular.system.model.Revenue"> <id column="id" property="id"/> <result column="type" property="type"/> <result column="userType" property="userType"/> <result column="userId" property="userId"/> <result column="orderId" property="orderId"/> <result column="amount" property="amount"/> <result column="createTime" property="createTime"/> </resultMap> </mapper> user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/UserToCouponMapper.xml
@@ -18,6 +18,7 @@ <select id="queryCoupon" resultType="com.supersavedriving.user.modular.system.model.Coupon"> select b.id, a.* from t_coupon a left join t_user_to_coupon b on (a.id = b.couponId) user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/YouTuiDriverMapper.xml
@@ -8,6 +8,10 @@ <result column="driverId" property="driverId" /> <result column="youTuiId" property="youTuiId" /> <result column="integral" property="integral" /> <result column="type" property="type"/> <result column="surplusQuantity" property="surplusQuantity"/> <result column="endTime" property="endTime"/> <result column="state" property="state"/> <result column="failureTime" property="failureTime" /> <result column="createTime" property="createTime" /> </resultMap> user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/model/AccountChangeDetail.java
@@ -38,6 +38,11 @@ @TableField("type") private Integer type; /** * 变动类型(1=订单收入,2=订单支出,3=充值,4=提现,5=佣金收入,6=佣金提现,7=优惠券收入,8=保险支付) */ @TableField("changeType") private Integer changeType; /** * 历史数据 */ @TableField("oldData") user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/model/Driver.java
@@ -128,6 +128,11 @@ @TableField("backgroundBalance") private Double backgroundBalance; /** * 优惠券余额(订单优惠券支付的金额) */ @TableField("couponBalance") private Double couponBalance; /** * 审核状态(1=待审核,2=已同意,3=已拒绝) */ @TableField("approvalStatus") user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/model/Revenue.java
New file @@ -0,0 +1,54 @@ package com.supersavedriving.user.modular.system.model; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; import lombok.Data; import java.util.Date; /** * @author zhibing.pu * @date 2023/3/13 9:58 */ @Data @TableName("t_revenue") public class Revenue { /** * 主键 */ @TableId(value = "id", type = IdType.AUTO) @TableField("id") private Integer id; /** * 收入类型(1=订单收入,2=分佣收入) */ @TableField("type") private Integer type; /** * 用户类型(1=用户,2=司机,3=代理商) */ @TableField("userType") private Integer userType; /** * 用户id */ @TableField("userId") private Integer userId; /** * 订单id */ @TableField("orderId") private Long orderId; /** * 收入金额 */ @TableField("amount") private Double amount; /** * 添加时间 */ @TableField("createTime") private Date createTime; } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/model/YouTuiDriver.java
@@ -38,6 +38,26 @@ @TableField("integral") private Integer integral; /** * 优推类型(1=次数,2=小时) */ @TableField("type") private Integer type; /** * 优推剩余数量 */ @TableField("surplusQuantity") private Integer surplusQuantity; /** * 优推结束时间 */ @TableField("endTime") private Integer endTime; /** * 状态(1=未使用,2=使用中,3=已结束) */ @TableField("state") private Integer state; /** * 失效时间 */ @TableField("failureTime") user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/IOrderService.java
@@ -74,7 +74,21 @@ * @return * @throws Exception */ OrderPriceWarpper queryOrderPrice(Integer uid, Long orderId, Integer payType) throws Exception; OrderPriceWarpper queryOrderPrice(Integer uid, Long orderId) throws Exception; /** * 重新计算费用明细 * @param orderId * @param couponId * @param payType * @param balance * @return * @throws Exception */ OrderPriceWarpper calculationOfExpenses(Integer uid, Long orderId, Integer couponId, Integer payType, Double balance) throws Exception; /** * 获取支付页面的可用优惠券列表 user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/IRevenueService.java
New file @@ -0,0 +1,11 @@ package com.supersavedriving.user.modular.system.service; import com.baomidou.mybatisplus.service.IService; import com.supersavedriving.user.modular.system.model.Revenue; /** * @author zhibing.pu * @date 2023/3/13 10:09 */ public interface IRevenueService extends IService<Revenue> { } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -87,6 +87,9 @@ @Autowired private IEvaluateService evaluateService; @Autowired private IRevenueService revenueService; @@ -454,8 +457,10 @@ List<Location> locations = mongoTemplate.find(query, Location.class); List<Integer> driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); Integer driver = null; YouTuiDriver youTuiDriver1 = null; if(driverIds.size() > 0){ List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds).last(" and now() < failureTime")); List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds) .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime")); Double d = null; for (YouTuiDriver youTuiDriver : youTuiDrivers) { String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId()); @@ -467,10 +472,14 @@ if(d == null || d.compareTo(wgs84) > 0){ d = wgs84; driver = youTuiDriver.getDriverId(); youTuiDriver1 = youTuiDriver; } } } if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){ youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1); youTuiDriverService.updateById(youTuiDriver1); } //开始范围查找 if(null == driver){ @@ -633,7 +642,7 @@ * @throws Exception */ @Override public OrderPriceWarpper queryOrderPrice(Integer uid, Long orderId, Integer payType) throws Exception { public OrderPriceWarpper queryOrderPrice(Integer uid, Long orderId) throws Exception { Order order = this.selectById(orderId); OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper(); BeanUtils.copyProperties(order, orderPriceWarpper); @@ -644,29 +653,68 @@ Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); if(null != coupon){ orderMoney = orderMoney - coupon.getCouponPreferentialAmount(); orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); orderPriceWarpper.setCouponId(coupon.getId()); } //再算折扣(余额完全可以抵扣费用才能有折扣) if(payType == 1 && appUser.getAccountBalance() > orderMoney){//使用余额抵扣 orderPriceWarpper.setDiscount(appUser.getHavDiscount() == 0 ? 0 : 9D); orderPriceWarpper.setDiscountAmount(orderMoney * 0.1); orderPriceWarpper.setPayType(2);//余额支付 orderMoney = orderMoney - orderPriceWarpper.getDiscountAmount(); } if(payType == 0){//不使用余额抵扣 orderPriceWarpper.setDiscount(0D); orderPriceWarpper.setDiscountAmount(0D); orderPriceWarpper.setPayType(1);//微信支付 } if(payType == 1 && appUser.getAccountBalance() > 0 && appUser.getAccountBalance() < orderMoney){//使用余额抵扣部分 orderPriceWarpper.setDiscount(0D); orderPriceWarpper.setDiscountAmount(0D); orderPriceWarpper.setPayType(4);//微信+余额 orderMoney = orderMoney - appUser.getAccountBalance(); } orderPriceWarpper.setPayMoney(orderMoney); return orderPriceWarpper; } /** * 重新计算费用明细 * @param orderId * @param couponId * @param payType * @param balance * @return * @throws Exception */ @Override public OrderPriceWarpper calculationOfExpenses(Integer uid, Long orderId, Integer couponId, Integer payType, Double balance) throws Exception { Order order = this.selectById(orderId); OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper(); BeanUtils.copyProperties(order, orderPriceWarpper); AppUser appUser = appUserService.selectById(uid); orderPriceWarpper.setBalance(appUser.getAccountBalance()); orderPriceWarpper.setDiscount(0D); orderPriceWarpper.setDiscountAmount(0D); orderPriceWarpper.setPayType(1);//微信支付 Double orderMoney = order.getOrderMoney(); //先算优惠券 Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); if(null != coupon && null == couponId){ orderMoney = orderMoney - coupon.getCouponPreferentialAmount(); orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); orderPriceWarpper.setCouponId(coupon.getId()); } if(null != couponId){ UserToCoupon userToCoupon = userToCouponService.selectById(couponId); Coupon coupon1 = couponService.selectById(userToCoupon.getCouponId()); orderMoney = orderMoney - coupon1.getCouponPreferentialAmount(); orderPriceWarpper.setDiscountedPrice(coupon1.getCouponPreferentialAmount()); orderPriceWarpper.setCouponId(couponId); } if(payType == 1 && appUser.getHavDiscount() == 1){//使用余额抵扣 orderPriceWarpper.setDiscount(9D); orderPriceWarpper.setDiscountAmount(orderMoney * 0.1); orderMoney = orderMoney * 0.9; } if(payType == 0){//不使用余额抵扣 orderPriceWarpper.setPayType(1); } if(payType == 1 && balance >= orderMoney){//使用余额抵扣 orderPriceWarpper.setPayType(2); } if(payType == 1 && balance < orderMoney){//使用余额抵扣部分 orderPriceWarpper.setPayType(4); } orderPriceWarpper.setPayMoney(orderMoney); return orderPriceWarpper; } /** * 获取订单支付页面优惠券列表 @@ -754,7 +802,7 @@ * @param appUser * @return */ public ResultUtil balancePayment(Order order, AppUser appUser, Integer couponId){ public ResultUtil balancePayment(Order order, AppUser appUser, Integer couponId) throws Exception{ Double payMoney = order.getOrderMoney(); if(null != couponId){ UserToCoupon userToCoupon = userToCouponService.selectById(couponId); @@ -785,11 +833,15 @@ accountChangeDetail.setCreateTime(new Date()); accountChangeDetail.setOldData(appUser.getAccountBalance()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(2); accountChangeDetail.setExplain("代驾服务费"); appUser.setAccountBalance(appUser.getAccountBalance() - payMoney); accountChangeDetail.setNewData(appUser.getAccountBalance()); appUserService.updateById(appUser); accountChangeDetailService.insert(accountChangeDetail); //处理佣金和收入记录 saveCommission(order); return ResultUtil.success(); } @@ -825,6 +877,7 @@ accountChangeDetail.setCreateTime(new Date()); accountChangeDetail.setOldData(appUser.getAccountBalance()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(2); accountChangeDetail.setExplain("代驾服务费"); appUser.setAccountBalance(appUser.getAccountBalance() > payMoney ? appUser.getAccountBalance() - payMoney : 0); accountChangeDetail.setNewData(appUser.getAccountBalance()); @@ -883,6 +936,7 @@ OrderServiceImpl.this.updateById(order1); //处理抽成及收入 saveCommission(order1); return; } if("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)){ @@ -922,7 +976,7 @@ order.setOrderNo(transaction_id); this.updateById(order); //添加收入明细 saveCommission(order); return ResultUtil.success(); } @@ -974,7 +1028,293 @@ accountChangeDetailService.insert(accountChangeDetail); } } if(score < 3){//差评扣减积分 SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); if(null != systemConfig){ //{"num1":"10:00","num2":"14:00","num3":10,"num4":10,"num5":10,"num6":10,"num7":10,"num8":10,"num9":5,"num10":5} JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); Integer num9 = jsonObject.getInteger("num9"); //增加积分变动记录 AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(order.getDriverId()); accountChangeDetail.setCreateTime(new Date()); accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); accountChangeDetail.setType(2); accountChangeDetail.setExplain("差评扣减积分"); driver.setIntegral(driver.getIntegral() - num9); accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); accountChangeDetailService.insert(accountChangeDetail); } } driverService.updateById(driver); return ResultUtil.success(); } /** * 处理订单收入及分佣抽成 * @param order * @return * @throws Exception */ public void saveCommission(Order order) throws Exception{ //司机收入和代理商抽成(先分佣,后抽成) //司机分佣和司机推荐用户首单奖励都在平台的抽佣中扣除,剩余的为平台抽佣。 Driver driver = driverService.selectById(order.getDriverId()); AppUser appUser = appUserService.selectById(order.getUserId()); Double payMoney = order.getPayMoney(); SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3)); if(null != systemConfig){ JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); Double num2 = jsonObject.getDouble("num2"); Double num3 = jsonObject.getDouble("num3"); if(order.getPayMoney() >= num2){ payMoney = payMoney - num3;//司机收入 SystemConfig systemConfig1 = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 2)); if(null != systemConfig1){ JSONObject jsonObject1 = JSON.parseObject(systemConfig1.getContent()); //司机推荐首单收入 List<Integer> state = Arrays.asList(108, 109); int count = this.selectCount(new EntityWrapper<Order>().eq("userId", appUser.getId()).eq("status", 1).in("state", state)); if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && count == 1){ Double num1 = jsonObject1.getDouble("num1"); num1 = (num3 >= num1 ? num1 : num3); if(num1 > 0){ Driver driver1 = driverService.selectById(appUser.getInviterId()); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(driver1.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(5); accountChangeDetail.setOldData(driver1.getCommission()); accountChangeDetail.setExplain("订单分佣收入"); accountChangeDetail.setCreateTime(new Date()); driver1.setCommission(driver1.getCommission() + num1); accountChangeDetail.setNewData(driver1.getCommission()); driverService.updateById(driver1); accountChangeDetailService.saveData(accountChangeDetail); 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); } num3 = (num3 >= num1 ? num3 - num1 : 0); } //开始处理层级抽佣 if(null != driver.getInviterType() && driver.getInviterType() == 2){ Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机 if(null != driver1.getInviterType() && driver1.getInviterType() == 2){ Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机 if(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 accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(driver1.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(5); accountChangeDetail.setOldData(driver1.getCommission()); accountChangeDetail.setExplain("订单分佣收入"); accountChangeDetail.setCreateTime(new Date()); driver1.setCommission(driver1.getCommission() + num5); accountChangeDetail.setNewData(driver1.getCommission()); driverService.updateById(driver1); accountChangeDetailService.saveData(accountChangeDetail); num3 = (num3 >= num5 ? num3 - 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(num6); revenue.setCreateTime(new Date()); revenueService.insert(revenue); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(driver2.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(5); accountChangeDetail.setOldData(driver2.getCommission()); accountChangeDetail.setExplain("订单分佣收入"); accountChangeDetail.setCreateTime(new Date()); driver2.setCommission(driver2.getCommission() + num6); accountChangeDetail.setNewData(driver2.getCommission()); driverService.updateById(driver2); accountChangeDetailService.saveData(accountChangeDetail); num3 = (num3 >= num6 ? num3 - 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(num7); revenue.setCreateTime(new Date()); revenueService.insert(revenue); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(driver3.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(5); accountChangeDetail.setOldData(driver3.getCommission()); accountChangeDetail.setExplain("订单分佣收入"); accountChangeDetail.setCreateTime(new Date()); driver3.setCommission(driver3.getCommission() + num7); accountChangeDetail.setNewData(driver3.getCommission()); driverService.updateById(driver3); accountChangeDetailService.saveData(accountChangeDetail); 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.setUserType(2); accountChangeDetail.setUserId(driver1.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(5); accountChangeDetail.setOldData(driver1.getCommission()); accountChangeDetail.setExplain("订单分佣收入"); accountChangeDetail.setCreateTime(new Date()); driver1.setCommission(driver1.getCommission() + num3_); accountChangeDetail.setNewData(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.setUserType(2); accountChangeDetail.setUserId(driver2.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(5); accountChangeDetail.setOldData(driver2.getCommission()); accountChangeDetail.setExplain("订单分佣收入"); accountChangeDetail.setCreateTime(new Date()); driver2.setCommission(driver2.getCommission() + num4); accountChangeDetail.setNewData(driver2.getCommission()); driverService.updateById(driver2); accountChangeDetailService.saveData(accountChangeDetail); num3 = (num3 >= num4 ? num3 - num4 : 0); } } }else{ Double num2_ = jsonObject1.getDouble("num2"); num2_ = (num3 >= num2_ ? num2_ : num3); if(num2_ > 0){ Revenue revenue = new Revenue(); revenue.setType(2); revenue.setUserType(2); revenue.setUserId(driver1.getId()); revenue.setOrderId(order.getId()); revenue.setAmount(num2_); revenue.setCreateTime(new Date()); revenueService.insert(revenue); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(driver1.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(5); accountChangeDetail.setOldData(driver1.getCommission()); accountChangeDetail.setExplain("订单分佣收入"); accountChangeDetail.setCreateTime(new Date()); driver1.setCommission(driver1.getCommission() + num2_); accountChangeDetail.setNewData(driver1.getCommission()); driverService.updateById(driver1); accountChangeDetailService.saveData(accountChangeDetail); num3 = (num3 >= num2_ ? num3 - num2_ : 0); } } } //处理代理商抽佣 if(num3 > 0){ Revenue revenue = new Revenue(); revenue.setType(1); revenue.setUserType(3); revenue.setUserId(driver.getAgentId()); revenue.setOrderId(order.getId()); revenue.setAmount(num3); revenue.setCreateTime(new Date()); revenueService.insert(revenue); } } } } //司机订单收入 Revenue revenue = new Revenue(); revenue.setType(1); revenue.setUserType(2); revenue.setUserId(driver.getId()); revenue.setOrderId(order.getId()); revenue.setAmount(payMoney + order.getDiscountedPrice()); revenue.setCreateTime(new Date()); revenueService.insert(revenue); AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); accountChangeDetail.setUserType(2); accountChangeDetail.setUserId(driver.getId()); accountChangeDetail.setType(1); accountChangeDetail.setChangeType(1); accountChangeDetail.setOldData(driver.getBalance() + driver.getCouponBalance()); accountChangeDetail.setExplain("订单收入"); accountChangeDetail.setCreateTime(new Date()); driver.setBalance(driver.getBalance() + payMoney); if(null != order.getCouponId()){ driver.setCouponBalance(driver.getCouponBalance() + order.getDiscountedPrice()); } accountChangeDetail.setNewData(driver.getBalance() + driver.getCouponBalance()); driverService.updateById(driver); accountChangeDetailService.saveData(accountChangeDetail); } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/RevenueServiceImpl.java
New file @@ -0,0 +1,15 @@ package com.supersavedriving.user.modular.system.service.impl; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.supersavedriving.user.modular.system.dao.RevenueMapper; import com.supersavedriving.user.modular.system.model.Revenue; import com.supersavedriving.user.modular.system.service.IRevenueService; import org.springframework.stereotype.Service; /** * @author zhibing.pu * @date 2023/3/13 10:09 */ @Service public class RevenueServiceImpl extends ServiceImpl<RevenueMapper, Revenue> implements IRevenueService { } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/httpClinet/HttpClientUtil.java
@@ -236,7 +236,7 @@ } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, key.toCharArray()).build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] {"TLSv1"}, null, new SSLConnectionSocketFactory(sslcontext, null, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); return HttpClients.custom().setSSLSocketFactory(sslsf).build(); } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/huawei/OBSUtil.java
New file @@ -0,0 +1,43 @@ package com.supersavedriving.user.modular.system.util.huawei; import com.obs.services.ObsClient; import com.obs.services.model.PutObjectRequest; import com.obs.services.model.PutObjectResult; import java.io.*; /** * 对象存储上传 * @author zhibing.pu * @date 2023/3/15 11:32 */ public class OBSUtil { public static String endPoint = "https://obs.cn-south-1.myhuaweicloud.com"; public static String ak = "N52IGR6DHOC3JAZFHZIW"; public static String sk = "jq7Q7jnFS4Gxamwh3naN2sbNKwQQ7cZISPVumGBS"; public static String bucketname = "csxdj"; /** * 上传文件 * @param inputStream * @param objectKey * @return */ public static String putObjectToBucket(InputStream inputStream, String objectKey) { try { // 创建ObsClient实例 ObsClient obsClient = new ObsClient(ak, sk, endPoint); // 待上传的本地文件路径,需要指定到具体的文件名 PutObjectRequest request = new PutObjectRequest(); request.setBucketName(bucketname); request.setObjectKey(objectKey); request.setInput(inputStream); PutObjectResult putObjectResult = obsClient.putObject(request); return putObjectResult.getObjectUrl(); }catch (Exception e){ e.printStackTrace(); } return null; } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/huawei/SMSUtil.java
New file @@ -0,0 +1,241 @@ package com.supersavedriving.user.modular.system.util.huawei; import javax.net.ssl.*; import java.io.*; import java.net.URL; import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.text.SimpleDateFormat; import java.util.*; /** * 短信工具类 * @author zhibing.pu * @date 2023/3/15 11:23 */ public class SMSUtil { //无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值 private static final String WSSE_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\""; //无需修改,用于格式化鉴权头域,给"Authorization"参数赋值 private static final String AUTH_HEADER_VALUE = "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""; /** * 发送短信 * @param phones //必填,全局号码格式(包含国家码),示例:+8615123456789,多个号码之间用英文逗号分隔 * @param templateId //模板ID * @param templateParas //模板变量,此处以单变量验证码短信为例,请客户自行生成6位验证码,并定义为字符串类型,以杜绝首位0丢失的问题(例如:002569变成了2569)。 * @throws Exception */ public static void send(String phones, String templateId, String templateParas) throws Exception { //必填,请参考"开发准备"获取如下数据,替换为实际值 String url = "https://smsapi.cn-south-1.myhuaweicloud.com:443/sms/batchSendSms/v1"; //APP接入地址(在控制台"应用管理"页面获取)+接口访问URI String appKey = "9I0xrhdGXthf1fv9nn8G3glZ6Zng"; //APP_Key String appSecret = "U7WxwX2LVk2YD6KAHxjc9tdnXoM9"; //APP_Secret String sender = "8823031523874"; //国内短信签名通道号或国际/港澳台短信通道号 // String templateId = "8ff55eac1d0b478ab3c06c3c6a492300"; //模板ID //条件必填,国内短信关注,当templateId指定的模板类型为通用模板时生效且必填,必须是已审核通过的,与模板类型一致的签名名称 //国际/港澳台短信不用关注该参数 String signature = "超省新代驾"; //签名名称 //必填,全局号码格式(包含国家码),示例:+8615123456789,多个号码之间用英文逗号分隔 // String receiver = "+86151****6789,+86152****7890"; //短信接收人号码 //选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告 String statusCallBack = ""; /** * 选填,使用无变量模板时请赋空值 String templateParas = ""; * 单变量模板示例:模板内容为"您的验证码是${1}"时,templateParas可填写为"[\"369751\"]" * 双变量模板示例:模板内容为"您有${1}件快递请到${2}领取"时,templateParas可填写为"[\"3\",\"人民公园正门\"]" * 模板中的每个变量都必须赋值,且取值不能为空 * 查看更多模板和变量规范:产品介绍>模板和变量规范 */ // String templateParas = "[\"369751\"]"; //模板变量,此处以单变量验证码短信为例,请客户自行生成6位验证码,并定义为字符串类型,以杜绝首位0丢失的问题(例如:002569变成了2569)。 //请求Body,不携带签名名称时,signature请填null String body = buildRequestBody(sender, phones, templateId, templateParas, statusCallBack, signature); if (null == body || body.isEmpty()) { System.out.println("body is null."); return; } //请求Headers中的X-WSSE参数值 String wsseHeader = buildWsseHeader(appKey, appSecret); if (null == wsseHeader || wsseHeader.isEmpty()) { System.out.println("wsse header is null."); return; } Writer out = null; BufferedReader in = null; StringBuffer result = new StringBuffer(); HttpsURLConnection connection = null; InputStream is = null; HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }; trustAllHttpsCertificates(); try { URL realUrl = new URL(url); connection = (HttpsURLConnection) realUrl.openConnection(); connection.setHostnameVerifier(hv); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(true); //请求方法 connection.setRequestMethod("POST"); //请求Headers参数 connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Authorization", AUTH_HEADER_VALUE); connection.setRequestProperty("X-WSSE", wsseHeader); connection.connect(); out = new OutputStreamWriter(connection.getOutputStream()); out.write(body); //发送请求Body参数 out.flush(); out.close(); int status = connection.getResponseCode(); if (200 == status) { //200 is = connection.getInputStream(); } else { //400/401 is = connection.getErrorStream(); } in = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = ""; while ((line = in.readLine()) != null) { result.append(line); } System.out.println(result.toString()); //打印响应消息实体 } catch (Exception e) { e.printStackTrace(); } finally { try { if (null != out) { out.close(); } if (null != is) { is.close(); } if (null != in) { in.close(); } } catch (Exception e) { e.printStackTrace(); } } } /** * 构造请求Body体 * @param sender * @param receiver * @param templateId * @param templateParas * @param statusCallBack * @param signature | 签名名称,使用国内短信通用模板时填写 * @return */ static String buildRequestBody(String sender, String receiver, String templateId, String templateParas, String statusCallBack, String signature) { if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() || templateId.isEmpty()) { System.out.println("buildRequestBody(): sender, receiver or templateId is null."); return null; } Map<String, String> map = new HashMap<String, String>(); map.put("from", sender); map.put("to", receiver); map.put("templateId", templateId); if (null != templateParas && !templateParas.isEmpty()) { map.put("templateParas", templateParas); } if (null != statusCallBack && !statusCallBack.isEmpty()) { map.put("statusCallback", statusCallBack); } if (null != signature && !signature.isEmpty()) { map.put("signature", signature); } StringBuilder sb = new StringBuilder(); String temp = ""; for (String s : map.keySet()) { try { temp = URLEncoder.encode(map.get(s), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } sb.append(s).append("=").append(temp).append("&"); } return sb.deleteCharAt(sb.length()-1).toString(); } /** * 构造X-WSSE参数值 * @param appKey * @param appSecret * @return */ static String buildWsseHeader(String appKey, String appSecret) { if (null == appKey || null == appSecret || appKey.isEmpty() || appSecret.isEmpty()) { System.out.println("buildWsseHeader(): appKey or appSecret is null."); return null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); String time = sdf.format(new Date()); //Created String nonce = UUID.randomUUID().toString().replace("-", ""); //Nonce MessageDigest md; byte[] passwordDigest = null; try { md = MessageDigest.getInstance("SHA-256"); md.update((nonce + time + appSecret).getBytes()); passwordDigest = md.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } //如果JDK版本是1.8,请加载原生Base64类,并使用如下代码 String passwordDigestBase64Str = Base64.getEncoder().encodeToString(passwordDigest); //PasswordDigest //如果JDK版本低于1.8,请加载三方库提供Base64类,并使用如下代码 //String passwordDigestBase64Str = Base64.encodeBase64String(passwordDigest); //PasswordDigest //若passwordDigestBase64Str中包含换行符,请执行如下代码进行修正 //passwordDigestBase64Str = passwordDigestBase64Str.replaceAll("[\\s*\t\n\r]", ""); return String.format(WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time); } /*** @throws Exception */ static void trustAllHttpsCertificates() throws Exception { TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { return; } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { return; } public X509Certificate[] getAcceptedIssuers() { return null; } } }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/warpper/OrderPriceWarpper.java
@@ -53,6 +53,8 @@ private Double discount; @ApiModelProperty("折扣金额") private Double discountAmount; @ApiModelProperty("优惠券id") private Integer couponId; @ApiModelProperty("优惠券金额") private Double discountedPrice; @ApiModelProperty("当前余额")