diff --git a/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java b/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java index 3cb1fb81..70516e34 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java @@ -224,7 +224,11 @@ public class OutRechargeOrderController { if (companyId != null) { map.put("companyId", companyId); } else if (userInfoModel.getSecRole().getRoleType() != 1){ - map.put("companyId", userInfoModel.getBsCompany().getId()); + if (userInfoModel.getSecRole().getRoleType() == 7) { + map.put("companyId", 23); + } else { + map.put("companyId", userInfoModel.getBsCompany().getId()); + } } map.put("rechargeStatus", rechargeStatus); map.put("payStatus", payStatus); diff --git a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java index b41cbc2f..3844e1fd 100644 --- a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java +++ b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java @@ -129,6 +129,12 @@ public enum ErrorCode { REQUEST_TIMED_OUT("3006","请求超时,请稍后重试"), SIGN_VERIFY("6001","签名校验失败"), + ACCOUNT_NOT_EXIST("6002","账号不存在"), + PHONE_ERROR("6003","手机号码格式有误"), + INSUFFICIENT_BALANCE("6006","账户余额不足,请及时充值"), + ORDER_ALREADY_EXISTS("6007","订单已存在"), + IP_ERROR("6008","IP不在白名单"), + PRODUCT_ERROR("6009","商品错误"), MSG_EVENT_NULL("2999","消息类型为空"), USE_VISIT_ILLEGAL("4001","用户身份错误"), diff --git a/hai-service/src/main/java/com/hai/service/ApiOpenService.java b/hai-service/src/main/java/com/hai/service/ApiOpenService.java new file mode 100644 index 00000000..215b3ee0 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/ApiOpenService.java @@ -0,0 +1,24 @@ +package com.hai.service; + +import com.alibaba.fastjson.JSONObject; + +/** + * @serviceName ApiOpenService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // api开发接口 + * @createTime 17:29 2022/6/10 + **/ +public interface ApiOpenService { + + /** + * @Author Sum1Dream + * @name createOrder.java + * @Description // 充值预下单 + * @Date 17:31 2022/6/10 + * @Param [com.alibaba.fastjson.JSONObject] + * @return com.alibaba.fastjson.JSONObject + */ + JSONObject createOrder(JSONObject object); + +} diff --git a/hai-service/src/main/java/com/hai/service/ApiProductService.java b/hai-service/src/main/java/com/hai/service/ApiProductService.java index f3cdc626..fef16861 100644 --- a/hai-service/src/main/java/com/hai/service/ApiProductService.java +++ b/hai-service/src/main/java/com/hai/service/ApiProductService.java @@ -86,4 +86,14 @@ public interface ApiProductService { * @return com.hai.entity.ApiProductConfig */ ApiProductConfig findProductConfigById(Long id); + + /** + * @Author Sum1Dream + * @name findMchProduct.java + * @Description // 查询商户商品 + * @Date 17:38 2022/6/10 + * @Param [java.util.Map] + * @return com.hai.entity.ApiProductConfig + */ + ApiProductConfig findMchProduct(Map map); } diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java new file mode 100644 index 00000000..8ea3e303 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java @@ -0,0 +1,58 @@ +package com.hai.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.entity.ApiMerchants; +import com.hai.entity.ApiOrderRecord; +import com.hai.entity.ApiProduct; +import com.hai.service.ApiMerchantsService; +import com.hai.service.ApiOpenService; +import com.hai.service.ApiOrderRecordService; +import com.hai.service.ApiProductService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@Service("apiOpenService") +public class ApiOpenServiceImpl implements ApiOpenService { + + @Resource + private ApiOrderRecordService apiOrderRecordService; + + @Resource + private ApiMerchantsService apiMerchantsService; + + @Resource + private ApiProductService apiProductService; + + @Override + @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) + public JSONObject createOrder(JSONObject object) { + + Map orderMap = new HashMap<>(); + orderMap.put("sourceOrderNo" , object.getString("orderNo")); + + // 查询是否用重复订单 + ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(orderMap); + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiOrderRecord != null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_ALREADY_EXISTS); + } + + ApiProduct apiProduct = apiProductService.findById(object.getLong("goodsId")); + // 当前账号余额是否可以充值当前金额 +// if (apiMerchants.getAmounts().compareTo(apiProduct.)) + + + return null; + } +} diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java index 07a148a8..e15491b5 100644 --- a/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java @@ -6,6 +6,7 @@ import com.hai.entity.ApiOrderRecordExample; import com.hai.service.ApiOrderRecordService; import com.itextpdf.text.pdf.qrcode.MaskUtil; import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -25,8 +26,12 @@ public class ApiOrderRecordServiceImpl implements ApiOrderRecordService { ApiOrderRecordExample example = new ApiOrderRecordExample(); ApiOrderRecordExample.Criteria criteria = example.createCriteria(); - criteria.andSourceOrderNoEqualTo(MapUtils.getString(map , "sourceOrderNo")); - criteria.andMchIdEqualTo(MapUtils.getString(map , "merchId")); + if (StringUtils.isNotBlank(MapUtils.getString(map , "sourceOrderNo"))) { + criteria.andSourceOrderNoEqualTo(MapUtils.getString(map , "sourceOrderNo")); + } + if (StringUtils.isNotBlank(MapUtils.getString(map , "merchId"))) { + criteria.andMchIdEqualTo(MapUtils.getString(map , "merchId")); + } List list = apiOrderRecordMapper.selectByExample(example); diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java index 1efd8890..47662bb5 100644 --- a/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java @@ -138,4 +138,26 @@ public class ApiProductServiceImpl implements ApiProductService { public void updateConfigApiProduct(ApiProductConfig apiProductConfig) { apiProductConfigMapper.updateByPrimaryKey(apiProductConfig); } + + @Override + public ApiProductConfig findMchProduct(Map map) { + ApiProductConfigExample example = new ApiProductConfigExample(); + ApiProductConfigExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map , "merchantsId") != null) { + criteria.andMerchantsIdEqualTo(MapUtils.getLong(map , "merchantsId")); + } + if (MapUtils.getLong(map , "productId") != null) { + criteria.andProductIdEqualTo(MapUtils.getLong(map , "productId")); + } + + List list = apiProductConfigMapper.selectByExample(example); + + if (list.size() > 0) { + return list.get(0); + } else { + return null; + } + + } } diff --git a/v1/src/main/java/com/v1/controller/RechargeProductController.java b/v1/src/main/java/com/v1/controller/RechargeProductController.java index 16d80ced..b7a0cae6 100644 --- a/v1/src/main/java/com/v1/controller/RechargeProductController.java +++ b/v1/src/main/java/com/v1/controller/RechargeProductController.java @@ -5,10 +5,7 @@ import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.ResponseMsgUtil; -import com.hai.entity.ApiMerchants; -import com.hai.entity.ApiOrderRecord; -import com.hai.entity.HighUser; -import com.hai.entity.OutRechargeOrder; +import com.hai.entity.*; import com.hai.model.ResponseData; import com.hai.service.*; import io.swagger.annotations.Api; @@ -51,6 +48,9 @@ public class RechargeProductController { @Resource private ApiOrderRecordService apiOrderRecordService; + @Resource + private ApiProductService apiProductService; + @RequestMapping(value = "/getRechargeProduct", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "获取充值产品") @@ -67,7 +67,7 @@ public class RechargeProductController { if (!secConfigService.isConfig("IP_WHITE" , ip)) { log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); } if (object.getString("apiKey") == null || @@ -79,11 +79,11 @@ public class RechargeProductController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); } - ApiMerchants apiMerchants = apiMerchantsService.findById(object.getLong("merchId")); + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); if (apiMerchants == null) { - log.error("getRechargeProduct error!", "商户号错误!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户号错误!"); + log.error("getRechargeProduct error!", "错误商户,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } Map map = new HashMap<>(); @@ -121,7 +121,7 @@ public class RechargeProductController { if (!secConfigService.isConfig("IP_WHITE" , ip)) { log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); } if (object.getString("apiKey") == null || @@ -132,11 +132,11 @@ public class RechargeProductController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); } - ApiMerchants apiMerchants = apiMerchantsService.findById(object.getLong("merchId")); + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); if (apiMerchants == null) { log.error("getRechargeProduct error!", "商户号错误!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户号错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } Map map = new HashMap<>(); @@ -173,7 +173,7 @@ public class RechargeProductController { if (!secConfigService.isConfig("IP_WHITE" , ip)) { log.error("getRechargeProduct error!", "非法ip地址,请联系管理人员!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); } if (object.getString("apiKey") == null || @@ -186,11 +186,11 @@ public class RechargeProductController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); } - ApiMerchants apiMerchants = apiMerchantsService.findById(object.getLong("merchId")); + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); if (apiMerchants == null) { log.error("getRechargeProduct error!", "商户号错误!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户号错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); } Map map = new HashMap<>(); @@ -231,4 +231,76 @@ public class RechargeProductController { return ResponseMsgUtil.exception(e); } } + + + @RequestMapping(value = "/createOrder", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "充值预下单") + public ResponseData createOrder(@RequestBody JSONObject object , HttpServletRequest request ) { + try { + + String ip = ""; + // 有的user可能使用代理,为处理用户使用代理的情况,使用x-forwarded-for + if (request.getHeader("x-forwarded-for") == null) { + ip = request.getRemoteAddr(); + } else { + ip = request.getHeader("x-forwarded-for"); + } + + if (!secConfigService.isConfig("IP_WHITE" , ip)) { + log.error("createOrder error!", "非法ip地址,请联系管理人员!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.IP_ERROR, "非法ip地址,请联系管理人员!"); + } + + if (object.getString("mobile") == null || + object.getString("goodsId") == null || + object.getString("appKey") == null || + object.getString("orderNo") == null || + object.getString("notifyUrl") == null || + object.getString("sign") == null || + object.getString("merchId") == null + ) { + log.error("createOrder error!", "请求参数校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR); + } + + ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId")); + + if (apiMerchants == null) { + log.error("createOrder error!", "商户错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_NOT_EXIST); + } + + Map productMap = new HashMap<>(); + + productMap.put("productId" , object.getString("goodsId")); + productMap.put("merchantsId" , apiMerchants.getId()); + + if (apiProductService.findMchProduct(productMap) == null) { + log.error("createOrder error!", " 商品错误!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.PRODUCT_ERROR); + } + + Map map = new HashMap<>(); + map.put("mobile" , object.getString("mobile")); + map.put("goodsId" , object.getString("goodsId")); + map.put("orderNo" , object.getString("orderNo")); + map.put("notifyUrl" , object.getString("notifyUrl")); + map.put("apiKey" , object.getString("apiKey")); + map.put("merchId" , object.getString("merchId")); + map.put("sign" , object.getString("sign")); + + if (!secConfigService.isSignVerify(map)) { + log.error("createOrder error!", "签名校验失败!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.SIGN_VERIFY); + } + + return ResponseMsgUtil.success(apiMerchants.getAmounts()); + + } catch (Exception e) { + log.error("HighOpenApiController --> createOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } + }