‘linchangsheng’ 1 week ago
parent
commit
6754f11cd8

+ 4 - 0
src/main/java/com/gree/mall/miniapp/bean/user/CurrentCompanyWechat.java

@@ -2,6 +2,7 @@ package com.gree.mall.miniapp.bean.user;
 
 import com.gree.mall.miniapp.plus.entity.AdminCompanyWechat;
 import com.gree.mall.miniapp.plus.entity.AdminCompanyWechatOther;
+import com.gree.mall.miniapp.plus.entity.AdminWebsit;
 import com.gree.mall.miniapp.plus.entity.User;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -21,6 +22,9 @@ public class CurrentCompanyWechat extends AdminCompanyWechat{
     @ApiModelProperty("企业其他配置")
     private AdminCompanyWechatOther adminCompanyWechatOther;
 
+    @ApiModelProperty("用户当前门店信息")
+    private AdminWebsit adminWebsit;
+
     @ApiModelProperty("师傅昵称")
     private User user;
 

+ 37 - 0
src/main/java/com/gree/mall/miniapp/bean/user/RegionBean.java

@@ -0,0 +1,37 @@
+package com.gree.mall.miniapp.bean.user;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class RegionBean {
+
+    @ApiModelProperty(value = "经纬度")
+    private String lnglat;
+
+    @ApiModelProperty(value = "省id")
+    private String provinceId;
+
+    @ApiModelProperty(value ="省名称")
+    private String provinceName;
+
+    @ApiModelProperty(value ="市id")
+    private String cityId;
+
+    @ApiModelProperty(value = "市名称")
+    private String cityName;
+
+    @ApiModelProperty(value = "区id")
+    private String areaId;
+
+    @ApiModelProperty(value = "区名称")
+    private String areaName;
+
+    @ApiModelProperty(value = "街道id")
+    private String lbsId;
+
+    @ApiModelProperty(value = "街道名称")
+    private String name;
+
+
+}

+ 12 - 4
src/main/java/com/gree/mall/miniapp/controller/user/UserController.java

@@ -5,10 +5,7 @@ import com.aliyuncs.utils.StringUtils;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gree.mall.miniapp.annotation.ApiNotAuth;
 import com.gree.mall.miniapp.bean.Page;
-import com.gree.mall.miniapp.bean.user.MyProfitBean;
-import com.gree.mall.miniapp.bean.user.RankBean;
-import com.gree.mall.miniapp.bean.user.RankItemBean;
-import com.gree.mall.miniapp.bean.user.UserWxBean;
+import com.gree.mall.miniapp.bean.user.*;
 import com.gree.mall.miniapp.exception.RemoteServiceException;
 import com.gree.mall.miniapp.helper.ResponseHelper;
 import com.gree.mall.miniapp.logic.user.UserLogic;
@@ -234,4 +231,15 @@ public class UserController {
         return ResponseHelper.success(websitUrl);
     }
 
+    @PostMapping("/address")
+    @ApiOperation(value = "获得经纬度地址")
+    public ResponseHelper<RegionBean> address(
+            @ApiParam(required = false, value = "经纬度") @RequestParam(required = false) String lat,
+            @ApiParam(required = false, value = "经纬度") @RequestParam(required = false) String lng,
+            HttpServletRequest request
+    ) throws RemoteServiceException {
+        RegionBean address = userLogic.address(request,lat,lng);
+        return ResponseHelper.success(address);
+    }
+
 }

+ 51 - 0
src/main/java/com/gree/mall/miniapp/logic/LbsAmapLogic.java

@@ -3,11 +3,13 @@ package com.gree.mall.miniapp.logic;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
+import com.gree.mall.miniapp.bean.user.RegionBean;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.util.HashMap;
 import java.util.Map;
 
 @Slf4j
@@ -43,6 +45,55 @@ public class LbsAmapLogic {
         return location;
     }
 
+    /**
+     * 根据经纬度反查省市区街道
+     * @Param lng,lat
+     * @Return {"area":"番禺区","province":"广东省","city":"广州市","street":"大龙街道"}
+     */
+    public RegionBean getRegionByLngLat(String lnglat){
+        //String lnglat = lng + "," + lat;
+        //String lbsWebKey = "b772f8b0ace6bc96c04ae8e48f241e36";
+        String url = "https://restapi.amap.com/v3/geocode/regeo?key="+lbsWebKey+"&location="+lnglat;
+        String s = HttpUtil.get(url);
+        JSONObject jsonObject = new JSONObject(s);
+        String status = jsonObject.getStr("status");
+        if(!status.equals("1")){
+            return null;
+        }
+        JSONObject regeocode = jsonObject.getJSONObject("regeocode");
+        JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
+        Map<String,String> map = new HashMap<>();
+        map.put("province",addressComponent.getStr("province"));
+        if(addressComponent.getStr("city").equals("[]")) {
+            map.put("city", addressComponent.getStr("province"));
+        }else{
+            map.put("city", addressComponent.getStr("city"));
+        }
+        if(addressComponent.getStr("district").equals("[]")) {
+            map.put("area", addressComponent.getStr("city"));
+        }else{
+            map.put("area", addressComponent.getStr("district"));
+        }
+        map.put("street",addressComponent.getStr("township"));
+        //System.out.print(new JSONObject(map).toString());
+        log.info("根据经纬度反查地址,经纬度:{},反查的地址:{}",lnglat,new JSONObject(addressComponent));
 
+        String street = map.get("street");
+        String province = map.get("province");
+        String city = map.get("city");
+        String area = map.get("area");
+//        LbsAmap lbsAmap = this.getByRegion(province, city, area, street);
+//        if(lbsAmap == null){
+//            return null;
+//        }
+//        RegionBean regionBean = BeanUtil.copyProperties(lbsAmap, RegionBean.class);
+        RegionBean regionBean = new RegionBean();
+        regionBean.setLnglat(lnglat);
+        regionBean.setProvinceName(province);
+        regionBean.setCityName(city);
+        regionBean.setAreaName(area);
+        regionBean.setName(street);
+        return regionBean;
+    }
 
 }

+ 7 - 0
src/main/java/com/gree/mall/miniapp/logic/common/CommonLogic.java

@@ -63,6 +63,9 @@ public class CommonLogic {
     @Value("${wechat.sub.secret}")
     private String wechatSubSecret;
 
+    @Autowired
+    AdminWebsitService adminWebsitService;
+
 
     //高德的webkey
     private final String mapWebKey = "69cebe7cded9307a588237b0618856c9";
@@ -109,6 +112,10 @@ public class CommonLogic {
         currentCompanyWechat.setSubSecret(wechatSubSecret);
         currentCompanyWechat.setUserId(CommonUtils.getUserId(request));
         currentCompanyWechat.setUser(user);
+
+
+        AdminWebsit adminWebsit = adminWebsitService.getById(user.getWebsitId());
+        currentCompanyWechat.setAdminWebsit(adminWebsit);
         return currentCompanyWechat;
 
     }

+ 2 - 1
src/main/java/com/gree/mall/miniapp/logic/order/OrderLogic.java

@@ -453,6 +453,7 @@ public class OrderLogic {
         orderInfo.setTotalProductAmount(totalPrice);
         orderInfo.setDispatchType(orderBuyBean.getDispatchType());
         orderInfo.setClientIp(ip);
+        orderInfo.setPayWorkerCodeId(currentCompanyWechat.getAdminWebsit().getPayWorkerCodeId());
         //团购的折扣活动
         if (!isGoodsPackage) {
             PromotionDiscountBean promotionDiscountBean = this.discountPromotion(orderBuyBean.getBuyGoods(), orderInfo.getPayAmount());
@@ -499,7 +500,7 @@ public class OrderLogic {
             payDetail = umsLogic.payment(orderInfo, orderInfo.getPayAmount(), user.getOpenId(), user.getCompanyWechatId(), orderDetail, ip);
         } else {
             payDetail = wechatLogic.payment(orderInfo.getOrderId(), orderInfo.getPayAmount(), user.getOpenId(),
-                    profitSharingFlag, ip, user.getCompanyWechatId());
+                    profitSharingFlag, ip, currentCompanyWechat.getAdminWebsit().getPayWorkerCodeId());
             //不需要支付
             if (!payDetail.getIsPay()) {
                 payLogic.payCall(payDetail.getId(), "", BigDecimal.valueOf(0), null);

+ 9 - 0
src/main/java/com/gree/mall/miniapp/logic/user/UserLogic.java

@@ -15,6 +15,7 @@ import com.gree.mall.miniapp.enums.QrCodeEnum;
 import com.gree.mall.miniapp.enums.UserTypeEnum;
 import com.gree.mall.miniapp.exception.RemoteServiceException;
 import com.gree.mall.miniapp.helper.ResponseHelper;
+import com.gree.mall.miniapp.logic.LbsAmapLogic;
 import com.gree.mall.miniapp.logic.common.CommonLogic;
 import com.gree.mall.miniapp.logic.common.WechatLogic;
 import com.gree.mall.miniapp.logic.coupon.CouponLogic;
@@ -89,6 +90,9 @@ public class UserLogic {
     @Value("${wechat.sub.appid}")
     private String wechatSubAppid;
 
+    @Autowired
+    LbsAmapLogic lbsAmapLogic;
+
     /**
      * 微信授权
      *
@@ -679,4 +683,9 @@ public class UserLogic {
         return ;
 
     }
+
+    public RegionBean address(HttpServletRequest request, String lat, String lng) {
+        RegionBean regionBean = lbsAmapLogic.getRegionByLngLat(lng + "," + lat);
+        return regionBean;
+    }
 }