新增:余额支付接口
This commit is contained in:
@@ -36,23 +36,49 @@ public class RequestUtil {
|
|||||||
ACCESS_TOKEN = token;
|
ACCESS_TOKEN = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 微信支付通知
|
// 预付请求付款(余额支付)
|
||||||
public void pushWxPayNotify(Transaction transaction){
|
public Object balancePay(Order order){
|
||||||
System.out.println("transaction = " + transaction);
|
|
||||||
// 设置租户ID
|
// 设置租户ID
|
||||||
// setTenantId(payment.getTenantId().toString());
|
setTenantId(order.getTenantId().toString());
|
||||||
// 推送支付通知地址
|
// 设置token
|
||||||
// String path = payment.getNotifyUrl();
|
setAccessToken(order.getAccessToken());
|
||||||
|
// 余额支付接口
|
||||||
|
String path = "/system/payment/balancePay";
|
||||||
try {
|
try {
|
||||||
// 链式构建请求
|
// 链式构建请求
|
||||||
String result = HttpRequest.post("http://pxf4av.natappfree.cc/api/shop/wx-pay/nbg/paySuccess")
|
final String body = HttpRequest.post(host.concat(path))
|
||||||
.header("Tenantid", "10158")
|
.header("Tenantid", TENANT_ID)
|
||||||
.body(JSONUtil.toJSONString(transaction))//表单内容
|
.header("Authorization", ACCESS_TOKEN)
|
||||||
|
.body(JSONUtil.toJSONString(order))//表单内容
|
||||||
.timeout(20000)//超时,毫秒
|
.timeout(20000)//超时,毫秒
|
||||||
.execute().body();
|
.execute().body();
|
||||||
|
|
||||||
|
return JSONUtil.parseObject(body, ApiResult.class).getData();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 微信支付通知
|
||||||
|
public String pushWxPayNotify(Transaction transaction, Payment payment){
|
||||||
|
// 设置租户ID
|
||||||
|
setTenantId(payment.getTenantId().toString());
|
||||||
|
// 推送支付通知地址
|
||||||
|
String path = payment.getNotifyUrl();
|
||||||
|
try {
|
||||||
|
// 链式构建请求
|
||||||
|
return HttpRequest.post(path)
|
||||||
|
.header("Tenantid", TENANT_ID)
|
||||||
|
.body(JSONUtil.toJSONString(transaction))//表单内容
|
||||||
|
.timeout(20000)//超时,毫秒
|
||||||
|
.execute().body();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "支付失败";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -102,32 +102,48 @@ public class CartController extends BaseController {
|
|||||||
if (loginUser == null) {
|
if (loginUser == null) {
|
||||||
return fail("请先登录");
|
return fail("请先登录");
|
||||||
}
|
}
|
||||||
|
// 附加用户ID
|
||||||
// 查询参数
|
|
||||||
final CartParam param = new CartParam();
|
|
||||||
param.setType(cart.getType());
|
|
||||||
|
|
||||||
// 购物车是否已存在
|
|
||||||
final Cart item = cartService.getOne(new LambdaQueryWrapper<Cart>()
|
|
||||||
.eq(Cart::getUserId, loginUser.getUserId())
|
|
||||||
.eq(Cart::getGoodsId, cart.getGoodsId())
|
|
||||||
.eq(Cart::getType,cart.getType())
|
|
||||||
.last("limit 1"));
|
|
||||||
|
|
||||||
cart.setUserId(loginUser.getUserId());
|
cart.setUserId(loginUser.getUserId());
|
||||||
|
|
||||||
// 字段验证
|
// 字段验证
|
||||||
if (cart.getCartNum() == null) {
|
if (cart.getCartNum() == null) {
|
||||||
return fail("购买数量不能为空");
|
return fail("购买数量不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("cart = " + cart);
|
// 立即购买按钮
|
||||||
|
if(cart.getIsNew() != null && cart.getIsNew()){
|
||||||
|
cartService.save(cart);
|
||||||
|
return success(cart);
|
||||||
|
}
|
||||||
|
|
||||||
// 修改购物车
|
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
if (cart.getIsNew() != null) {
|
||||||
|
queryWrapper.eq(Cart::getIsNew,cart.getIsNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 购物车是否已存在
|
||||||
|
queryWrapper.eq(Cart::getUserId, loginUser.getUserId())
|
||||||
|
.eq(Cart::getGoodsId, cart.getGoodsId())
|
||||||
|
.eq(Cart::getType, cart.getType())
|
||||||
|
.last("limit 1");
|
||||||
|
|
||||||
|
Cart item = cartService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
// 查询购物车的参数
|
||||||
|
final CartParam param = new CartParam();
|
||||||
|
param.setType(cart.getType());
|
||||||
|
if (cart.getIsNew() != null) {
|
||||||
|
param.setIsNew(cart.getIsNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重复商品叠加数量
|
||||||
if(item != null){
|
if(item != null){
|
||||||
|
System.out.println("item = " + item);
|
||||||
item.setCartNum(item.getCartNum() + cart.getCartNum());
|
item.setCartNum(item.getCartNum() + cart.getCartNum());
|
||||||
cartService.updateById(item);
|
if (cartService.updateById(item)) {
|
||||||
|
return success("更新成功", computeCart(param));
|
||||||
return success("添加成功",computeCart(param));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新添加商品
|
// 新添加商品
|
||||||
@@ -220,8 +236,6 @@ public class CartController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @ApiOperation("按店铺ID更新选择状态")
|
// @ApiOperation("按店铺ID更新选择状态")
|
||||||
// @PutMapping("/updateCartByMerchantId/{id}")
|
// @PutMapping("/updateCartByMerchantId/{id}")
|
||||||
// public ApiResult<?> updateCartByMerchantId(@PathVariable("id") Long id) {
|
// public ApiResult<?> updateCartByMerchantId(@PathVariable("id") Long id) {
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ public class OrderController extends BaseController {
|
|||||||
// TODO 余额支付
|
// TODO 余额支付
|
||||||
if (order.getPayType().equals(0)) {
|
if (order.getPayType().equals(0)) {
|
||||||
order.setAccessToken(order.getAccessToken());
|
order.setAccessToken(order.getAccessToken());
|
||||||
return success("下单成功", orderService.payByBalance(order));
|
return success("下单成功", requestUtil.balancePay(order));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 微信统一下单接口
|
// TODO 微信统一下单接口
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
@Api(tags = "微信支付结果通知")
|
@Api(tags = "微信支付结果通知")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/shop/wx-pay/nbg")
|
@RequestMapping("/api/shop/wx-pay/notify/nbg")
|
||||||
public class WxPayNotifyNbgController extends BaseController {
|
public class WxPayNotifyNbgController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private OrderService orderService;
|
private OrderService orderService;
|
||||||
@@ -52,7 +52,7 @@ public class WxPayNotifyNbgController extends BaseController {
|
|||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@ApiModelProperty("微信支付通知")
|
@ApiModelProperty("微信支付通知")
|
||||||
@PostMapping("/notify")
|
@PostMapping()
|
||||||
public String demo(@RequestBody Transaction transaction){
|
public String demo(@RequestBody Transaction transaction){
|
||||||
|
|
||||||
System.out.println("支付通知 >>>>> ");
|
System.out.println("支付通知 >>>>> ");
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements Ca
|
|||||||
if(param.getType() != null){
|
if(param.getType() != null){
|
||||||
mpjLambdaWrapper.eq(Cart::getType,param.getType());
|
mpjLambdaWrapper.eq(Cart::getType,param.getType());
|
||||||
}
|
}
|
||||||
|
if(param.getIsNew() != null){
|
||||||
|
mpjLambdaWrapper.eq(Cart::getIsNew,param.getIsNew());
|
||||||
|
}
|
||||||
|
|
||||||
return baseMapper.selectJoinList(Cart.class, mpjLambdaWrapper);
|
return baseMapper.selectJoinList(Cart.class, mpjLambdaWrapper);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
.select(GoodsSpec::getSpecValue)
|
.select(GoodsSpec::getSpecValue)
|
||||||
.select(GoodsSpec::getSpecName)
|
.select(GoodsSpec::getSpecName)
|
||||||
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
|
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
|
||||||
|
.gt(Goods::getStock,0)
|
||||||
.eq(Goods::getType,0);
|
.eq(Goods::getType,0);
|
||||||
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
|
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
|
||||||
}
|
}
|
||||||
@@ -135,6 +136,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
.select(GoodsSpec::getSpecValue)
|
.select(GoodsSpec::getSpecValue)
|
||||||
.select(GoodsSpec::getSpecName)
|
.select(GoodsSpec::getSpecName)
|
||||||
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
|
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
|
||||||
|
.gt(Goods::getStock,0)
|
||||||
.eq(Goods::getType,1);
|
.eq(Goods::getType,1);
|
||||||
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
|
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import com.gxwebsoft.shop.param.OrderParam;
|
|||||||
import com.gxwebsoft.shop.service.*;
|
import com.gxwebsoft.shop.service.*;
|
||||||
import com.wechat.pay.java.core.Config;
|
import com.wechat.pay.java.core.Config;
|
||||||
import com.wechat.pay.java.core.RSAConfig;
|
import com.wechat.pay.java.core.RSAConfig;
|
||||||
|
import com.gxwebsoft.common.system.entity.Payment;
|
||||||
|
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||||
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||||
|
|||||||
Reference in New Issue
Block a user