java110 лет назад: 5
Родитель
Сommit
d8a8ffcf8b

+ 59 - 0
java110-bean/src/main/java/com/java110/dto/rentingPool/RentingPoolDto.java

@@ -19,10 +19,14 @@ public class RentingPoolDto extends PageDto implements Serializable {
     public static final String STATE_PROXY_AUDIT = "1";
     public static final String STATE_PROXY_VIEW_ROOM = "2";
     public static final String STATE_TO_PAY = "3";
+    public static final String STATE_OWNER_TO_PAY = "7";
     public static final String STATE_APPLY_AGREE = "4";
     public static final String STATE_ADMIN_AUDIT = "5";
     public static final String STATE_FINISH = "6";
 
+    //房屋服务费 redis前缀
+    public static final String REDIS_PAY_RENTING = "PAY_RENTING_";
+
     private String latitude;
     private String ownerTel;
     private String rentingConfigId;
@@ -49,6 +53,13 @@ public class RentingPoolDto extends PageDto implements Serializable {
 
     private String statusCd = "0";
 
+    private String serviceOwnerRate;
+    private String serviceTenantRate;
+    private String adminSeparateRate;
+    private String proxySeparateRate;
+    private String propertySeparateRate;
+    private String servicePrice;
+
 
     public String getLatitude() {
         return latitude;
@@ -218,4 +229,52 @@ public class RentingPoolDto extends PageDto implements Serializable {
     public void setRoomName(String roomName) {
         this.roomName = roomName;
     }
+
+    public String getServiceOwnerRate() {
+        return serviceOwnerRate;
+    }
+
+    public void setServiceOwnerRate(String serviceOwnerRate) {
+        this.serviceOwnerRate = serviceOwnerRate;
+    }
+
+    public String getServiceTenantRate() {
+        return serviceTenantRate;
+    }
+
+    public void setServiceTenantRate(String serviceTenantRate) {
+        this.serviceTenantRate = serviceTenantRate;
+    }
+
+    public String getAdminSeparateRate() {
+        return adminSeparateRate;
+    }
+
+    public void setAdminSeparateRate(String adminSeparateRate) {
+        this.adminSeparateRate = adminSeparateRate;
+    }
+
+    public String getProxySeparateRate() {
+        return proxySeparateRate;
+    }
+
+    public void setProxySeparateRate(String proxySeparateRate) {
+        this.proxySeparateRate = proxySeparateRate;
+    }
+
+    public String getPropertySeparateRate() {
+        return propertySeparateRate;
+    }
+
+    public void setPropertySeparateRate(String propertySeparateRate) {
+        this.propertySeparateRate = propertySeparateRate;
+    }
+
+    public String getServicePrice() {
+        return servicePrice;
+    }
+
+    public void setServicePrice(String servicePrice) {
+        this.servicePrice = servicePrice;
+    }
 }

+ 3 - 1
java110-db/src/main/resources/mapper/user/RentingPoolServiceDaoImplMapper.xml

@@ -22,7 +22,9 @@
         statusCd,t.renting_title,t.renting_title rentingTitle,t.check_in,t.check_in
         checkIn,t.renting_id,t.renting_id rentingId,t.room_id,t.room_id roomId,t.payment_type,t.payment_type
         paymentType,t.owner_name,t.owner_name ownerName,t.price,t.state,t.community_id,t.community_id
-        communityId,t.longitude,td.name stateName,td2.name paymentTypeName,rc.renting_type rentingType
+        communityId,t.longitude,td.name stateName,td2.name paymentTypeName,rc.renting_type rentingType,
+        rc.service_owner_rate serviceOwnerRate,rc.service_tenant_rate serviceTenantRate,rc.admin_separate_rate adminSeparateRate,
+        rc.proxy_separate_rate proxySeparateRate,rc.property_separate_rate propertySeparateRate,rc.service_price servicePrice
         from renting_pool t
         left join t_dict td on td.status_cd = t.state and td.table_name = 'renting_pool' and td.table_columns = 'state'
         left join t_dict td2 on td2.status_cd = t.payment_type and td2.table_name = 'renting_pool' and td2.table_columns = 'payment_type'

+ 3 - 0
java110-utils/src/main/java/com/java110/utils/cache/CommonCache.java

@@ -11,6 +11,9 @@ public class CommonCache extends BaseCache {
     public final static int defaultExpireTime = 5 * 60;
     public final static int RESEND_DEFAULT_EXPIRETIME = 1 * 60;
 
+    //支付默认回话
+    public final static int PAY_DEFAULT_EXPIRE_TIME = 2 * 60 * 60;
+
     /**
      * 获取值(用户ID)
      *

+ 31 - 7
service-front/src/main/java/com/java110/front/controller/PaymentController.java

@@ -1,11 +1,12 @@
 package com.java110.front.controller;
 
-import com.java110.front.smo.payment.IToNotifySMO;
-import com.java110.front.smo.payment.IToPaySMO;
-import com.java110.front.smo.payment.IToPayTempCarInoutSMO;
 import com.java110.core.base.controller.BaseController;
 import com.java110.core.context.IPageData;
 import com.java110.core.context.PageData;
+import com.java110.front.smo.payment.IRentingToPaySMO;
+import com.java110.front.smo.payment.IToNotifySMO;
+import com.java110.front.smo.payment.IToPaySMO;
+import com.java110.front.smo.payment.IToPayTempCarInoutSMO;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.util.StringUtil;
 import org.slf4j.Logger;
@@ -30,6 +31,9 @@ public class PaymentController extends BaseController {
     @Autowired
     private IToPaySMO toPaySMOImpl;
 
+    @Autowired
+    private IRentingToPaySMO rentingToPaySMOImpl;
+
     @Autowired
     private IToPayTempCarInoutSMO toPayTempCarInoutSMOImpl;
 
@@ -46,8 +50,8 @@ public class PaymentController extends BaseController {
     public ResponseEntity<String> toPay(@RequestBody String postInfo, HttpServletRequest request) {
         IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
         /*IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);*/
-       String appId = request.getHeader("APP_ID");
-        if(StringUtil.isEmpty(appId)){
+        String appId = request.getHeader("APP_ID");
+        if (StringUtil.isEmpty(appId)) {
             appId = request.getHeader("APP-ID");
         }
 
@@ -68,7 +72,7 @@ public class PaymentController extends BaseController {
         IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
         /*IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);*/
         String appId = request.getHeader("APP_ID");
-        if(StringUtil.isEmpty(appId)){
+        if (StringUtil.isEmpty(appId)) {
             appId = request.getHeader("APP-ID");
         }
         IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getUserName(), pd.getToken(), postInfo,
@@ -89,9 +93,29 @@ public class PaymentController extends BaseController {
 
         logger.debug("微信支付回调报文" + postInfo);
 
-        return toNotifySMOImpl.toNotify(postInfo,request);
+        return toNotifySMOImpl.toNotify(postInfo, request);
+
+
+    }
 
+    /**
+     * <p>出租统一下单入口</p>
+     *
+     * @param request
+     * @throws Exception
+     */
+    @RequestMapping(path = "/rentingToPay", method = RequestMethod.POST)
+    public ResponseEntity<String> rentingToPay(@RequestBody String postInfo, HttpServletRequest request) {
+        IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+        String appId = request.getHeader("APP_ID");
+        if (StringUtil.isEmpty(appId)) {
+            appId = request.getHeader("APP-ID");
+        }
 
+        IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getUserName(), pd.getToken(), postInfo,
+                "", "", "", pd.getSessionId(),
+                appId);
+        return rentingToPaySMOImpl.toPay(newPd);
     }
 
 }

+ 8 - 1
service-front/src/main/java/com/java110/front/smo/AppAbstractComponentSMO.java

@@ -14,7 +14,11 @@ import com.java110.utils.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.HttpStatusCodeException;
 import org.springframework.web.client.RestTemplate;
 
@@ -112,6 +116,9 @@ public abstract class AppAbstractComponentSMO extends AbstractComponentSMO {
                 resultMap.put("prepayid", resMap.get("prepay_id"));
                 //resultMap.put("signType", "MD5");
                 resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword()));
+            } else if (WechatAuthProperties.TRADE_TYPE_NATIVE.equals(tradeType)) {
+                resultMap.put("prepayId", resMap.get("prepay_id"));
+                resultMap.put("codeUrl", resMap.get("code_url"));
             }
             resultMap.put("code", "0");
             resultMap.put("msg", "下单成功");

+ 17 - 0
service-front/src/main/java/com/java110/front/smo/payment/IRentingToPaySMO.java

@@ -0,0 +1,17 @@
+package com.java110.front.smo.payment;
+
+import com.java110.core.context.IPageData;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * 统一下单接口类
+ */
+public interface IRentingToPaySMO {
+
+    /**
+     * 下单
+     * @param pd
+     * @return
+     */
+    public ResponseEntity<String> toPay(IPageData pd);
+}

+ 163 - 0
service-front/src/main/java/com/java110/front/smo/payment/impl/RentingToPaySMOImpl.java

@@ -0,0 +1,163 @@
+package com.java110.front.smo.payment.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.context.IPageData;
+import com.java110.core.context.PageData;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.rentingPool.RentingPoolDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.front.properties.WechatAuthProperties;
+import com.java110.front.smo.AppAbstractComponentSMO;
+import com.java110.front.smo.payment.IRentingToPaySMO;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.constant.ServiceConstant;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+@Service("rentingToPaySMOImpl")
+public class RentingToPaySMOImpl extends AppAbstractComponentSMO implements IRentingToPaySMO {
+    private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class);
+
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @Autowired
+    private RestTemplate outRestTemplate;
+
+
+    @Autowired
+    private WechatAuthProperties wechatAuthProperties;
+
+    @Override
+    public ResponseEntity<String> toPay(IPageData pd) {
+        return super.businessProcess(pd);
+    }
+
+    @Override
+    protected void validate(IPageData pd, JSONObject paramIn) {
+
+        Assert.jsonObjectHaveKey(paramIn, "rentingId", "请求报文中未包含房源ID");
+
+    }
+
+    @Override
+    protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws Exception {
+
+        ResponseEntity responseEntity = null;
+
+        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
+        smallWeChatDto.setAppId(wechatAuthProperties.getAppId());
+        smallWeChatDto.setAppSecret(wechatAuthProperties.getSecret());
+        smallWeChatDto.setMchId(wechatAuthProperties.getMchId());
+        smallWeChatDto.setPayPassword(wechatAuthProperties.getKey());
+
+
+        //查询用户ID
+        paramIn.put("userId", pd.getUserId());
+        //查询
+        String url = ServiceConstant.SERVICE_API_URL + "/api/renting/queryRentingPool?rentingId="
+                + paramIn.getString("rentingId") + "&row=1&page=1";
+        responseEntity = super.callCenterService(restTemplate, pd, "", url, HttpMethod.GET);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            return responseEntity;
+        }
+
+        JSONObject body = JSONObject.parseObject(responseEntity.getBody().toString());
+
+        if (ResultVo.CODE_OK != body.getInteger("code")) {
+            return responseEntity;
+        }
+
+        if (body.getInteger("total") < 1) {
+            return responseEntity;
+        }
+
+        RentingPoolDto rentingPoolDto = BeanConvertUtil.covertBean(body.getJSONArray("data").get(0), RentingPoolDto.class);
+
+        String appType = OwnerAppUserDto.APP_TYPE_WECHAT;
+
+        Map tmpParamIn = new HashMap();
+        tmpParamIn.put("userId", pd.getUserId());
+        tmpParamIn.put("appType", appType);
+
+        String orderId = GenerateCodeFactory.getOId();
+        double service = Double.parseDouble(rentingPoolDto.getServicePrice());
+        double rate = 0.0;
+        String feeName = rentingPoolDto.getRoomName() + "出租服务费";
+        if (RentingPoolDto.STATE_TO_PAY.equals(rentingPoolDto.getState())) {
+            rate = Double.parseDouble(rentingPoolDto.getServiceTenantRate());
+            feeName += "(租客)";
+        } else if (RentingPoolDto.STATE_TO_PAY.equals(rentingPoolDto.getState())) {
+            rate = Double.parseDouble(rentingPoolDto.getServiceOwnerRate());
+            feeName += "(业主)";
+        } else {
+            throw new IllegalAccessException("当前状态不是支付状态");
+        }
+
+        BigDecimal serviceDec = new BigDecimal(service);
+        BigDecimal rateDec = new BigDecimal(rate);
+        double money = serviceDec.multiply(rateDec).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+
+        Map result = super.java110Payment(outRestTemplate, feeName, WechatAuthProperties.TRADE_TYPE_NATIVE, orderId, money, "", smallWeChatDto);
+        result.put("money", money);
+        responseEntity = new ResponseEntity(JSONObject.toJSONString(result), HttpStatus.OK);
+        if (!"0".equals(result.get("code"))) {
+            return responseEntity;
+        }
+
+        Map orderInfo = BeanConvertUtil.beanCovertMap(rentingPoolDto);
+        orderInfo.put("orderId", orderId);
+        orderInfo.put("money", money);
+        orderInfo.put("feeName", feeName);
+
+        String order = JSONObject.toJSONString(orderInfo);
+
+        CommonCache.setValue(RentingPoolDto.REDIS_PAY_RENTING + orderId, order, CommonCache.PAY_DEFAULT_EXPIRE_TIME);
+
+        return responseEntity;
+    }
+
+
+    private SmallWeChatDto getSmallWechat(IPageData pd, JSONObject paramIn) {
+
+        ResponseEntity responseEntity = null;
+
+        pd = PageData.newInstance().builder(pd.getUserId(), "", "", pd.getReqData(),
+                "", "", "", "",
+                pd.getAppId());
+        responseEntity = this.callCenterService(restTemplate, pd, "",
+                ServiceConstant.SERVICE_API_URL + "/api/smallWeChat.listSmallWeChats?appId="
+                        + paramIn.getString("appId") + "&page=1&row=1", HttpMethod.GET);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            return null;
+        }
+        JSONObject smallWechatObj = JSONObject.parseObject(responseEntity.getBody().toString());
+        JSONArray smallWeChats = smallWechatObj.getJSONArray("smallWeChats");
+
+        if (smallWeChats == null || smallWeChats.size() < 1) {
+            return null;
+        }
+
+        return BeanConvertUtil.covertBean(smallWeChats.get(0), SmallWeChatDto.class);
+    }
+
+
+}

+ 14 - 3
service-user/src/main/java/com/java110/user/api/RentingApi.java

@@ -13,7 +13,11 @@ import com.java110.user.bmo.rentingConfig.IDeleteRentingConfigBMO;
 import com.java110.user.bmo.rentingConfig.IGetRentingConfigBMO;
 import com.java110.user.bmo.rentingConfig.ISaveRentingConfigBMO;
 import com.java110.user.bmo.rentingConfig.IUpdateRentingConfigBMO;
-import com.java110.user.bmo.rentingPool.*;
+import com.java110.user.bmo.rentingPool.IAuditRentingBMO;
+import com.java110.user.bmo.rentingPool.IDeleteRentingPoolBMO;
+import com.java110.user.bmo.rentingPool.IGetRentingPoolBMO;
+import com.java110.user.bmo.rentingPool.ISaveRentingPoolBMO;
+import com.java110.user.bmo.rentingPool.IUpdateRentingPoolBMO;
 import com.java110.user.bmo.rentingPoolAttr.IDeleteRentingPoolAttrBMO;
 import com.java110.user.bmo.rentingPoolAttr.IGetRentingPoolAttrBMO;
 import com.java110.user.bmo.rentingPoolAttr.ISaveRentingPoolAttrBMO;
@@ -23,7 +27,12 @@ import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 
 @RestController
@@ -144,10 +153,12 @@ public class RentingApi {
     @RequestMapping(value = "/queryRentingConfig", method = RequestMethod.GET)
     public ResponseEntity<String> queryRentingConfig(
             @RequestParam(value = "page") int page,
-            @RequestParam(value = "row") int row) {
+            @RequestParam(value = "row") int row,
+            @RequestParam(value = "rentingConfigId", required = false) String rentingConfigId) {
         RentingConfigDto rentingConfigDto = new RentingConfigDto();
         rentingConfigDto.setPage(page);
         rentingConfigDto.setRow(row);
+        rentingConfigDto.setRentingConfigId(rentingConfigId);
         return getRentingConfigBMOImpl.get(rentingConfigDto);
     }