diff --git a/hai-bweb/src/main/java/com/bweb/controller/ApiMerchantsController.java b/hai-bweb/src/main/java/com/bweb/controller/ApiMerchantsController.java new file mode 100644 index 00000000..5248a48f --- /dev/null +++ b/hai-bweb/src/main/java/com/bweb/controller/ApiMerchantsController.java @@ -0,0 +1,281 @@ +package com.bweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.security.SessionObject; +import com.hai.common.security.UserCenter; +import com.hai.common.utils.*; +import com.hai.entity.ApiMerchants; +import com.hai.entity.ApiProduct; +import com.hai.enum_type.ApiAmountRecordTypeEnum; +import com.hai.enum_type.CompanyAmountSourceTypeEnum; +import com.hai.model.HighMerchantModel; +import com.hai.model.ResponseData; +import com.hai.model.UserInfoModel; +import com.hai.service.ApiMerchantsService; +import com.hai.service.ApiProductService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DeadlockLoserDataAccessException; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Controller +@RequestMapping(value = "/apiMerchants") +@Api(value = "api商户") +public class ApiMerchantsController { + + Logger log = LoggerFactory.getLogger(ApiProductController.class); + + @Resource + private ApiMerchantsService apiMerchantsService; + + @Autowired + private UserCenter userCenter; + + @Resource + private RedisUtil redisUtil; + + @RequestMapping(value = "/getListApiMerchant", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询产品列表") + public ResponseData getListApiMerchant( + @RequestParam(value = "merchantName", required = false) String merchantName, + @RequestParam(value = "mchId", required = false) String mchId, + @RequestParam(value = "phone", required = false) String phone, + @RequestParam(value = "status", required = false) Integer status, + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request + ) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + Map map = new HashMap<>(); + + map.put("merchantName", merchantName); + map.put("phone", phone); + map.put("mchId", mchId); + map.put("status", status); + + PageHelper.startPage(pageNum,pageSize); + + List list = apiMerchantsService.getListApiMerchants(map); + return ResponseMsgUtil.success(new PageInfo<>(list)); + + } catch (Exception e) { + log.error("ApiMerchantsController --> getListUser() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getListApiMerchantByAll", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询所以可用商户列表") + public ResponseData getListApiMerchantByAll(HttpServletRequest request) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + Map map = new HashMap<>(); + + map.put("status", 100); + + List list = apiMerchantsService.getListApiMerchants(map); + return ResponseMsgUtil.success(list); + + } catch (Exception e) { + log.error("ApiMerchantsController --> getListUser() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/insertMerchant",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "增加商户") + public ResponseData insertMerchant(@RequestBody ApiMerchants apiMerchants, HttpServletRequest request) { + try { + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + if (userInfoModel.getBsCompany() == null) { + log.error("HighMerchantController -> updateMerchant() error!","该主角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); + } + + if (StringUtils.isBlank(apiMerchants.getMerchantName()) + || StringUtils.isBlank(apiMerchants.getPhone()) + || StringUtils.isBlank(apiMerchants.getUserName()) + ) { + log.error("ApiMerchantsController -> insertMerchant() error!","参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + apiMerchants.setCreateTime(new Date()); + apiMerchants.setOperatorId(userInfoModel.getSecUser().getId()); + apiMerchants.setOperatorName(userInfoModel.getSecUser().getUserName()); + apiMerchants.setStatus(100); + apiMerchants.setAmounts(new BigDecimal(0)); + apiMerchants.setUpdateTime(new Date()); + apiMerchants.setMchId(DateUtil.date2String(new Date(), "yyyyMM") + IDGenerator.nextId(5)); + apiMerchants.setApiKey(WxUtils.MD5(apiMerchants.getMchId() , true)); + apiMerchantsService.insertApiMerchants(apiMerchants); + + return ResponseMsgUtil.success("新增成功"); + } catch (Exception e) { + log.error("ApiMerchantsController -> insertMerchant() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/updateMerchant",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "修改商户") + public ResponseData updateMerchant(@RequestBody ApiMerchants apiMerchants, HttpServletRequest request) { + try { + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + if (userInfoModel.getBsCompany() == null) { + log.error("ApiMerchantsController -> updateMerchant() error!","该主角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); + } + + ApiMerchants merchants = apiMerchantsService.findById(apiMerchants.getId()); + + if (StringUtils.isBlank(apiMerchants.getMerchantName()) + || StringUtils.isBlank(apiMerchants.getPhone()) + || StringUtils.isBlank(apiMerchants.getUserName()) + || apiMerchants.getId() == null + ) { + log.error("ApiMerchantsController -> insertMerchant() error!","参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + merchants.setOperatorId(userInfoModel.getSecUser().getId()); + merchants.setOperatorName(userInfoModel.getSecUser().getUserName()); + merchants.setUpdateTime(new Date()); + merchants.setMerchantName(apiMerchants.getMerchantName()); + merchants.setPhone(apiMerchants.getPhone()); + merchants.setUserName(apiMerchants.getUserName()); + apiMerchantsService.updateApiMerchants(merchants); + + return ResponseMsgUtil.success("修改成功"); + } catch (Exception e) { + log.error("HighMerchantController -> insertMerchant() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + + @RequestMapping(value = "/findById", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "根据id查询详情") + public ResponseData findById(@RequestParam(value = "id", required = true) Long id) { + try { + + return ResponseMsgUtil.success(apiMerchantsService.findById(id)); + + } catch (Exception e) { + log.error("ApiMerchantsController --> findById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/editMerchantsStatus", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "修改商户状态") + public ResponseData editMerchantsStatus(@RequestBody JSONObject object, HttpServletRequest request) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + ApiMerchants merchants = apiMerchantsService.findById(object.getLong("id")); + + merchants.setStatus(object.getInteger("status")); + merchants.setOperatorName(userInfoModel.getSecUser().getUserName()); + merchants.setOperatorId(userInfoModel.getSecUser().getId()); + apiMerchantsService.updateApiMerchants(merchants); + + return ResponseMsgUtil.success("修改成功"); + + } catch (Exception e) { + log.error("ApiMerchantsController --> editPriceStatus() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + + @RequestMapping(value = "/recharge", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "余额充值") + public synchronized ResponseData recharge(@RequestBody JSONObject body) { + try { + + if (body.getLong("merchantId") == null + || body.getBigDecimal("amount") == null + || StringUtils.isBlank(body.getString("smsCode"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + if (body.getBigDecimal("amount").compareTo(new BigDecimal("0")) < 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "充值金额不能小于0"); + } + + if (redisUtil.get("COMPANY_AMOUNT_RECHARGE_SMS_CODE") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); + } + if (!redisUtil.get("COMPANY_AMOUNT_RECHARGE_SMS_CODE").toString().equals(body.getString("smsCode"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); + } + + Map map = new HashMap<>(); + map.put("sourceType", ApiAmountRecordTypeEnum.type1.getType()); + map.put("sourceContent", "充值金额:" + body.getBigDecimal("amount") + " 元"); + apiMerchantsService.recharge(body.getLong("merchantId"), body.getBigDecimal("amount"), map); + + return ResponseMsgUtil.success("操作成功"); + + } catch (DeadlockLoserDataAccessException deadlockLoserDataAccessException) { + log.error("ApiMerchantsController -> userLottery() error!", "服务器繁忙"); + return ResponseMsgUtil.builderResponse(ErrorCode.SERVER_BUSY_ERROR.getCode(),ErrorCode.SERVER_BUSY_ERROR.getMsg(),null); + + } catch (Exception e) { + log.error("ApiMerchantsController --> recharge() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getMerchRechargeData", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询商户充值记录") + public ResponseData getMerchRechargeData(@RequestParam(value = "merchantId", required = true) Long merchantId) { + try { + + return ResponseMsgUtil.success(apiMerchantsService.getMerchRechargeData(merchantId)); + + } catch (Exception e) { + log.error("ApiMerchantsController --> findById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/hai-bweb/src/main/java/com/bweb/controller/ApiProductController.java b/hai-bweb/src/main/java/com/bweb/controller/ApiProductController.java new file mode 100644 index 00000000..7d1f5d3c --- /dev/null +++ b/hai-bweb/src/main/java/com/bweb/controller/ApiProductController.java @@ -0,0 +1,256 @@ +package com.bweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.security.SessionObject; +import com.hai.common.security.UserCenter; +import com.hai.common.utils.PageUtil; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.ApiProduct; +import com.hai.entity.BsOperationLog; +import com.hai.entity.HighAgent; +import com.hai.entity.OutRechargePrice; +import com.hai.model.OutRechargePriceModel; +import com.hai.model.ResponseData; +import com.hai.model.UserInfoModel; +import com.hai.service.ApiProductService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.util.*; + +@Controller +@RequestMapping(value = "/apiProduct") +@Api(value = "api产品") +public class ApiProductController { + + Logger log = LoggerFactory.getLogger(ApiProductController.class); + + @Resource + private ApiProductService apiProductService; + + @Autowired + private UserCenter userCenter; + + @RequestMapping(value = "/getListApiProduct", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询产品列表") + public ResponseData getListApiProduct( + @RequestParam(value = "operatorType", required = false) Integer operatorType, + @RequestParam(value = "rechargePlatform", required = false) Integer rechargePlatform, + @RequestParam(value = "phoneRechargeType", required = false) Integer phoneRechargeType, + @RequestParam(value = "status", required = false) Integer status, + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request + ) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + Map map = new HashMap<>(); + + map.put("operatorType", operatorType); + map.put("rechargePlatform", "-" + rechargePlatform + "-"); + map.put("phoneRechargeType", phoneRechargeType); + map.put("status", status); + + PageHelper.startPage(pageNum,pageSize); + PageHelper.startPage(pageNum, pageSize); + + List list = apiProductService.getListApiProduct(map); + return ResponseMsgUtil.success(new PageInfo<>(list)); + + } catch (Exception e) { + log.error("OutRechargePriceController --> getListUser() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + + @RequestMapping(value = "/insertProduct", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "新增产品") + public ResponseData insertProduct(@RequestBody JSONObject object, HttpServletRequest request) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + if (object == null || + object.getJSONArray("prices") == null || + object.getInteger("operatorType") == null || + object.getJSONArray("rechargePlatform") == null || + object.getInteger("phoneRechargeType") == null + ) { + log.error("ApiProductController -> insertProduct() error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + + object.put("operatorId", userInfoModel.getSecUser().getId()); + object.put("operatorName", userInfoModel.getSecUser().getLoginName()); + + apiProductService.insertApiProduct(object); + + return ResponseMsgUtil.success("新增成功"); + + } catch (Exception e) { + log.error("ApiProductController --> insertPrice() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/updateProduct", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "修改产品") + public ResponseData updateProduct(@RequestBody JSONObject object, HttpServletRequest request) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + if (object == null || + object.getLong("id") == null || + object.getInteger("operatorType") == null || + object.getJSONArray("rechargePlatform") == null || + object.getInteger("phoneRechargeType") == null + ) { + log.error("ApiProductController -> updateProduct() error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + ApiProduct apiProduct = apiProductService.findById(object.getLong("id")); + + if (apiProduct.getStatus() != 102) { + log.error("ApiProductController -> updateProduct() error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态错误"); + } + + apiProduct.setOperatorId(userInfoModel.getSecUser().getId()); + apiProduct.setOperatorName(userInfoModel.getSecUser().getLoginName()); + apiProduct.setRechargeType(object.getInteger("rechargeType")); + apiProduct.setPhoneRechargeType(object.getInteger("phoneRechargeType")); + apiProduct.setOperatorType(object.getInteger("operatorType")); + apiProduct.setRechargePlatform("-" + StringUtils.join(object.getJSONArray("rechargePlatform"), "-") + "-"); + apiProduct.setUpdateTime(new Date()); + apiProduct.setSort(object.getInteger("sort")); + apiProduct.setProductId(object.getLong("productId")); + apiProduct.setOperatorName(object.getString("operatorName")); + apiProduct.setOperatorId(object.getLong("operatorId")); + + apiProductService.updateApiProduct(apiProduct); + + return ResponseMsgUtil.success("新增成功"); + + } catch (Exception e) { + log.error("ApiProductController --> insertPrice() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/editProductStatus", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "修改产品状态") + public ResponseData editProductStatus(@RequestBody JSONObject object, HttpServletRequest request) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + ApiProduct apiProduct = apiProductService.findById(object.getLong("id")); + + if (object.getInteger("status") == 101 && apiProduct.getRechargePlatform().contains("-2-") && apiProduct.getProductId() == null) { + log.error("ApiProductController -> editProductStatus() error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "龙阅平台需要输入商品编码!"); + } + + apiProduct.setStatus(object.getInteger("status")); + apiProduct.setOperatorName(userInfoModel.getSecUser().getUserName()); + apiProduct.setOperatorId(userInfoModel.getSecUser().getId()); + apiProductService.updateApiProduct(apiProduct); + + + return ResponseMsgUtil.success("修改成功"); + + } catch (Exception e) { + log.error("ApiProductController --> editPriceStatus() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/findById", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "根据id查询详情") + public ResponseData findById(@RequestParam(value = "id", required = true) Long id) { + try { + + return ResponseMsgUtil.success(apiProductService.findById(id)); + + } catch (Exception e) { + log.error("OutRechargePriceController --> findById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getAvailableApiProductByList", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询可用产品列表") + public ResponseData getAvailableApiProductByList( + HttpServletRequest request + ) { + try { + + Map map = new HashMap<>(); + map.put("rechargeType", 1); + map.put("status", 101); + + List list = apiProductService.getListApiProduct(map); + return ResponseMsgUtil.success(list); + + } catch (Exception e) { + log.error("OutRechargePriceController --> getListUser() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/configApiProduct", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "配置产品") + public ResponseData configApiProduct(@RequestBody JSONObject object) { + try { + + if (object == null || + object.getJSONArray("productIds") == null || + object.getInteger("discount") == null || + object.getLong("merchantsId") == null + ) { + log.error("ApiProductController -> configApiProduct() error!"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + apiProductService.configApiProduct(object); + + return ResponseMsgUtil.success("新增成功"); + + } catch (Exception e) { + log.error("ApiProductController --> insertPrice() error!", e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java b/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java index 6f884edc..2b0036f6 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java @@ -149,7 +149,7 @@ public class HighOpenApiController { String token = huiLianTongConfig.getToken(); // 查询电子卡券类型 - JSONObject data = HuiLianTongConfig.getCouState(token, object.getString("orderNo")); + JSONObject data = HuiLianTongConfig.getCouState(token, object.getString("couNo")); if (!data.getString("result").equals("success")) { log.error("HighOpenApiController -> insertCoupon() error!","查询电子券状态失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询电子券状态失败"); diff --git a/hai-bweb/src/main/java/com/bweb/controller/SendSmsController.java b/hai-bweb/src/main/java/com/bweb/controller/SendSmsController.java index 51d8eeac..95e1762a 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/SendSmsController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/SendSmsController.java @@ -10,9 +10,12 @@ import com.hai.common.security.VerifyCodeStorage; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.RedisUtil; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.config.MessageConfig; +import com.hai.entity.ApiMerchants; import com.hai.entity.BsOrganization; import com.hai.model.MtSmsMessageModel; import com.hai.model.ResponseData; +import com.hai.service.ApiMerchantsService; import com.hai.service.BsCompanyService; import com.hai.service.BsOrganizationService; import io.swagger.annotations.Api; @@ -47,6 +50,12 @@ public class SendSmsController { private static Logger log = LoggerFactory.getLogger(CmsContentController.class); + @Resource + private MessageConfig messageConfig; + + @Resource + private ApiMerchantsService apiMerchantsService; + /** * 设置不验证主机 */ @@ -202,4 +211,91 @@ public class SendSmsController { sc.init(null, trustAllCerts, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } + + @RequestMapping(value = "/sendRechargeSmsCodeByMchId", method = RequestMethod.GET) + @ApiOperation(value = "发送充值短信验证码") + @ResponseBody + public ResponseData sendRechargeSmsCodeByMchId(@RequestParam(value = "phone", required = true) String phone, + @RequestParam(value = "merchantId", required = true) Long merchantId, + @RequestParam(value = "price", required = true) BigDecimal price) { + try { + // 查询部门信息 + ApiMerchants apiMerchants = apiMerchantsService.findById(merchantId); + if (apiMerchants == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户信息"); + } + + String smsCode = String.valueOf(new Random().nextInt(899999) + 100000); + + // ip:port根据实际情况填写 + String url = "https://139.9.32.119:18312/common/sms/sendTemplateMessage"; + String smsTemplateId = "SMS_22041400005"; + Map templateParas = new HashMap(); + templateParas.put("name", apiMerchants.getMerchantName()); + templateParas.put("price", "¥" + price.toString()); + templateParas.put("code", smsCode); + String account = "760887"; //实际账号 + String password = "Z.o'&mO%7_?5M,Br"; //实际密码 + + // If the request body does not contain the signature name, set signature to null. + Map body = buildRequestBody(phone, smsTemplateId, templateParas, account, password); + if (null == body || body.isEmpty()) { + return ResponseMsgUtil.success(""); + } + + HttpsURLConnection connection = null; + InputStream is = null; + BufferedReader br = null; + trustAllHttpsCertificates(); + try { + URL realUrl = new URL(url); + connection = (HttpsURLConnection) realUrl.openConnection(); + connection.setHostnameVerifier(DO_NOT_VERIFY); + connection.setDoInput(true); // 设置可输入 + connection.setDoOutput(true); // 设置该连接是可以输出的 + connection.setRequestMethod("POST"); // 设置请求方式 + connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); + // connection.connect(); + ObjectMapper objectMapper = new ObjectMapper(); + PrintWriter pw = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); + pw.write(objectMapper.writeValueAsString(body)); + pw.flush(); + pw.close(); + + br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); + int status = connection.getResponseCode(); + if (200 == status) { // 200 + is = connection.getInputStream(); + } else { // 400/401 + is = connection.getErrorStream(); + } + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + String line = null; + StringBuilder result = new StringBuilder(); + while ((line = br.readLine()) != null) { // 读取数据 + result.append(line + ""); + } + connection.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (null != is) { + is.close(); + } + if (null != br) { + br.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + redisUtil.set("COMPANY_AMOUNT_RECHARGE_SMS_CODE",smsCode, 60*5); + return ResponseMsgUtil.success("发送成功"); + + } catch (Exception e) { + log.error("CmsContentController --> sendSmsCode() error!", e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java index 1f708f70..6fbc5353 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java @@ -133,7 +133,10 @@ public class OutRechargeOrderController { Map map = new HashMap<>(); map.put("userId", userInfoModel.getHighUser().getId().toString()); - map.put("payStatus", status.toString()); + if (status != null) { + map.put("payStatus", status.toString()); + } + map.put("orderNo", orderNo); PageHelper.startPage(pageNum, pageSize); diff --git a/hai-service/src/main/java/com/hai/dao/HighCompanyAccountMapper.java b/hai-service/src/main/java/com/hai/dao/HighCompanyAccountMapper.java index 12230ff7..ec74c86f 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCompanyAccountMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighCompanyAccountMapper.java @@ -119,4 +119,4 @@ public interface HighCompanyAccountMapper extends HighCompanyAccountMapperExt { "where id = #{id,jdbcType=BIGINT}" }) int updateByPrimaryKey(HighCompanyAccount record); -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java b/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java index 8cbe6204..da3277e6 100644 --- a/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java +++ b/hai-service/src/main/java/com/hai/entity/ApiAmountRecord.java @@ -45,7 +45,7 @@ public class ApiAmountRecord implements Serializable { private String mchId; /** - * 100:充值金额 101:订单退款 102 话费消费 + * 1:充值金额 2:订单退款 3 话费消费 */ private Integer sourceType; @@ -335,4 +335,4 @@ public class ApiAmountRecord implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/enum_type/ApiAmountRecordTypeEnum.java b/hai-service/src/main/java/com/hai/enum_type/ApiAmountRecordTypeEnum.java new file mode 100644 index 00000000..4fec2f51 --- /dev/null +++ b/hai-service/src/main/java/com/hai/enum_type/ApiAmountRecordTypeEnum.java @@ -0,0 +1,42 @@ +package com.hai.enum_type; + +/** + * @serviceName ApiAmountRecordTypeEnum.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // api金额记录类型 + * @createTime 10:28 2022/6/8 + **/ +public enum ApiAmountRecordTypeEnum { + + type1(1, "金额充值"), + type2(2, "订单退款"), + type3(3, "话费消费") + ; + + private Integer type; + + private String name; + + ApiAmountRecordTypeEnum(int type, String name) { + this.type = type; + this.name = name; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/hai-service/src/main/java/com/hai/service/ApiMerchantsService.java b/hai-service/src/main/java/com/hai/service/ApiMerchantsService.java new file mode 100644 index 00000000..11db0ffc --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/ApiMerchantsService.java @@ -0,0 +1,81 @@ +package com.hai.service; + +import com.alibaba.fastjson.JSONObject; +import com.hai.entity.ApiAmountRecord; +import com.hai.entity.ApiMerchants; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @serviceName ApiMerchantsService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // api商户接口 + * @createTime 17:31 2022/6/7 + **/ +public interface ApiMerchantsService { + + /** + * @Author Sum1Dream + * @name insertApiMerchants.java + * @Description // 新增api商户 + * @Date 14:55 2022/6/7 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void insertApiMerchants(ApiMerchants apiMerchants); + + /** + * @Author Sum1Dream + * @name updateApiMerchants.java + * @Description // 修改api商户 + * @Date 14:56 2022/6/7 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void updateApiMerchants(ApiMerchants apiMerchants); + + /** + * @Author Sum1Dream + * @name getListApiMerchants.java + * @Description // 查询api商户列表 + * @Date 14:57 2022/6/7 + * @Param [java.util.Map] + * @return java.util.List + */ + List getListApiMerchants(Map map); + + /** + * @Author Sum1Dream + * @name findById.java + * @Description // 根据id 查询api商户 + * @Date 15:24 2022/6/7 + * @Param [java.lang.Long] + * @return com.hai.entity.ApiMerchants + */ + ApiMerchants findById(Long id); + + /** + * @Author Sum1Dream + * @name recharge.java + * @Description // 进账 + * @Date 10:33 2022/6/8 + * @Param [java.lang.Long, java.math.BigDecimal, java.util.Map] + * @return void + */ + void recharge(Long merchantId, BigDecimal amount, Map otherParam); + + /** + * @Author Sum1Dream + * @name getMerchRechargeData.java + * @Description // 查询商户充值记录 + * @Date 15:14 2022/6/8 + * @Param [java.lang.Long] + * @return java.util.List + */ + List getMerchRechargeData(Long merchantId); + + +} diff --git a/hai-service/src/main/java/com/hai/service/ApiProductService.java b/hai-service/src/main/java/com/hai/service/ApiProductService.java new file mode 100644 index 00000000..702073ce --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/ApiProductService.java @@ -0,0 +1,68 @@ +package com.hai.service; + +import com.alibaba.fastjson.JSONObject; +import com.hai.entity.ApiProduct; +import io.swagger.annotations.Api; + +import java.util.List; +import java.util.Map; + +/** + * @serviceName ApiProductService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // Api产品配置 + * @createTime 14:54 2022/6/7 + **/ +public interface ApiProductService { + + /** + * @Author Sum1Dream + * @name insertApiProduct.java + * @Description // 新增api产品 + * @Date 14:55 2022/6/7 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void insertApiProduct(JSONObject object); + + /** + * @Author Sum1Dream + * @name updateApiProduct.java + * @Description // 修改api产品 + * @Date 14:56 2022/6/7 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void updateApiProduct(ApiProduct apiProduct); + + /** + * @Author Sum1Dream + * @name getListApiProduct.java + * @Description // 查询api产品列表 + * @Date 14:57 2022/6/7 + * @Param [java.util.Map] + * @return java.util.List + */ + List getListApiProduct(Map map); + + /** + * @Author Sum1Dream + * @name findById.java + * @Description // 根据id 查询api产品 + * @Date 15:24 2022/6/7 + * @Param [java.lang.Long] + * @return com.hai.entity.ApiProduct + */ + ApiProduct findById(Long id); + + /** + * @Author Sum1Dream + * @name insertApiProduct.java + * @Description // 配置产品api产品 + * @Date 14:55 2022/6/7 + * @Param [com.alibaba.fastjson.JSONObject] + * @return void + */ + void configApiProduct(JSONObject object); +} diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiMerchantsServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiMerchantsServiceImpl.java new file mode 100644 index 00000000..9906d362 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/ApiMerchantsServiceImpl.java @@ -0,0 +1,137 @@ +package com.hai.service.impl; + +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.security.UserCenter; +import com.hai.common.utils.RedisUtil; +import com.hai.dao.ApiAmountRecordMapper; +import com.hai.dao.ApiMerchantsMapper; +import com.hai.entity.*; +import com.hai.model.UserInfoModel; +import com.hai.service.ApiMerchantsService; +import org.apache.commons.collections4.MapUtils; +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.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Service("apiMerchantsService") +public class ApiMerchantsServiceImpl implements ApiMerchantsService { + + @Resource + private ApiMerchantsMapper apiMerchantsMapper; + + @Resource + private UserCenter userCenter; + + @Resource + private RedisUtil redisUtil; + + @Resource + private ApiAmountRecordMapper apiAmountRecordMapper; + + @Override + public void insertApiMerchants(ApiMerchants apiMerchants) { + apiMerchantsMapper.insert(apiMerchants); + } + + @Override + public void updateApiMerchants(ApiMerchants apiMerchants) { + apiMerchantsMapper.updateByPrimaryKey(apiMerchants); + } + + @Override + public List getListApiMerchants(Map map) { + ApiMerchantsExample example = new ApiMerchantsExample(); + ApiMerchantsExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getString(map, "merchantName") != null) { + criteria.andMerchantNameLike("%" + MapUtils.getString(map, "merchantName") + "%"); + } + if (MapUtils.getString(map, "phone") != null) { + criteria.andPhoneEqualTo(MapUtils.getString(map, "phone")); + } + if (MapUtils.getString(map, "mchId") != null) { + criteria.andMchIdEqualTo(MapUtils.getString(map, "mchId")); + } + + if (MapUtils.getLong(map, "status") != null) { + criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); + } + return apiMerchantsMapper.selectByExample(example); + } + + @Override + public ApiMerchants findById(Long id) { + return apiMerchantsMapper.selectByPrimaryKey(id); + } + + @Override + @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) + public void recharge(Long merchantId, BigDecimal amount, Map otherParam) { + + // 查询商户 + ApiMerchants apiMerchants = apiMerchantsMapper.selectByPrimaryKey(merchantId); + if (apiMerchants == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); + } + // 操作人 + UserInfoModel sessionModel = userCenter.getSessionModel(UserInfoModel.class); + if (sessionModel == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知用户"); + } + if ( sessionModel.getSecRole().getRoleType() != 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "权限不足"); + } + if (apiMerchants.getStatus() != 100) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户被禁用"); + } + + // 变更前金额 + BigDecimal beforeAmount = apiMerchants.getAmounts(); + // 计算金额 + apiMerchants.setAmounts(apiMerchants.getAmounts().add(amount)); + // 变更后金额 + BigDecimal afterAmount = apiMerchants.getAmounts(); + + updateApiMerchants(apiMerchants); + + ApiAmountRecord apiAmountRecord = new ApiAmountRecord(); + + apiAmountRecord.setCreateTime(new Date()); + apiAmountRecord.setUpdateTime(new Date()); + apiAmountRecord.setMchId(apiMerchants.getMchId()); + apiAmountRecord.setOperatorId(sessionModel.getSecUser().getId()); + apiAmountRecord.setOperatorName(sessionModel.getSecUser().getUserName()); + apiAmountRecord.setStatus(100); + apiAmountRecord.setAmount(amount); + apiAmountRecord.setAfterAmount(afterAmount); + apiAmountRecord.setBeforeAmount(beforeAmount); + apiAmountRecord.setAmountType(1); + apiAmountRecord.setSourceType(MapUtils.getInteger(otherParam, "sourceType")); + apiAmountRecord.setSourceId(MapUtils.getLong(otherParam, "sourceId")); + apiAmountRecord.setSourceContent(apiMerchants.getMerchantName() + MapUtils.getString(otherParam, "sourceContent")); + + apiAmountRecordMapper.insert(apiAmountRecord); + + redisUtil.del("COMPANY_AMOUNT_RECHARGE_SMS_CODE"); + + } + + @Override + public List getMerchRechargeData(Long merchantId) { + + ApiMerchants apiMerchants = apiMerchantsMapper.selectByPrimaryKey(merchantId); + + ApiAmountRecordExample example = new ApiAmountRecordExample(); + example.createCriteria().andMchIdEqualTo(apiMerchants.getMchId()); + return apiAmountRecordMapper.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 new file mode 100644 index 00000000..b28ff8a8 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/ApiProductServiceImpl.java @@ -0,0 +1,128 @@ +package com.hai.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hai.common.security.UserCenter; +import com.hai.dao.ApiProductConfigMapper; +import com.hai.dao.ApiProductMapper; +import com.hai.entity.*; +import com.hai.model.UserInfoModel; +import com.hai.service.ApiProductService; +import com.hai.service.CommonService; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Service("apiProductService") +public class ApiProductServiceImpl implements ApiProductService { + + @Resource + private CommonService commonService; + + @Resource + private ApiProductMapper apiProductMapper; + + @Resource + private UserCenter userCenter; + + @Resource + private ApiProductConfigMapper apiProductConfigMapper; + + @Override + public void insertApiProduct(JSONObject object) { + // 转换金额数组 + JSONArray priceArray = object.getJSONArray("prices"); + + // api产品 + ApiProduct apiProduct; + + for (Object price : priceArray) { + SecDictionary dictionary = commonService.mappingSysCode("RECHARGE_AMOUNT", String.valueOf(price)); + BigDecimal priceBd = new BigDecimal(dictionary.getCodeName()); + apiProduct = new ApiProduct(); + apiProduct.setRechargePrice(priceBd); + apiProduct.setRechargeType(object.getInteger("rechargeType")); + apiProduct.setPhoneRechargeType(object.getInteger("phoneRechargeType")); + apiProduct.setOperatorType(object.getInteger("operatorType")); + apiProduct.setRechargePlatform("-" + StringUtils.join(object.getJSONArray("rechargePlatform"), "-") + "-"); + apiProduct.setCreateTime(new Date()); + apiProduct.setUpdateTime(new Date()); + apiProduct.setStatus(102); + apiProduct.setSort(1); + apiProduct.setRechargeType(1); + apiProduct.setOperatorName(object.getString("operatorName")); + apiProduct.setOperatorId(object.getLong("operatorId")); + apiProductMapper.insert(apiProduct); + } + + } + + @Override + public void updateApiProduct(ApiProduct apiProduct) { + apiProductMapper.updateByPrimaryKeySelective(apiProduct); + } + + @Override + public List getListApiProduct(Map map) { + ApiProductExample example = new ApiProductExample(); + ApiProductExample.Criteria criteria = example.createCriteria(); + + + if (MapUtils.getLong(map, "rechargePlatform") != null) { + criteria.andRechargePlatformLike("%" + MapUtils.getLong(map, "rechargePlatform") + "%"); + } + if (MapUtils.getLong(map, "rechargeType") != null) { + criteria.andRechargeTypeEqualTo(MapUtils.getInteger(map, "rechargeType")); + } + if (MapUtils.getLong(map, "operatorType") != null) { + criteria.andOperatorTypeEqualTo(MapUtils.getInteger(map, "operatorType")); + } + if (MapUtils.getLong(map, "phoneRechargeType") != null) { + criteria.andPhoneRechargeTypeEqualTo(MapUtils.getInteger(map, "phoneRechargeType")); + } + if (MapUtils.getLong(map, "status") != null) { + criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); + } else { + criteria.andStatusNotEqualTo(100); + } + + example.setOrderByClause("sort asc"); + return apiProductMapper.selectByExample(example); + } + + @Override + public ApiProduct findById(Long id) { + return apiProductMapper.selectByPrimaryKey(id); + } + + @Override + public void configApiProduct(JSONObject object) { + + // 操作人 + UserInfoModel sessionModel = userCenter.getSessionModel(UserInfoModel.class); + + // 转换产品数组 + JSONArray productsArray = object.getJSONArray("productIds"); + ApiProductConfig apiProductConfig; + for (Object productId : productsArray) { + apiProductConfig = new ApiProductConfig(); + apiProductConfig.setProductId(Long.valueOf(productId.toString())); + apiProductConfig.setCreateTime(new Date()); + apiProductConfig.setOperatorId(sessionModel.getSecUser().getId()); + apiProductConfig.setOperatorName(sessionModel.getSecUser().getUserName()); + apiProductConfig.setStatus(101); + apiProductConfig.setDiscount(object.getBigDecimal("discount")); + apiProductConfig.setMerchantsId(object.getLong("merchantsId")); + apiProductConfig.setUpdateTime(new Date()); + apiProductConfigMapper.insert(apiProductConfig); + } + } +} diff --git a/hai-service/src/main/resources/dev/commonConfig.properties b/hai-service/src/main/resources/dev/commonConfig.properties index 01d060e7..e1b6f8d6 100644 --- a/hai-service/src/main/resources/dev/commonConfig.properties +++ b/hai-service/src/main/resources/dev/commonConfig.properties @@ -14,10 +14,10 @@ qinzhuSecret=ktxb49sh2jfhgn8g qianzhuOrderNotify=https://hsg.dctpay.com/crest/qianzhu/orderNotify # ??????? -huiliantongUrl=https://gzapitest.deepermobile.com.cn:441 -huiliantongAppNo=guizhouhltcs -huiliantongAppkey=g%2BNnjR54YSUWM2iKg%2Fd82A9x9hg2kYV7 -huiliantongAppsecret=FA28E95ACABFA4B2B8E25857437B07F1 +huiliantongUrl=https://gzapi.deepermobile.com.cn +huiliantongAppNo=guizhouhuilt +huiliantongAppkey=e0ja2Ex%2BmQ2hIPF6x%2BHA%3D +huiliantongAppsecret=52662415DDCE55C7BA34223BCF53877A # ???????? HuiLianTongUnionCardUrl=http://hltgz.com:4010/api/v2/execute.json