parent
bc6713e33b
commit
a9bcd6800f
@ -1,696 +0,0 @@ |
|||||||
/* |
|
||||||
package com.cweb.controller; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.alibaba.fastjson.JSONArray; |
|
||||||
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.AESEncodeUtil; |
|
||||||
import com.hai.common.security.SessionObject; |
|
||||||
import com.hai.common.security.UserCenter; |
|
||||||
import com.hai.common.utils.DateUtil; |
|
||||||
import com.hai.common.utils.IDGenerator; |
|
||||||
import com.hai.common.utils.ResponseMsgUtil; |
|
||||||
import com.hai.config.CommonSysConfig; |
|
||||||
import com.hai.config.CommonSysConst; |
|
||||||
import com.hai.config.TuanYouConfig; |
|
||||||
import com.hai.entity.*; |
|
||||||
import com.hai.enum_type.DiscountUseScope; |
|
||||||
import com.hai.enum_type.GasClassGroupTaskStatus; |
|
||||||
import com.hai.enum_type.MerAccountMarketingType; |
|
||||||
import com.hai.enum_type.OrderChildGoodsTypeEnum; |
|
||||||
import com.hai.model.GasPayPriceModel; |
|
||||||
import com.hai.model.HighMerchantStoreModel; |
|
||||||
import com.hai.model.HighUserModel; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.service.*; |
|
||||||
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.math.MathContext; |
|
||||||
import java.math.RoundingMode; |
|
||||||
import java.net.URLDecoder; |
|
||||||
import java.util.*; |
|
||||||
import java.util.stream.Collectors; |
|
||||||
|
|
||||||
*/ |
|
||||||
/** |
|
||||||
* @Auther: 胡锐 |
|
||||||
* @Description: |
|
||||||
* @Date: 2021/3/26 23:08 |
|
||||||
*//*
|
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/highOrder") |
|
||||||
@Api(value = "订单接口") |
|
||||||
public class HighOrderController { |
|
||||||
private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class); |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private UserCenter userCenter; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private CommonService commonService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderService highOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighCouponService highCouponService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighMerchantStoreService highMerchantStoreService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighMerchantAccountMarketingService merchantAccountMarketingService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighCouponCodeService highCouponCodeService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountUserRelService highDiscountUserRelService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountCouponRelService highDiscountCouponRelService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountPackageService discountPackageService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountPackageActualService discountPackageActualService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserService highUserService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighTyAgentOilStationService tyAgentOilStationService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighTyAgentPriceService tyAgentPriceService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighGasDiscountOilPriceService gasDiscountOilPriceService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighGasStaffService gasStaffService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighGasClassGroupTaskService gasClassGroupTaskService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private BsCompanyService bsCompanyService; |
|
||||||
|
|
||||||
@RequestMapping(value="/addOrder",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "增加订单") |
|
||||||
public ResponseData addOrder(@RequestBody HighOrder highOrder, HttpServletRequest request) { |
|
||||||
try { |
|
||||||
// 用户
|
|
||||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
|
||||||
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); |
|
||||||
|
|
||||||
if (highOrder.getHighChildOrderList() == null |
|
||||||
|| highOrder.getHighChildOrderList().size() == 0 |
|
||||||
) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
if (StringUtils.isBlank(userInfoModel.getHighUser().getPhone())) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未绑定手机号"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NO_BIND_PHONE, ""); |
|
||||||
} |
|
||||||
|
|
||||||
HighDiscountUserRel highDiscountUserRel = null; |
|
||||||
if (highOrder.getMemDiscountId() != null) { |
|
||||||
// 卡优惠券信息
|
|
||||||
highDiscountUserRel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId()); |
|
||||||
if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 定义当前卡券是否可以直冲积分
|
|
||||||
boolean buyPoints = false; |
|
||||||
|
|
||||||
BigDecimal totalPrice = new BigDecimal("0"); |
|
||||||
BigDecimal totalActualPrice = new BigDecimal("0"); |
|
||||||
for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { |
|
||||||
if (childOrder.getGoodsType() == null || childOrder.getGoodsId() == null || childOrder.getSaleCount() == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 商品类型 1:卡卷 2:金币充值 3:团油【加油站】
|
|
||||||
if (childOrder.getGoodsType() == 1) { |
|
||||||
if (childOrder.getSaleCount() != 1) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "卡卷只能购买一张"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡卷只能购买一张"); |
|
||||||
} |
|
||||||
// 查询卡卷信息
|
|
||||||
HighCoupon coupon = highCouponService.getCouponById(childOrder.getGoodsId()); |
|
||||||
|
|
||||||
|
|
||||||
// 判断是否实物商品
|
|
||||||
if (coupon.getWherePost() != null && coupon.getWherePost()) { |
|
||||||
if (highOrder.getPostData().getString("address").length() == 0 || highOrder.getPostData().getString("user").length() == 0 || highOrder.getPostData().getString("phone").length() == 0 ) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "请输入收货相关信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入收货相关信息"); |
|
||||||
} |
|
||||||
// 先把String对象转换成Json对象
|
|
||||||
highOrder.setRemarks(highOrder.getPostData().toString()); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
if (coupon == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); |
|
||||||
} |
|
||||||
if (coupon.getReserveStatus() == true) { |
|
||||||
if (childOrder.getStoreId() == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未选择门店"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未选择门店"); |
|
||||||
} |
|
||||||
// 查询门店信息
|
|
||||||
HighMerchantStoreModel merchantStore = highMerchantStoreService.getMerchantStoreById(childOrder.getStoreId()); |
|
||||||
if (merchantStore == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未选择门店"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到门店信息"); |
|
||||||
} |
|
||||||
if (!merchantStore.getMerchantId().equals(coupon.getMerchantId())) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "卡券无法在此门店消费"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券无法在此门店消费"); |
|
||||||
} |
|
||||||
} |
|
||||||
// 支付类型:1.微信支付 2.金币支付
|
|
||||||
if(coupon.getPayType() == 2) { |
|
||||||
highOrder.setPayModel(1); // 支付模式:1 金币,2 第三方平台,3 混合
|
|
||||||
highOrder.setPayType(3); // 支付方式: 1:支付宝 2:微信 3:金币
|
|
||||||
} |
|
||||||
// 是否达到限购数量
|
|
||||||
if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "已达到限购数量"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",已达到限购数量"); |
|
||||||
} |
|
||||||
// 校验优惠券是否可用 如果使用优惠券就只能使用卡券的原价
|
|
||||||
if (highDiscountUserRel != null) { |
|
||||||
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId()); |
|
||||||
if (discountCouponRelList.size() > 0) { |
|
||||||
HighDiscountUserRel finalHighDiscountUserRel = highDiscountUserRel; |
|
||||||
List<HighDiscountCouponRel> collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(finalHighDiscountUserRel.getDiscountId())).collect(Collectors.toList()); |
|
||||||
if (collect == null || collect.size() == 0) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "无法使用优惠券"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券"); |
|
||||||
} |
|
||||||
} |
|
||||||
childOrder.setGoodsPrice(coupon.getSalesPrice()); |
|
||||||
} else { |
|
||||||
childOrder.setGoodsPrice(coupon.getDiscountPrice()); |
|
||||||
} |
|
||||||
// 贵州中石化
|
|
||||||
if (coupon.getCouponSource() != 4 && coupon.getCouponSource() != 5) { |
|
||||||
if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) <= 0) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "卡卷库存数量不足"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "系统维护中"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (coupon.getBuyPoints()) { |
|
||||||
buyPoints = true; |
|
||||||
} |
|
||||||
|
|
||||||
childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); |
|
||||||
childOrder.setGoodsName(coupon.getCouponName()); |
|
||||||
childOrder.setGoodsImg(coupon.getCouponImg()); |
|
||||||
childOrder.setGoodsSpecName("默认"); |
|
||||||
childOrder.setExt1(coupon.getCouponSource().toString()); |
|
||||||
} |
|
||||||
|
|
||||||
if (childOrder.getGoodsType() == 2) { |
|
||||||
if (childOrder.getGoodsPrice() == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "请设置充值金额"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请设置充值金额"); |
|
||||||
} |
|
||||||
// 查询用户信息
|
|
||||||
HighUser user = highUserService.findByUserId(childOrder.getGoodsId()); |
|
||||||
if (user == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未找到用户"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, ""); |
|
||||||
} |
|
||||||
childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); |
|
||||||
childOrder.setGoodsName(user.getName()); |
|
||||||
childOrder.setGoodsImg(user.getHeaderImg()); |
|
||||||
childOrder.setGoodsSpecName("默认"); |
|
||||||
} |
|
||||||
|
|
||||||
if (childOrder.getGoodsType() == 3) { |
|
||||||
if (childOrder.getGasPriceGun() == null || childOrder.getGasPriceVip() == null || StringUtils.isBlank(childOrder.getGasGunNo()) || StringUtils.isBlank(childOrder.getGasOilNo()) || childOrder.getGasOilType() == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 加油限制
|
|
||||||
if (childOrder.getGasOilType().equals(1)) { |
|
||||||
SecDictionary refuelLimit = commonService.mappingSysName("REFUEL_LIMIT", "汽油"); |
|
||||||
if (refuelLimit != null && childOrder.getGoodsPrice().compareTo(new BigDecimal(refuelLimit.getCodeValue())) == 1) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "汽油加油金额不能超过" + refuelLimit.getCodeValue()+"元"); |
|
||||||
} |
|
||||||
} else if (childOrder.getGasOilType().equals(2)){ |
|
||||||
SecDictionary refuelLimit = commonService.mappingSysName("REFUEL_LIMIT", "柴油"); |
|
||||||
if (refuelLimit != null && childOrder.getGoodsPrice().compareTo(new BigDecimal(refuelLimit.getCodeValue())) == 1) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "柴油加油金额不能超过" + refuelLimit.getCodeValue()+"元"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (highOrderService.getGasTheDayOrderNum(userInfoModel.getHighUser().getId()) >= 1) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已达到每日加油次数上限"); |
|
||||||
} |
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(highOrder.getGasStaffCode())) { |
|
||||||
String qrCodeSignKey = commonService.getDictionaryCodeName("QR_CODE_SIGN_KEY", "1"); |
|
||||||
if (StringUtils.isBlank(qrCodeSignKey)) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知秘钥"); |
|
||||||
} |
|
||||||
|
|
||||||
String staffId; |
|
||||||
try { |
|
||||||
staffId = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(URLDecoder.decode(highOrder.getGasStaffCode(),"UTF-8")), qrCodeSignKey); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "收银员code解析失败"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "收银员code解析失败"); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询员工
|
|
||||||
HighGasStaff gasStaff = gasStaffService.getStaffDetailById(Long.parseLong(staffId)); |
|
||||||
if (gasStaff == null) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知收银员"); |
|
||||||
} |
|
||||||
if (gasStaff.getMerchantStoreId().equals(childOrder.getGoodsId())) { |
|
||||||
childOrder.setGasStaffId(gasStaff.getId()); |
|
||||||
childOrder.setGasStaffName(gasStaff.getName()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 查询加油站是否开启班组
|
|
||||||
Map<String, Object> classGroup = new HashMap<>(); |
|
||||||
classGroup.put("merchantStoreId", childOrder.getGoodsId()); |
|
||||||
classGroup.put("status", GasClassGroupTaskStatus.status1.getStatus()); |
|
||||||
List<HighGasClassGroupTask> groupTaskList = gasClassGroupTaskService.getGroupTaskList(classGroup); |
|
||||||
if (groupTaskList.size() > 0) { |
|
||||||
HighGasClassGroupTask groupTask = groupTaskList.get(0); |
|
||||||
childOrder.setGasClassGroupId(groupTask.getGasClassGroupId()); |
|
||||||
childOrder.setGasClassGroupName(groupTask.getGasClassGroupName()); |
|
||||||
childOrder.setGasClassGroupTaskId(groupTask.getId()); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询门店
|
|
||||||
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(childOrder.getGoodsId()); |
|
||||||
if (store == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未找到门店信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到门店信息"); |
|
||||||
} |
|
||||||
if (highOrder.getIsTyAgent() != null && highOrder.getIsTyAgent().equals(true)) { |
|
||||||
// 查询加油站
|
|
||||||
HighTyAgentOilStation oilStation = tyAgentOilStationService.getDetailByOilStationId(childOrder.getGoodsId()); |
|
||||||
if (oilStation != null) { |
|
||||||
childOrder.setGasSalesmanId(oilStation.getTySalesmanId()); |
|
||||||
childOrder.setGasSalesmanName(oilStation.getTySalesmanName()); |
|
||||||
childOrder.setGasAgentId(oilStation.getTyAgentId()); |
|
||||||
childOrder.setGasAgentName(oilStation.getTyAgentName()); |
|
||||||
childOrder.setGasOrgId(oilStation.getOrganizationId()); |
|
||||||
childOrder.setGasOrgName(oilStation.getOrganizationName()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 营销减免的金额
|
|
||||||
BigDecimal marketingPrice = merchantAccountMarketingService.getPrice(store.getMerchantId(), MerAccountMarketingType.type3.getType(), Integer.valueOf(childOrder.getGasOilNo())); |
|
||||||
|
|
||||||
// 计算价格
|
|
||||||
GasPayPriceModel priceModel = gasDiscountOilPriceService.oilPriceDiscountCompute(childOrder.getGoodsPrice(), childOrder.getGoodsId(), childOrder.getGasOilNo(), highOrder.getIsTyAgent()); |
|
||||||
|
|
||||||
// 使用了优惠价
|
|
||||||
if (highDiscountUserRel != null) { |
|
||||||
// 支付价格
|
|
||||||
childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); |
|
||||||
// 油价信息
|
|
||||||
childOrder.setGasPriceGun(priceModel.getPriceGun()); |
|
||||||
childOrder.setGasPriceVip(priceModel.getPriceGun()); |
|
||||||
childOrder.setGasPriceOfficial(new BigDecimal("0")); |
|
||||||
childOrder.setGasPricePlatform(priceModel.getPriceGun()); |
|
||||||
childOrder.setGasOilLiters(priceModel.getOilLiters()); |
|
||||||
childOrder.setGasDiscount(new BigDecimal("0")); |
|
||||||
childOrder.setExt1(childOrder.getGasPricePlatform().toString()); |
|
||||||
childOrder.setGasOilSubsidy(new BigDecimal("0")); |
|
||||||
childOrder.setGasLitersPreferences(new BigDecimal("0")); |
|
||||||
childOrder.setGasPricePreferences(priceModel.getPriceGun()); |
|
||||||
} else { |
|
||||||
// 支付价格
|
|
||||||
childOrder.setGoodsActualPrice(priceModel.getPayPrice()); |
|
||||||
// 油价信息
|
|
||||||
childOrder.setGasPriceGun(priceModel.getPriceGun()); |
|
||||||
childOrder.setGasPriceVip(priceModel.getPriceVip()); |
|
||||||
childOrder.setGasPriceOfficial(priceModel.getPriceOfficial()); |
|
||||||
childOrder.setGasPricePlatform(priceModel.getPricePlatform()); |
|
||||||
childOrder.setGasOilLiters(priceModel.getOilLiters()); |
|
||||||
childOrder.setGasDiscount(priceModel.getDiscount()); |
|
||||||
childOrder.setExt1(priceModel.getPricePlatform().toString()); |
|
||||||
childOrder.setGasOilSubsidy(priceModel.getPreferentialMargin()); |
|
||||||
childOrder.setGasLitersPreferences(priceModel.getLitersPreferences()); |
|
||||||
childOrder.setGasPricePreferences(priceModel.getPricePreferences()); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
// 来源类型 1:平台自建 2:团油
|
|
||||||
if (store.getSourceType().equals(1)) { |
|
||||||
childOrder.setGoodsImg(CommonSysConst.getSysConfig().getHsgDomainName()+"/filesystem/"+store.getStoreLogo()); |
|
||||||
} else { |
|
||||||
childOrder.setGoodsImg(store.getStoreLogo()); |
|
||||||
} |
|
||||||
|
|
||||||
childOrder.setGoodsName(store.getStoreName()); |
|
||||||
childOrder.setGoodsSpecName("默认"); |
|
||||||
childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); |
|
||||||
|
|
||||||
// 成本价 油站价 减 营销策略价
|
|
||||||
childOrder.setGasPriceCost(priceModel.getPriceGun().subtract(marketingPrice)); |
|
||||||
if (marketingPrice.compareTo(new BigDecimal("0")) <= 0) { |
|
||||||
childOrder.setGasPriceCostTotal(childOrder.getTotalPrice()); |
|
||||||
} else { |
|
||||||
childOrder.setGasPriceCostTotal(childOrder.getGasPriceCost().multiply(childOrder.getGasOilLiters()).setScale(2, BigDecimal.ROUND_HALF_DOWN)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (childOrder.getGoodsType() == 7) { |
|
||||||
// 查询优惠券包
|
|
||||||
HighDiscountPackage discountPackage = discountPackageService.findDiscountPackageById(childOrder.getGoodsId().intValue()); |
|
||||||
|
|
||||||
if (discountPackage == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", ""); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到优惠券包"); |
|
||||||
} |
|
||||||
if (discountPackage.getStatus() != 1) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", ""); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券包不可用"); |
|
||||||
} |
|
||||||
if (discountPackageActualService.getStockByPackageId(discountPackage.getId()) == 0) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", ""); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "库存数量不足"); |
|
||||||
} |
|
||||||
|
|
||||||
if (discountPackage.getPurchaseNum() < discountPackageActualService.userPurchaseByUserId(userInfoModel.getHighUser().getId().intValue(), discountPackage.getId())) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", ""); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "超过购买限制"); |
|
||||||
} |
|
||||||
|
|
||||||
childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); |
|
||||||
childOrder.setGoodsName(discountPackage.getTitle()); |
|
||||||
childOrder.setGoodsImg(discountPackage.getListImg()); |
|
||||||
childOrder.setGoodsPrice(discountPackage.getPrice()); |
|
||||||
childOrder.setGoodsActualPrice(discountPackage.getPrice()); |
|
||||||
childOrder.setGoodsSpecName("默认"); |
|
||||||
} |
|
||||||
// 汇联通充值
|
|
||||||
if (childOrder.getGoodsType() == 8) { |
|
||||||
if (childOrder.getGoodsPrice() == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "请设置充值金额"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请设置充值金额"); |
|
||||||
} |
|
||||||
if (highOrder.getMemCardNo() == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "请设置充值卡号"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请设置充值卡号"); |
|
||||||
} |
|
||||||
// 查询用户信息
|
|
||||||
HighUser user = highUserService.findByUserId(childOrder.getGoodsId()); |
|
||||||
if (user == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未找到用户"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, ""); |
|
||||||
} |
|
||||||
highOrder.setPayType(2); // 第三方平台
|
|
||||||
childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); |
|
||||||
childOrder.setGoodsName(user.getName()); |
|
||||||
childOrder.setGoodsImg(user.getHeaderImg()); |
|
||||||
childOrder.setGoodsSpecName("默认"); |
|
||||||
} |
|
||||||
|
|
||||||
childOrder.setMemId(userInfoModel.getHighUser().getId()); |
|
||||||
childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); |
|
||||||
childOrder.setGiveawayType(false); // 是否是赠品 0:否 1:是
|
|
||||||
childOrder.setChildOrdeStatus(1); // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
|
|
||||||
childOrder.setPraiseStatus(0); |
|
||||||
|
|
||||||
// 累计订单价格
|
|
||||||
totalPrice = totalPrice.add(childOrder.getTotalPrice()); |
|
||||||
totalActualPrice = totalActualPrice.add(childOrder.getGoodsActualPrice()); |
|
||||||
} |
|
||||||
|
|
||||||
// 积分抵扣金额
|
|
||||||
BigDecimal integralDeductionPrice = new BigDecimal(0); |
|
||||||
if (buyPoints && highOrder.getPayGold() != null) { |
|
||||||
integralDeductionPrice = new BigDecimal(highOrder.getPayGold()).divide(new BigDecimal(100)); |
|
||||||
String remark = "订单" + highOrder.getOrderNo() + "购买,使用积分:" + highOrder.getPayGold(); |
|
||||||
highUserService.goldHandle(userInfoModel.getHighUser().getId(), highOrder.getPayGold(), 2, 2, highOrder.getId() , remark); |
|
||||||
BigDecimal payGold = new BigDecimal(highOrder.getPayGold()); |
|
||||||
|
|
||||||
if (payGold.compareTo(totalActualPrice.subtract(integralDeductionPrice)) < 0) { |
|
||||||
highOrder.setPayModel(2); // 支付模式:1 金币,2 第三方平台,3 混合
|
|
||||||
highOrder.setPayType(2); // 支付方式: 1:支付宝 2:微信 3:金币
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (request.getHeader("regionId") != null && request.getHeader("regionId").length() != 0) { |
|
||||||
SecRegion region = commonService.getParentByRegion(Long.valueOf(request.getHeader("regionId"))); |
|
||||||
if (region != null) { |
|
||||||
BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); |
|
||||||
if (bsCompany != null) { |
|
||||||
highOrder.setCompanyId(bsCompany.getId()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
highOrder.setMerchId(request.getHeader("mchId")); |
|
||||||
highOrder.setWhetherRebate(false); |
|
||||||
highOrder.setTotalPrice(totalPrice); |
|
||||||
highOrder.setPayablePrice(totalActualPrice); |
|
||||||
|
|
||||||
// 是否使用了优惠券
|
|
||||||
if (highDiscountUserRel != null) { |
|
||||||
highOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); |
|
||||||
|
|
||||||
// 优惠券使用范围
|
|
||||||
if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType())) { |
|
||||||
// 暂无限制
|
|
||||||
} else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type2.getType())) { |
|
||||||
// 1:卡卷 2:金币充值 3:团油【加油站】 4: KFC 5:电影票 6:话费充值
|
|
||||||
if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(1)) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "此优惠券只能购买卡券商品使用"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此优惠券只能购买卡券商品使用"); |
|
||||||
} |
|
||||||
} else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) { |
|
||||||
if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(6)) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "此优惠券只能充值话费中使用"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此优惠券只能充值话费中使用"); |
|
||||||
} |
|
||||||
} else if (highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type7.getType())) { |
|
||||||
if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(3)) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "此优惠券只能充值话费中使用"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此优惠券只能充值话费中使用"); |
|
||||||
} |
|
||||||
} else { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "暂时无法使用此优惠券"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法使用此优惠券"); |
|
||||||
} |
|
||||||
|
|
||||||
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
||||||
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { |
|
||||||
// 如果订单总额 小于 满减价格
|
|
||||||
if (highOrder.getTotalPrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 1) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); |
|
||||||
} |
|
||||||
// 订单总额 - 满减额度
|
|
||||||
BigDecimal payablePrice = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); |
|
||||||
|
|
||||||
highOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); |
|
||||||
// 如果总额小于0
|
|
||||||
if (payablePrice.compareTo(new BigDecimal("0")) < 0) { |
|
||||||
highOrder.setPayablePrice(new BigDecimal("0")); |
|
||||||
} else { |
|
||||||
highOrder.setPayablePrice(payablePrice); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
||||||
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { |
|
||||||
// 订单总额 - 满减额度
|
|
||||||
BigDecimal payablePrice = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); |
|
||||||
highOrder.setDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); |
|
||||||
|
|
||||||
// 如果总额小于0
|
|
||||||
if (payablePrice.compareTo(new BigDecimal("0")) == -1) { |
|
||||||
highOrder.setPayablePrice(new BigDecimal("0")); |
|
||||||
} else { |
|
||||||
highOrder.setPayablePrice(payablePrice); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 卡卷类型 1:满减 2:抵扣 3:折扣
|
|
||||||
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { |
|
||||||
// 折扣除100
|
|
||||||
BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice(); |
|
||||||
// 订单总额 * 折扣
|
|
||||||
BigDecimal payablePrice = highOrder.getTotalPrice().multiply(discountPrice).setScale(2, BigDecimal.ROUND_HALF_DOWN); |
|
||||||
highOrder.setDeductionPrice(highOrder.getTotalPrice().subtract(payablePrice)); |
|
||||||
highOrder.setPayablePrice(payablePrice); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
highOrder.setOrderNo("HF" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); |
|
||||||
highOrder.setMemId(userInfoModel.getHighUser().getId()); |
|
||||||
highOrder.setMemName(userInfoModel.getHighUser().getName()); |
|
||||||
highOrder.setMemPhone(userInfoModel.getHighUser().getPhone()); |
|
||||||
highOrder.setCreateTime(new Date()); |
|
||||||
highOrder.setOrderStatus(1); |
|
||||||
highOrder.setPrintStatus(false); |
|
||||||
highOrder.setPrintNum(0); |
|
||||||
highOrder.setPayPrice(highOrder.getPayablePrice().subtract(integralDeductionPrice)); |
|
||||||
highOrder.setDeductionPrice(highOrder.getTotalPrice().subtract(highOrder.getPayPrice())); |
|
||||||
|
|
||||||
highOrderService.insertOrder(highOrder); |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(highOrderService.getOrderById(highOrder.getId())); |
|
||||||
|
|
||||||
} catch (DeadlockLoserDataAccessException deadlockLoserDataAccessException) { |
|
||||||
log.error("HighActivityController -> userLottery() error!", "服务器繁忙"); |
|
||||||
return ResponseMsgUtil.builderResponse(ErrorCode.SERVER_BUSY_ERROR.getCode(),ErrorCode.SERVER_BUSY_ERROR.getMsg(),null); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController -> addOrder() error!",e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/getOrderByOrderNo", method = RequestMethod.GET) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "根据订单号查询订单详情") |
|
||||||
public ResponseData getOrderByOrderNo(@RequestParam(name = "orderNo", required = true) String orderNo) { |
|
||||||
try { |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(highOrderService.getOrderByOrderNo(orderNo)); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController --> getOrderByOrderNo() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/getOrderById", method = RequestMethod.GET) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "根据id查询订单详情") |
|
||||||
public ResponseData getOrderById(@RequestParam(name = "orderId", required = true) Long orderId) { |
|
||||||
try { |
|
||||||
return ResponseMsgUtil.success(highOrderService.getOrderById(orderId)); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController --> getOrderById() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/cancelOrder", method = RequestMethod.GET) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "根据订单id 取消订单") |
|
||||||
public ResponseData cancelOrder(@RequestParam(name = "orderId", required = true) Long orderId) { |
|
||||||
try { |
|
||||||
|
|
||||||
highOrderService.cancelOrder(orderId); |
|
||||||
|
|
||||||
return ResponseMsgUtil.success("操作成功"); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController --> cancelOrder() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/orderCheck", method = RequestMethod.GET) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "根据订单id查看订单") |
|
||||||
public ResponseData orderCheck(@RequestParam(name = "orderId", required = true) Long orderId) { |
|
||||||
try { |
|
||||||
|
|
||||||
highOrderService.orderCheck(orderId); |
|
||||||
|
|
||||||
return ResponseMsgUtil.success("操作成功"); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController --> cancelOrder() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/cancelOrderByOrderNo", method = RequestMethod.GET) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "根据订单号 取消订单") |
|
||||||
public ResponseData cancelOrderByOrderNo(@RequestParam(name = "orderNo", required = true) String orderNo) { |
|
||||||
try { |
|
||||||
|
|
||||||
HighOrder order = highOrderService.getOrderByOrderNo(orderNo); |
|
||||||
if (order == null) { |
|
||||||
log.error("HighOrderController --> addOrder() error!", "未找到订单"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); |
|
||||||
} |
|
||||||
highOrderService.cancelOrder(order.getId()); |
|
||||||
|
|
||||||
return ResponseMsgUtil.success("操作成功"); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController --> cancelOrderByOrderNo() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/getUserOrderList", method = RequestMethod.GET) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "获取用户订单") |
|
||||||
public ResponseData getUserOrderList( |
|
||||||
@RequestParam(name = "status", required = false) String status, |
|
||||||
@RequestParam(name = "orderNo", required = false) String orderNo, |
|
||||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
|
||||||
@RequestParam(name = "pageSize", required = true) Integer pageSize, |
|
||||||
HttpServletRequest request) { |
|
||||||
try { |
|
||||||
|
|
||||||
// 用户
|
|
||||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
|
||||||
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); |
|
||||||
|
|
||||||
Map<String,Object> map = new HashMap<>(); |
|
||||||
map.put("memId", userInfoModel.getHighUser().getId()); |
|
||||||
map.put("status", status); |
|
||||||
map.put("orderNo", orderNo); |
|
||||||
|
|
||||||
PageHelper.startPage(pageNum,pageSize); |
|
||||||
return ResponseMsgUtil.success(new PageInfo<>(highOrderService.getOrderList(map))); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("HighOrderController --> getUserOrderList() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
*/ |
|
@ -1,556 +0,0 @@ |
|||||||
package com.cweb.controller.pay; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.cweb.config.SysConst; |
|
||||||
import com.cweb.config.WxMsgConfig; |
|
||||||
import com.google.gson.JsonObject; |
|
||||||
import com.hai.common.exception.ErrorCode; |
|
||||||
import com.hai.common.exception.ErrorHelp; |
|
||||||
import com.hai.common.exception.SysCode; |
|
||||||
import com.hai.common.pay.WechatPayUtil; |
|
||||||
import com.hai.common.pay.entity.WeChatPayReqInfo; |
|
||||||
import com.hai.common.pay.util.MD5Util; |
|
||||||
import com.hai.common.security.AESEncodeUtil; |
|
||||||
import com.hai.common.security.SessionObject; |
|
||||||
import com.hai.common.security.UserCenter; |
|
||||||
import com.hai.common.utils.*; |
|
||||||
import com.hai.config.CommonSysConst; |
|
||||||
import com.hai.config.UnionPayConfig; |
|
||||||
import com.hai.dao.HighGasOrderPushMapper; |
|
||||||
import com.hai.dao.HighGasOrderRefundMapper; |
|
||||||
import com.hai.entity.*; |
|
||||||
import com.hai.enum_type.OrderPushType; |
|
||||||
import com.hai.enum_type.RechargePayType; |
|
||||||
import com.hai.model.HighUserModel; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.service.*; |
|
||||||
import com.hai.service.pay.impl.GoodsOrderServiceImpl; |
|
||||||
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.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.*; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import javax.servlet.http.HttpServletResponse; |
|
||||||
import java.io.PrintWriter; |
|
||||||
import java.math.BigDecimal; |
|
||||||
import java.util.*; |
|
||||||
import java.util.concurrent.ThreadLocalRandom; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/czOrder") |
|
||||||
@Api(value = "充值回调") |
|
||||||
public class CzOrderController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(TuanYouController.class); |
|
||||||
|
|
||||||
@Resource |
|
||||||
private UserCenter userCenter; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private OutRechargeOrderService outRechargeOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private OutRechargeChildOrderService outRechargeChildOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private BsRequestRecordService bsRequestRecordService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserService highUserService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private UnionPayConfig unionPayConfig; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserPayPasswordService highUserPayPasswordService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserCardService highUserCardService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighGasOrderPushMapper highGasOrderPushMapper; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private WechatPayUtil wechatPayUtil; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ApiOrderRecordService apiOrderRecordService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private BsIntegralRebateService bsIntegralRebateService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighGoldRecService highGoldRecService; |
|
||||||
|
|
||||||
@RequestMapping(value = "/rechargeCallbackByJj", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "尖椒充值回调") |
|
||||||
@ResponseBody |
|
||||||
public void rechargeCallbackByJj(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
|
|
||||||
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); |
|
||||||
|
|
||||||
// 推送记录
|
|
||||||
HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); |
|
||||||
highGasOrderPush.setType(OrderPushType.type2.getType()); |
|
||||||
highGasOrderPush.setOrderNo(dataObject.getString("out_order_id")); |
|
||||||
highGasOrderPush.setCreateTime(new Date()); |
|
||||||
highGasOrderPush.setCode(dataObject.getString("status")); |
|
||||||
highGasOrderPush.setRequestContent(JSONObject.toJSONString(dataObject)); |
|
||||||
highGasOrderPush.setReturnContent(dataObject.toJSONString()); |
|
||||||
highGasOrderPushMapper.insert(highGasOrderPush); |
|
||||||
|
|
||||||
|
|
||||||
// 1 尖椒 2 龙阅
|
|
||||||
dataObject.put("orderNo" , dataObject.getString("out_order_id")); |
|
||||||
|
|
||||||
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(dataObject.getString("out_order_id")); |
|
||||||
|
|
||||||
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); |
|
||||||
|
|
||||||
BsRequestRecord bsRequestRecord = bsRequestRecordService.findRequestRecordByOrderNo(childOrder.getOrderNo()); |
|
||||||
|
|
||||||
bsRequestRecord.setReturnContent(String.valueOf(dataObject)); |
|
||||||
bsRequestRecord.setUpdateTime(new Date()); |
|
||||||
bsRequestRecordService.updateRequestRecord(bsRequestRecord); |
|
||||||
|
|
||||||
// 判断是否充值成功
|
|
||||||
if (dataObject.getInteger("status") == 3) { |
|
||||||
if (rechargeOrder.getRechargeStatus() ==201) { |
|
||||||
new Thread(() -> { |
|
||||||
HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); |
|
||||||
WxMsgConfig.rechargedSuccess( |
|
||||||
rechargeOrder.getRechargeContent() + "充值成功", |
|
||||||
String.valueOf(rechargeOrder.getPayRealPrice()), |
|
||||||
rechargeOrder.getOrderNo(), |
|
||||||
rechargeOrder.getFinishTime(), |
|
||||||
RechargePayType.getNameByType(rechargeOrder.getPayType()), |
|
||||||
highUser.getOpenId()); |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
|
|
||||||
childOrder.setStatus(101); |
|
||||||
rechargeOrder.setRechargeStatus(202); |
|
||||||
rechargeOrder.setPayStatus(100); |
|
||||||
|
|
||||||
outRechargeOrderService.updateOrder(rechargeOrder); |
|
||||||
outRechargeChildOrderService.updateOrder(childOrder); |
|
||||||
if (rechargeOrder.getPayType() == 6) { |
|
||||||
apiOrderRecord(rechargeOrder); |
|
||||||
} |
|
||||||
|
|
||||||
} else { |
|
||||||
callbackResult(childOrder , rechargeOrder); |
|
||||||
} |
|
||||||
|
|
||||||
response.setCharacterEncoding("UTF-8"); |
|
||||||
response.setContentType("text/html;charset=utf-8"); |
|
||||||
PrintWriter writer= response.getWriter(); |
|
||||||
writer.write("SUCCESS"); |
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/rechargeCallbackByLy", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "龙阅充值回调") |
|
||||||
@ResponseBody |
|
||||||
public void rechargeCallbackByLy( |
|
||||||
@RequestParam(name = "out_trade_num", required = true) String out_trade_num, |
|
||||||
@RequestParam(name = "userid", required = true) Long userid, |
|
||||||
@RequestParam(name = "state", required = true) Long state, |
|
||||||
@RequestBody String reqBodyStr , |
|
||||||
HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
// 推送记录
|
|
||||||
HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); |
|
||||||
highGasOrderPush.setType(OrderPushType.type2.getType()); |
|
||||||
highGasOrderPush.setOrderNo(out_trade_num); |
|
||||||
highGasOrderPush.setCreateTime(new Date()); |
|
||||||
highGasOrderPush.setCode(state.toString()); |
|
||||||
highGasOrderPush.setReturnContent(reqBodyStr); |
|
||||||
highGasOrderPushMapper.insert(highGasOrderPush); |
|
||||||
|
|
||||||
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(out_trade_num); |
|
||||||
|
|
||||||
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); |
|
||||||
|
|
||||||
BsRequestRecord bsRequestRecord = bsRequestRecordService.findRequestRecordByOrderNo(childOrder.getOrderNo()); |
|
||||||
|
|
||||||
bsRequestRecord.setReturnContent(reqBodyStr); |
|
||||||
bsRequestRecord.setUpdateTime(new Date()); |
|
||||||
bsRequestRecordService.updateRequestRecord(bsRequestRecord); |
|
||||||
|
|
||||||
|
|
||||||
// 判断是否充值成功
|
|
||||||
if (state == 1) { |
|
||||||
|
|
||||||
if (rechargeOrder.getRechargeStatus() ==201) { |
|
||||||
new Thread(() -> { |
|
||||||
HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); |
|
||||||
WxMsgConfig.rechargedSuccess( |
|
||||||
rechargeOrder.getRechargeContent() + "充值成功", |
|
||||||
String.valueOf(rechargeOrder.getPayRealPrice()), |
|
||||||
rechargeOrder.getOrderNo(), |
|
||||||
rechargeOrder.getFinishTime(), |
|
||||||
RechargePayType.getNameByType(rechargeOrder.getPayType()), |
|
||||||
highUser.getOpenId()); |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
childOrder.setStatus(101); |
|
||||||
rechargeOrder.setRechargeStatus(202); |
|
||||||
rechargeOrder.setPayStatus(100); |
|
||||||
rechargeOrder.setFinishTime(new Date()); |
|
||||||
|
|
||||||
outRechargeOrderService.updateOrder(rechargeOrder); |
|
||||||
outRechargeChildOrderService.updateOrder(childOrder); |
|
||||||
if (rechargeOrder.getPayType() == 6) { |
|
||||||
apiOrderRecord(rechargeOrder); |
|
||||||
} |
|
||||||
} else { |
|
||||||
callbackResult(childOrder , rechargeOrder); |
|
||||||
} |
|
||||||
|
|
||||||
response.setCharacterEncoding("UTF-8"); |
|
||||||
response.setContentType("text/html;charset=utf-8"); |
|
||||||
PrintWriter writer= response.getWriter(); |
|
||||||
writer.write("SUCCESS"); |
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/rechargeCallbackByCy", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "城宇充值回调") |
|
||||||
@ResponseBody |
|
||||||
public void rechargeCallbackByCy(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
|
|
||||||
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); |
|
||||||
|
|
||||||
// 推送记录
|
|
||||||
HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); |
|
||||||
highGasOrderPush.setType(OrderPushType.type2.getType()); |
|
||||||
highGasOrderPush.setOrderNo(dataObject.getString("out_order_id")); |
|
||||||
highGasOrderPush.setCreateTime(new Date()); |
|
||||||
highGasOrderPush.setCode(dataObject.getString("status")); |
|
||||||
highGasOrderPush.setRequestContent(JSONObject.toJSONString(dataObject)); |
|
||||||
highGasOrderPush.setReturnContent(dataObject.toJSONString()); |
|
||||||
highGasOrderPushMapper.insert(highGasOrderPush); |
|
||||||
//
|
|
||||||
//
|
|
||||||
// // 1 尖椒 2 龙阅
|
|
||||||
// dataObject.put("orderNo" , dataObject.getString("out_order_id"));
|
|
||||||
//
|
|
||||||
// OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(dataObject.getString("out_order_id"));
|
|
||||||
//
|
|
||||||
// OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId());
|
|
||||||
//
|
|
||||||
// BsRequestRecord bsRequestRecord = bsRequestRecordService.findRequestRecordByOrderNo(childOrder.getOrderNo());
|
|
||||||
//
|
|
||||||
// bsRequestRecord.setReturnContent(String.valueOf(dataObject));
|
|
||||||
// bsRequestRecord.setUpdateTime(new Date());
|
|
||||||
// bsRequestRecordService.updateRequestRecord(bsRequestRecord);
|
|
||||||
//
|
|
||||||
// // 判断是否充值成功
|
|
||||||
// if (dataObject.getInteger("status") == 3) {
|
|
||||||
// new Thread(() -> {
|
|
||||||
// HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId());
|
|
||||||
// WxMsgConfig.rechargedSuccess(
|
|
||||||
// rechargeOrder.getRechargeContent() + "充值成功",
|
|
||||||
// String.valueOf(rechargeOrder.getPayRealPrice()),
|
|
||||||
// rechargeOrder.getOrderNo(),
|
|
||||||
// rechargeOrder.getFinishTime(),
|
|
||||||
// RechargePayType.getNameByType(rechargeOrder.getPayType()),
|
|
||||||
// highUser.getOpenId());
|
|
||||||
// }).start();
|
|
||||||
// childOrder.setStatus(101);
|
|
||||||
// rechargeOrder.setRechargeStatus(202);
|
|
||||||
// rechargeOrder.setPayStatus(100);
|
|
||||||
//
|
|
||||||
// outRechargeOrderService.updateOrder(rechargeOrder);
|
|
||||||
// outRechargeChildOrderService.updateOrder(childOrder);
|
|
||||||
// if (rechargeOrder.getPayType() == 6) {
|
|
||||||
// apiOrderRecord(rechargeOrder);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// callbackResult(childOrder , rechargeOrder);
|
|
||||||
// }
|
|
||||||
|
|
||||||
response.setCharacterEncoding("UTF-8"); |
|
||||||
response.setContentType("text/html;charset=utf-8"); |
|
||||||
PrintWriter writer= response.getWriter(); |
|
||||||
writer.write("SUCCESS"); |
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 回调结果处理
|
|
||||||
private void callbackResult(OutRechargeChildOrder childOrder , OutRechargeOrder rechargeOrder) throws Exception { |
|
||||||
|
|
||||||
// 101:充值成功 102: 充值中 103:充值失败 104 未充值
|
|
||||||
// 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款
|
|
||||||
if (childOrder.getStatus() == 102 && rechargeOrder.getPayStatus() == 102) { |
|
||||||
|
|
||||||
Date rechargeTime = rechargeOrder.getCreateTimed(); |
|
||||||
Date currentTime = new Date(); |
|
||||||
// 当前时间减去充值时间
|
|
||||||
int hours = (int) ((currentTime.getTime() - rechargeTime.getTime()) / (1000 * 60 * 60)); |
|
||||||
|
|
||||||
// // 判断快充 并且 充值时间小于6
|
|
||||||
// if (rechargeOrder.getRechargeType() == 1 && hours < 6) {
|
|
||||||
// outRechargeOrderService.pollRequest(rechargeOrder);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// 判断慢充 并且 充值时间小于72
|
|
||||||
if (hours < 72) { |
|
||||||
outRechargeOrderService.pollRequest(rechargeOrder); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
rechargeOrder.setRechargeStatus(203); |
|
||||||
childOrder.setStatus(103); |
|
||||||
outRechargeOrderService.updateOrder(rechargeOrder); |
|
||||||
outRechargeChildOrderService.updateOrder(childOrder); |
|
||||||
|
|
||||||
outRechargeOrderService.refundOrder(rechargeOrder.getId()); |
|
||||||
|
|
||||||
|
|
||||||
new Thread(() -> { |
|
||||||
HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); |
|
||||||
WxMsgConfig.rechargedFail( |
|
||||||
rechargeOrder.getRechargeContent() + "充值失败", |
|
||||||
String.valueOf(rechargeOrder.getPayRealPrice()), |
|
||||||
highUser.getOpenId()); |
|
||||||
}).start(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value="/apiCallBack",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "apiCallBack") |
|
||||||
public String test(@RequestBody String reqBodyStr) { |
|
||||||
try { |
|
||||||
if (StringUtils.isBlank(reqBodyStr)) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
System.out.println("reqBodyStr"); |
|
||||||
|
|
||||||
return "SUCCESS"; |
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value="/orderToPayByWx",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "微信订单支付发起支付") |
|
||||||
public ResponseData orderToPayByWx(@RequestBody String reqBodyStr) { |
|
||||||
try { |
|
||||||
if (StringUtils.isBlank(reqBodyStr)) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); |
|
||||||
Long orderId = jsonObject.getLong("orderId"); |
|
||||||
Integer openIdType = jsonObject.getInteger("openIdType"); // openId类型 1:小程序 2:公众号
|
|
||||||
String openId = jsonObject.getString("openId"); // openId
|
|
||||||
if (orderId == null || StringUtils.isBlank(openId)) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单
|
|
||||||
OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); |
|
||||||
if (order == null) { |
|
||||||
log.error("orderToPay error!", "未找到订单信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款
|
|
||||||
if (order.getPayStatus() != 101) { |
|
||||||
log.error("orderToPayByWx error!", "无法支付,订单不处于待支付状态"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); |
|
||||||
} |
|
||||||
|
|
||||||
Map<String,Object> map = new HashMap<>(); |
|
||||||
map.put("orderNo", order.getOrderNo()); |
|
||||||
map.put("payPrice", order.getPayRealPrice()); |
|
||||||
map.put("orderScene", "RECHARGE_ORDER"); |
|
||||||
map.put("body","充值话费"); |
|
||||||
map.put("subject","充值话费"); |
|
||||||
|
|
||||||
//微信支付
|
|
||||||
String nonce_str = MD5Util.MD5Encode(String.valueOf(ThreadLocalRandom.current().nextInt(10000)), "UTF-8"); |
|
||||||
int total_fee = MathUtils.objectConvertBigDecimal(map.get("payPrice")).multiply(new BigDecimal("100")).intValue(); |
|
||||||
WeChatPayReqInfo weChatPayReqInfo = new WeChatPayReqInfo(); |
|
||||||
weChatPayReqInfo.setAppid(SysConst.getSysConfig().getWxMchAppId()); //公众号id
|
|
||||||
weChatPayReqInfo.setMch_id(SysConst.getSysConfig().getWxMchId()); //商户号
|
|
||||||
if (openIdType != null && openIdType.equals(2)) { |
|
||||||
weChatPayReqInfo.setSub_appid("wxa075e8509802f826"); //商户号公众号
|
|
||||||
} else { |
|
||||||
weChatPayReqInfo.setSub_appid(SysConst.getSysConfig().getWxSubAppId());//小程序
|
|
||||||
} |
|
||||||
weChatPayReqInfo.setSub_mch_id("1614670195"); |
|
||||||
weChatPayReqInfo.setSub_openid(openId); |
|
||||||
weChatPayReqInfo.setNonce_str(nonce_str); //随机字符串
|
|
||||||
weChatPayReqInfo.setBody(map.get("body").toString()); //商品描述
|
|
||||||
weChatPayReqInfo.setOut_trade_no(map.get("orderNo").toString()); //商户订单号
|
|
||||||
weChatPayReqInfo.setTotal_fee(total_fee); //总金额
|
|
||||||
weChatPayReqInfo.setSpbill_create_ip("139.159.177.244"); //终端ip
|
|
||||||
weChatPayReqInfo.setNotify_url(SysConst.getSysConfig().getNotifyUrl()); //通知url
|
|
||||||
weChatPayReqInfo.setTrade_type("JSAPI"); //交易类型
|
|
||||||
weChatPayReqInfo.setAttach(map.get("orderScene").toString()); |
|
||||||
weChatPayReqInfo.setProfit_sharing("N"); |
|
||||||
//附加数据,区分订单类型
|
|
||||||
Map<String,String> payMap = new HashMap<>(); |
|
||||||
|
|
||||||
payMap.put("app_id", weChatPayReqInfo.getSub_appid()); |
|
||||||
payMap.put("api_key",SysConst.getSysConfig().getWxApiKey()); |
|
||||||
payMap.put("unified_order_url",SysConst.getSysConfig().getWxUnifiedOrderUrl()); |
|
||||||
SortedMap<Object, Object> sortedMap = wechatPayUtil.goWechatPay(weChatPayReqInfo,payMap); |
|
||||||
return ResponseMsgUtil.success(sortedMap); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("orderToPay error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value="/hltUnionCardPay",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "工会卡支付") |
|
||||||
public ResponseData hltUnionCardPay(@RequestBody JSONObject body,HttpServletRequest request) { |
|
||||||
try { |
|
||||||
// 用户
|
|
||||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
|
||||||
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); |
|
||||||
|
|
||||||
if (body == null |
|
||||||
|| body.getLong("orderId") == null |
|
||||||
|| StringUtils.isBlank(body.getString("password")) |
|
||||||
|| StringUtils.isBlank(body.getString("cardNo")) |
|
||||||
) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单
|
|
||||||
OutRechargeOrder order = outRechargeOrderService.findByOrderId(body.getLong("orderId")); |
|
||||||
|
|
||||||
if (order == null) { |
|
||||||
log.error("hltUnionCardPay error!", "未找到订单信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款
|
|
||||||
if (order.getPayStatus() != 101) { |
|
||||||
log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询用户支付密码
|
|
||||||
HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(order.getUserId()); |
|
||||||
|
|
||||||
if (userPayPassword == null) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); |
|
||||||
} |
|
||||||
if (StringUtils.isBlank(body.getString("password"))) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); |
|
||||||
} |
|
||||||
// 校验支付密码
|
|
||||||
if (!AESEncodeUtil.aesEncrypt(body.getString("password")).equals(userPayPassword.getPassword())) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询用户与卡号的关系
|
|
||||||
HighUserCard userCard = highUserCardService.getDetailByUserCardNo(userInfoModel.getHighUser().getId(), body.getString("cardNo")); |
|
||||||
if (userCard == null) { |
|
||||||
log.error("hltUnionCardPay() ERROR", "未绑定卡号"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未绑定卡号"); |
|
||||||
} |
|
||||||
|
|
||||||
outRechargeOrderService.hltUnionCardPay(userCard, order); |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(outRechargeOrderService.findByOrderId(body.getLong("orderId"))); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("hltUnionCardPay error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value="/orderToUnionPay",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "订单支付发起银联支付") |
|
||||||
public ResponseData orderToUnionPay(@RequestBody String reqBodyStr,HttpServletRequest request) { |
|
||||||
try { |
|
||||||
// 用户
|
|
||||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
|
||||||
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); |
|
||||||
|
|
||||||
if (StringUtils.isBlank(reqBodyStr)) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); |
|
||||||
Long orderId = jsonObject.getLong("orderId"); |
|
||||||
|
|
||||||
if (orderId == null) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
// 订单
|
|
||||||
OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); |
|
||||||
if (order == null) { |
|
||||||
log.error("hltUnionCardPay error!", "未找到订单信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款
|
|
||||||
if (order.getPayStatus() != 101) { |
|
||||||
log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); |
|
||||||
} |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, order.getOrderNo(), order.getPayRealPrice(), "话费充值", CommonSysConst.getSysConfig().getUnionPayTelNotifyUrl(), request)); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("orderToPay error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private void apiOrderRecord(OutRechargeOrder rechargeOrder) { |
|
||||||
Map<String, Object> orderMap = new HashMap<>(); |
|
||||||
orderMap.put("orderId" , rechargeOrder.getId()); |
|
||||||
|
|
||||||
// 查询是否用重复订单
|
|
||||||
ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(orderMap); |
|
||||||
|
|
||||||
apiOrderRecord.setStatus(100); |
|
||||||
apiOrderRecord.setRequestTime(new Date()); |
|
||||||
apiOrderRecordService.updateOrderRecord(apiOrderRecord); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
File diff suppressed because it is too large
Load Diff
@ -1,108 +0,0 @@ |
|||||||
package com.cweb.controller.pay; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.hai.common.security.AESEncodeUtil; |
|
||||||
import com.hai.config.CommonSysConst; |
|
||||||
import com.hai.config.WxOrderConfig; |
|
||||||
import com.hai.dao.HighGasOrderRefundMapper; |
|
||||||
import com.hai.entity.HighChildOrder; |
|
||||||
import com.hai.entity.HighGasOrderRefund; |
|
||||||
import com.hai.entity.HighOrder; |
|
||||||
import com.hai.model.OrderRefundModel; |
|
||||||
import com.hai.service.HighOrderService; |
|
||||||
import io.swagger.annotations.Api; |
|
||||||
import io.swagger.annotations.ApiOperation; |
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.RequestBody; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMethod; |
|
||||||
import org.springframework.web.bind.annotation.ResponseBody; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import javax.servlet.http.HttpServletResponse; |
|
||||||
import java.io.PrintWriter; |
|
||||||
import java.util.Date; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/qianzhu") |
|
||||||
@Api(value = "千猪回调") |
|
||||||
public class QzOrderController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(QzOrderController.class); |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderService highOrderService; |
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/orderNotify", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "千猪订单回调") |
|
||||||
public void orderNotify(@RequestBody String reqBodyStr,HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
log.info(reqBodyStr); |
|
||||||
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); |
|
||||||
HighOrder order = highOrderService.getOrderByOrderNo(dataObject.getString("orderNo")); |
|
||||||
if (order != null) { |
|
||||||
JSONObject data = dataObject.getJSONObject("data"); |
|
||||||
for (HighChildOrder childOrder : order.getHighChildOrderList()) { |
|
||||||
// 4:KFC肯德基 5:电影票
|
|
||||||
if (childOrder.getGoodsType() == 4) { |
|
||||||
// 10:已出票 -5:已取消 -3:部分取消 -10:退款
|
|
||||||
if (dataObject.getInteger("eventType") == -5) { |
|
||||||
// 微信退款
|
|
||||||
OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), data.getBigDecimal("cancelReason"), data.getBigDecimal("cancelReason")); |
|
||||||
if(orderRefundModel.getResult_code().equals("SUCCESS")) { |
|
||||||
childOrder.setChildOrderStatus(5); |
|
||||||
order.setOrderStatus(5); |
|
||||||
order.setCancelTime(new Date()); |
|
||||||
order.setCancelRemarks(data.getString("cancelReason")); |
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (dataObject.getInteger("eventType") == -10) { |
|
||||||
// 微信退款
|
|
||||||
OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), data.getBigDecimal("refundAmount"), data.getBigDecimal("refundAmount")); |
|
||||||
if(orderRefundModel.getResult_code().equals("SUCCESS")) { |
|
||||||
childOrder.setChildOrderStatus(4); |
|
||||||
order.setOrderStatus(4); |
|
||||||
//order.setRefundTime(new Date());
|
|
||||||
//order.setRefundPrice(data.getBigDecimal("refundAmount"));
|
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (childOrder.getGoodsType() == 5) { |
|
||||||
|
|
||||||
// 5:已支付(默认不发) 10:已出票 -5:已取消 15:交易成功
|
|
||||||
if (dataObject.getInteger("eventType") == -5) { |
|
||||||
childOrder.setChildOrderStatus(5); |
|
||||||
order.setOrderStatus(5); |
|
||||||
order.setCancelTime(new Date()); |
|
||||||
order.setCancelRemarks(data.getString("cancelReason")); |
|
||||||
} |
|
||||||
|
|
||||||
if (dataObject.getInteger("eventType") == 15) { |
|
||||||
childOrder.setChildOrderStatus(3); |
|
||||||
order.setOrderStatus(3); |
|
||||||
order.setFinishTime(new Date()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
highOrderService.updateOrder(order); |
|
||||||
|
|
||||||
response.setCharacterEncoding("UTF-8"); |
|
||||||
response.setContentType("text/html;charset=utf-8"); |
|
||||||
PrintWriter writer= response.getWriter(); |
|
||||||
writer.write("success"); |
|
||||||
} |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,256 +0,0 @@ |
|||||||
package com.cweb.controller.pay; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.cweb.config.SysConst; |
|
||||||
import com.hai.common.exception.ErrorCode; |
|
||||||
import com.hai.common.exception.ErrorHelp; |
|
||||||
import com.hai.common.exception.SysCode; |
|
||||||
import com.hai.common.pay.WechatPayUtil; |
|
||||||
import com.hai.common.pay.entity.OrderType; |
|
||||||
import com.hai.common.pay.entity.WeChatPayReqInfo; |
|
||||||
import com.hai.common.pay.util.MD5Util; |
|
||||||
import com.hai.common.security.AESEncodeUtil; |
|
||||||
import com.hai.common.security.SessionObject; |
|
||||||
import com.hai.common.security.UserCenter; |
|
||||||
import com.hai.common.utils.MathUtils; |
|
||||||
import com.hai.common.utils.ResponseMsgUtil; |
|
||||||
import com.hai.config.CommonSysConst; |
|
||||||
import com.hai.config.QianZhuConfig; |
|
||||||
import com.hai.config.UnionPayConfig; |
|
||||||
import com.hai.entity.*; |
|
||||||
import com.hai.model.HighUserModel; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.service.HighOrderService; |
|
||||||
import com.hai.service.HighUserCardService; |
|
||||||
import com.hai.service.HighUserPayPasswordService; |
|
||||||
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.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.RequestBody; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMethod; |
|
||||||
import org.springframework.web.bind.annotation.ResponseBody; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import java.math.BigDecimal; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.SortedMap; |
|
||||||
import java.util.concurrent.ThreadLocalRandom; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/thirdOrder") |
|
||||||
@Api(value = "第三方订单支付接口") |
|
||||||
public class ThirdOrderController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(TuanYouController.class); |
|
||||||
|
|
||||||
@Resource |
|
||||||
private UserCenter userCenter; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderService highOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private WechatPayUtil wechatPayUtil; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserCardService highUserCardService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private UnionPayConfig unionPayConfig; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserPayPasswordService highUserPayPasswordService; |
|
||||||
|
|
||||||
@RequestMapping(value="/orderToPayByWx",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "微信订单支付发起支付") |
|
||||||
public ResponseData orderToPayByWx(@RequestBody String reqBodyStr) { |
|
||||||
try { |
|
||||||
if (StringUtils.isBlank(reqBodyStr)) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); |
|
||||||
Long orderId = jsonObject.getLong("orderId"); |
|
||||||
Integer openIdType = jsonObject.getInteger("openIdType"); // openId类型 1:小程序 2:公众号
|
|
||||||
String openId = jsonObject.getString("openId"); // openId
|
|
||||||
if (orderId == null || StringUtils.isBlank(openId)) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单
|
|
||||||
HighOrder order = highOrderService.getOrderById(jsonObject.getLong("orderId")); |
|
||||||
|
|
||||||
if (order == null) { |
|
||||||
log.error("orderToPay error!", "未找到订单信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款
|
|
||||||
if (order.getOrderStatus() != 1) { |
|
||||||
log.error("orderToPayByWx error!", "无法支付,订单不处于待支付状态"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); |
|
||||||
} |
|
||||||
|
|
||||||
Map<String,Object> map = new HashMap<>(); |
|
||||||
map.put("orderNo", order.getOrderNo()); |
|
||||||
map.put("payPrice", order.getPayRealPrice()); |
|
||||||
if (order.getHighChildOrderList().get(0).getGoodsType() == 4) { |
|
||||||
map.put("orderScene", OrderType.KFC_ORDER.getModuleCode()); |
|
||||||
} else if (order.getHighChildOrderList().get(0).getGoodsType() == 9) { |
|
||||||
map.put("orderScene", OrderType.STARBUCKS_ORDER.getModuleCode()); |
|
||||||
} else if (order.getHighChildOrderList().get(0).getGoodsType() == 10) { |
|
||||||
map.put("orderScene", OrderType.THIRD_ORDER.getModuleCode()); |
|
||||||
} |
|
||||||
|
|
||||||
// 肯德基订单 星巴克订单
|
|
||||||
map.put("body", "购买第三方产品"); |
|
||||||
map.put("subject","购买第三方产品"); |
|
||||||
|
|
||||||
//微信支付
|
|
||||||
String nonce_str = MD5Util.MD5Encode(String.valueOf(ThreadLocalRandom.current().nextInt(10000)), "UTF-8"); |
|
||||||
int total_fee = MathUtils.objectConvertBigDecimal(map.get("payPrice")).multiply(new BigDecimal("100")).intValue(); |
|
||||||
WeChatPayReqInfo weChatPayReqInfo = new WeChatPayReqInfo(); |
|
||||||
weChatPayReqInfo.setAppid(SysConst.getSysConfig().getWxMchAppId()); //公众号id
|
|
||||||
weChatPayReqInfo.setMch_id(SysConst.getSysConfig().getWxMchId()); //商户号
|
|
||||||
if (openIdType != null && openIdType.equals(2)) { |
|
||||||
weChatPayReqInfo.setSub_appid("wxa075e8509802f826"); //商户号公众号
|
|
||||||
} else { |
|
||||||
weChatPayReqInfo.setSub_appid(SysConst.getSysConfig().getWxSubAppId());//小程序
|
|
||||||
} |
|
||||||
weChatPayReqInfo.setSub_mch_id("1614670195"); |
|
||||||
weChatPayReqInfo.setSub_openid(openId); |
|
||||||
weChatPayReqInfo.setNonce_str(nonce_str); //随机字符串
|
|
||||||
weChatPayReqInfo.setBody(map.get("body").toString()); //商品描述
|
|
||||||
weChatPayReqInfo.setOut_trade_no(map.get("orderNo").toString()); //商户订单号
|
|
||||||
weChatPayReqInfo.setTotal_fee(total_fee); //总金额
|
|
||||||
weChatPayReqInfo.setSpbill_create_ip("139.159.177.244"); //终端ip
|
|
||||||
weChatPayReqInfo.setNotify_url(SysConst.getSysConfig().getNotifyUrl()); //通知url
|
|
||||||
weChatPayReqInfo.setTrade_type("JSAPI"); //交易类型
|
|
||||||
weChatPayReqInfo.setAttach(map.get("orderScene").toString()); |
|
||||||
weChatPayReqInfo.setProfit_sharing("N"); |
|
||||||
//附加数据,区分订单类型
|
|
||||||
Map<String,String> payMap = new HashMap<>(); |
|
||||||
|
|
||||||
payMap.put("app_id", weChatPayReqInfo.getSub_appid()); |
|
||||||
payMap.put("api_key",SysConst.getSysConfig().getWxApiKey()); |
|
||||||
payMap.put("unified_order_url",SysConst.getSysConfig().getWxUnifiedOrderUrl()); |
|
||||||
SortedMap<Object, Object> sortedMap = wechatPayUtil.goWechatPay(weChatPayReqInfo,payMap); |
|
||||||
return ResponseMsgUtil.success(sortedMap); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("orderToPay error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value="/hltUnionCardPay",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "工会卡支付") |
|
||||||
public ResponseData hltUnionCardPay(@RequestBody JSONObject body, HttpServletRequest request) { |
|
||||||
try { |
|
||||||
// 用户
|
|
||||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
|
||||||
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); |
|
||||||
|
|
||||||
if (body == null |
|
||||||
|| body.getLong("orderId") == null |
|
||||||
|| StringUtils.isBlank(body.getString("password")) |
|
||||||
|| StringUtils.isBlank(body.getString("cardNo")) |
|
||||||
) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询用户与卡号的关系
|
|
||||||
HighUserCard userCard = highUserCardService.getDetailByUserCardNo(userInfoModel.getHighUser().getId(), body.getString("cardNo")); |
|
||||||
if (userCard == null) { |
|
||||||
log.error("hltUnionCardPay() ERROR", "未绑定卡号"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未绑定卡号"); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单
|
|
||||||
HighOrder order = highOrderService.getOrderById(body.getLong("orderId")); |
|
||||||
|
|
||||||
if (order == null) { |
|
||||||
log.error("hltUnionCardPay error!", "未找到订单信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单状态 : 订单支付状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款
|
|
||||||
if (order.getOrderStatus() != 1) { |
|
||||||
log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询用户支付密码
|
|
||||||
HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(order.getMemId()); |
|
||||||
|
|
||||||
if (userPayPassword == null) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); |
|
||||||
} |
|
||||||
if (StringUtils.isBlank(body.getString("password"))) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); |
|
||||||
} |
|
||||||
// 校验支付密码
|
|
||||||
if (!AESEncodeUtil.aesEncrypt(body.getString("password")).equals(userPayPassword.getPassword())) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); |
|
||||||
} |
|
||||||
|
|
||||||
highOrderService.hltUnionCardPayByThirdProduct(userCard, order.getId()); |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(order); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("hltUnionCardPay error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value="/orderToUnionPay",method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "订单支付发起银联支付") |
|
||||||
public ResponseData orderToUnionPay(@RequestBody String reqBodyStr,HttpServletRequest request) { |
|
||||||
try { |
|
||||||
// 用户
|
|
||||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
|
||||||
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); |
|
||||||
|
|
||||||
if (StringUtils.isBlank(reqBodyStr)) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); |
|
||||||
Long orderId = jsonObject.getLong("orderId"); |
|
||||||
|
|
||||||
if (orderId == null) { |
|
||||||
log.error("orderToPay error!", "参数错误"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
// 订单
|
|
||||||
HighOrder order = highOrderService.getOrderById(orderId); |
|
||||||
if (order == null) { |
|
||||||
log.error("hltUnionCardPay error!", "未找到订单信息"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
|
|
||||||
// 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款
|
|
||||||
if (order.getOrderStatus() != 1) { |
|
||||||
log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); |
|
||||||
} |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(unionPayConfig.upPreOrder(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, order.getOrderNo(), order.getPayRealPrice(), "购买第三方产品", CommonSysConst.getSysConfig().getUnionPayNotifyUrl(), request)); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("orderToPay error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,228 +0,0 @@ |
|||||||
package com.cweb.controller.pay; |
|
||||||
|
|
||||||
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.common.security.AESEncodeUtil; |
|
||||||
import com.hai.common.utils.DateUtil; |
|
||||||
import com.hai.common.utils.ResponseMsgUtil; |
|
||||||
import com.hai.config.CommonSysConst; |
|
||||||
import com.hai.config.HuiLianTongUnionCardConfig; |
|
||||||
import com.hai.config.UnionPayConfig; |
|
||||||
import com.hai.config.WxOrderConfig; |
|
||||||
import com.hai.dao.HighGasOrderRefundMapper; |
|
||||||
import com.hai.entity.HighChildOrder; |
|
||||||
import com.hai.entity.HighGasOrderRefund; |
|
||||||
import com.hai.entity.HighOrder; |
|
||||||
import com.hai.enum_type.OrderPayTypeEnum; |
|
||||||
import com.hai.model.OrderRefundModel; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.service.HighOilCardService; |
|
||||||
import com.hai.service.HighOrderService; |
|
||||||
import com.hai.service.HighUserService; |
|
||||||
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.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.*; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import javax.servlet.http.HttpServletResponse; |
|
||||||
import java.io.*; |
|
||||||
import java.math.BigDecimal; |
|
||||||
import java.security.*; |
|
||||||
import java.text.SimpleDateFormat; |
|
||||||
import java.util.*; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/tuanyou") |
|
||||||
@Api(value = "团油回调") |
|
||||||
public class TuanYouController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(TuanYouController.class); |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderService highOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighGasOrderRefundMapper highGasOrderRefundMapper; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserService highUserService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOilCardService oilCardService; |
|
||||||
|
|
||||||
@RequestMapping(value = "/orderPaymentNotify", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "订单支付回调") |
|
||||||
public void orderPaymentNotify(HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/orderRefundNotify", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "订单退款回调") |
|
||||||
@ResponseBody |
|
||||||
public void orderRefundNotify(@RequestBody String reqBodyStr,HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
log.info(reqBodyStr); |
|
||||||
HighGasOrderRefund highGasOrderRefund = new HighGasOrderRefund(); |
|
||||||
highGasOrderRefund.setCreateTime(new Date()); |
|
||||||
highGasOrderRefund.setReturnContent(reqBodyStr); |
|
||||||
highGasOrderRefundMapper.insert(highGasOrderRefund); |
|
||||||
|
|
||||||
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); |
|
||||||
String dataStr = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(dataObject.getString("data")), CommonSysConst.getSysConfig().getTuanYouAppSecret()); |
|
||||||
JSONObject object = JSONObject.parseObject(dataStr); |
|
||||||
|
|
||||||
// 查询订单
|
|
||||||
HighOrder order = highOrderService.getOrderByOrderNo(object.getString("thirdOrderNo")); |
|
||||||
|
|
||||||
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
|
|
||||||
if (order != null) { |
|
||||||
if (order.getOrderStatus() == 2 || order.getOrderStatus() == 3 || order.getOrderStatus() == 6 || order.getOrderStatus() == 7) { |
|
||||||
// 退单结果 true:成功 false:失败
|
|
||||||
if (object.getBoolean("refundResult") == true && order != null) { |
|
||||||
|
|
||||||
if (order.getPayType() == 2) { |
|
||||||
OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), order.getPayRealPrice(), order.getPayRealPrice()); |
|
||||||
if(orderRefundModel.getResult_code().equals("SUCCESS")) { |
|
||||||
order.setOrderStatus(4); |
|
||||||
//order.setRefundTime(new Date());
|
|
||||||
//order.setRefundPrice(order.getPayRealPrice());
|
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
} |
|
||||||
} else if (order.getPayType() == 3){ |
|
||||||
String remark = "订单" + order.getOrderNo() + "退款,退还积分:" + order.getPayGold(); |
|
||||||
// 积分退款
|
|
||||||
highUserService.goldHandle(order.getMemId(), order.getPayGold(),1, 3, order.getId() , remark); |
|
||||||
order.setOrderStatus(4); |
|
||||||
//order.setRefundTime(new Date());
|
|
||||||
//order.setRefundPrice(order.getPayRealPrice());
|
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
|
|
||||||
} else if (order.getPayType() == 4) { |
|
||||||
String refundOrderNo = String.valueOf(System.currentTimeMillis()); |
|
||||||
JSONObject refund = HuiLianTongUnionCardConfig.refund(refundOrderNo, order.getPaySerialNo()); |
|
||||||
if(!refund.getString("respCode").equals("0000")) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR,refund.getString("respMessage")); |
|
||||||
} |
|
||||||
JSONObject consumptionResult = HuiLianTongUnionCardConfig.resolveResponse(refund.getString("data")); |
|
||||||
if (consumptionResult.getBoolean("success") != true) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易失败!"+consumptionResult.getString("message")); |
|
||||||
} |
|
||||||
order.setOrderStatus(4); |
|
||||||
//order.setRefundTime(new Date());
|
|
||||||
//order.setRefundPrice(order.getPayRealPrice());
|
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
} else if (order.getPayType() == 5) { |
|
||||||
|
|
||||||
Calendar startTime = Calendar.getInstance(); |
|
||||||
startTime.set(Calendar.HOUR_OF_DAY, 00); |
|
||||||
startTime.set(Calendar.MINUTE, 00); |
|
||||||
startTime.set(Calendar.SECOND, 00); |
|
||||||
|
|
||||||
Calendar endTime = Calendar.getInstance(); |
|
||||||
startTime.set(Calendar.HOUR_OF_DAY, 23); |
|
||||||
startTime.set(Calendar.MINUTE, 59); |
|
||||||
startTime.set(Calendar.SECOND, 59); |
|
||||||
|
|
||||||
// 订单是否处于当日的订单
|
|
||||||
if (DateUtil.isEffectiveDate(order.getPayTime(), startTime.getTime(), endTime.getTime())) { |
|
||||||
// 订单撤销
|
|
||||||
JSONObject refund = UnionPayConfig.cancel(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, order.getOrderNo(), order.getPaySerialNo()); |
|
||||||
System.out.println(refund.toJSONString()); |
|
||||||
if (!refund.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); |
|
||||||
} |
|
||||||
|
|
||||||
order.setOrderStatus(4); |
|
||||||
//order.setRefundTime(new Date());
|
|
||||||
//order.setRefundPrice(order.getPayRealPrice());
|
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
|
|
||||||
} else { |
|
||||||
// 订单退款
|
|
||||||
JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); |
|
||||||
System.out.println(refund.toJSONString()); |
|
||||||
if (!refund.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { |
|
||||||
JSONObject refund2 = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID1, UnionPayConfig.TERM_ID1, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); |
|
||||||
if (!refund2.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund2.getString("returnmsg")); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
order.setOrderStatus(4); |
|
||||||
//order.setRefundTime(new Date());
|
|
||||||
//order.setRefundPrice(order.getPayRealPrice());
|
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
|
|
||||||
} |
|
||||||
} else if (order.getPayType().equals(OrderPayTypeEnum.type7.getType())) { |
|
||||||
// 油卡退款
|
|
||||||
oilCardService.refund(order.getOrderNo()); |
|
||||||
} |
|
||||||
|
|
||||||
} else if (!object.getBoolean("refundResult") == true && order != null) { |
|
||||||
order.setOrderStatus(7); |
|
||||||
//order.setRefusalRefundContent(object.getString("refundFailReason"));
|
|
||||||
highOrderService.updateOrderDetail(order); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} finally { |
|
||||||
response.setCharacterEncoding("UTF-8"); |
|
||||||
response.setContentType("text/html;charset=utf-8"); |
|
||||||
PrintWriter writer= null; |
|
||||||
try { |
|
||||||
writer = response.getWriter(); |
|
||||||
} catch (IOException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
writer.write("success"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/abnormalOrderRefund", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "异常订单退款") |
|
||||||
@ResponseBody |
|
||||||
public ResponseData abnormalOrderRefund(@RequestBody JSONObject body) { |
|
||||||
try { |
|
||||||
if (StringUtils.isNotBlank(body.getString("orderNo"))) { |
|
||||||
// 查询订单
|
|
||||||
HighOrder order = highOrderService.getOrderByOrderNo(body.getString("orderNo")); |
|
||||||
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
|
|
||||||
if (order != null && order.getOrderStatus() == 2) { |
|
||||||
OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), order.getPayRealPrice(), order.getPayRealPrice()); |
|
||||||
if(orderRefundModel.getResult_code().equals("SUCCESS")) { |
|
||||||
for (HighChildOrder childOrder : order.getHighChildOrderList()) { |
|
||||||
childOrder.setChildOrderStatus(4); |
|
||||||
} |
|
||||||
order.setOrderStatus(4); |
|
||||||
//order.setRefundTime(new Date());
|
|
||||||
//order.setRefundPrice(order.getPayRealPrice());
|
|
||||||
highOrderService.updateOrder(order); |
|
||||||
return ResponseMsgUtil.success("退款成功"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败"); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,587 +0,0 @@ |
|||||||
package com.cweb.controller.pay; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.alibaba.fastjson.JSONArray; |
|
||||||
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.common.utils.DateUtil; |
|
||||||
import com.hai.common.utils.IDGenerator; |
|
||||||
import com.hai.common.utils.ResponseMsgUtil; |
|
||||||
import com.hai.config.*; |
|
||||||
import com.hai.dao.HighCouponCodeOtherMapper; |
|
||||||
import com.hai.dao.HighGasOrderPushMapper; |
|
||||||
import com.hai.dao.HighPayRecordMapper; |
|
||||||
import com.hai.dao.HighUserCouponMapper; |
|
||||||
import com.hai.entity.*; |
|
||||||
import com.hai.enum_type.MerStoreAmountSourceTypeEnum; |
|
||||||
import com.hai.enum_type.MerStoreAmountTypeEnum; |
|
||||||
import com.hai.enum_type.MerchantStoreSourceType; |
|
||||||
import com.hai.enum_type.OrderPushType; |
|
||||||
import com.hai.model.HighMerchantStoreModel; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.msg.entity.MsgTopic; |
|
||||||
import com.hai.service.*; |
|
||||||
import com.hai.service.pay.NotifyService; |
|
||||||
import io.swagger.annotations.Api; |
|
||||||
import io.swagger.annotations.ApiOperation; |
|
||||||
import org.apache.commons.collections4.MapUtils; |
|
||||||
import org.apache.commons.io.filefilter.IOFileFilter; |
|
||||||
import org.apache.commons.lang3.StringUtils; |
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import org.springframework.data.redis.core.RedisTemplate; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.*; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import javax.servlet.http.HttpServletResponse; |
|
||||||
import java.io.BufferedOutputStream; |
|
||||||
import java.math.BigDecimal; |
|
||||||
import java.net.URLDecoder; |
|
||||||
import java.util.*; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/unionPay") |
|
||||||
@Api(value = "银联支付") |
|
||||||
public class UnionPayController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(UnionPayController.class); |
|
||||||
|
|
||||||
@Resource |
|
||||||
private RedisTemplate redisTemplate; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderService highOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderPreService highOrderPreService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighGasOrderPushMapper highGasOrderPushMapper; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighCouponService highCouponService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighCouponCodeService highCouponCodeService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserService highUserService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserCouponMapper highUserCouponMapper; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighMerchantStoreService highMerchantStoreService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighProfitSharingRecordService highProfitSharingRecordService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighCouponCodeOtherMapper highCouponCodeOtherMapper; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighActivityInfoService highActivityInfoService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighActivityUserLotteryNumService highActivityUserLotteryNumService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private NotifyService notifyService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HuiLianTongConfig huiLianTongConfig; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighPayRecordMapper highPayRecordMapper; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountPackageDiscountActualService discountPackageDiscountActualService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountPackageActualService discountPackageActualService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountPackageService discountPackageService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountPackageRecordService discountPackageRecordService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighDiscountUserRelService highDiscountUserRelService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private OutRechargeOrderService outRechargeOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ApiMemberProductService apiMemberProductService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private ShellGroupService shellGroupService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private JinZhuJiaYouService jinZhuJiaYouService; |
|
||||||
|
|
||||||
@RequestMapping(value = "/notify", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "银联支付 -> 异步回调") |
|
||||||
public void notify(@RequestBody String params,HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
|
|
||||||
System.out.println(params); |
|
||||||
log.info(params); |
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(params)) { |
|
||||||
// 参数解码
|
|
||||||
String paramsStr = URLDecoder.decode(params,"utf-8"); |
|
||||||
|
|
||||||
// 记录请求参数
|
|
||||||
HighPayRecord payRecord = new HighPayRecord(); |
|
||||||
payRecord.setCreateTime(new Date()); |
|
||||||
payRecord.setResType(2); |
|
||||||
payRecord.setPayType(3); |
|
||||||
payRecord.setBodyInfo(paramsStr); |
|
||||||
highPayRecordMapper.insert(payRecord); |
|
||||||
|
|
||||||
// 转换成JSON格式
|
|
||||||
JSONObject body = JSONObject.parseObject(paramsStr.substring(0, paramsStr.length() - 1)); |
|
||||||
if (StringUtils.isNotBlank(body.getString("tradetrace"))) { |
|
||||||
// 查询订单信息
|
|
||||||
HighOrder order = highOrderService.getOrderByOrderNo(body.getString("tradetrace")); |
|
||||||
if (order == null) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询用户
|
|
||||||
HighUser highUser = highUserService.findByUserId(order.getMemId()); |
|
||||||
|
|
||||||
if (order.getOrderStatus() == 1) { |
|
||||||
order.setPaySerialNo(body.getString("wtorderid")); // 支付流水号
|
|
||||||
//order.setPayRealPrice(body.getBigDecimal("payamt")); // 实付金额
|
|
||||||
order.setPayRealPrice(order.getPayPrice()); // 实付金额
|
|
||||||
order.setPayTime(new Date()); // 支付时间
|
|
||||||
//order.setPayModel(2); // 支付模式:1 金币,2 第三方平台,3 混合
|
|
||||||
order.setPayType(5); // 支付方式: 1:支付宝 2:微信 3:金币 4:工会卡 5:银联 6:银联分期
|
|
||||||
order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
|
|
||||||
/* |
|
||||||
|
|
||||||
for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { |
|
||||||
// 商品类型 商品类型 1:卡卷 2:金币充值
|
|
||||||
if (highChildOrder.getGoodsType() == 1) { |
|
||||||
highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
|
|
||||||
|
|
||||||
HighCoupon coupon = highCouponService.getCouponById(highChildOrder.getGoodsId()); |
|
||||||
|
|
||||||
// 是否预约
|
|
||||||
if (coupon.getReserveStatus() == true) { |
|
||||||
HighOrderPre orderPre = new HighOrderPre(); |
|
||||||
orderPre.setCompanyId(coupon.getCompanyId()); |
|
||||||
orderPre.setMerchantId(coupon.getMerchantId()); |
|
||||||
orderPre.setMerchantStoreId(highChildOrder.getStoreId()); |
|
||||||
orderPre.setPreOrderNo(System.currentTimeMillis()+""); |
|
||||||
orderPre.setOrderId(order.getId()); |
|
||||||
orderPre.setOrderNo(order.getOrderNo()); |
|
||||||
orderPre.setChildOrderId(highChildOrder.getId()); |
|
||||||
orderPre.setPayRealPrice(order.getPayRealPrice()); |
|
||||||
orderPre.setGoodsType(1); |
|
||||||
orderPre.setGoodsName(coupon.getCouponName()); |
|
||||||
orderPre.setGoodsId(coupon.getId()); |
|
||||||
orderPre.setPreUserId(order.getMemId()); |
|
||||||
orderPre.setPreUserName(order.getMemName()); |
|
||||||
orderPre.setPreUserPhone(order.getMemPhone()); |
|
||||||
orderPre.setPreUserRemark(order.getRemarks()); |
|
||||||
orderPre.setStatus(1); |
|
||||||
highOrderPreService.insertOrderPre(orderPre); |
|
||||||
} |
|
||||||
|
|
||||||
// 贵州中石化
|
|
||||||
if (coupon.getCouponSource() == 4) { |
|
||||||
Map<String,Object> push = new HashMap<>(); |
|
||||||
push.put("couTypeCode", coupon.getCouponKey()); |
|
||||||
push.put("distCouCount", highChildOrder.getSaleCount()); |
|
||||||
push.put("userPhone", highUser.getPhone()); |
|
||||||
push.put("thirdUserId", highUser.getUnionId()); |
|
||||||
|
|
||||||
// 推送给高速
|
|
||||||
JSONObject returnParam = HuiLianTongConfig.costRechargeOrder(highChildOrder.getExt2()); |
|
||||||
if (returnParam != null && returnParam.getString("respCode").equals("0000")) { |
|
||||||
// 解密
|
|
||||||
JSONObject jsonObject = HuiLianTongUnionCardConfig.resolveResponse(returnParam.getString("data")); |
|
||||||
JSONArray dataArray = JSONObject.parseObject(jsonObject.getString("data"), JSONArray.class); |
|
||||||
for (Object data : dataArray) { |
|
||||||
JSONObject dataObject = (JSONObject) data; |
|
||||||
HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); |
|
||||||
couponCodeOther.setType(1); |
|
||||||
couponCodeOther.setOrderId(order.getId()); |
|
||||||
couponCodeOther.setChildOrderId(highChildOrder.getId()); |
|
||||||
couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode")); |
|
||||||
couponCodeOther.setCouNo(dataObject.getString("couNo")); |
|
||||||
couponCodeOther.setActiveTime(dataObject.getDate("activeTime")); |
|
||||||
couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate")); |
|
||||||
couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate")); |
|
||||||
couponCodeOther.setStatus(20); |
|
||||||
couponCodeOther.setCreateTime(new Date()); |
|
||||||
highCouponCodeOtherMapper.insert(couponCodeOther); |
|
||||||
|
|
||||||
// 卡卷关联用户
|
|
||||||
HighUserCoupon highUserCoupon = new HighUserCoupon(); |
|
||||||
highUserCoupon.setOrderId(order.getId()); |
|
||||||
highUserCoupon.setChildOrderId(highChildOrder.getId()); |
|
||||||
highUserCoupon.setMerchantId(coupon.getMerchantId()); |
|
||||||
highUserCoupon.setCouponId(coupon.getId()); |
|
||||||
highUserCoupon.setUserId(order.getMemId()); |
|
||||||
highUserCoupon.setCreateTime(new Date()); |
|
||||||
highUserCoupon.setQrCodeImg(dataObject.getString("couNo")); |
|
||||||
highUserCoupon.setUseEndTime(dataObject.getDate("validEndDate")); |
|
||||||
highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
|
|
||||||
highUserCouponMapper.insert(highUserCoupon); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 推送记录
|
|
||||||
HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); |
|
||||||
highGasOrderPush.setType(OrderPushType.type6.getType()); |
|
||||||
highGasOrderPush.setOrderNo(order.getOrderNo()); |
|
||||||
highGasOrderPush.setCreateTime(new Date()); |
|
||||||
highGasOrderPush.setCode(returnParam.getString("result")); |
|
||||||
highGasOrderPush.setRequestContent(JSONObject.toJSONString(push)); |
|
||||||
highGasOrderPush.setReturnContent(returnParam.toJSONString()); |
|
||||||
highGasOrderPushMapper.insert(highGasOrderPush); |
|
||||||
|
|
||||||
} else if (coupon.getCouponSource() == 5) { |
|
||||||
// 给用户发码
|
|
||||||
JSONObject sendResponse = ChongQingCNPCService.sendCNPCTicket(coupon.getCouponKey(), order.getOrderNo(), highChildOrder.getSaleCount(), order.getMemPhone()); |
|
||||||
|
|
||||||
// 推送记录
|
|
||||||
JSONObject sendRequest = new JSONObject(); |
|
||||||
sendRequest.put("requestCode", coupon.getCouponKey()); |
|
||||||
sendRequest.put("tradeId", order.getOrderNo()); |
|
||||||
sendRequest.put("ticketSum", highChildOrder.getSaleCount()); |
|
||||||
sendRequest.put("phone", order.getMemPhone()); |
|
||||||
|
|
||||||
HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); |
|
||||||
highGasOrderPush.setType(OrderPushType.type10.getType()); |
|
||||||
highGasOrderPush.setOrderNo(order.getOrderNo()); |
|
||||||
highGasOrderPush.setCreateTime(new Date()); |
|
||||||
highGasOrderPush.setRequestContent(sendRequest.toJSONString()); |
|
||||||
highGasOrderPush.setReturnContent(sendResponse.toJSONString()); |
|
||||||
highGasOrderPushMapper.insert(highGasOrderPush); |
|
||||||
|
|
||||||
JSONObject couponDetail = sendResponse.getJSONObject("ticketDetail"); |
|
||||||
JSONArray codeList = sendResponse.getJSONArray("codeList"); |
|
||||||
|
|
||||||
for (Object data : codeList) { |
|
||||||
HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); |
|
||||||
couponCodeOther.setType(2); |
|
||||||
couponCodeOther.setOrderId(order.getId()); |
|
||||||
couponCodeOther.setChildOrderId(highChildOrder.getId()); |
|
||||||
couponCodeOther.setCouTypeCode(couponDetail.getString("requestCode")); |
|
||||||
couponCodeOther.setCouNo(ChongQingCNPCService.decryptCouponCode(String.valueOf(data))); |
|
||||||
couponCodeOther.setActiveTime(DateUtil.format(couponDetail.getString("effectiveTime"), "yyyy-MM-dd")); |
|
||||||
couponCodeOther.setValidStartDate(DateUtil.format(couponDetail.getString("effectiveTime"), "yyyy-MM-dd")); |
|
||||||
couponCodeOther.setValidEndDate(DateUtil.format(couponDetail.getString("expiredDate"), "yyyy-MM-dd")); |
|
||||||
couponCodeOther.setStatus(20); |
|
||||||
couponCodeOther.setCreateTime(new Date()); |
|
||||||
highCouponCodeOtherMapper.insert(couponCodeOther); |
|
||||||
|
|
||||||
// 卡卷关联用户
|
|
||||||
HighUserCoupon highUserCoupon = new HighUserCoupon(); |
|
||||||
highUserCoupon.setOrderId(order.getId()); |
|
||||||
highUserCoupon.setChildOrderId(highChildOrder.getId()); |
|
||||||
highUserCoupon.setMerchantId(coupon.getMerchantId()); |
|
||||||
highUserCoupon.setCouponId(coupon.getId()); |
|
||||||
highUserCoupon.setUserId(order.getMemId()); |
|
||||||
highUserCoupon.setCreateTime(new Date()); |
|
||||||
highUserCoupon.setQrCodeImg(couponCodeOther.getCouNo()); |
|
||||||
highUserCoupon.setUseEndTime(couponCodeOther.getValidEndDate()); |
|
||||||
highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
|
|
||||||
highUserCouponMapper.insert(highUserCoupon); |
|
||||||
} |
|
||||||
} else { |
|
||||||
HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); |
|
||||||
code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付
|
|
||||||
code.setReceiveTime(new Date()); |
|
||||||
highCouponCodeService.updateCouponCode(code); |
|
||||||
// 卡卷关联用户
|
|
||||||
HighUserCoupon highUserCoupon = new HighUserCoupon(); |
|
||||||
highUserCoupon.setOrderId(order.getId()); |
|
||||||
highUserCoupon.setChildOrderId(highChildOrder.getId()); |
|
||||||
highUserCoupon.setMerchantId(code.getMerchantId()); |
|
||||||
highUserCoupon.setCouponId(code.getCouponId()); |
|
||||||
highUserCoupon.setUserId(order.getMemId()); |
|
||||||
highUserCoupon.setCouponCodeId(code.getId()); |
|
||||||
highUserCoupon.setCreateTime(new Date()); |
|
||||||
highUserCoupon.setQrCodeImg(code.getExt1()); |
|
||||||
|
|
||||||
// 计算使用有效期
|
|
||||||
Calendar userEndTime = Calendar.getInstance(); |
|
||||||
userEndTime.setTime(new Date()); |
|
||||||
userEndTime.set(Calendar.HOUR_OF_DAY, 23); |
|
||||||
userEndTime.set(Calendar.MINUTE, 59); |
|
||||||
userEndTime.set(Calendar.SECOND, 59); |
|
||||||
userEndTime.add(Calendar.DATE, coupon.getRecycleDay()); |
|
||||||
if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) { |
|
||||||
highUserCoupon.setUseEndTime(code.getUseEndTime()); |
|
||||||
} else { |
|
||||||
highUserCoupon.setUseEndTime(userEndTime.getTime()); |
|
||||||
} |
|
||||||
highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
|
|
||||||
highUserCouponMapper.insert(highUserCoupon); |
|
||||||
} |
|
||||||
|
|
||||||
// 查询卡券是否有活动
|
|
||||||
Map<String, Object> activity = highActivityInfoService.getNewActivityByCouponId(coupon.getId()); |
|
||||||
if (activity != null && MapUtils.getLong(activity, "id") != null) { |
|
||||||
highActivityUserLotteryNumService.addLotteryNum(MapUtils.getLong(activity, "id"),order.getMemId(), 1); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (highChildOrder.getGoodsType() == 2) { |
|
||||||
highChildOrder.setChildOrdeStatus(3); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
|
|
||||||
// 金币 1:100
|
|
||||||
Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue(); |
|
||||||
String remark = "订单" + order.getOrderNo() + "积分充值积分:" + goldNum; |
|
||||||
highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId() , remark); |
|
||||||
} |
|
||||||
|
|
||||||
if (highChildOrder.getGoodsType() == 3) { |
|
||||||
highChildOrder.setChildOrdeStatus(3); |
|
||||||
order.setOrderStatus(3); |
|
||||||
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); |
|
||||||
|
|
||||||
// 来源类型 1:平台自建 2:团油
|
|
||||||
if (store.getSourceType().equals(1)) { |
|
||||||
|
|
||||||
// 预存类型 0:非预存 1:预存门店
|
|
||||||
if (store.getPrestoreType() != null && store.getPrestoreType().equals(1)) { |
|
||||||
Map<String, Object> pushParam = new HashMap<>(); |
|
||||||
pushParam.put("businessType", MerStoreAmountTypeEnum.type2.getType()); |
|
||||||
pushParam.put("storeId", highChildOrder.getGoodsId()); |
|
||||||
pushParam.put("price", order.getTotalPrice()); |
|
||||||
pushParam.put("sourceType", MerStoreAmountSourceTypeEnum.type2.getType()); |
|
||||||
pushParam.put("sourceId", order.getId()); |
|
||||||
pushParam.put("sourceContent", "订单号:" + order.getOrderNo() + ",加油金额:¥" + order.getTotalPrice()); |
|
||||||
pushParam.put("opUserId", order.getMemId()); |
|
||||||
pushParam.put("opUserName", order.getMemName()); |
|
||||||
// 扣预存款
|
|
||||||
this.redisTemplate.boundListOps(MsgTopic.MerStoreAccount.getName()).leftPush(pushParam); |
|
||||||
} |
|
||||||
|
|
||||||
} else if (store.getSourceType().equals(2)) { |
|
||||||
// 推送团油订单
|
|
||||||
Map<String,Object> paramMap = new HashMap<>(); |
|
||||||
paramMap.put("gasId", store.getStoreKey()); |
|
||||||
paramMap.put("oilNo", highChildOrder.getGasOilNo()); |
|
||||||
paramMap.put("gunNo", highChildOrder.getGasGunNo()); |
|
||||||
BigDecimal priceGun = highChildOrder.getGasPriceGun(); |
|
||||||
BigDecimal priceVip = highChildOrder.getGasPriceVip(); |
|
||||||
paramMap.put("priceGun", priceGun); // 枪单价
|
|
||||||
paramMap.put("priceVip", priceVip); // 优惠价
|
|
||||||
paramMap.put("driverPhone", order.getMemPhone()); |
|
||||||
paramMap.put("thirdSerialNo", order.getOrderNo()); |
|
||||||
paramMap.put("refuelingAmount", highChildOrder.getTotalPrice()); |
|
||||||
|
|
||||||
// 油品类型 1:汽油:2:柴油;3:天然气
|
|
||||||
if (highChildOrder.getGasOilType() == 1) { |
|
||||||
paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount()); |
|
||||||
} else if (highChildOrder.getGasOilType() == 2) { |
|
||||||
paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount()); |
|
||||||
} |
|
||||||
JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap); |
|
||||||
// 推送团油订单记录
|
|
||||||
HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); |
|
||||||
highGasOrderPush.setType(OrderPushType.type1.getType()); |
|
||||||
highGasOrderPush.setOrderNo(order.getOrderNo()); |
|
||||||
highGasOrderPush.setCreateTime(new Date()); |
|
||||||
highGasOrderPush.setCode(orderPushObject.getString("code")); |
|
||||||
highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap)); |
|
||||||
highGasOrderPush.setReturnContent(orderPushObject.toJSONString()); |
|
||||||
highGasOrderPushMapper.insert(highGasOrderPush); |
|
||||||
|
|
||||||
if (orderPushObject != null && orderPushObject.getString("code").equals("200")) { |
|
||||||
highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); |
|
||||||
} |
|
||||||
} else if (store.getSourceType().equals(MerchantStoreSourceType.type3.getNumber())) { |
|
||||||
|
|
||||||
// 推送加好油
|
|
||||||
shellGroupService.gasSyncPayment(order.getOrderNo(), |
|
||||||
store.getStoreKey(), |
|
||||||
order.getPayTime(), |
|
||||||
highChildOrder.getTotalPrice(), |
|
||||||
highChildOrder.getGasOilNo(), |
|
||||||
highChildOrder.getGasGunNo(), |
|
||||||
order.getPayablePrice(), |
|
||||||
order.getDeductionPrice() |
|
||||||
); |
|
||||||
|
|
||||||
} else if (store.getSourceType().equals(MerchantStoreSourceType.type4.getNumber())) { |
|
||||||
// 推送金猪加油
|
|
||||||
jinZhuJiaYouService.payOrder(order.getOrderNo(), highChildOrder.getGasPriceChannelPay()); |
|
||||||
} |
|
||||||
} |
|
||||||
if (highChildOrder.getGoodsType() == 4 || highChildOrder.getGoodsType() == 9) { |
|
||||||
highChildOrder.setChildOrdeStatus(2); |
|
||||||
} |
|
||||||
if (highChildOrder.getGoodsType() == 7) { |
|
||||||
highChildOrder.setChildOrdeStatus(2); |
|
||||||
HighDiscountPackageActual actual = discountPackageActualService.getDetailByChildOrderId(highChildOrder.getId()); |
|
||||||
if (actual != null) { |
|
||||||
List<HighDiscountPackageDiscountActual> discountList = discountPackageDiscountActualService.getHighDiscountPackageDiscountActualList(actual.getId()); |
|
||||||
for (HighDiscountPackageDiscountActual discount : discountList) { |
|
||||||
highDiscountUserRelService.receiveDiscount(order.getMemId(), discount.getAgentDiscountCodeId()); |
|
||||||
} |
|
||||||
HighDiscountPackage discountPackage = discountPackageService.findDiscountPackageById(actual.getDiscountPackageId()); |
|
||||||
HighDiscountPackageRecord record = new HighDiscountPackageRecord(); |
|
||||||
record.setDiscountPackageId(discountPackage.getId()); |
|
||||||
record.setDiscountPackageTitle(discountPackage.getTitle()); |
|
||||||
record.setUsingAttribution(discountPackage.getUsingAttribution()); |
|
||||||
record.setCompanyId(discountPackage.getCompanyId()); |
|
||||||
record.setOrderId(order.getId().intValue()); |
|
||||||
record.setChildOrderId(highChildOrder.getId().intValue()); |
|
||||||
record.setRecordNo(System.currentTimeMillis()+""); |
|
||||||
record.setSalesType(1); |
|
||||||
record.setPrice(order.getPayPrice()); |
|
||||||
record.setUserId(order.getMemId().intValue()); |
|
||||||
discountPackageRecordService.insertRecord(record); |
|
||||||
actual.setAllocationTime(new Date()); |
|
||||||
actual.setStatus(3); // 状态: 1: 待分配 2:预分配(售卖)3:已分配
|
|
||||||
discountPackageActualService.updateHighDiscountPackageActual(actual); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
HighGasOrderPush orderPush = new HighGasOrderPush(); |
|
||||||
JSONObject returnObject = new JSONObject(); |
|
||||||
|
|
||||||
if (order.getHighChildOrderList().get(0).getGoodsType() == 4) { |
|
||||||
returnObject = QianZhuConfig.payKfcOrder(order.getOrderNo()); |
|
||||||
} else if (order.getHighChildOrderList().get(0).getGoodsType() == 9) { |
|
||||||
returnObject = QianZhuConfig.starbucksOrdersPay(order.getOrderNo()); |
|
||||||
} else if (order.getHighChildOrderList().get(0).getGoodsType() == 10){ |
|
||||||
orderPush.setType(OrderPushType.type9.getType()); |
|
||||||
ApiMemberProduct memberProduct = apiMemberProductService.findById(order.getHighChildOrderList().get(0).getGoodsId()); |
|
||||||
returnObject = QianZhuConfig.insertV2(memberProduct.getProductId() , order.getOrderNo() , order.getRemarks()); |
|
||||||
} |
|
||||||
|
|
||||||
highOrderService.updateOrder(order); |
|
||||||
|
|
||||||
orderPush.setOrderNo(order.getOrderNo()); |
|
||||||
orderPush.setCreateTime(new Date()); |
|
||||||
orderPush.setRequestContent(order.getOrderNo()); |
|
||||||
orderPush.setReturnContent(returnObject.toJSONString()); |
|
||||||
highGasOrderPushMapper.insert(orderPush); |
|
||||||
|
|
||||||
|
|
||||||
if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) { |
|
||||||
new Thread(() -> { |
|
||||||
highOrderService.printGasOrder(order.getHighChildOrderList().get(0).getGoodsId(), order, false); |
|
||||||
}).start(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
|
||||||
JSONObject result = new JSONObject(); |
|
||||||
result.put("resultcode", "00"); |
|
||||||
out.write(result.toJSONString().getBytes()); |
|
||||||
out.flush(); |
|
||||||
out.close(); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("UnionPayController --> notify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/notifyTel", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "银联支付 -> 异步回调") |
|
||||||
public void notifyTel(@RequestBody String params,HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
|
|
||||||
System.out.println(params); |
|
||||||
log.info(params); |
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(params)) { |
|
||||||
// 参数解码
|
|
||||||
String paramsStr = URLDecoder.decode(params,"utf-8"); |
|
||||||
|
|
||||||
// 记录请求参数
|
|
||||||
HighPayRecord payRecord = new HighPayRecord(); |
|
||||||
payRecord.setCreateTime(new Date()); |
|
||||||
payRecord.setResType(2); |
|
||||||
payRecord.setPayType(3); |
|
||||||
payRecord.setBodyInfo(paramsStr); |
|
||||||
highPayRecordMapper.insert(payRecord); |
|
||||||
|
|
||||||
// 转换成JSON格式
|
|
||||||
JSONObject body = JSONObject.parseObject(paramsStr.substring(0, paramsStr.length() - 1)); |
|
||||||
if (StringUtils.isNotBlank(body.getString("tradetrace"))) { |
|
||||||
OutRechargeOrder order = outRechargeOrderService.findByOrderNo(body.getString("tradetrace")); |
|
||||||
if (order == null) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
|
|
||||||
order.setPaySerialNo(body.getString("wtorderid")); // 支付流水号
|
|
||||||
order.setPayRealPrice(order.getPayRealPrice()); // 实付金额
|
|
||||||
|
|
||||||
order.setPayStatus(102); |
|
||||||
order.setRechargeStatus(204); |
|
||||||
order.setPayType(4); |
|
||||||
order.setPayTime(new Date()); // 支付时间
|
|
||||||
outRechargeOrderService.updateOrder(order); |
|
||||||
outRechargeOrderService.pollRequest(order); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
|
||||||
JSONObject result = new JSONObject(); |
|
||||||
result.put("resultcode", "00"); |
|
||||||
out.write(result.toJSONString().getBytes()); |
|
||||||
out.flush(); |
|
||||||
out.close(); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("UnionPayController --> notify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/refreshStagingOrder", method = RequestMethod.POST) |
|
||||||
@ResponseBody |
|
||||||
@ApiOperation(value = "银联分期支付 -> 刷新分期订单") |
|
||||||
public ResponseData refreshStagingOrder(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
|
|
||||||
if (body == null || StringUtils.isBlank(body.getString("orderNo"))) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
||||||
} |
|
||||||
// 查询订单信息
|
|
||||||
HighOrder order = highOrderService.getOrderByOrderNo(body.getString("orderNo")); |
|
||||||
if (order == null) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); |
|
||||||
} |
|
||||||
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
|
|
||||||
if (order.getOrderStatus().equals(1)) { |
|
||||||
String orgTrace = CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(0,4) |
|
||||||
+CommonSysConst.getSysConfig().getUnionStagingPayOrgId().substring(CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length() - 4,CommonSysConst.getSysConfig().getUnionStagingPayOrgId().length()) |
|
||||||
+ DateUtil.format(new Date(), DateUtil.YMDHMS) |
|
||||||
+ IDGenerator.nextId(6); |
|
||||||
|
|
||||||
JSONObject responseObject = UnionStagingPayConfig.queryStaging(orgTrace, order.getPaySerialNo(), "", order.getCreateTime(), request); |
|
||||||
if (responseObject.getString("sysRetCode").equals("000000")) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
return ResponseMsgUtil.success(responseObject); |
|
||||||
} |
|
||||||
return ResponseMsgUtil.success(order); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
log.error("UnionPayController --> refreshStagingOrder() error!", e); |
|
||||||
return ResponseMsgUtil.exception(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,212 +0,0 @@ |
|||||||
package com.cweb.controller.pay; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
|
||||||
import com.cweb.config.SysConst; |
|
||||||
import com.cweb.config.WxMsgConfig; |
|
||||||
import com.hai.common.exception.ErrorCode; |
|
||||||
import com.hai.common.exception.ErrorHelp; |
|
||||||
import com.hai.common.exception.SysCode; |
|
||||||
import com.hai.common.pay.WechatPayUtil; |
|
||||||
import com.hai.common.pay.entity.WechatCallBackInfo; |
|
||||||
import com.hai.common.pay.util.IOUtil; |
|
||||||
import com.hai.common.pay.util.XmlUtil; |
|
||||||
import com.hai.common.pay.util.sdk.WXPayConstants; |
|
||||||
import com.hai.common.utils.HttpsUtils; |
|
||||||
import com.hai.common.utils.ResponseMsgUtil; |
|
||||||
import com.hai.common.utils.WxUtils; |
|
||||||
import com.hai.entity.*; |
|
||||||
import com.hai.enum_type.GoodsType; |
|
||||||
import com.hai.enum_type.PayType; |
|
||||||
import com.hai.model.ResponseData; |
|
||||||
import com.hai.model.WxSharingOrderRequestModel; |
|
||||||
import com.hai.model.WxSharingReceiversVO; |
|
||||||
import com.hai.service.HighOrderService; |
|
||||||
import com.hai.service.HighProfitSharingRecordService; |
|
||||||
import com.hai.service.HighUserService; |
|
||||||
import com.hai.service.TelApiService; |
|
||||||
import com.hai.service.pay.NotifyService; |
|
||||||
import com.hai.service.pay.PayRecordService; |
|
||||||
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; |
|
||||||
import io.swagger.annotations.Api; |
|
||||||
import io.swagger.annotations.ApiOperation; |
|
||||||
import net.sf.cglib.beans.BeanMap; |
|
||||||
import org.apache.http.HttpEntity; |
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse; |
|
||||||
import org.apache.http.client.methods.HttpPost; |
|
||||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
|
||||||
import org.apache.http.entity.StringEntity; |
|
||||||
import org.apache.http.impl.client.CloseableHttpClient; |
|
||||||
import org.apache.http.impl.client.HttpClients; |
|
||||||
import org.apache.http.ssl.SSLContexts; |
|
||||||
import org.apache.http.util.EntityUtils; |
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMethod; |
|
||||||
import org.springframework.web.bind.annotation.RequestParam; |
|
||||||
import org.springframework.web.bind.annotation.ResponseBody; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
|
||||||
import javax.net.ssl.SSLContext; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import javax.servlet.http.HttpServletResponse; |
|
||||||
import java.io.BufferedOutputStream; |
|
||||||
import java.io.FileInputStream; |
|
||||||
import java.io.FileNotFoundException; |
|
||||||
import java.io.UnsupportedEncodingException; |
|
||||||
import java.math.BigDecimal; |
|
||||||
import java.security.*; |
|
||||||
import java.util.*; |
|
||||||
|
|
||||||
@Controller |
|
||||||
@RequestMapping(value = "/wechatpay") |
|
||||||
@Api(value = "微信支付") |
|
||||||
public class WechatPayController { |
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(WechatPayController.class); |
|
||||||
|
|
||||||
private WXPayConstants.SignType signType; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private NotifyService notifyService; |
|
||||||
@Resource |
|
||||||
private PayRecordService payRecordService; |
|
||||||
@Resource |
|
||||||
private WechatPayUtil wechatPayUtil; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighOrderService highOrderService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private HighUserService highUserService; |
|
||||||
|
|
||||||
@Resource |
|
||||||
private TelApiService telApiService; |
|
||||||
@Resource |
|
||||||
private HighProfitSharingRecordService highProfitSharingRecordService; |
|
||||||
|
|
||||||
@RequestMapping(value = "/notify", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "微信支付 -> 异步回调") |
|
||||||
public void wechatNotify(HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
log.info("微信支付 -> 异步通知:处理开始"); |
|
||||||
|
|
||||||
String resXml = ""; // 反馈给微信服务器
|
|
||||||
String notifyXml = null; // 微信支付系统发送的数据(<![CDATA[product_001]]>格式)
|
|
||||||
notifyXml = IOUtil.inputStreamToString(request.getInputStream(), "UTF-8"); |
|
||||||
|
|
||||||
log.info("微信支付系统发送的数据:" + notifyXml); |
|
||||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); |
|
||||||
|
|
||||||
resXml = notifyService.wechatNotify(map); |
|
||||||
|
|
||||||
/* if (SignatureUtil.reCheckIsSignValidFromWeiXin(notifyXml, SysConst.getSysConfig().getWxApiKey(), "UTF-8")) { |
|
||||||
log.info("微信支付系统发送的数据:" + notifyXml); |
|
||||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); |
|
||||||
|
|
||||||
resXml = notifyService.wechatNotify(map); |
|
||||||
} else { |
|
||||||
log.error("微信支付 -> 异步通知:验签失败"); |
|
||||||
log.error("apiKey:" + SysConst.getSysConfig().getWxApiKey()); |
|
||||||
log.error("返回信息:" + notifyXml); |
|
||||||
resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" |
|
||||||
+ "<return_msg><![CDATA[签名验证错误]]></return_msg>" + "</xml> "; |
|
||||||
}*/ |
|
||||||
|
|
||||||
new Thread(() -> { |
|
||||||
// 查询订单信息
|
|
||||||
HighOrder order = highOrderService.getOrderByOrderNo(map.get("out_trade_no")); |
|
||||||
if (order == null) { |
|
||||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); |
|
||||||
} |
|
||||||
HighUser highUser = highUserService.findByUserId(order.getMemId()); |
|
||||||
HighChildOrder presentation = highOrderService.getChildOrderByPresentation(order.getId()); |
|
||||||
WxMsgConfig.pushOneUser( |
|
||||||
presentation.getGoodsName() + "(" + GoodsType.getNameByType(presentation.getGoodsType()) + ")", |
|
||||||
String.valueOf(order.getPayPrice()), |
|
||||||
order.getOrderNo(), |
|
||||||
order.getPayTime(), |
|
||||||
PayType.getNameByType(order.getPayType()), order.getId(), |
|
||||||
highUser.getOpenId()); |
|
||||||
}).start(); |
|
||||||
|
|
||||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
|
||||||
out.write(resXml.getBytes()); |
|
||||||
out.flush(); |
|
||||||
out.close(); |
|
||||||
log.info("微信支付 -> 异步通知:处理完成"); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping(value = "/addLedgerReceiver", method = RequestMethod.POST) |
|
||||||
@ApiOperation(value = "微信支付 -> 添加分账接收方") |
|
||||||
public void addLedgerReceiver(@RequestParam(name = "sub_mch_id", required = true) String sub_mch_id, |
|
||||||
HttpServletRequest request, HttpServletResponse response) { |
|
||||||
try { |
|
||||||
|
|
||||||
WxSharingReceiversVO receiversVO = new WxSharingReceiversVO(); |
|
||||||
receiversVO.setAccount("1603942866"); |
|
||||||
receiversVO.setType("MERCHANT_ID"); |
|
||||||
receiversVO.setName("重庆惠昕石化有限责任公司"); |
|
||||||
receiversVO.setRelation_type("SERVICE_PROVIDER"); |
|
||||||
|
|
||||||
Map<String , String> map = new HashMap<>(); |
|
||||||
|
|
||||||
map.put("mch_id" , "1289663601"); |
|
||||||
map.put("sub_mch_id" , sub_mch_id); |
|
||||||
map.put("appid" , "wxa075e8509802f826"); |
|
||||||
map.put("nonce_str" , WxUtils.makeNonStr()); |
|
||||||
map.put("sign_type" , "HMAC-SHA256"); |
|
||||||
map.put("receiver" , JSONObject.toJSONString(receiversVO)); |
|
||||||
|
|
||||||
String sign = WxUtils.generateSignature(map, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); |
|
||||||
|
|
||||||
map.put("sign" , sign); |
|
||||||
|
|
||||||
String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver"; |
|
||||||
String xm = WxUtils.mapToXml(map); |
|
||||||
String rest = String.valueOf(HttpsUtils.postData(url, xm)); |
|
||||||
|
|
||||||
System.out.println(rest); |
|
||||||
log.info("微信支付 -> 添加分账接收方:处理开始"); |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("WechatPayController --> wechatNotify() error!", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
String getToken(String method, String url, String body) throws UnsupportedEncodingException, SignatureException, NoSuchAlgorithmException, InvalidKeyException, FileNotFoundException { |
|
||||||
|
|
||||||
long timeMillis = System.currentTimeMillis(); |
|
||||||
String nonceStr = String.valueOf(timeMillis); |
|
||||||
long timestamp = System.currentTimeMillis() / 1000; |
|
||||||
String message = buildMessage(method, url, timestamp, nonceStr, body); |
|
||||||
PrivateKey privateKey = PemUtil.loadPrivateKey(new FileInputStream("G:/hurui-project/hai-parent/hai-cweb/src/main/resources/privatekey/apiclient_key.pem")); |
|
||||||
String signature = sign(privateKey,message.getBytes("utf-8")); |
|
||||||
|
|
||||||
return "mchid=\"" + SysConst.getSysConfig().getWxSubMchId() + "\"," |
|
||||||
+ "nonce_str=\"" + nonceStr + "\"," |
|
||||||
+ "timestamp=\"" + timestamp + "\"," |
|
||||||
+ "serial_no=\"" + "1B08DC2A078B0B1F77A65C97C445AAD545B5EAA6" + "\"," |
|
||||||
+ "signature=\"" + signature + "\""; |
|
||||||
} |
|
||||||
|
|
||||||
String sign(PrivateKey privateKey,byte[] message) throws SignatureException, NoSuchAlgorithmException, InvalidKeyException { |
|
||||||
Signature sign = Signature.getInstance("SHA256withRSA"); |
|
||||||
sign.initSign(privateKey); |
|
||||||
sign.update(message); |
|
||||||
return Base64.getEncoder().encodeToString(sign.sign()); |
|
||||||
} |
|
||||||
|
|
||||||
String buildMessage(String method, String url, long timestamp, String nonceStr, String body) { |
|
||||||
return method + "" |
|
||||||
+ url + "" |
|
||||||
+ timestamp + "" |
|
||||||
+ nonceStr + "" |
|
||||||
+ body + ""; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,50 +0,0 @@ |
|||||||
package com.hai.enum_type; |
|
||||||
|
|
||||||
import java.util.Objects; |
|
||||||
|
|
||||||
/** |
|
||||||
* 支付方式 |
|
||||||
* @author hurui |
|
||||||
*/ |
|
||||||
public enum OrderPayTypeEnum { |
|
||||||
type1(1 , "支付宝"), |
|
||||||
type2(2 , "微信"), |
|
||||||
type3(3 , "金币"), |
|
||||||
type4(4 , "汇联通工会卡"), |
|
||||||
type5(5 , "银联"), |
|
||||||
type6(6 , "银联分期"), |
|
||||||
type7(7 , "嗨森逛油卡"), |
|
||||||
type8(8 , "API商户"), |
|
||||||
; |
|
||||||
|
|
||||||
private Integer type; |
|
||||||
private String name; |
|
||||||
|
|
||||||
OrderPayTypeEnum(int type , String name) { |
|
||||||
this.type = type; |
|
||||||
this.name = name; |
|
||||||
} |
|
||||||
|
|
||||||
public static String getNameByType(Integer type) { |
|
||||||
for (OrderPayTypeEnum ele : values()) { |
|
||||||
if(Objects.equals(type,ele.getType())) return ele.getName(); |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
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; |
|
||||||
} |
|
||||||
} |
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue