优化话费业务流程

new-dev
袁野 2 years ago
parent 92ed037465
commit e25f2021a8
  1. 18
      hai-bweb/src/main/java/com/bweb/controller/HighGoodsTypeController.java
  2. 2
      hai-bweb/src/main/java/com/bweb/controller/HighTestController.java
  3. 21
      hai-cweb/src/main/java/com/cweb/controller/CmsContentController.java
  4. 4
      hai-service/src/main/java/com/hai/common/exception/ErrorCode.java
  5. 2
      hai-service/src/main/java/com/hai/common/security/UserCenter.java
  6. 50
      hai-service/src/main/java/com/hai/config/DataUtilConfig.java
  7. 57
      hai-service/src/main/java/com/hai/config/WeChatQrcodeUtils.java
  8. 57
      hai-service/src/main/java/com/hai/openApi/config/PriceComputeConfig.java
  9. 10
      hai-service/src/main/java/com/hai/openApi/service/ApiOrderCreateHandleService.java
  10. 122
      hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderCreateHandleServiceImpl.java
  11. 75
      hai-service/src/main/java/com/hai/openApi/service/impl/ApiOrderServiceImpl.java
  12. 2
      hai-service/src/main/java/com/hai/order/service/OrderPayService.java
  13. 2
      hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java
  14. 37
      hai-service/src/main/java/com/hai/order/service/impl/OrderPayServiceImpl.java
  15. 4
      hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java
  16. 6
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java
  17. 6
      hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java
  18. 22
      v1/src/main/java/com/v1/controller/WxMsgController.java
  19. 33
      v1/src/main/java/com/v1/controller/orderController.java
  20. 2
      v1/src/main/resources/dev/application.yml

@ -55,10 +55,14 @@ public class HighGoodsTypeController {
@RequestParam(name = "userService", required = false) String userService,
HttpServletRequest request) {
try {
//发布人员
SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
Map<String,String> map = new HashMap<>();
map.put("title", title);
map.put("userService", userService);
map.put("companyId", userInfoModel.getBsCompany().getId().toString());
PageHelper.startPage(pageNum,pageSize);
return ResponseMsgUtil.success(new PageInfo<>(highGoodsTypeService.getListGoodsType(map)));
@ -130,15 +134,16 @@ public class HighGoodsTypeController {
if (StringUtils.isBlank(highGoodsType.getTitle())
|| StringUtils.isBlank(highGoodsType.getImg())
|| highGoodsType.getBusinessType() == null
) {
log.error("HighAgentController -> insertAgent() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 校验账号用户名是否存在
// 校验名称是否重复
if (highGoodsTypeService.findByTitle(highGoodsType.getTitle())) {
log.error("HighGoodsTypeController --> insertGoodsType() error!", "已存在");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_REPEATEDLY, "");
log.error("HighGoodsTypeController --> insertGoodsType() error!", "名称已存在");
throw ErrorHelp.genException(SysCode.System, ErrorCode.TITLE_, "");
}
highGoodsType.setCreatedTime(new Date());
@ -146,6 +151,7 @@ public class HighGoodsTypeController {
highGoodsType.setUpdatedTime(new Date());
highGoodsType.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue());
highGoodsType.setStatus(1);
highGoodsType.setCompanyId(userInfoModel.getBsCompany().getId());
highGoodsTypeService.insertGoodsType(highGoodsType);
@ -169,6 +175,7 @@ public class HighGoodsTypeController {
if (StringUtils.isBlank(highGoodsType.getTitle())
|| StringUtils.isBlank(highGoodsType.getImg())
|| highGoodsType.getBusinessType() == null
|| highGoodsType.getId() == null
) {
log.error("HighAgentController -> insertAgent() error!","参数错误");
@ -179,13 +186,14 @@ public class HighGoodsTypeController {
// 校验账号用户名是否存在
if (highGoodsTypeService.findByTitle(highGoodsType.getTitle()) && !highGoodsTypes.getId().equals(highGoodsType.getId())) {
log.error("HighGoodsTypeController --> insertGoodsType() error!", "已存在");
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_REPEATEDLY, "");
log.error("HighGoodsTypeController --> insertGoodsType() error!", "名称已存在");
throw ErrorHelp.genException(SysCode.System, ErrorCode.TITLE_, "");
}
highGoodsTypes.setUpdatedTime(new Date());
highGoodsTypes.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue());
highGoodsTypes.setImg(highGoodsType.getImg());
highGoodsTypes.setCompanyId(userInfoModel.getBsCompany().getId());
highGoodsTypes.setTitle(highGoodsType.getTitle());
highGoodsTypeService.updateGoodsType(highGoodsTypes);

File diff suppressed because one or more lines are too long

@ -60,8 +60,15 @@ public class CmsContentController {
@RequestParam(name = "categoryCode", required = true) String categoryCode, HttpServletRequest request) {
try {
Boolean dataWhetherNull = true;
List<CmsContent> cmsContent;
SessionObject sessionObject = userCenter.getSessionObjectByCms(request);
HighUserModel userInfoModel = new HighUserModel();
System.out.println("sessionObject============" + sessionObject);
if (sessionObject != null) {
// 用户
userInfoModel = (HighUserModel) sessionObject.getObject();
@ -88,14 +95,19 @@ public class CmsContentController {
object.put("name" , cmsCategory.getName());
object.put("sort" , cmsCategory.getSort());
object.put("code" , cmsCategory.getCode());
object.put("childCategory" , cmsContentService.getListCmsContentByCategoryId(cmsCategory.getId() , companyId , platform));
cmsContent = cmsContentService.getListCmsContentByCategoryId(cmsCategory.getId() , companyId , platform);
if (cmsContent.size() > 0) {
dataWhetherNull = false;
}
object.put("childCategory" , cmsContent);
} else if(cmsCategory.getType() == 6 || cmsCategory.getType() == 9) {
object.put("type" , cmsCategory.getType());
object.put("name" , cmsCategory.getName());
object.put("sort" , cmsCategory.getSort());
object.put("code" , cmsCategory.getCode());
List<CmsContent> cmsContent = cmsContentService.getListCmsContentByCategoryId(cmsCategory.getId() , companyId , platform);
cmsContent = cmsContentService.getListCmsContentByCategoryId(cmsCategory.getId() , companyId , platform);
if (cmsContent.size() > 0) {
dataWhetherNull = false;
object.put("jumpType" , cmsContent.get(0).getJumpType());
object.put("jumpUrl" , cmsContent.get(0).getJumpUrl());
object.put("detailJumpUrl" , cmsContent.get(0).getExt1());
@ -106,8 +118,9 @@ public class CmsContentController {
object.put("name" , cmsCategory.getName());
object.put("sort" , cmsCategory.getSort());
object.put("code" , cmsCategory.getCode());
List<CmsContent> cmsContent = cmsContentService.getListCmsContentByCategoryId(cmsCategory.getId() , companyId , platform);
cmsContent = cmsContentService.getListCmsContentByCategoryId(cmsCategory.getId() , companyId , platform);
if (cmsContent.size() > 0) {
dataWhetherNull = false;
object.put("jumpType" , cmsContent.get(0).getJumpType());
object.put("jumpUrl" , cmsContent.get(0).getJumpUrl());
}
@ -149,7 +162,7 @@ public class CmsContentController {
}
return ResponseMsgUtil.success(objectList);
return ResponseMsgUtil.success(dataWhetherNull ? null:objectList);
} else {
JSONObject object = new JSONObject();
object.put("type" , category.getType());

@ -116,7 +116,7 @@ public enum ErrorCode {
NOT_ENTER_USER_PAY_PWD("2131","未输入支付密码"),
USER_PAY_PWD_ERROR("2132","支付密码错误"),
NO_BIND_PHONE("2133","未设置手机号"),
title_("2134","名称已存在"),
TITLE_("2134","名称已存在"),
ADD_REPEATEDLY("2135","重复添加"),
NOT_FOUND_TOW_PWD("2136","未设置二级密码"),
@ -138,7 +138,7 @@ public enum ErrorCode {
PRODUCT_ERROR("6009","商品错误"),
MERCHANT_NOT_AUTHORIZED("6010","帐户无权限"),
TIME_OUT("6011","请求时间超时"),
PAY_FAIL("6012","支付失败"),
//////////////////订单异常/////////////
ORDER_UNKNOWN_ERROR("90000","哦豁,订单未知错误,请稍后重试!"),

@ -123,7 +123,9 @@ public class UserCenter {
}
public SessionObject getSessionObjectByCms(HttpServletRequest request) {
String token = request.getHeader("Authorization");
System.out.println("token====" + token);
if (StringUtils.isBlank(token)) {
if (StringUtils.isNotBlank(read(request))) {
token = read(request);

@ -0,0 +1,50 @@
package com.hai.config;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import java.util.Objects;
/**
* @serviceName DataUtilConfig.java
* @author Sum1Dream
* @version 1.0.0
* @Description // 数据工具类
* @createTime 16:07 2023/4/4
**/
@Configuration
public class DataUtilConfig {
/**
* @Author Sum1Dream
* @Name dataFindByKfc
* @Description // 根据产品id 查询对应内容
* @Date 16:09 2023/4/4
* @Param object 数据内容
* @Param productId 产品id
* @Return com.alibaba.fastjson.JSONObject
*/
public static JSONObject dataFindByKfc(JSONObject kfcObject , String productId) {
if (kfcObject.getJSONArray("products") != null) {
for (Object products : kfcObject.getJSONArray("products")) {
JSONObject productsObject = (JSONObject) products;
if (Objects.equals(productsObject.getString("productId"), productId)) {
return productsObject;
}
if (productsObject.getJSONArray("specGroups") != null) {
for (Object specGroups : productsObject.getJSONArray("specGroups")) {
JSONObject specGroupsObject = (JSONObject) specGroups;
if (Objects.equals(specGroupsObject.getString("productId"), productId)) {
return specGroupsObject;
}
}
}
}
}
return null;
}
}

@ -13,10 +13,13 @@ import com.hai.common.utils.RedisUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.enum_type.ActionNameEnum;
import com.hai.model.TextMessage;
import com.hai.service.impl.OutRechargeOrderServiceImpl;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -42,10 +45,12 @@ import static org.apache.catalina.manager.Constants.CHARSET;
* @Description // 生成带参数的二维码
* @createTime 16:11 2022/9/2
**/
@Slf4j
@Component
public class WeChatQrcodeUtils {
private static final Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class);
@Autowired
private WxMpService wxMpService;
@ -114,26 +119,64 @@ public class WeChatQrcodeUtils {
object.put("action_name" , actionName);
object.put("expire_seconds" , 2592000);
object.put("action_info" , objectActionInfo);
return HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getWxToken(), object);
return HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getWxToken(false), object);
}
// 获取微信Token存入redis
public String getWxToken() {
public String getWxToken(Boolean whetherRedis) {
if (!whetherRedis) {
Object token = redisUtil.get("WxToken");
if (null != token) {
return token.toString();
};
}
}
log.info("获取最新微信token");
// 获取access_token
Map<String, Object> params = new HashMap<>();
JSONObject params = new JSONObject();
params.put("appid", CommonSysConst.getSysConfig().getWxH5AppId());
params.put("secret", CommonSysConst.getSysConfig().getWxH5AppSecret());
params.put("grant_type", "client_credential");
JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params);
redisUtil.set("WxToken" , accessTokenObject.getString("access_token") , 5000);
JSONObject accessTokenObject = HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/stable_token", params);
redisUtil.set("WxToken" , accessTokenObject.getString("access_token") , 7000);
return accessTokenObject.getString("access_token");
}
// 获取签名
public JSONObject getTicket(Boolean whetherRedis) {
int WxTokenRequestNum = Integer.parseInt(redisUtil.get("WxTokenRequestNum") == null ? "1" :redisUtil.get("WxTokenRequestNum").toString());
redisUtil.set("WxTokenRequestNum" , WxTokenRequestNum + 1 , 1000);
String token = getWxToken(whetherRedis);;
log.info("获取微信token次数: " + WxTokenRequestNum);
log.info("获取微信token-回调参数: " + token);
JSONObject jsapiTicket;
// 获取ticket
Map<String, Object> ticketParams = new HashMap<>();
ticketParams.put("access_token", token);
ticketParams.put("type", "jsapi");
jsapiTicket = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket", ticketParams);
log.info("获取ticket-回调参数: " + jsapiTicket);
if (jsapiTicket != null && jsapiTicket.getInteger("errcode") != 0 && WxTokenRequestNum < 6) {
jsapiTicket = getTicket(true);
}
redisUtil.del("WxTokenRequestNum");
return jsapiTicket;
}
/**
* <pre>
* 换取二维码图片文件jpg格式

@ -1,9 +1,6 @@
package com.hai.openApi.config;
import com.hai.entity.ApiAmountRecord;
import com.hai.entity.ApiMerchants;
import com.hai.entity.ApiOrder;
import com.hai.entity.HighOrder;
import com.hai.entity.*;
import com.hai.openApi.service.ApiOrderService;
import com.hai.order.type.OrderProductType;
import com.hai.service.ApiAmountRecordService;
@ -89,8 +86,60 @@ public class PriceComputeConfig {
}
/**
* @Author Sum1Dream
* @Name computationPriceCost
* @Description // 计算成本价加上我们赚的利润
* @Date 18:11 2023/4/3
* @Param [discount, price, costPrice]
* @Return java.math.BigDecimal
*/
public BigDecimal computationPriceCost(BigDecimal discount , BigDecimal price , BigDecimal costPrice) {
return costPrice.add(price.multiply(discount.divide(new BigDecimal(100)))).setScale(2, RoundingMode.HALF_UP);
}
/**
* @Author Sum1Dream
* @Name getStarbucksCpuSizePriceMarket
* @Description // 查询市场价 不同杯型不同的价格
* @Date 18:48 2023/4/4
* @Param starbucksProducts 星巴克对象
* @Param cpuSize 杯型
* @Return java.math.BigDecimal
*/
public BigDecimal getStarbucksCpuSizePriceMarket(ApiStarbucksProducts starbucksProducts , String cpuSize) {
switch (cpuSize) {
case "中杯":
return starbucksProducts.getMarketTallPrice();
case "大杯":
return starbucksProducts.getMarketGrandePrice();
case "超大杯":
return starbucksProducts.getMarketVentiPrice();
default:
return null;
}
}
/**
* @Author Sum1Dream
* @Name getStarbucksCpuSizePriceMarket
* @Description // 查询销售价格 不同杯型不同的价格
* @Date 18:48 2023/4/4
* @Param starbucksProducts 星巴克对象
* @Param cpuSize 杯型
* @Return java.math.BigDecimal
*/
public BigDecimal getStarbucksCpuSizePriceSales(ApiStarbucksProducts starbucksProducts , String cpuSize) {
switch (cpuSize) {
case "中杯":
return starbucksProducts.getSalesTallPrice();
case "大杯":
return starbucksProducts.getSalesGrandePrice();
case "超大杯":
return starbucksProducts.getSalesVentiPrice();
default:
return null;
}
}
}

@ -58,4 +58,14 @@ public interface ApiOrderCreateHandleService {
*/
ApiOrder kfcHandle(JSONObject object) throws Exception;
/**
* @Author Sum1Dream
* @Name starbucksHandle
* @Description // 星巴克操作
* @Date 17:58 2023/4/4
* @Param [object]
* @Return com.hai.entity.ApiOrder
*/
ApiOrder starbucksHandle(JSONObject object) throws Exception;
}

@ -5,6 +5,7 @@ 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.config.DataUtilConfig;
import com.hai.config.QianZhuConfig;
import com.hai.entity.*;
import com.hai.openApi.config.PriceComputeConfig;
@ -17,9 +18,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
@Service("apiOrderCreateHandleService")
public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleService {
@ -45,6 +44,9 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ
@Resource
private OutRechargePriceService rechargePriceService;
@Resource
private ApiProductService apiProductService;
@Override
public ApiOrder oilHandle(JSONObject object) throws Exception {
@ -218,16 +220,11 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ
// 获取下单内容
JSONObject dataObject = JSONObject.parseObject(object.getString("content"));
JSONArray dataArray = dataObject.getJSONArray("data");
// 查询api商户
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
// 查询折扣比例
Map<String , Object> mchProductMap = new HashMap<>();
mchProductMap.put("productType" , object.getString("productType"));
mchProductMap.put("mchId" , object.getString("merchId"));
ApiMchProduct mchProduct = apiMchProductService.findByMap(mchProductMap);
// 查询肯德基门店菜单
JSONObject jsonObject = QianZhuConfig.listByStoreCode(dataObject.getString("storeCode"));
JSONArray array = jsonObject.getJSONArray("data");
@ -235,36 +232,109 @@ public class ApiOrderCreateHandleServiceImpl implements ApiOrderCreateHandleServ
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "门店编码错误");
}
// 查询折扣比例
Map<String, Object> mapProduct = new HashMap<>();
mapProduct.put("mchId" , object.getString("merchId"));
mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE2.getNumber());
ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct);
StringBuffer orderItems = new StringBuffer();
BigDecimal priceTotal = new BigDecimal(0);
BigDecimal facePrice = new BigDecimal(0);
Map<String , String> map = new HashMap<>();
for (Object o : dataArray) {
JSONObject itemData = (JSONObject) o;
orderItems.append(itemData.getString("productId")).append("|").append(itemData.getInteger("num")).append(",");
for (Object data : array) {
JSONObject kfcObject = (JSONObject) data;
if (kfcObject.getJSONArray("products") != null) {
for (Object products : kfcObject.getJSONArray("products")) {
JSONObject productsObject = (JSONObject) products;
productsObject.put("taxOriginalPrice" , null);
productsObject.put("taxOriginalTotalPrice" , null);
productsObject.put("price" , priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , productsObject.getBigDecimal("originalPrice") , productsObject.getBigDecimal("price")));
productsObject.put("taxPrice" , null);
if (productsObject.getJSONArray("specGroups") != null) {
for (Object specGroups : productsObject.getJSONArray("specGroups")) {
JSONObject specGroupsObject = (JSONObject) specGroups;
specGroupsObject.put("taxOriginalPrice" , null);
specGroupsObject.put("taxOriginalTotalPrice" , null);
specGroupsObject.put("price" , priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , specGroupsObject.getBigDecimal("originalPrice") , specGroupsObject.getBigDecimal("price")));
specGroupsObject.put("taxPrice" , null);
JSONObject kfcData = DataUtilConfig.dataFindByKfc(kfcObject , itemData.getString("productId"));
if (kfcData != null) {
if (map.containsKey(itemData.getString("productId"))) {
break;
}
map.put(itemData.getString("productId") , itemData.getString("productId"));
priceTotal = priceTotal.add(priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , kfcData.getBigDecimal("originalPrice") , kfcData.getBigDecimal("price")).multiply(itemData.getBigDecimal("num")));
facePrice = facePrice.add(kfcData.getBigDecimal("originalPrice").multiply(itemData.getBigDecimal("num")));
}
}
}
dataObject.put("orderItems" , orderItems);
// 组装api订单
ApiOrder apiOrder = new ApiOrder();
apiOrder.setCreateTime(new Date());
apiOrder.setTitle(apiMerchants.getMerchantName() + "|" + OrderProductType.PRODUCT_TYPE2.getName() + "|扣款" + priceTotal);
apiOrder.setFacePrice(facePrice);
apiOrder.setCostPrice(priceTotal);
apiOrder.setMchId(object.getString("merchId"));
apiOrder.setMchName(apiMerchants.getMerchantName());
apiOrder.setUpdateTime(new Date());
apiOrder.setProductType(object.getInteger("productType"));
apiOrder.setMchOrderNo(object.getString("orderNo"));
apiOrder.setOrderPrice(facePrice);
apiOrder.setNotifyUrl(object.getString("notifyUrl"));
apiOrder.setContent(dataObject.toJSONString());
return apiOrder;
}
return null;
@Override
public ApiOrder starbucksHandle(JSONObject object) throws Exception {
// 获取下单内容
JSONObject dataObject = JSONObject.parseObject(object.getString("content"));
JSONArray dataArray = dataObject.getJSONArray("data");
// 查询api商户
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
// 查询折扣比例
Map<String, Object> mapProduct = new HashMap<>();
mapProduct.put("mchId" , object.getString("merchId"));
mapProduct.put("productType" , OrderProductType.PRODUCT_TYPE2.getNumber());
ApiMchProduct apiMchProducts = apiMchProductService.findByMap(mapProduct);
BigDecimal priceTotal = new BigDecimal(0);
BigDecimal facePrice = new BigDecimal(0);
for (Object starbucksObject : dataArray) {
JSONObject starbucksData = (JSONObject) starbucksObject;
ApiStarbucksProducts starbucksProducts = apiProductService.findStarbucksProductsByGoodsId(starbucksData.getLong("productId"));
BigDecimal marketPrice = priceComputeConfig.getStarbucksCpuSizePriceMarket(starbucksProducts , starbucksData.getString("cupSize"));
BigDecimal salesPrice = priceComputeConfig.getStarbucksCpuSizePriceSales(starbucksProducts , starbucksData.getString("cupSize"));
priceTotal = priceTotal.add(priceComputeConfig.computationPriceCost(apiMchProducts.getDiscount() , marketPrice , salesPrice).multiply(starbucksData.getBigDecimal("num")));
facePrice = facePrice.add(marketPrice.multiply(starbucksData.getBigDecimal("num")));
}
// 组装api订单
ApiOrder apiOrder = new ApiOrder();
apiOrder.setCreateTime(new Date());
apiOrder.setTitle(apiMerchants.getMerchantName() + "|" + OrderProductType.PRODUCT_TYPE1.getName() + "|扣款" + priceTotal);
apiOrder.setFacePrice(facePrice);
apiOrder.setCostPrice(priceTotal);
apiOrder.setMchId(object.getString("merchId"));
apiOrder.setMchName(apiMerchants.getMerchantName());
apiOrder.setUpdateTime(new Date());
apiOrder.setProductType(object.getInteger("productType"));
apiOrder.setMchOrderNo(object.getString("orderNo"));
apiOrder.setOrderPrice(facePrice);
apiOrder.setNotifyUrl(object.getString("notifyUrl"));
apiOrder.setContent(dataObject.toJSONString());
return apiOrder;
}
}

@ -57,7 +57,7 @@ public class ApiOrderServiceImpl implements ApiOrderService {
private ApiOrderService apiOrderService;
@Override
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW)
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW)
public ApiOrder createOrder(JSONObject object) throws Exception {
ApiOrder apiOrder = new ApiOrder();
@ -87,6 +87,55 @@ public class ApiOrderServiceImpl implements ApiOrderService {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_ALREADY_EXISTS);
}
// 处理星巴克订单
if (OrderProductType.PRODUCT_TYPE1.getNumber().equals(object.getInteger("productType"))) {
apiOrder = orderCreateHandleService.starbucksHandle(object);
// 组装子订单内容
CreateOrderChildModel createOrderChildModel = new CreateOrderChildModel();
createOrderChildModel.setMemName(apiMerchants.getMerchantName());
createOrderChildModel.setMemPhone(apiMerchants.getPhone());
createOrderChildModel.setCompanyId(2L);
createOrderChildModel.setGoodsType(OrderChildGoodsType.TYPE9.getNumber());
createOrderChildModel.setCustomerMobile(dataObject.getString("customerMobile"));
createOrderChildModel.setOrderItems(dataObject.getJSONArray("data"));
createOrderChildModel.setStoreCode(dataObject.getString("storeCode"));
createOrderChildModel.setSaleCount(1);
createOrderChildModel.setIsTyAgent(false);
createOrderChildModel.setGoodsPrice(apiOrder.getOrderPrice());
// 组装订单
createOrderModel.getChildOrderList().add(createOrderChildModel);
orderService.createOrder(createOrderModel);
}
// 处理肯德基订单
if (OrderProductType.PRODUCT_TYPE2.getNumber().equals(object.getInteger("productType"))) {
apiOrder = orderCreateHandleService.kfcHandle(object);
String orderItems = JSONObject.parseObject(apiOrder.getContent()).getString("orderItems");
orderItems = orderItems.substring(0 , orderItems.length() - 1);
// 组装子订单内容
CreateOrderChildModel createOrderChildModel = new CreateOrderChildModel();
createOrderChildModel.setMemName(apiMerchants.getMerchantName());
createOrderChildModel.setMemPhone(apiMerchants.getPhone());
createOrderChildModel.setCompanyId(2L);
createOrderChildModel.setGoodsType(OrderChildGoodsType.TYPE4.getNumber());
createOrderChildModel.setCustomerMobile(dataObject.getString("customerMobile"));
createOrderChildModel.setEatType(dataObject.getInteger("eatType"));
createOrderChildModel.setStoreCode(dataObject.getString("storeCode"));
createOrderChildModel.setOrderItems(orderItems);
createOrderChildModel.setSaleCount(1);
createOrderChildModel.setIsTyAgent(false);
createOrderChildModel.setGoodsPrice(apiOrder.getOrderPrice());
// 组装订单
createOrderModel.getChildOrderList().add(createOrderChildModel);
orderService.createOrder(createOrderModel);
}
// 处理会员充值订单
if (OrderProductType.PRODUCT_TYPE3.getNumber().equals(object.getInteger("productType"))) {
apiOrder = orderCreateHandleService.memberRechargeHandle(object);
@ -99,6 +148,7 @@ public class ApiOrderServiceImpl implements ApiOrderService {
createOrderChildModel.setGoodsType(OrderChildGoodsType.TYPE10.getNumber());
createOrderChildModel.setGoodsId(Long.valueOf(apiOrder.getExt1()));
createOrderChildModel.setRechargeContent(dataObject.getString("mobile"));
createOrderChildModel.setCustomerMobile(dataObject.getString("mobile"));
createOrderChildModel.setSaleCount(1);
createOrderChildModel.setIsTyAgent(false);
createOrderChildModel.setGoodsPrice(apiOrder.getOrderPrice());
@ -155,6 +205,12 @@ public class ApiOrderServiceImpl implements ApiOrderService {
apiOrder.setOrderNo(createOrderModel.getOrderNo());
apiOrder.setStatus(1);
// 当前账号余额是否可以充值当前金额
if (apiMerchants.getAmounts().compareTo(apiOrder.getCostPrice()) < 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE);
}
apiOrderMapper.insert(apiOrder);
return apiOrder;
@ -163,8 +219,8 @@ public class ApiOrderServiceImpl implements ApiOrderService {
@Override
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW)
public ApiOrder payOrder(JSONObject object) {
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW)
public ApiOrder payOrder(JSONObject object) throws Exception{
ApiMerchants apiMerchants = apiMerchantsService.findByMchId(object.getString("merchId"));
@ -181,9 +237,18 @@ public class ApiOrderServiceImpl implements ApiOrderService {
orderPayBeforeService.payOrderCheck(order);
// 处理订单
HighOrder highOrder = orderPayService.apiMchAmount(order , apiMerchants , apiOrder);
HighOrder highOrder = orderPayService.apiMchAmount(order.getOrderNo() , apiMerchants , apiOrder);
if (highOrder == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.PAY_FAIL, "");
}
if (highOrder.getExceptionStatus()) {
apiOrder.setWhetherException(true);
apiOrder.setRemark("当前订单存在异常请联系客服!");
}
if (highOrder.getOrderStatus() != OrderStatus.STATUS1.getNumber()) {
if (!Objects.equals(highOrder.getOrderStatus(), OrderStatus.STATUS1.getNumber())) {
apiOrder.setStatus(highOrder.getOrderStatus());
apiOrder.setUpdateTime(new Date());
apiOrderMapper.updateByPrimaryKey(apiOrder);

@ -45,6 +45,6 @@ public interface OrderPayService {
* @Param [order, apiMerchants]
* @Return com.hai.entity.HighOrder
*/
HighOrder apiMchAmount(HighOrder order , ApiMerchants apiMerchants , ApiOrder apiOrder);
HighOrder apiMchAmount(String orderNo , ApiMerchants apiMerchants , ApiOrder apiOrder) throws Exception;
}

@ -735,7 +735,7 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请选择就餐方式!");
}
// 下单
jsonObject = QianZhuConfig.createKfcOrder(object.getInteger("eatType"), object.getString("storeCode"), object.getString("customerMobile"), object.getString("orderItems"), object.getString("userId"));
jsonObject = QianZhuConfig.createKfcOrder(object.getInteger("eatType"), object.getString("storeCode"), object.getString("customerMobile"), object.getString("orderItems"), "19940218");
// 判断下单是否成功
if (!Objects.equals(jsonObject.getString("code"), "10000")) {

@ -13,11 +13,12 @@ import com.hai.order.service.OrderPaySuccessService;
import com.hai.order.service.OrderService;
import com.hai.order.type.OrderPayType;
import com.hai.order.type.OrderProductType;
import com.hai.service.HighFleetOilCardService;
import com.hai.service.HighGasOrderService;
import com.hai.service.HighOilCardService;
import com.hai.service.HighUserCardService;
import com.hai.order.type.OrderStatus;
import com.hai.service.*;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -44,8 +45,8 @@ public class OrderPayServiceImpl implements OrderPayService {
@Resource
private HighFleetOilCardService fleetOilCardService;
@Resource
private OrderService orderService;
@Autowired
private RedisTemplate redisTemplate;
@Resource
private HighGasOrderService gasOrderService;
@ -53,6 +54,9 @@ public class OrderPayServiceImpl implements OrderPayService {
@Resource
private PriceComputeConfig priceComputeConfig;
@Resource
private HighOrderService highOrderService;
@Override
public HighOrder hltCardPay(HighOrder order, HighUserCard userCard) throws Exception {
String goodsDesc = "";
@ -156,8 +160,20 @@ public class OrderPayServiceImpl implements OrderPayService {
}
@Override
public HighOrder apiMchAmount(HighOrder order, ApiMerchants apiMerchants , ApiOrder apiOrder) {
public HighOrder apiMchAmount(String orderNo, ApiMerchants apiMerchants , ApiOrder apiOrder) throws Exception {
String key = "apiMerchant" + apiMerchants.getMchId();
// 分布式锁占坑
Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, apiOrder.getOrderNo());
HighOrder order = highOrderService.getOrderByOrderNo(orderNo);
if(!order.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_NO_STAY_PAY, "");
}
if(Boolean.TRUE.equals(lock)) {
// 判断金额是否充足
if (!priceComputeConfig.mchBalance(apiMerchants , apiOrder.getCostPrice() , apiOrder.getMchOrderNo())) {
@ -171,6 +187,11 @@ public class OrderPayServiceImpl implements OrderPayService {
null,
order.getPayPrice(),
null);
} else {
// 加锁失败,重试
Thread.sleep(100);
apiMchAmount(orderNo , apiMerchants , apiOrder);
}
return null;
}
}

@ -212,6 +212,10 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue(), detailsList.getAgentId());
List<HighDiscountAgentCode> discountAgentCodeList = highDiscountAgentCodeService.getDiscountAgentCodByLimit(discountAgentRel.getId() , detailsList.getNum().longValue());
System.out.println(discountAgentCodeList.size() < detailsList.getNum());
System.out.println(discountAgentCodeList.size());
System.out.println(detailsList.getNum());
if (discountAgentCodeList.size() < detailsList.getNum()) {
throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , detailsList.getDiscountName() +"优惠券库存不足");
}

@ -865,6 +865,12 @@ public class HighOrderServiceImpl implements HighOrderService {
DateUtil.format(MapUtils.getString(map, "createTimeE"), "yyyy-MM-dd HH:mm:ss"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "refundTimeS")) && StringUtils.isNotBlank(MapUtils.getString(map, "refundTimeE"))) {
criteria.andRefundTimeBetween(
DateUtil.format(MapUtils.getString(map, "refundTimeS"), "yyyy-MM-dd HH:mm:ss"),
DateUtil.format(MapUtils.getString(map, "refundTimeE"), "yyyy-MM-dd HH:mm:ss"));
}
// example.setOrderByClause("create_time desc");

@ -770,6 +770,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
// 没有充值中的订单 查询所有订单中最新的一条订单状态
if (childOrders102.size() == 0) {
if (childOrderList.size() > 0) {
// -1 取消,0充值中 ,1充值成功,2充值失败,3部分成功
Integer status = getRechargeOrderLegality(childOrderList.get(0));
if (status == 2 || status == -1) {
@ -789,6 +790,11 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
rechargeChildOrderHandle(childOrderList.get(0) , 101);
return 5;
}
} else {
// 如果订单记录超过71小时 反之继续充值
return hours > 71 ? 2 : 1;
}
}
return 3;

@ -25,6 +25,7 @@ import com.hai.model.HighMerchantStoreModel;
import com.hai.model.ResponseData;
import com.hai.service.HighMerchantStoreService;
import com.hai.service.HighUserService;
import com.hai.service.impl.OutRechargeOrderServiceImpl;
import com.v1.config.SysConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -59,7 +60,9 @@ import static org.apache.catalina.manager.Constants.CHARSET;
@Api(value = "微信")
public class WxMsgController {
private static Logger log = LoggerFactory.getLogger(WxMsgController.class);
private static final Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class);
@Autowired
private WeChatQrcodeUtils weChatQrcodeUtils;
@ -319,7 +322,7 @@ public class WxMsgController {
public ResponseData getWxToken() {
try {
return ResponseMsgUtil.success(weChatQrcodeUtils.getWxToken());
return ResponseMsgUtil.success(weChatQrcodeUtils.getWxToken(false));
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
@ -401,11 +404,9 @@ public class WxMsgController {
public ResponseData verifyWx(@RequestParam(value = "url", required = true) String url) {
try {
// 获取ticket
Map<String, Object> ticketParams = new HashMap<>();
ticketParams.put("access_token", weChatQrcodeUtils.getWxToken());
ticketParams.put("type", "jsapi");
JSONObject jsapiTicket = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket", ticketParams);
JSONObject jsapiTicket = weChatQrcodeUtils.getTicket(false);
log.info("获取jsapiTicket"+ jsapiTicket);
// 拼接签名
Map<String, Object> map = new HashMap<>();
map.put("noncestr", WxUtils.makeNonStr());
@ -413,12 +414,16 @@ public class WxMsgController {
map.put("timestamp", new Date().getTime());
map.put("url",url);
log.info("拼接map"+ map);
Map<String, Object> objectMap = new HashMap<>();
objectMap.put("appId" , SysConst.getSysConfig().getWxH5AppId());
objectMap.put("timestamp" , map.get("timestamp"));
objectMap.put("nonceStr" , map.get("noncestr"));
objectMap.put("signature" , WxUtils.getSHA1(map));
log.info("拼接objectMap"+ objectMap);
return ResponseMsgUtil.success(objectMap);
} catch (Exception e) {
return null;
@ -436,7 +441,7 @@ public class WxMsgController {
JSONObject postObject = new JSONObject();
postObject.put("expire_type" ,1);
postObject.put("expire_interval" ,30);
JSONObject object = HttpsUtils.doPost("https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + weChatQrcodeUtils.getWxToken(), postObject);
JSONObject object = HttpsUtils.doPost("https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + weChatQrcodeUtils.getWxToken(false), postObject);
return ResponseMsgUtil.success(object);
} catch (Exception e) {
return null;
@ -444,6 +449,7 @@ public class WxMsgController {
}
// @RequestMapping(value = "/verifyWx", method = RequestMethod.GET)
// @ResponseBody
// @ApiOperation(value = "微信签名")

@ -21,6 +21,8 @@ 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.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -46,6 +48,9 @@ public class orderController {
@Resource
private SecConfigService secConfigService;
@Autowired
private RedisTemplate redisTemplate;
@Resource
private ApiOrderService orderService;
@ -128,8 +133,9 @@ public class orderController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未填写加油信息;加油金额、油号、抢号");
}
}
if (object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE9.getNumber()) || object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE3.getNumber())) {
JSONObject dataObject = JSONObject.parseObject(object.getString("content"));
if (object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE9.getNumber()) || object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE3.getNumber())) {
if (StringUtils.isBlank(dataObject.getString("productId"))
|| StringUtils.isBlank(dataObject.getString("mobile"))
) {
@ -138,6 +144,24 @@ public class orderController {
}
}
if (object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE1.getNumber())) {
if (StringUtils.isBlank(dataObject.getString("customerMobile"))
) {
log.error("OrderController -> create() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未填写下单手机号");
}
}
if (object.getInteger("productType").equals(OrderProductType.PRODUCT_TYPE2.getNumber())) {
if (dataObject.getJSONArray("data") == null
|| StringUtils.isBlank(dataObject.getString("customerMobile"))
|| StringUtils.isBlank(dataObject.getString("storeCode"))
|| dataObject.getInteger("eatType") == null
) {
log.error("OrderController -> create() error!","");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未填写下单手机号,就餐方式,下单信息,门店编码");
}
}
return ResponseMsgUtil.success(orderService.createOrder(object));
} catch (Exception e) {
@ -201,11 +225,16 @@ public class orderController {
object.put("orderNo" , apiOrder.getOrderNo());
return ResponseMsgUtil.success(orderService.payOrder(object));
ApiOrder order = orderService.payOrder(object);
return ResponseMsgUtil.success(order);
} catch (Exception e) {
log.error("HighOpenApiController --> createOrder() error!", e);
return ResponseMsgUtil.exception(e);
} finally {
// 删除key,释放锁
redisTemplate.delete( "apiMerchant" + object.getString("merchId"));
}
}

@ -28,7 +28,7 @@ spring:
poolPreparedStatements: true
maxOpenPreparedStatements: 20
redis:
database: 0
database: 1
host: 139.9.154.68
port: 36379
password: HF123456.Redis

Loading…
Cancel
Save