parent
fbb87cea49
commit
897c9dbfa7
@ -1,11 +1,270 @@ |
|||||||
package com.cweb.controller.pay; |
package com.cweb.controller.pay; |
||||||
|
|
||||||
|
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.config.CommonSysConst; |
||||||
|
import com.hai.config.HuiLianTongConfig; |
||||||
|
import com.hai.config.TuanYouConfig; |
||||||
|
import com.hai.dao.HighCouponCodeOtherMapper; |
||||||
|
import com.hai.dao.HighGasOrderPushMapper; |
||||||
|
import com.hai.dao.HighUserCouponMapper; |
||||||
|
import com.hai.entity.*; |
||||||
|
import com.hai.enum_type.OrderPushType; |
||||||
|
import com.hai.model.HighMerchantStoreModel; |
||||||
|
import com.hai.service.*; |
||||||
|
import com.hai.service.pay.NotifyService; |
||||||
import io.swagger.annotations.Api; |
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import org.apache.commons.collections4.MapUtils; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
import org.springframework.stereotype.Controller; |
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.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.BufferedOutputStream; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
@Controller |
@Controller |
||||||
@RequestMapping(value = "/unionPay") |
@RequestMapping(value = "/unionPay") |
||||||
@Api(value = "银联支付") |
@Api(value = "银联支付") |
||||||
public class UnionPayController { |
public class UnionPayController { |
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(UnionPayController.class); |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighOrderService highOrderService; |
||||||
|
|
||||||
|
@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; |
||||||
|
|
||||||
|
@RequestMapping(value = "/notify", method = RequestMethod.POST) |
||||||
|
@ApiOperation(value = "银联支付 -> 异步回调") |
||||||
|
public void notify(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { |
||||||
|
try { |
||||||
|
|
||||||
|
if (body == null){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (StringUtils.isBlank(body.getString("tradetrace"))) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 查询订单信息
|
||||||
|
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.setPayTime(new Date()); // 支付时间
|
||||||
|
order.setPayModel(2); // 支付模式:1 金币,2 第三方平台,3 混合
|
||||||
|
order.setPayType(5); // 支付方式: 1:支付宝 2:微信 3:金币 4:工会卡 5:银联
|
||||||
|
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.getCouponSource() == 4) { |
||||||
|
// 获取token
|
||||||
|
String token = huiLianTongConfig.getToken(); |
||||||
|
|
||||||
|
Map<String,Object> push = new HashMap<>(); |
||||||
|
push.put("token", token); |
||||||
|
push.put("couTypeCode", coupon.getCouponKey()); |
||||||
|
push.put("distCouCount", highChildOrder.getSaleCount()); |
||||||
|
push.put("userPhone", highUser.getPhone()); |
||||||
|
push.put("thirdUserId", highUser.getUnionId()); |
||||||
|
|
||||||
|
// 推送给高速
|
||||||
|
JSONObject returnParam = HuiLianTongConfig.couJointDist(token, order.getOrderNo(),coupon.getCouponKey(), highChildOrder.getSaleCount(), highUser.getPhone(), highUser.getUnionId()); |
||||||
|
if (returnParam != null && returnParam.getString("result").equals("success")) { |
||||||
|
JSONArray dataArray = returnParam.getJSONArray("data"); |
||||||
|
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.setStatus(20); |
||||||
|
couponCodeOther.setCreateTime(new Date()); |
||||||
|
couponCodeOther.setActiveTime(dataObject.getDate("activeTime")); |
||||||
|
couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate")); |
||||||
|
couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate")); |
||||||
|
highCouponCodeOtherMapper.insert(couponCodeOther); |
||||||
|
|
||||||
|
// 卡卷关联用户
|
||||||
|
HighUserCoupon highUserCoupon = new HighUserCoupon(); |
||||||
|
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 { |
||||||
|
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.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(); |
||||||
|
highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId()); |
||||||
|
} |
||||||
|
|
||||||
|
if (highChildOrder.getGoodsType() == 3) { |
||||||
|
highChildOrder.setChildOrdeStatus(3); |
||||||
|
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId()); |
||||||
|
// 推送团油订单
|
||||||
|
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")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
highOrderService.updateOrder(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); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue