| | |
| | | if(proportionPercent.compareTo(BigDecimal.ZERO)>0){ |
| | | PaymentDelaytransHFTXVo result = new PaymentDelaytransHFTXVo(); |
| | | // 计算分成金额 |
| | | int amount = orderMoney.multiply(proportionPercent).setScale(0, RoundingMode.UP).intValue(); |
| | | int amount = orderMoney.multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).intValue(); |
| | | BigDecimal multiply = orderMoney.multiply(proportionPercent.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN); |
| | | log.info("订单分账:{} 分账金额: {}", orderNo, amount); |
| | | if (amount > 0) { |
| | |
| | | |
| | | //分账对象 |
| | | JSONArray acctInfos = new JSONArray(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("div_amt", String.format("%.2f", multiply.doubleValue())); |
| | | jsonObject.put("huifu_id", vo.getHuifuId()); |
| | | acctInfos.add(jsonObject); |
| | | if(multiply.compareTo(BigDecimal.ZERO) > 0){ |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("div_amt", String.format("%.2f", multiply.doubleValue())); |
| | | jsonObject.put("huifu_id", vo.getHuifuId()); |
| | | acctInfos.add(jsonObject); |
| | | } |
| | | //平台商户 |
| | | double pt_amount = orderMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | JSONObject jsonObject1 = new JSONObject(); |
| | | jsonObject1.put("div_amt", String.format("%.2f", pt_amount)); |
| | | jsonObject1.put("huifu_id", "6666000141216769"); |
| | | acctInfos.add(jsonObject1); |
| | | BigDecimal pt_amount = orderMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN); |
| | | if(pt_amount.compareTo(BigDecimal.ZERO) > 0){ |
| | | JSONObject jsonObject1 = new JSONObject(); |
| | | jsonObject1.put("div_amt", String.format("%.2f", pt_amount.doubleValue())); |
| | | jsonObject1.put("huifu_id", "6666000141216769"); |
| | | acctInfos.add(jsonObject1); |
| | | } |
| | | |
| | | R<PaymentDelaytransHFTXVo> hftxVoR = HuiFuTianXiaUtil.paymentDelaytrans(request.getOutOrderNo(), org_req_date, outTradeNo, acctInfos); |
| | | if(hftxVoR.getCode() != 200){ |
| | | throw new ServiceException(hftxVoR.getMsg()); |
| | |
| | | @Data |
| | | public class AppNearShopVo { |
| | | |
| | | |
| | | private Long shopId; |
| | | |
| | | private Float distance; |
| | | |
| | | private String longitude; |
| | | |
| | | private String latitude; |
| | | } |
| | |
| | | * @param appNearbyShopDto |
| | | * @return |
| | | */ |
| | | AppNearShopVo getNearbyShop(@Param("param")AppNearbyShopDto appNearbyShopDto); |
| | | List<AppNearShopVo> getNearbyShop(@Param("param")AppNearbyShopDto appNearbyShopDto); |
| | | |
| | | |
| | | /** |
| | | * 获取最近商户 |
| | | * @param appNearbyShopDto |
| | | * @return |
| | | */ |
| | | List<AppNearShopVo> getNearbyShops(@Param("param")AppNearbyShopDto appNearbyShopDto); |
| | | |
| | | |
| | | /** |
| | | * @description 平台获取商户分成列表 |
| | |
| | | import com.ruoyi.shop.service.task.ShopTaskService; |
| | | import com.ruoyi.shop.util.HuiFuTianXiaUtil; |
| | | import com.ruoyi.shop.util.WechatPayUtils; |
| | | import com.ruoyi.shop.util.map.MapUtil; |
| | | import com.ruoyi.shop.util.map.vo.TencentDistanceMatrix; |
| | | import com.ruoyi.shop.util.map.vo.TencentDistanceMatrixElements; |
| | | import com.ruoyi.system.api.constant.AppErrorConstant; |
| | | import com.ruoyi.system.api.constant.SecurityConstant; |
| | | import com.ruoyi.system.api.domain.dto.*; |
| | |
| | | //获取绑定商户 |
| | | shop = this.getById(member.getRelationShopId()); |
| | | }else if(StringUtils.isNotBlank(appNearbyShopDto.getLatitude())&&StringUtils.isNotBlank(appNearbyShopDto.getLongitude())){ |
| | | AppNearShopVo appNearShopVo = shopMapper.getNearbyShop(appNearbyShopDto); |
| | | shop = this.getById(appNearShopVo.getShopId()); |
| | | List<AppNearShopVo> appNearShopVos = shopMapper.getNearbyShops(appNearbyShopDto); |
| | | if(appNearShopVos.size() > 0){ |
| | | StringBuffer to = new StringBuffer(); |
| | | for (AppNearShopVo appNearShopVo : appNearShopVos) { |
| | | to.append(appNearShopVo.getLatitude() + "," + appNearShopVo.getLongitude() + ";"); |
| | | } |
| | | String form = appNearbyShopDto.getLatitude() + "," + appNearbyShopDto.getLongitude(); |
| | | R<List<TencentDistanceMatrix>> r = MapUtil.tencentDistanceMatrix(form, to.substring(0, to.length() - 1), "walking"); |
| | | if(r.getCode() != 200){ |
| | | throw new ServiceException(r.getMsg()); |
| | | } |
| | | List<TencentDistanceMatrix> data = r.getData(); |
| | | //存储最短距离 |
| | | BigDecimal dis = new BigDecimal(0); |
| | | AppNearShopVo appNearShopVo = null; |
| | | List<TencentDistanceMatrixElements> elements = data.get(0).getElements(); |
| | | for (int i = 0; i < elements.size(); i++) { |
| | | TencentDistanceMatrixElements matrix = elements.get(i); |
| | | if(dis.compareTo(BigDecimal.ZERO) == 0 || dis.compareTo(new BigDecimal(matrix.getDistance())) > 0){ |
| | | dis = new BigDecimal(matrix.getDistance()); |
| | | appNearShopVo = appNearShopVos.get(i); |
| | | } |
| | | } |
| | | shop = this.getById(appNearShopVo.getShopId()); |
| | | } |
| | | }else{ |
| | | return appNearbyShopVo; |
| | | } |
New file |
| | |
| | | package com.ruoyi.shop.util.map; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.shop.util.map.vo.TencentDistanceMatrix; |
| | | import com.ruoyi.shop.util.map.vo.TencentDistanceMatrixElements; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 地图工具 |
| | | * @author zhibing.pu |
| | | * @Date 2023/10/30 9:44 |
| | | */ |
| | | public class MapUtil { |
| | | |
| | | private static final String tencentKey = "FATBZ-V3AWH-7IJDS-WC7NC-QXY3Q-TQFDJ"; |
| | | |
| | | |
| | | /** |
| | | * 距离矩阵计算-腾讯 |
| | | * @param form 起点经纬度-lat,lng,[header],[roadtype],[speed],[accuracy],[timestamp]|lat,lng,[header],[roadtype],[speed],[accuracy],[timestamp]… |
| | | * @param to 终点经纬度-lat,lng;lat,lng… |
| | | * @param mode 计算方式,取值:driving:驾车 walking:步行 bicycling:自行车 |
| | | * @return |
| | | */ |
| | | public static R<List<TencentDistanceMatrix>> tencentDistanceMatrix(String form, String to, String mode){ |
| | | String url = "https://apis.map.qq.com/ws/distance/v1/matrix"; |
| | | HttpRequest get = HttpUtil.createGet(url) |
| | | .form("key", tencentKey) |
| | | .form("from", form) |
| | | .form("to", to) |
| | | .form("mode", mode); |
| | | HttpResponse execute = get.execute(); |
| | | JSONObject jsonObject = JSON.parseObject(execute.body()); |
| | | Integer status = jsonObject.getInteger("status"); |
| | | String message = jsonObject.getString("message"); |
| | | if(0 == status){ |
| | | JSONObject result = jsonObject.getJSONObject("result"); |
| | | JSONArray rows = result.getJSONArray("rows"); |
| | | List<TencentDistanceMatrix> list = new ArrayList<>(); |
| | | for (int i = 0; i < rows.size(); i++) { |
| | | TencentDistanceMatrix tencentDistanceMatrix = new TencentDistanceMatrix(); |
| | | |
| | | JSONObject jsonObject1 = rows.getJSONObject(i); |
| | | JSONArray elements = jsonObject1.getJSONArray("elements"); |
| | | List<TencentDistanceMatrixElements> elementsList = new ArrayList<>(); |
| | | for (int j = 0; j < elements.size(); j++) { |
| | | JSONObject jsonObject2 = elements.getJSONObject(j); |
| | | TencentDistanceMatrixElements elements1 = new TencentDistanceMatrixElements(); |
| | | elements1.setDistance(jsonObject2.getInteger("distance")); |
| | | elements1.setDuration(jsonObject2.getInteger("duration")); |
| | | elementsList.add(elements1); |
| | | } |
| | | tencentDistanceMatrix.setElements(elementsList); |
| | | list.add(tencentDistanceMatrix); |
| | | } |
| | | return R.ok(list); |
| | | } |
| | | return R.fail(message); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.shop.util.map.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 距离矩阵 |
| | | * @author zhibing.pu |
| | | * @Date 2023/10/30 10:05 |
| | | */ |
| | | @Data |
| | | public class TencentDistanceMatrix { |
| | | List<TencentDistanceMatrixElements> elements; |
| | | } |
New file |
| | |
| | | package com.ruoyi.shop.util.map.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 距离矩阵 |
| | | * @author zhibing.pu |
| | | * @Date 2023/10/30 10:05 |
| | | */ |
| | | @Data |
| | | public class TencentDistanceMatrixElements { |
| | | /** |
| | | * 距离(米) |
| | | */ |
| | | private Integer distance; |
| | | /** |
| | | * 时间(秒) |
| | | */ |
| | | private Integer duration; |
| | | } |
| | |
| | | ORDER BY distance ASC LIMIT 1 |
| | | </select> |
| | | |
| | | |
| | | <select id="getNearbyShops" resultType="com.ruoyi.shop.domain.vo.AppNearShopVo"> |
| | | SELECT |
| | | ts.shop_id shopId, |
| | | 6378.138 * 2 * ASIN(SQRT(POW(SIN((#{param.latitude} * PI() / 180 - ts.shop_latitude * PI() / 180) / 2), 2) |
| | | + COS(#{param.latitude} * PI() / 180) * COS(ts.shop_latitude * PI() / 180) * POW( |
| | | SIN((#{param.longitude} * PI() / 180 - ts.shop_longitude * PI() / 180) / 2), 2 |
| | | ))) AS distance, |
| | | shop_longitude as longitude, |
| | | shop_latitude as latitude |
| | | FROM t_shop ts |
| | | WHERE del_flag = 0 AND shop_status = 1 |
| | | ORDER BY distance ASC LIMIT 0, 5 |
| | | </select> |
| | | |
| | | |
| | | <select id="pageMgtShopProportion" resultType="com.ruoyi.shop.domain.vo.MgtShopProportionPageVo"> |
| | | SELECT |
| | | tsp.proportion_id proportionId, |
| | |
| | | package com.ruoyi.system.service.impl.config; |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.system.api.constant.SecurityConstant; |
| | | import com.ruoyi.system.domain.pojo.config.Region; |
| | |
| | | import com.ruoyi.system.mapper.config.RegionMapper; |
| | | import com.ruoyi.system.service.config.RegionService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.system.util.HttpUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | return regionVoList1; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // public R renewalRegion(){ |
| | | // HttpUtils.doPost() |
| | | // } |
| | | } |