This commit is contained in:
parent
df3d8bb46f
commit
4a2c4575fe
|
|
@ -6,6 +6,8 @@ package com.bonus.common.houqin.constant;
|
|||
*/
|
||||
public class GlobalConstants {
|
||||
public static final Long TENANT_ID = 99999999L;
|
||||
|
||||
public static final String PERSONAL_RECHARGE = "PERSONAL_RECHARGE";
|
||||
/**
|
||||
* 字符串 MSIE
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.bonus.canteen.core.account.constants;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
public enum AccTradeStateEnum {
|
||||
CREATE(1, "待生效"),
|
||||
TAKE_EFFECT(2, "生效"),
|
||||
CANCELED(3, "已撤销"),
|
||||
CLOSE(4, "关闭");
|
||||
|
||||
private final Integer key;
|
||||
private final String desc;
|
||||
|
||||
private AccTradeStateEnum(Integer key, String desc) {
|
||||
this.key = key;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.bonus.canteen.core.account.constants;
|
||||
|
||||
public enum AccTradeTypeEnum {
|
||||
RECHARGE(10, "充值"),
|
||||
RECHARGE_GIFT(11, "赠送"),
|
||||
REVOKE_RECHARGE_GIFT(12, "撤销赠送"),
|
||||
REVOKE_RECHARGE(40, "撤销充值"),
|
||||
SUBSIDY(20, "补贴"),
|
||||
REVOKE_SUBSIDY(50, "撤销补贴"),
|
||||
CLEAR(100, "清空"),
|
||||
LUCK_MONEY(140, "红包发放"),
|
||||
WITHDRAW(30, "提现"),
|
||||
TRANSFER_OUT(60, "转出"),
|
||||
TRANSFER_IN(70, "转入"),
|
||||
FREEZE(80, "冻结"),
|
||||
UN_FREEZE(90, "解冻"),
|
||||
CONSUME(110, "消费"),
|
||||
CONSUME_REPAIR(120, "消费补扣"),
|
||||
CONSUME_REFUND(130, "消费退款");
|
||||
|
||||
private final Integer key;
|
||||
private final String desc;
|
||||
|
||||
private AccTradeTypeEnum(Integer key, String desc) {
|
||||
this.key = key;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,8 @@ public interface AccTradeMapper {
|
|||
*/
|
||||
public int insertAccTrade(AccTrade accTrade);
|
||||
|
||||
// public int insertAccTradeVo(AccTradeVo accTrade);
|
||||
|
||||
/**
|
||||
* 修改账户交易记录
|
||||
*
|
||||
|
|
@ -42,6 +44,8 @@ public interface AccTradeMapper {
|
|||
*/
|
||||
public int updateAccTrade(AccTrade accTrade);
|
||||
|
||||
// public int updateAccTradeVo(AccTradeVo accTrade);
|
||||
|
||||
/**
|
||||
* 删除账户交易记录
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.bonus.canteen.core.account.service;
|
|||
|
||||
import java.util.List;
|
||||
import com.bonus.canteen.core.account.domain.AccTrade;
|
||||
import com.bonus.canteen.core.pay.dto.AccTradeVo;
|
||||
|
||||
/**
|
||||
* 账户交易记录Service接口
|
||||
|
|
@ -34,6 +35,8 @@ public interface IAccTradeService {
|
|||
*/
|
||||
public int insertAccTrade(AccTrade accTrade);
|
||||
|
||||
public int insertAccTradeVo(AccTradeVo accTrade);
|
||||
|
||||
/**
|
||||
* 修改账户交易记录
|
||||
*
|
||||
|
|
@ -42,6 +45,8 @@ public interface IAccTradeService {
|
|||
*/
|
||||
public int updateAccTrade(AccTrade accTrade);
|
||||
|
||||
public int updateAccTradeVo(AccTradeVo accTrade);
|
||||
|
||||
/**
|
||||
* 批量删除账户交易记录
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.bonus.canteen.core.account.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.bonus.canteen.core.pay.dto.AccTradeVo;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.canteen.core.account.mapper.AccTradeMapper;
|
||||
|
|
@ -58,6 +60,18 @@ public class AccTradeServiceImpl implements IAccTradeService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertAccTradeVo(AccTradeVo accTradeVo) {
|
||||
accTradeVo.setCreateTime(DateUtils.getNowDate());
|
||||
try {
|
||||
AccTrade accTrade = new AccTrade();
|
||||
BeanUtils.copyProperties(accTradeVo, accTrade);
|
||||
return accTradeMapper.insertAccTrade(accTrade);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("错误信息描述");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改账户交易记录
|
||||
*
|
||||
|
|
@ -74,6 +88,18 @@ public class AccTradeServiceImpl implements IAccTradeService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateAccTradeVo(AccTradeVo accTradeVo) {
|
||||
accTradeVo.setUpdateTime(DateUtils.getNowDate());
|
||||
try {
|
||||
AccTrade accTrade = new AccTrade();
|
||||
BeanUtils.copyProperties(accTradeVo, accTrade);
|
||||
return accTradeMapper.updateAccTrade(accTrade);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("错误信息描述");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除账户交易记录
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package com.bonus.canteen.core.alloc.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.bonus.canteen.core.alloc.domain.AllocCanteen;
|
||||
import com.bonus.canteen.core.alloc.mapper.AllocCanteenMapper;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.houqin.constant.GlobalConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.canteen.core.alloc.service.IAllocCanteenService;
|
||||
|
|
@ -96,4 +99,11 @@ public class AllocCanteenServiceImpl implements IAllocCanteenService {
|
|||
public int deleteAllocCanteenByCanteenId(Long canteenId) {
|
||||
return allocCanteenMapper.deleteAllocCanteenByCanteenId(canteenId);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BigDecimal bigDecimal = new BigDecimal("123.45");
|
||||
long longValue = bigDecimal.multiply(new BigDecimal(100)).longValue();
|
||||
System.out.println(longValue);
|
||||
System.out.println(GlobalConstants.TENANT_ID + "_" + UUID.randomUUID().toString().replaceAll("-",""));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,14 @@ package com.bonus.canteen.core.pay.controller;
|
|||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.bonus.canteen.core.account.constants.AccTradeStateEnum;
|
||||
import com.bonus.canteen.core.account.service.IAccTradeService;
|
||||
import com.bonus.canteen.core.pay.constants.PayStateEnum;
|
||||
import com.bonus.canteen.core.pay.dto.AccTradeVo;
|
||||
import com.bonus.canteen.core.pay.util.AlipayConfig;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
@ -20,6 +25,10 @@ import java.util.Map;
|
|||
@RestController
|
||||
@RequestMapping("/alipay/notify")
|
||||
public class NotifyCotroller {
|
||||
|
||||
@Autowired
|
||||
IAccTradeService accTradeService;
|
||||
|
||||
@RequestMapping("getnotify")
|
||||
public void getNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException, IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
|
@ -42,11 +51,11 @@ public class NotifyCotroller {
|
|||
PrintWriter out = response.getWriter();
|
||||
if (singVerified) {
|
||||
//商户订单号
|
||||
String out_trade_no = request.getParameter("out_trade_no");
|
||||
//商户订单号
|
||||
String order_no = request.getParameter("out_trade_no");
|
||||
//金额
|
||||
String total_amount = request.getParameter("total_amount");
|
||||
//支付宝交易号
|
||||
String trade_no = request.getParameter("trade_no");
|
||||
String third_trade_no = request.getParameter("trade_no");
|
||||
//交易状态
|
||||
String trade_status = request.getParameter("trade_status");
|
||||
if ("TRADE_FINISHED".equals(trade_status)) {
|
||||
|
|
@ -54,11 +63,34 @@ public class NotifyCotroller {
|
|||
//如果没做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详情,判断金额是否等于 total_amount,并执行商户的业务程序
|
||||
//如果做过处理,不执行商户的业务程序
|
||||
//注意: 退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态 TRADE_FINISHED
|
||||
AccTradeVo updateTrade = new AccTradeVo();
|
||||
updateTrade.setOrderNo(order_no);
|
||||
updateTrade.setThirdTradeNo(third_trade_no);
|
||||
updateTrade.setPayState(PayStateEnum.PAY_SUCC.getKey());
|
||||
updateTrade.setTradeState(AccTradeStateEnum.TAKE_EFFECT.getKey());
|
||||
updateTrade.setFailReason(trade_status);
|
||||
this.accTradeService.updateAccTradeVo(updateTrade);
|
||||
} else if ("TRADE_SUCCESS".equals(trade_status)) {
|
||||
//判断该笔订单是否已经做过处理
|
||||
//如果没做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详情,判断金额是否等于 total_amount,并执行商户的业务程序
|
||||
//如果做过处理,不执行商户的业务程序
|
||||
//注意: 付款完成后,支付宝系统发送该交易状态 TRADE_SUCCESS
|
||||
AccTradeVo updateTrade = new AccTradeVo();
|
||||
updateTrade.setOrderNo(order_no);
|
||||
updateTrade.setThirdTradeNo(third_trade_no);
|
||||
updateTrade.setPayState(PayStateEnum.PAY_SUCC.getKey());
|
||||
updateTrade.setTradeState(AccTradeStateEnum.TAKE_EFFECT.getKey());
|
||||
updateTrade.setFailReason(trade_status);
|
||||
this.accTradeService.updateAccTradeVo(updateTrade);
|
||||
//TODO 增加用户的个人钱包 acc_wallet_info
|
||||
} else {
|
||||
AccTradeVo updateTrade = new AccTradeVo();
|
||||
updateTrade.setOrderNo(order_no);
|
||||
updateTrade.setThirdTradeNo(third_trade_no);
|
||||
updateTrade.setPayState(PayStateEnum.PAY_FAIL.getKey());
|
||||
updateTrade.setTradeState(AccTradeStateEnum.CLOSE.getKey());
|
||||
updateTrade.setFailReason(trade_status);
|
||||
this.accTradeService.updateAccTradeVo(updateTrade);
|
||||
}
|
||||
|
||||
out.println("success");
|
||||
|
|
|
|||
|
|
@ -4,16 +4,26 @@ import com.alipay.api.AlipayApiException;
|
|||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.request.AlipayTradePagePayRequest;
|
||||
import com.alipay.api.response.AlipayTradePagePayResponse;
|
||||
import com.bonus.canteen.core.account.constants.AccTradeStateEnum;
|
||||
import com.bonus.canteen.core.account.constants.AccTradeTypeEnum;
|
||||
import com.bonus.canteen.core.account.service.IAccTradeService;
|
||||
import com.bonus.canteen.core.pay.constants.PayStateEnum;
|
||||
import com.bonus.canteen.core.pay.util.AlipayConfig;
|
||||
import com.bonus.canteen.core.pay.dto.UpOrder;
|
||||
import com.bonus.canteen.core.pay.dto.AccTradeVo;
|
||||
import com.bonus.common.houqin.constant.GlobalConstants;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "支付接口")
|
||||
|
|
@ -24,23 +34,37 @@ public class PayCotroller {
|
|||
AlipayClient alipayClient;
|
||||
@Resource
|
||||
AlipayTradePagePayRequest alipayRequest;
|
||||
@Autowired
|
||||
IAccTradeService accTradeService;
|
||||
|
||||
@RequestMapping("pay")
|
||||
public void pay(@RequestBody UpOrder order, HttpServletResponse response) throws AlipayApiException, IOException {
|
||||
alipayRequest.setReturnUrl(AlipayConfig.return_url);
|
||||
alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
|
||||
public void pay(@RequestBody AccTradeVo accTradeVo, HttpServletResponse response) throws AlipayApiException, IOException {
|
||||
// 预装数据,存档
|
||||
accTradeVo.setUserId(SecurityUtils.getUserId());
|
||||
accTradeVo.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
||||
accTradeVo.setTradeType(AccTradeTypeEnum.CONSUME.getKey());
|
||||
accTradeVo.setOrderNo(GlobalConstants.TENANT_ID + "_" + UUID.randomUUID().toString().replaceAll("-",""));
|
||||
accTradeVo.setOrderName(GlobalConstants.TENANT_ID + "_" + SecurityUtils.getUserId() + "_" + GlobalConstants.PERSONAL_RECHARGE);
|
||||
accTradeVo.setTradeTime(new Date());
|
||||
accTradeVo.setAmount(accTradeVo.getPaymentAmount().multiply(new BigDecimal(100)).longValue());
|
||||
accTradeVo.setPayState(PayStateEnum.PAY_INPROCESS.getKey());
|
||||
accTradeVo.setTradeState(AccTradeStateEnum.CREATE.getKey());
|
||||
accTradeService.insertAccTradeVo(accTradeVo);
|
||||
// 调用alipay
|
||||
alipayRequest.setBizContent(
|
||||
"{\"out_trade_no\":\""+ order.getCode() +"\","
|
||||
+ "\"total_amount\":\""+ order.getPaymentAmount().toString() +"\","
|
||||
+ "\"subject\":\""+ order.getOrderName() +"\","
|
||||
+ "\"body\":\""+ order.getProductDesc() +"\","
|
||||
"{\"out_trade_no\":\""+ accTradeVo.getOrderNo() +"\","
|
||||
+ "\"total_amount\":\""+ accTradeVo.getPaymentAmount().toString() +"\","
|
||||
+ "\"subject\":\""+ accTradeVo.getOrderName() +"\","
|
||||
+ "\"body\":\""+ accTradeVo.getProductDesc() +"\","
|
||||
+ "\"timeout_express\":\"10m\","
|
||||
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
|
||||
alipayRequest.setReturnUrl(AlipayConfig.return_url);
|
||||
alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
|
||||
AlipayTradePagePayResponse alipayResponse = alipayClient.pageExecute(alipayRequest);
|
||||
log.info("alipay body = " + alipayResponse.getBody());
|
||||
log.info("alipay msg = " + alipayResponse.getMsg());
|
||||
response.setContentType("text/html;charset=UTF-8");
|
||||
response.getWriter().println(alipayResponse.getBody()); //write(alipayResponse.getBody());
|
||||
response.getWriter().println(alipayResponse.getBody());
|
||||
response.getWriter().flush();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.bonus.canteen.core.pay.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class AccTradeVo {
|
||||
private Long userId;
|
||||
private Long deptId;
|
||||
private String orderNo;//商户订单号, 商户网站订单系统中唯一订单号,必填
|
||||
private String orderName;//订单名称, 必填
|
||||
private BigDecimal paymentAmount;//付款金额, 必填
|
||||
private String productDesc;//商品描述
|
||||
private Long amount; //金额(单位:分)
|
||||
private Integer tradeType;
|
||||
@JsonFormat(
|
||||
pattern = "yyyy-MM-dd HH:mm:ss"
|
||||
)
|
||||
private Date tradeTime;
|
||||
private Integer tradeState;
|
||||
private Integer payType;
|
||||
private Integer payState; //是否付款 true - 已付 false-未付
|
||||
private String thirdTradeNo; //三方,支付宝交易号
|
||||
private String failReason;
|
||||
@JsonFormat(
|
||||
pattern = "yyyy-MM-dd HH:mm:ss"
|
||||
)
|
||||
private Date createTime;
|
||||
@JsonFormat(
|
||||
pattern = "yyyy-MM-dd HH:mm:ss"
|
||||
)
|
||||
private Date updateTime;
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.bonus.canteen.core.pay.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class UpOrder {
|
||||
private String code;//商户订单号, 商户网站订单系统中唯一订单号,必填
|
||||
private String orderName;//订单名称, 必填
|
||||
private BigDecimal paymentAmount;//付款金额, 必填
|
||||
private String productDesc;//商品描述
|
||||
private String createBy;//创建人Code
|
||||
private Long createTime;//创建时间(时间戳)
|
||||
private Integer createByType;//创建人类型 1-专家 2-企业用户
|
||||
private Boolean status;//是否付款 true - 已付 false-未付
|
||||
private Long payTime;//订单支付时间-支付后才存在 (时间戳)
|
||||
}
|
||||
Loading…
Reference in New Issue