|
@@ -2,8 +2,10 @@ package com.book.server.service.impl;
|
|
|
|
|
|
import com.book.dao.VO.*;
|
|
import com.book.dao.VO.*;
|
|
import com.book.dao.cps.entity.Goods;
|
|
import com.book.dao.cps.entity.Goods;
|
|
|
|
+import com.book.dao.cps.entity.OrdersCollect;
|
|
import com.book.dao.cps.mapper.*;
|
|
import com.book.dao.cps.mapper.*;
|
|
import com.book.dao.cps.pojo.*;
|
|
import com.book.dao.cps.pojo.*;
|
|
|
|
+import com.book.dao.cps.pojo.example.OrdersCollectExample;
|
|
import com.book.dao.utils.DateUtils;
|
|
import com.book.dao.utils.DateUtils;
|
|
import com.book.dao.utils.TimeUtil;
|
|
import com.book.dao.utils.TimeUtil;
|
|
import com.book.server.config.Const;
|
|
import com.book.server.config.Const;
|
|
@@ -20,6 +22,7 @@ import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.sql.Date;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@@ -36,7 +39,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
public static final String PALMPAY_APPID = "";
|
|
public static final String PALMPAY_APPID = "";
|
|
public static final String PALMPAY_APPKEY = "";
|
|
public static final String PALMPAY_APPKEY = "";
|
|
public static final String PALMPAY_MCHID = "";
|
|
public static final String PALMPAY_MCHID = "";
|
|
-// public static final String PALMPAY_URL = "https://pay.palmpay.cn/sdkServer/thirdpays/pay/WECHAT_SUB";
|
|
|
|
|
|
+ // public static final String PALMPAY_URL = "https://pay.palmpay.cn/sdkServer/thirdpays/pay/WECHAT_SUB";
|
|
public static final String PALMPAY_URL = "http://101.200.72.53:18085/sdkServer/thirdpays/pay/WECHAT_SUB";
|
|
public static final String PALMPAY_URL = "http://101.200.72.53:18085/sdkServer/thirdpays/pay/WECHAT_SUB";
|
|
@Autowired
|
|
@Autowired
|
|
private GoodsMapper goodsMapper;
|
|
private GoodsMapper goodsMapper;
|
|
@@ -60,6 +63,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
private AdminExtendMapper adminExtendMapper;
|
|
private AdminExtendMapper adminExtendMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private CacheService cacheService;
|
|
private CacheService cacheService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OrdersCollectMapper ordersCollectMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public WxPayInfo createOrder(WxPayRequest wxPayRequest) {
|
|
public WxPayInfo createOrder(WxPayRequest wxPayRequest) {
|
|
@@ -139,8 +144,6 @@ public class WxPayServiceImpl implements WxPayService {
|
|
map.put("ip", wxPayRequest.getIp());
|
|
map.put("ip", wxPayRequest.getIp());
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
String str = palmpayAppid + "WECHAT_SUB" + amount + mchOrderid + palmpayAppkey;
|
|
String str = palmpayAppid + "WECHAT_SUB" + amount + mchOrderid + palmpayAppkey;
|
|
|
|
|
|
String sign = Md5Util.md5(str);
|
|
String sign = Md5Util.md5(str);
|
|
@@ -152,8 +155,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
WxPayInfo wxPayInfo = new WxPayInfo();
|
|
WxPayInfo wxPayInfo = new WxPayInfo();
|
|
wxPayInfo.setUserId(userByUserId.getId() + "");
|
|
wxPayInfo.setUserId(userByUserId.getId() + "");
|
|
wxPayInfo.setOrderId(String.valueOf(order.getId()));
|
|
wxPayInfo.setOrderId(String.valueOf(order.getId()));
|
|
- if ( StringUtils.isNotEmpty(wxPayRequest.getOpenid())) {
|
|
|
|
- map.put("subAppid", appid==null?"":appid);
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(wxPayRequest.getOpenid())) {
|
|
|
|
+ map.put("subAppid", appid == null ? "" : appid);
|
|
map.put("openid", wxPayRequest.getOpenid());
|
|
map.put("openid", wxPayRequest.getOpenid());
|
|
map.put("api", "1");
|
|
map.put("api", "1");
|
|
String result = HTTPSUtil.sendGetByHttps(PALMPAY_URL, map);
|
|
String result = HTTPSUtil.sendGetByHttps(PALMPAY_URL, map);
|
|
@@ -173,9 +176,9 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
|
|
|
|
updateOrder.setPayJson(pay_info);
|
|
updateOrder.setPayJson(pay_info);
|
|
- if(pay_info.startsWith("http")){
|
|
|
|
|
|
+ if (pay_info.startsWith("http")) {
|
|
wxPayInfo.setUrl(PALMPAY_URL + "?" + form);
|
|
wxPayInfo.setUrl(PALMPAY_URL + "?" + form);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
Map<String, Object> map1 = JsonUtils.getMap(pay_info);
|
|
Map<String, Object> map1 = JsonUtils.getMap(pay_info);
|
|
wxPayInfo.setPayInfo(map1);
|
|
wxPayInfo.setPayInfo(map1);
|
|
wxPayInfo.setUrl("");
|
|
wxPayInfo.setUrl("");
|
|
@@ -185,6 +188,43 @@ public class WxPayServiceImpl implements WxPayService {
|
|
} else {
|
|
} else {
|
|
wxPayInfo.setUrl(PALMPAY_URL + "?" + form);
|
|
wxPayInfo.setUrl(PALMPAY_URL + "?" + form);
|
|
}
|
|
}
|
|
|
|
+ try {
|
|
|
|
+ OrdersCollect ordersCollect = new OrdersCollect();
|
|
|
|
+ ordersCollect.setAdminId(adminConfig.getAdminId());
|
|
|
|
+ ordersCollect.setType("1");
|
|
|
|
+ ordersCollect.setFlag("1");
|
|
|
|
+ ordersCollect.setBusinessLine("1");
|
|
|
|
+
|
|
|
|
+ ordersCollect.setCreatedate(DateUtils.getDateNow() + "");
|
|
|
|
+ ordersCollect.setRechargeMoney(new BigDecimal(0.00));
|
|
|
|
+ ordersCollect.setRechargeMoneyBenefit(new BigDecimal(0.00));
|
|
|
|
+ ordersCollect.setNormalRechargeOrdersCount(1);
|
|
|
|
+ ordersCollect.setNormalRechargeOrders(0);
|
|
|
|
+ ordersCollect.setNormalRechargeMoney(new BigDecimal(0.00));
|
|
|
|
+ ordersCollect.setNormalRechargeMoneyBenefit(new BigDecimal(0.00));
|
|
|
|
+ ordersCollect.setNormalRechargeUserSucCount(0);
|
|
|
|
+ ordersCollect.setNormalRechargeUserCount(1);
|
|
|
|
+ ordersCollect.setNormalRechargeGuideOrders(0);
|
|
|
|
+ ordersCollect.setNoramlRechargeGuideMoney(new BigDecimal(0.00));
|
|
|
|
+ ordersCollect.setNoramlRechargeGuideMoneyBenefit(new BigDecimal(0.00));
|
|
|
|
+ ordersCollect.setKandianRechargeOrdersCount(1);
|
|
|
|
+ ordersCollect.setCreatetime(DateUtils.getNow());
|
|
|
|
+ ordersCollect.setRechargeUserCount(1);
|
|
|
|
+ ordersCollect.setKandianRechargeOrders(0);
|
|
|
|
+ OrdersCollectExample ordersCollectExample = OrdersCollectExample.newAndCreateCriteria().andAdminIdEqualTo(ordersCollect.getAdminId())
|
|
|
|
+ .andTypeEqualTo(ordersCollect.getType()).andFlagEqualTo(ordersCollect.getFlag()).andCreatedateEqualTo(ordersCollect.getCreatedate())
|
|
|
|
+ .example();
|
|
|
|
+
|
|
|
|
+ OrdersCollect selectOrdersCollect = ordersCollectMapper.selectOneByExample(ordersCollectExample);
|
|
|
|
+ if (selectOrdersCollect == null) {
|
|
|
|
+ ordersCollectMapper.insert(ordersCollect);
|
|
|
|
+ } else {
|
|
|
|
+ ordersCollectMapper.updateCollect(ordersCollect);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error("订单下单统计:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
return wxPayInfo;
|
|
return wxPayInfo;
|
|
@@ -236,6 +276,34 @@ public class WxPayServiceImpl implements WxPayService {
|
|
ordersMapper.updateByPrimaryKeySelective(orders);
|
|
ordersMapper.updateByPrimaryKeySelective(orders);
|
|
bookService.insertKandian(order.getUserId(), "1", order.getKandian(), order.getFreeKandian());
|
|
bookService.insertKandian(order.getUserId(), "1", order.getKandian(), order.getFreeKandian());
|
|
cacheService.updateUserByIdCache(order.getUserId());
|
|
cacheService.updateUserByIdCache(order.getUserId());
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ AdminExtend adminExtend = adminExtendMapper.selectByPrimaryKey(order.getAdminId());
|
|
|
|
+ OrdersCollect ordersCollect = new OrdersCollect();
|
|
|
|
+ ordersCollect.setAdminId(order.getAdminId());
|
|
|
|
+ ordersCollect.setType("1");
|
|
|
|
+ ordersCollect.setFlag("1");
|
|
|
|
+ ordersCollect.setCreatedate(DateUtils.getDateNow() + "");
|
|
|
|
+ ordersCollect.setRechargeMoney(order.getMoney());
|
|
|
|
+ ordersCollect.setRechargeMoneyBenefit(order.getMoney().multiply(adminExtend.getBenefit()));
|
|
|
|
+ /* ordersCollect.setNormalRechargeOrdersCount(0);
|
|
|
|
+ ordersCollect.setNormalRechargeUserCount(0);*/
|
|
|
|
+ ordersCollect.setNormalRechargeOrders(1);
|
|
|
|
+ ordersCollect.setNormalRechargeMoney(order.getMoney());
|
|
|
|
+ ordersCollect.setNormalRechargeMoneyBenefit(order.getMoney().multiply(adminExtend.getBenefit()));
|
|
|
|
+ ordersCollect.setNormalRechargeUserSucCount(1);
|
|
|
|
+ ordersCollect.setKandianRechargeOrders(1);
|
|
|
|
+ ordersCollect.setCreatetime(DateUtils.getNow());
|
|
|
|
+ ordersCollect.setRechargeUserCount(1);
|
|
|
|
+ ordersCollect.setKandianRechargeOrders(1);
|
|
|
|
+
|
|
|
|
+ ordersCollectMapper.updateCollect(ordersCollect);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error("统计失败:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -245,21 +313,20 @@ public class WxPayServiceImpl implements WxPayService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
- public String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code,String openid) {
|
|
|
|
|
|
+ public String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code, String openid) {
|
|
|
|
|
|
|
|
|
|
AdminConfig adminConfig = adminConfigMapper.selectByPrimaryKey(Integer.valueOf(channelId));
|
|
AdminConfig adminConfig = adminConfigMapper.selectByPrimaryKey(Integer.valueOf(channelId));
|
|
Integer wxpayId = adminConfig.getWxpayId();
|
|
Integer wxpayId = adminConfig.getWxpayId();
|
|
Wxpay wxpay = wxpayMapper.selectByPrimaryKey(wxpayId);
|
|
Wxpay wxpay = wxpayMapper.selectByPrimaryKey(wxpayId);
|
|
boolean newpay = true;
|
|
boolean newpay = true;
|
|
- if (newpay){
|
|
|
|
- if (StringUtils.isEmpty(openid)){
|
|
|
|
|
|
+ if (newpay) {
|
|
|
|
+ if (StringUtils.isEmpty(openid)) {
|
|
User userByUserId = userService.getUserByUserId(Long.parseLong(userId));
|
|
User userByUserId = userService.getUserByUserId(Long.parseLong(userId));
|
|
openid = userByUserId.getOpenid();
|
|
openid = userByUserId.getOpenid();
|
|
}
|
|
}
|
|
- String url =String.format( Const.URL_PAY_CENTER,wxpay.getPayHost(),userId,channelId,redirectUrl,redirectId,openid);
|
|
|
|
|
|
+ String url = String.format(Const.URL_PAY_CENTER, wxpay.getPayHost(), userId, channelId, redirectUrl, redirectId, openid);
|
|
return "redirect:" + url;
|
|
return "redirect:" + url;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -269,9 +336,9 @@ public class WxPayServiceImpl implements WxPayService {
|
|
String host = wxpay.getPayHost();
|
|
String host = wxpay.getPayHost();
|
|
if (StringUtils.isEmpty(code)) {
|
|
if (StringUtils.isEmpty(code)) {
|
|
String params = "userId=%s&channelId=%s&redirectUrl=%s&redirectId=%s";
|
|
String params = "userId=%s&channelId=%s&redirectUrl=%s&redirectId=%s";
|
|
- params = String.format(params,userId,channelId,redirectUrl,redirectId);
|
|
|
|
|
|
+ params = String.format(params, userId, channelId, redirectUrl, redirectId);
|
|
|
|
|
|
- String oau2thRedirectUrl = "http://" + host + "/api/wxpay/login?" +params;
|
|
|
|
|
|
+ String oau2thRedirectUrl = "http://" + host + "/api/wxpay/login?" + params;
|
|
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect";
|
|
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect";
|
|
try {
|
|
try {
|
|
url = String.format(url, appid, java.net.URLEncoder.encode(oau2thRedirectUrl, "UTF-8"), userId);
|
|
url = String.format(url, appid, java.net.URLEncoder.encode(oau2thRedirectUrl, "UTF-8"), userId);
|
|
@@ -287,8 +354,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
String format = String.format(openidUrl, appid, secret, code);
|
|
String format = String.format(openidUrl, appid, secret, code);
|
|
String s = HttpUtils.sendGet(format);
|
|
String s = HttpUtils.sendGet(format);
|
|
SnsapiBase object = JsonUtils.getObject(s, SnsapiBase.class);
|
|
SnsapiBase object = JsonUtils.getObject(s, SnsapiBase.class);
|
|
- openid = object.getOpenid();
|
|
|
|
- String url =String.format( Const.URL_PAY_CENTER,wxpay.getPayHost(),userId,channelId,redirectUrl,redirectId,openid);
|
|
|
|
|
|
+ openid = object.getOpenid();
|
|
|
|
+ String url = String.format(Const.URL_PAY_CENTER, wxpay.getPayHost(), userId, channelId, redirectUrl, redirectId, openid);
|
|
return "redirect:" + url;
|
|
return "redirect:" + url;
|
|
}
|
|
}
|
|
|
|
|