Commit b4f1f0ec by wnb0128

app支付完成订单成功同步接口添加--think.wang

1 parent b97e7478
...@@ -44,8 +44,8 @@ public class PlatformUser implements Serializable { ...@@ -44,8 +44,8 @@ public class PlatformUser implements Serializable {
private Integer status; private Integer status;
@Column(columnDefinition = "INT(11) COMMENT 'APP 账户ID'") @Column(columnDefinition = "INT(11) COMMENT 'APP 账户ID'")
private Integer appAccountId; private Integer appAccountId;
@Column(columnDefinition = "INT(11) COMMENT '涂鸦平台ID'") @Column(columnDefinition = "VARCHAR(50) COMMENT '涂鸦平台ID'")
private Integer tuYaId; private String tuYaId;
@Column(columnDefinition = "INT(11) COMMENT '创建人'") @Column(columnDefinition = "INT(11) COMMENT '创建人'")
private Integer createBy; private Integer createBy;
@Column(columnDefinition = "INT(11) COMMENT '更新人'") @Column(columnDefinition = "INT(11) COMMENT '更新人'")
......
package com.glsx.shop.service.shop; package com.glsx.shop.service.shop;
import java.util.Date;
import java.util.List;
import com.glsx.shop.bean.entity.shop.Order; import com.glsx.shop.bean.entity.shop.Order;
import com.glsx.shop.bean.entity.shop.OrderItem; import com.glsx.shop.bean.entity.shop.OrderItem;
import com.glsx.shop.bean.entity.shop.OrderLog; import com.glsx.shop.bean.entity.shop.OrderLog;
...@@ -20,6 +18,9 @@ import org.slf4j.LoggerFactory; ...@@ -20,6 +18,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service @Service
public class OrderService extends BaseService<Order, Long, OrderRepository> { public class OrderService extends BaseService<Order, Long, OrderRepository> {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
...@@ -65,10 +66,8 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> { ...@@ -65,10 +66,8 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> {
public void cancel(String orderSn) { public void cancel(String orderSn) {
Order order = getByOrderSn(orderSn); Order order = getByOrderSn(orderSn);
order.setStatus(OrderEnum.OrderStatusEnum.CANCEL.getId()); order.setStatus(OrderEnum.OrderStatusEnum.CANCEL.getId());
String descript = "用户取消订单"; saveOrderLog(order, "用户取消订单");
saveOrderLog(order, descript);
updateOrder(order); updateOrder(order);
} }
public Order getByOrderSn(String orderSn) { public Order getByOrderSn(String orderSn) {
...@@ -83,8 +82,7 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> { ...@@ -83,8 +82,7 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> {
public Order confirmReceive(String orderSn) { public Order confirmReceive(String orderSn) {
Order order = getByOrderSn(orderSn); Order order = getByOrderSn(orderSn);
order.setStatus(OrderEnum.OrderStatusEnum.FINISHED.getId()); order.setStatus(OrderEnum.OrderStatusEnum.FINISHED.getId());
String descript = "客户确认收货"; saveOrderLog(order, "客户确认收货");
saveOrderLog(order, descript);
updateOrder(order); updateOrder(order);
return order; return order;
} }
...@@ -132,15 +130,12 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> { ...@@ -132,15 +130,12 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> {
order.setRealPrice(order.getTotalPrice()); order.setRealPrice(order.getTotalPrice());
order.setPayType(payType); order.setPayType(payType);
updateOrder(order); updateOrder(order);
String descript = "用户付款成功"; saveOrderLog(order, "用户付款成功");
saveOrderLog(order, descript);
} }
public void send(Order order) { public void send(Order order) {
String descript = "管理员(" + JwtUtil.getUsername() + ")已发货";
updateOrder(order); updateOrder(order);
saveOrderLog(order, descript); saveOrderLog(order, "管理员(" + JwtUtil.getUsername() + ")已发货");
} }
} }
...@@ -13,6 +13,7 @@ import com.glsx.shop.security.UserService; ...@@ -13,6 +13,7 @@ import com.glsx.shop.security.UserService;
import com.glsx.shop.service.shop.PlatformCustomerService; import com.glsx.shop.service.shop.PlatformCustomerService;
import com.glsx.shop.service.shop.PlatformUserService; import com.glsx.shop.service.shop.PlatformUserService;
import com.glsx.shop.utils.HttpUtils; import com.glsx.shop.utils.HttpUtils;
import com.glsx.shop.utils.MD5;
import com.glsx.shop.utils.StringUtil; import com.glsx.shop.utils.StringUtil;
import com.glsx.shop.web.controller.BaseController; import com.glsx.shop.web.controller.BaseController;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -63,10 +64,12 @@ public class AppLoginController extends BaseController { ...@@ -63,10 +64,12 @@ public class AppLoginController extends BaseController {
return Rets.failure(ApplicationExceptionEnum.PARAM_ERROR); return Rets.failure(ApplicationExceptionEnum.PARAM_ERROR);
} }
JwtUser jwtUser = new JwtUser(); //JWT用户信息封装 JwtUser jwtUser = new JwtUser(); //JWT用户信息封装
Date now =new Date(); Date now = new Date();
PlatformUser user = platformUserService.findByContactNumber(userDTO.getContactNumber()); PlatformUser user = platformUserService.findByContactNumber(userDTO.getContactNumber());
String password = new StringBuffer(userDTO.getContactNumber())
.append(userDTO.getChannel()).toString();
String tuYaId = null;
if(user != null){ if(user != null){
result.put("tuYaId", user.getTuYaId());
jwtUser.setId(user.getId()); jwtUser.setId(user.getId());
jwtUser.setUserName(user.getNickname()); jwtUser.setUserName(user.getNickname());
BeanUtils.copyProperties(userDTO, user); BeanUtils.copyProperties(userDTO, user);
...@@ -76,6 +79,14 @@ public class AppLoginController extends BaseController { ...@@ -76,6 +79,14 @@ public class AppLoginController extends BaseController {
user.setUpdateTime(now); user.setUpdateTime(now);
user.setCustomerId(customer.getId().intValue()); user.setCustomerId(customer.getId().intValue());
} }
//防止注册时涂鸦平台服务异常
if(user.getTuYaId() == null){
tuYaId = this.syncUser(userDTO.getContactNumber(),
userDTO.getNickname(), MD5.md5(password, userDTO.getChannel())); //同步用户到涂鸦
user.setTuYaId(tuYaId);
}else{
tuYaId = user.getTuYaId();
}
platformUserService.update(user); platformUserService.update(user);
}else{ //用户首次注册 }else{ //用户首次注册
PlatformUser pUser = new PlatformUser(); PlatformUser pUser = new PlatformUser();
...@@ -85,42 +96,44 @@ public class AppLoginController extends BaseController { ...@@ -85,42 +96,44 @@ public class AppLoginController extends BaseController {
pUser.setCreateBy(-1); pUser.setCreateBy(-1);
pUser.setStatus(1); //默认用户正常 pUser.setStatus(1); //默认用户正常
pUser.setLastLoginTime(now); pUser.setLastLoginTime(now);
Integer tuYaId = this.syncUser(userDTO.getContactNumber()); //同步用户到涂鸦 tuYaId = this.syncUser(userDTO.getContactNumber(),
userDTO.getNickname(), MD5.md5(password, userDTO.getChannel())); //同步用户到涂鸦
pUser.setTuYaId(tuYaId); pUser.setTuYaId(tuYaId);
PlatformUser returnUser = platformUserService.insert(pUser); PlatformUser returnUser = platformUserService.insert(pUser);
jwtUser.setId(returnUser.getId()); jwtUser.setId(returnUser.getId());
result.put("tuYaId", tuYaId); jwtUser.setUserName(returnUser.getNickname());
} }
//JWT信息缓存 //JWT信息缓存
jwtUser.setPassword(userDTO.getChannel()); jwtUser.setPassword(userDTO.getChannel());
String token = userService.loginForToken(jwtUser); String token = userService.loginForToken(jwtUser);
result.put("tuYaId", tuYaId);
result.put("token", token); result.put("token", token);
return Rets.success(result); return Rets.success(result);
} }
private Integer syncUser(String mobile){ private String syncUser(String mobile, String nickName, String password){
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
object.put("schema", "glsx"); object.put("schema", "glsx");
object.put("country_code", "86"); object.put("country_code", "86");
object.put("username", mobile); object.put("username", mobile);
object.put("username_type", "1"); object.put("username_type", 1);
// object.put("nick_name", "wnb"); object.put("nick_name", nickName);
// object.put("password", "dsadada"); object.put("password", password);
try { try {
logger.info("请求注册涂鸦平台接口地址:{}", syncUserUrl); logger.info("请求注册涂鸦平台接口地址:{},参数:{}", syncUserUrl,object.toJSONString());
String result = HttpUtils.postJson(syncUserUrl, object.toJSONString()); String result = HttpUtils.postJson(syncUserUrl, object.toJSONString());
logger.info("注册涂鸦平台返回结果:{}", result); logger.info("注册涂鸦平台返回结果:{}", result);
if (StringUtils.isNotEmpty(result)) { if (StringUtils.isNotEmpty(result)) {
JSONObject json = JSON.parseObject(result); JSONObject json = JSON.parseObject(result);
if (json.containsKey("result")) { if (json.containsKey("result")) {
JSONObject jsonObject = json.getJSONObject("result"); JSONObject jsonObject = json.getJSONObject("result");
return jsonObject.getInteger("uid"); return jsonObject.getString("uid");
} }
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("同步涂鸦平台失败:{}", e); logger.error("同步涂鸦平台失败:{}", e);
} }
return -1; return null;
} }
/** /**
......
package com.glsx.shop.mobile.controller; package com.glsx.shop.mobile.controller;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.glsx.shop.bean.constant.CfgKey; import com.glsx.shop.bean.constant.CfgKey;
import com.glsx.shop.bean.constant.factory.PageFactory; import com.glsx.shop.bean.constant.factory.PageFactory;
import com.glsx.shop.bean.entity.shop.Address; import com.glsx.shop.bean.entity.shop.Address;
...@@ -30,11 +27,11 @@ import org.slf4j.Logger; ...@@ -30,11 +27,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import java.math.BigDecimal;
import org.springframework.web.bind.annotation.RequestParam; import java.util.List;
import org.springframework.web.bind.annotation.RestController; import java.util.Map;
/** /**
* @author glsx * @author glsx
...@@ -99,8 +96,7 @@ public class OrderController extends BaseController { ...@@ -99,8 +96,7 @@ public class OrderController extends BaseController {
public Object save( public Object save(
@RequestParam("idAddress") Long idAddress, @RequestParam("idAddress") Long idAddress,
@RequestParam(value = "message", required = false) String message, @RequestParam(value = "message", required = false) String message,
@RequestParam(value = "idCarts") String idCarts @RequestParam(value = "idCarts") String idCarts) {
) {
Long idUser = getIdUser(); Long idUser = getIdUser();
List<SearchFilter> filters = Lists.newArrayList( List<SearchFilter> filters = Lists.newArrayList(
...@@ -108,7 +104,6 @@ public class OrderController extends BaseController { ...@@ -108,7 +104,6 @@ public class OrderController extends BaseController {
SearchFilter.build("id", SearchFilter.Operator.IN, StringUtil.splitForLong(idCarts, ",")) SearchFilter.build("id", SearchFilter.Operator.IN, StringUtil.splitForLong(idCarts, ","))
); );
List<Cart> cartList = cartService.queryAll(filters); List<Cart> cartList = cartService.queryAll(filters);
Order order = new Order(); Order order = new Order();
order.setIdUser(idUser); order.setIdUser(idUser);
Address address = addressService.get(idAddress); Address address = addressService.get(idAddress);
...@@ -153,16 +148,15 @@ public class OrderController extends BaseController { ...@@ -153,16 +148,15 @@ public class OrderController extends BaseController {
@RequestMapping(value = "getExpressInfo/{orderSn}", method = RequestMethod.GET) @RequestMapping(value = "getExpressInfo/{orderSn}", method = RequestMethod.GET)
public Object getExpressInfo(@PathVariable(value = "orderSn") String orderSn) { public Object getExpressInfo(@PathVariable(value = "orderSn") String orderSn) {
Order order = orderService.getByOrderSn(orderSn); Order order = orderService.getByOrderSn(orderSn);
String apiKdniaoUserid = cfgService.getCfgValue(CfgKey.API_KDNIAO_USERID); String apiKdUserId = cfgService.getCfgValue(CfgKey.API_KDNIAO_USERID);
if (StringUtil.isEmpty(apiKdniaoUserid)) { if (StringUtil.isEmpty(apiKdUserId)) {
//该商城暂无配置物流查询服务 //该商城暂无配置物流查询服务
throw new ApplicationException(ApplicationExceptionEnum.SERVER_ERROR); throw new ApplicationException(ApplicationExceptionEnum.SERVER_ERROR);
} }
KdniaoResponse response = kdniaoService.realTimeQuery(order.getShippingSn(), order.getExpress().getCode()); KdniaoResponse response = kdniaoService.realTimeQuery(
Map data = Maps.newHashMap( order.getShippingSn(), order.getExpress().getCode());
"order", order, Map data = Maps.newHashMap("order", order,
"expressInfo", response "expressInfo", response);
);
return Rets.success(data); return Rets.success(data);
} }
} }
...@@ -11,11 +11,7 @@ import com.glsx.shop.service.shop.ShopUserService; ...@@ -11,11 +11,7 @@ import com.glsx.shop.service.shop.ShopUserService;
import com.glsx.shop.utils.StringUtil; import com.glsx.shop.utils.StringUtil;
import com.glsx.shop.web.controller.BaseController; import com.glsx.shop.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
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.RestController;
/** /**
* @author glsx * @author glsx
...@@ -56,6 +52,21 @@ public class PayController extends BaseController { ...@@ -56,6 +52,21 @@ public class PayController extends BaseController {
return msg; return msg;
} }
@RequestMapping(value = "success/{orderSn}/{payId}", method = RequestMethod.POST)
public Object cancel(@PathVariable("orderSn") String orderSn,
@PathVariable("payId") String payId) {
Order order = orderService.getByOrderSn(orderSn);
if (order == null) {
return Rets.failure("订单不存在sn = " + orderSn);
}
if (order.hasPayed()) { // 检查这个订单是否已经处理过
return Rets.success("订单已经处理成功!");
}
order.setPayId(payId);
orderService.paySuccess(order, OrderEnum.PayTypeEnum.UN_SEND.getKey());
return Rets.success();
}
/** /**
* 查询支付结果 * 查询支付结果
* *
......
package com.glsx.shop.service; package com.glsx.shop.service;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
...@@ -22,6 +19,10 @@ import org.slf4j.LoggerFactory; ...@@ -22,6 +19,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
/** /**
* 微信支付 * 微信支付
* *
...@@ -59,20 +60,16 @@ public class WeixinPayService { ...@@ -59,20 +60,16 @@ public class WeixinPayService {
public String resultNotify() { public String resultNotify() {
String xmlResult = null; String xmlResult = null;
try { try {
HttpServletRequest request = HttpUtil.getRequest(); HttpServletRequest request = HttpUtil.getRequest();
xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
} catch (IOException e) { } catch (IOException e) {
logger.error("解析微信支付结果通知异常", e); logger.error("解析微信支付结果通知异常", e);
return WxPayNotifyResponse.fail(e.getMessage()); return WxPayNotifyResponse.fail(e.getMessage());
} }
WxPayOrderNotifyResult result = null; WxPayOrderNotifyResult result = null;
try { try {
result = wxPayService.parseOrderNotifyResult(xmlResult); result = wxPayService.parseOrderNotifyResult(xmlResult);
if (!WxPayConstants.ResultCode.SUCCESS.equals(result.getResultCode())) { if (!WxPayConstants.ResultCode.SUCCESS.equals(result.getResultCode())) {
logger.error(xmlResult); logger.error(xmlResult);
throw new WxPayException("微信通知支付失败!"); throw new WxPayException("微信通知支付失败!");
...@@ -82,31 +79,24 @@ public class WeixinPayService { ...@@ -82,31 +79,24 @@ public class WeixinPayService {
throw new WxPayException("微信通知支付失败!"); throw new WxPayException("微信通知支付失败!");
} }
} catch (WxPayException e) { } catch (WxPayException e) {
e.printStackTrace();
return WxPayNotifyResponse.fail(e.getMessage()); return WxPayNotifyResponse.fail(e.getMessage());
} }
logger.info("处理腾讯支付平台的订单支付", Json.toJson(result)); logger.info("处理腾讯支付平台的订单支付", Json.toJson(result));
String orderSn = result.getOutTradeNo(); String orderSn = result.getOutTradeNo();
String payId = result.getTransactionId(); String payId = result.getTransactionId();
Integer totalFee = result.getTotalFee(); Integer totalFee = result.getTotalFee();
Order order = orderService.getByOrderSn(orderSn); Order order = orderService.getByOrderSn(orderSn);
if (order == null) { if (order == null) {
return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn); return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn);
} }
// 检查这个订单是否已经处理过 // 检查这个订单是否已经处理过
if (order.hasPayed()) { if (order.hasPayed()) {
return WxPayNotifyResponse.success("订单已经处理成功!"); return WxPayNotifyResponse.success("订单已经处理成功!");
} }
// 检查支付订单金额 // 检查支付订单金额
if (totalFee.intValue() != order.getTotalPrice().intValue()) { if (totalFee.intValue() != order.getTotalPrice().intValue()) {
return WxPayNotifyResponse.fail(order.getOrderSn() + " : 支付金额不符合 totalFee=" + totalFee); return WxPayNotifyResponse.fail(order.getOrderSn() + " : 支付金额不符合 totalFee=" + totalFee);
} }
order.setPayId(payId); order.setPayId(payId);
orderService.paySuccess(order, OrderEnum.PayTypeEnum.UN_SEND.getKey()); orderService.paySuccess(order, OrderEnum.PayTypeEnum.UN_SEND.getKey());
//todo 发送短信通知 //todo 发送短信通知
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!