|
|
@@ -14,6 +14,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.google.zxing.BarcodeFormat;
|
|
|
+import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
|
+import com.google.zxing.common.BitMatrix;
|
|
|
+import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
import com.zhongzheng.common.config.WxSmallConfig;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
@@ -42,7 +46,9 @@ import com.zhongzheng.modules.grade.service.IStudyCountLogService;
|
|
|
import com.zhongzheng.modules.order.bo.OrderGoodsQueryBo;
|
|
|
import com.zhongzheng.modules.order.domain.Order;
|
|
|
import com.zhongzheng.modules.order.domain.OrderGoods;
|
|
|
+import com.zhongzheng.modules.order.domain.OrderPay;
|
|
|
import com.zhongzheng.modules.order.service.IOrderGoodsService;
|
|
|
+import com.zhongzheng.modules.order.service.IOrderPayService;
|
|
|
import com.zhongzheng.modules.order.service.IOrderService;
|
|
|
import com.zhongzheng.modules.order.vo.OrderGoodsVo;
|
|
|
import com.zhongzheng.modules.polyv.bo.PolyvVideoAddBo;
|
|
|
@@ -73,6 +79,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
@@ -88,7 +96,7 @@ import static com.squareup.okhttp.internal.Util.md5Hex;
|
|
|
* @date 2021-06-11
|
|
|
*/
|
|
|
@Service
|
|
|
-public class WxPayServiceImpl implements IWxPayService {
|
|
|
+public class WxPayServiceImpl implements IWxPayService {
|
|
|
|
|
|
@Value("${wx.small.appid}")
|
|
|
private String appid;
|
|
|
@@ -123,7 +131,7 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
private WXPayConstants.SignType signType;
|
|
|
|
|
|
|
|
|
- // private String notifyUrl = "http://42.192.164.187:19005/wx/pay/callback";
|
|
|
+ // private String notifyUrl = "http://42.192.164.187:19005/wx/pay/callback";
|
|
|
|
|
|
private WXPayRequest wxPayRequest;
|
|
|
|
|
|
@@ -156,7 +164,8 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
@Autowired
|
|
|
private IClassGradeUserService iClassGradeUserService;
|
|
|
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IOrderPayService iOrderPayService;
|
|
|
|
|
|
|
|
|
private String gzh_tokenUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
|
|
@@ -164,8 +173,8 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
private String gzh_tokenParam = "grant_type=client_credential&appid=%s&secret=%s";
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, String> payment(String out_trade_no,String openid,String body,BigDecimal price) {
|
|
|
- WxSmallConfig config = new WxSmallConfig(appid,mchid,key);
|
|
|
+ public Map<String, String> payment(String out_trade_no, String openid, String body, BigDecimal price) {
|
|
|
+ WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
|
|
|
BigDecimal unit = new BigDecimal(100);
|
|
|
price = price.multiply(unit);
|
|
|
try {
|
|
|
@@ -175,7 +184,7 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
data.put("out_trade_no", out_trade_no);
|
|
|
data.put("device_info", "");
|
|
|
data.put("fee_type", "CNY");
|
|
|
- data.put("total_fee",price.intValue()+"");
|
|
|
+ data.put("total_fee", price.intValue() + "");
|
|
|
data.put("openid", openid);
|
|
|
data.put("spbill_create_ip", IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
data.put("notify_url", notifyUrl);
|
|
|
@@ -186,12 +195,12 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
Map<String, String> resp = wxpay.unifiedOrder(data);
|
|
|
System.out.println(resp);
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
- // result.put("provider","wxpay");
|
|
|
- result.put("appId",appid);
|
|
|
- result.put("timeStamp",String.valueOf(DateUtils.getNowTime()));
|
|
|
- result.put("nonceStr",resp.get("nonce_str"));
|
|
|
- result.put("package","prepay_id="+resp.get("prepay_id"));
|
|
|
- result.put("signType","MD5");
|
|
|
+ // result.put("provider","wxpay");
|
|
|
+ result.put("appId", appid);
|
|
|
+ result.put("timeStamp", String.valueOf(DateUtils.getNowTime()));
|
|
|
+ result.put("nonceStr", resp.get("nonce_str"));
|
|
|
+ result.put("package", "prepay_id=" + resp.get("prepay_id"));
|
|
|
+ result.put("signType", "MD5");
|
|
|
System.out.println(result);
|
|
|
System.out.println(key);
|
|
|
result.put("sign", WXPayUtil.generateSignature(result, key, WXPayConstants.SignType.MD5));
|
|
|
@@ -203,9 +212,52 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, String> paymentPc(String out_trade_no, String openid, String body, BigDecimal price) {
|
|
|
+ WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
|
|
|
+ BigDecimal unit = new BigDecimal(100);
|
|
|
+ price = price.multiply(unit);
|
|
|
+ try {
|
|
|
+ WXPay wxpay = new WXPay(config);
|
|
|
+ Map<String, String> data = new HashMap<String, String>();
|
|
|
+ data.put("body", body);
|
|
|
+ data.put("out_trade_no", out_trade_no);
|
|
|
+ data.put("device_info", "");
|
|
|
+ data.put("fee_type", "CNY");
|
|
|
+ data.put("total_fee", price.intValue() + "");
|
|
|
+ data.put("openid", openid);
|
|
|
+ data.put("spbill_create_ip", IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+ data.put("notify_url", notifyUrl);
|
|
|
+ data.put("trade_type", "NATIVE");
|
|
|
+ String TenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ data.put("attach", TenantId);
|
|
|
+ Map<String, String> resp = wxpay.unifiedOrder(data);
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
+ String code_url = resp.get("code_url");
|
|
|
+ if (Validator.isEmpty(code_url)) {
|
|
|
+ throw new CustomException("支付错误");
|
|
|
+ }
|
|
|
+ QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
|
|
+ BitMatrix bitMatrix = qrCodeWriter.encode(code_url, BarcodeFormat.QR_CODE, 120, 120);
|
|
|
+ // 写到输出流
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ MatrixToImageWriter.writeToStream(bitMatrix, "jpg", outputStream);
|
|
|
+ //转换为base64
|
|
|
+ Base64.Encoder encoder1 = Base64.getEncoder();
|
|
|
+ String urlBase64 = "data:image/jpeg;base64,"
|
|
|
+ + encoder1.encodeToString(outputStream.toByteArray());
|
|
|
+ result.put("urlBase64", urlBase64);
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, String> paymentGzh(String out_trade_no, String openid, String body, BigDecimal price, String url) {
|
|
|
- WxSmallConfig config = new WxSmallConfig(gzhAppid,mchid,key);
|
|
|
+ WxSmallConfig config = new WxSmallConfig(gzhAppid, mchid, key);
|
|
|
try {
|
|
|
WXPay wxpay = new WXPay(config);
|
|
|
BigDecimal unit = new BigDecimal(100);
|
|
|
@@ -215,7 +267,7 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
data.put("out_trade_no", out_trade_no);
|
|
|
data.put("device_info", "");
|
|
|
data.put("fee_type", "CNY");
|
|
|
- data.put("total_fee", price.intValue()+"");
|
|
|
+ data.put("total_fee", price.intValue() + "");
|
|
|
data.put("openid", openid);
|
|
|
data.put("spbill_create_ip", IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
data.put("notify_url", notifyUrl);
|
|
|
@@ -225,28 +277,28 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
Map<String, String> resp = wxpay.unifiedOrder(data);
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
// result.put("provider","wxpay");
|
|
|
- result.put("appId",gzhAppid);
|
|
|
- result.put("timeStamp",String.valueOf(DateUtils.getNowTime()));
|
|
|
- result.put("nonceStr",resp.get("nonce_str"));
|
|
|
- result.put("package","prepay_id="+resp.get("prepay_id"));
|
|
|
- result.put("signType","MD5");
|
|
|
+ result.put("appId", gzhAppid);
|
|
|
+ result.put("timeStamp", String.valueOf(DateUtils.getNowTime()));
|
|
|
+ result.put("nonceStr", resp.get("nonce_str"));
|
|
|
+ result.put("package", "prepay_id=" + resp.get("prepay_id"));
|
|
|
+ result.put("signType", "MD5");
|
|
|
result.put("paySign", WXPayUtil.generateSignature(result, key, WXPayConstants.SignType.MD5));
|
|
|
- result.put("configPaySign", wx_config_sign(result,url));
|
|
|
+ result.put("configPaySign", wx_config_sign(result, url));
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- throw new CustomException("错误"+e.getMessage());
|
|
|
+ throw new CustomException("错误" + e.getMessage());
|
|
|
}
|
|
|
|
|
|
- // return null;
|
|
|
+ // return null;
|
|
|
}
|
|
|
|
|
|
- public String wx_config_sign(Map<String, String> result,String url) {
|
|
|
+ public String wx_config_sign(Map<String, String> result, String url) {
|
|
|
String jsapi_ticket = wx_get_jsapi_ticket();
|
|
|
- if(!Validator.isNotNull(jsapi_ticket)){
|
|
|
- throw new CustomException("jsapi_ticket错误"+jsapi_ticket);
|
|
|
+ if (!Validator.isNotNull(jsapi_ticket)) {
|
|
|
+ throw new CustomException("jsapi_ticket错误" + jsapi_ticket);
|
|
|
}
|
|
|
- String str = "jsapi_ticket="+jsapi_ticket+"&noncestr="+result.get("nonceStr")+"×tamp="+result.get("timeStamp")+"&url="+url;
|
|
|
+ String str = "jsapi_ticket=" + jsapi_ticket + "&noncestr=" + result.get("nonceStr") + "×tamp=" + result.get("timeStamp") + "&url=" + url;
|
|
|
String signature = AES.SHA1(str);
|
|
|
return signature;
|
|
|
}
|
|
|
@@ -254,7 +306,7 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
@Override
|
|
|
public String paymentCallBack(String notifyData) {
|
|
|
String xmlBack = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[报文为空]]></return_msg></xml> ";
|
|
|
- WxSmallConfig config = new WxSmallConfig(appid,mchid,key);
|
|
|
+ WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
|
|
|
try {
|
|
|
WXPay wxpay = new WXPay(config);
|
|
|
|
|
|
@@ -262,18 +314,26 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
|
|
|
if (wxpay.isPayResultNotifySignatureValid(notifyMap)) {
|
|
|
String result_code = notifyMap.get("result_code");
|
|
|
- if("SUCCESS".equals(result_code)){
|
|
|
+ if ("SUCCESS".equals(result_code)) {
|
|
|
String out_trade_no = notifyMap.get("out_trade_no");
|
|
|
String transaction_id = notifyMap.get("transaction_id");
|
|
|
String TenantId = notifyMap.get("attach");
|
|
|
- ServletUtils.getRequestAttributes().getResponse().setHeader("TenantId",TenantId);
|
|
|
- if(dealOrder(out_trade_no,transaction_id)){
|
|
|
- xmlBack = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
|
|
|
- return xmlBack;
|
|
|
+ ServletUtils.getRequestAttributes().getResponse().setHeader("TenantId", TenantId);
|
|
|
+
|
|
|
+ OrderPay orderPay = iOrderPayService.getOne(new LambdaQueryWrapper<OrderPay>().eq(OrderPay::getPaySn, out_trade_no));
|
|
|
+ if(Validator.isNotEmpty(orderPay)){
|
|
|
+ String orderSn = orderPay.getOrderSn();
|
|
|
+ orderPay.setTransid(transaction_id);
|
|
|
+ orderPay.setStatus(1);
|
|
|
+ orderPay.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iOrderPayService.updateById(orderPay);
|
|
|
+ if (dealOrder(orderSn, transaction_id)) {
|
|
|
+ xmlBack = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
|
|
|
+ return xmlBack;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
// 签名错误,如果数据里没有sign字段,也认为是签名错误
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -286,59 +346,58 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
public String wx_get_jsapi_ticket() {
|
|
|
String key = "gzh_ticket";
|
|
|
String ticket = redisCache.getCacheObject(key);
|
|
|
- if(!Validator.isNotNull(ticket)){
|
|
|
+ if (!Validator.isNotNull(ticket)) {
|
|
|
String access_token = wx_get_token();
|
|
|
String param = String.format("access_token=%s&type=jsapi", access_token);
|
|
|
- String resultString = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket",param);
|
|
|
+ String resultString = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket", param);
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
ticket = String.valueOf(jsonObject.get("ticket"));
|
|
|
- if(ticket!=null){
|
|
|
- redisCache.setCacheObject(key, ticket, 2*50, TimeUnit.MINUTES);//2个小时
|
|
|
+ if (ticket != null) {
|
|
|
+ redisCache.setCacheObject(key, ticket, 2 * 50, TimeUnit.MINUTES);//2个小时
|
|
|
}
|
|
|
}
|
|
|
return ticket;
|
|
|
}
|
|
|
|
|
|
//获取微信公众号access_token
|
|
|
- public String wx_get_token()
|
|
|
- {
|
|
|
+ public String wx_get_token() {
|
|
|
String key = "gzh_access_token";
|
|
|
String access_token = redisCache.getCacheObject(key);
|
|
|
- if(!Validator.isNotNull(access_token)){
|
|
|
+ if (!Validator.isNotNull(access_token)) {
|
|
|
String param = String.format(gzh_tokenParam, gzhAppid, gzh_appsrcret);
|
|
|
- String resultString = HttpUtils.sendGet(gzh_tokenUrl,param);
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_tokenUrl, param);
|
|
|
//解析json
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
access_token = String.valueOf(jsonObject.get("access_token")); //这里应该把access_token缓存起来,至于要怎么缓存就看各位了,有效期是7200s
|
|
|
- if(access_token!=null){
|
|
|
- redisCache.setCacheObject(key, access_token, 2*50, TimeUnit.MINUTES);//2个小时
|
|
|
+ if (access_token != null) {
|
|
|
+ redisCache.setCacheObject(key, access_token, 2 * 50, TimeUnit.MINUTES);//2个小时
|
|
|
}
|
|
|
}
|
|
|
- if(!Validator.isNotNull(access_token)){
|
|
|
- throw new CustomException("access_token错误"+access_token);
|
|
|
+ if (!Validator.isNotNull(access_token)) {
|
|
|
+ throw new CustomException("access_token错误" + access_token);
|
|
|
}
|
|
|
return access_token;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean dealOrder(String out_trade_no,String transaction_id){
|
|
|
+ public boolean dealOrder(String out_trade_no, String transaction_id) {
|
|
|
String key = out_trade_no;
|
|
|
String ticket = redisCache.getCacheObject(key);
|
|
|
- if(Validator.isNotEmpty(ticket)){
|
|
|
+ if (Validator.isNotEmpty(ticket)) {
|
|
|
return false;
|
|
|
}
|
|
|
- redisCache.setCacheObject(key, "dealing", 1, TimeUnit.MINUTES);//1分钟
|
|
|
+ redisCache.setCacheObject(key, "dealing", 30, TimeUnit.SECONDS);//30秒
|
|
|
Order order = iOrderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn, out_trade_no));
|
|
|
- if(order!=null&&order.getOrderStatus()==0){
|
|
|
+ if (order != null && order.getOrderStatus() == 0) {
|
|
|
order.setOrderStatus(Order.ORDER_STATUS_PAY);
|
|
|
order.setPayStatus(Order.PAY_FULL);
|
|
|
order.setPayTime(DateUtils.getNowTime());
|
|
|
order.setTransid(transaction_id);
|
|
|
order.setOrderGeneral(out_trade_no);
|
|
|
order.setStatus(1);
|
|
|
- if(iOrderService.updateById(order)){
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("order_sn",out_trade_no);
|
|
|
+ if (iOrderService.updateById(order)) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("order_sn", out_trade_no);
|
|
|
List<OrderGoods> goodsList = iOrderGoodsService.listByMap(map);
|
|
|
for (OrderGoods g : goodsList) {
|
|
|
g.setPayStatus(OrderGoods.PAY_FULL);
|
|
|
@@ -347,8 +406,9 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
g = setServiceTime(g);
|
|
|
iOrderGoodsService.updateById(g);
|
|
|
//给用户增加商品考试次数前培次数
|
|
|
- updateUserExamGoods(g,order);
|
|
|
- joinLockGrade(order.getOrderSn(),g.getGoodsId(),g.getOrderGoodsId());
|
|
|
+ updateUserExamGoods(g, order);
|
|
|
+ joinLockGrade(order.getOrderSn(), g.getGoodsId(), g.getOrderGoodsId());
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -359,32 +419,30 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
|
|
|
//设置服务期
|
|
|
@Override
|
|
|
- public OrderGoods setServiceTime(OrderGoods g){
|
|
|
+ public OrderGoods setServiceTime(OrderGoods g) {
|
|
|
GoodsVo goodsVo = iGoodsService.queryById(g.getGoodsId());
|
|
|
//视频商品题库商品设置服务有效期
|
|
|
- if (goodsVo.getGoodsType().equals(1L)||goodsVo.getGoodsType().equals(2L)){
|
|
|
- if(Validator.isNotEmpty(goodsVo.getServiceTimeType())){
|
|
|
- if(Validator.isNotEmpty(goodsVo.getServiceTimeNum())){
|
|
|
- if(goodsVo.getServiceTimeType()==1){ //年
|
|
|
+ if (goodsVo.getGoodsType().equals(1) || goodsVo.getGoodsType().equals(2)) {
|
|
|
+ if (Validator.isNotEmpty(goodsVo.getServiceTimeType())) {
|
|
|
+ if (Validator.isNotEmpty(goodsVo.getServiceTimeNum())) {
|
|
|
+ if (goodsVo.getServiceTimeType() == 1) { //年
|
|
|
Calendar cal = new GregorianCalendar();
|
|
|
- cal.add(Calendar.YEAR,goodsVo.getServiceTimeNum().intValue());
|
|
|
+ cal.add(Calendar.YEAR, goodsVo.getServiceTimeNum().intValue());
|
|
|
g.setServiceStartTime(DateUtils.getNowTime());
|
|
|
- g.setServiceEndTime(cal.getTimeInMillis()/1000);
|
|
|
- }
|
|
|
- else if(goodsVo.getServiceTimeType()==2){ //月
|
|
|
+ g.setServiceEndTime(cal.getTimeInMillis() / 1000);
|
|
|
+ } else if (goodsVo.getServiceTimeType() == 2) { //月
|
|
|
Calendar cal = new GregorianCalendar();
|
|
|
- cal.add(Calendar.MONTH,goodsVo.getServiceTimeNum().intValue());
|
|
|
+ cal.add(Calendar.MONTH, goodsVo.getServiceTimeNum().intValue());
|
|
|
g.setServiceStartTime(DateUtils.getNowTime());
|
|
|
- g.setServiceEndTime(cal.getTimeInMillis()/1000);
|
|
|
- }
|
|
|
- else if(goodsVo.getServiceTimeType()==3){ //天
|
|
|
+ g.setServiceEndTime(cal.getTimeInMillis() / 1000);
|
|
|
+ } else if (goodsVo.getServiceTimeType() == 3) { //天
|
|
|
Calendar cal = new GregorianCalendar();
|
|
|
- cal.add(Calendar.DATE,goodsVo.getServiceTimeNum().intValue());
|
|
|
+ cal.add(Calendar.DATE, goodsVo.getServiceTimeNum().intValue());
|
|
|
g.setServiceStartTime(DateUtils.getNowTime());
|
|
|
- g.setServiceEndTime(cal.getTimeInMillis()/1000);
|
|
|
+ g.setServiceEndTime(cal.getTimeInMillis() / 1000);
|
|
|
}
|
|
|
}
|
|
|
- if(goodsVo.getServiceTimeType()==4){ //区间
|
|
|
+ if (goodsVo.getServiceTimeType() == 4) { //区间
|
|
|
g.setServiceStartTime(goodsVo.getStudyStartTime());
|
|
|
g.setServiceEndTime(goodsVo.getStudyEndTime());
|
|
|
}
|
|
|
@@ -394,13 +452,13 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateUserExamGoods(OrderGoods g,Order order) {
|
|
|
+ public void updateUserExamGoods(OrderGoods g, Order order) {
|
|
|
GoodsVo goodsVo = iGoodsService.queryById(g.getGoodsId());
|
|
|
//添加商品考试次数和补考次数
|
|
|
- if (goodsVo.getGoodsType().equals(1L)){
|
|
|
- if (userExamGoodsService.queryExamGoods(goodsVo.getGoodsId(),order.getUserId()) < 1){
|
|
|
+ if (goodsVo.getGoodsType().equals(1)) {
|
|
|
+ if (userExamGoodsService.queryExamGoods(goodsVo.getGoodsId(), order.getUserId()) < 1) {
|
|
|
ExamNumber examNumber = userExamGoodsService.queryExam(goodsVo.getGoodsId());
|
|
|
- if (examNumber != null) {
|
|
|
+ if ( Validator.isNotEmpty(examNumber)) {
|
|
|
UserExamGoods add = new UserExamGoods();
|
|
|
add.setGoodsId(g.getGoodsId());
|
|
|
add.setUserId(order.getUserId());
|
|
|
@@ -417,7 +475,7 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
userExamGoodsSupplementAddBo.setDoNumber(examNumber.getDoNumber());
|
|
|
userExamGoodsSupplementAddBo.setStatus(3);
|
|
|
userExamGoodsSupplementService.insertByAddBo(userExamGoodsSupplementAddBo);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//默认生成一条,避免商品以后才配置考试次数
|
|
|
UserExamGoods add = new UserExamGoods();
|
|
|
add.setGoodsId(g.getGoodsId());
|
|
|
@@ -432,12 +490,12 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
}
|
|
|
}
|
|
|
//增加前培次数
|
|
|
- if (goodsVo.getGoodsType().equals(4L)){
|
|
|
+ if (goodsVo.getGoodsType().equals(4)) {
|
|
|
UserExamGoodsQueryBo userExamGoodsQueryBo = new UserExamGoodsQueryBo();
|
|
|
userExamGoodsQueryBo.setUserId(order.getUserId());
|
|
|
userExamGoodsQueryBo.setGoodsId(goodsVo.getMakeGoodsId());
|
|
|
List<UserExamGoodsVo> userExamGoodsVos = userExamGoodsService.queryList(userExamGoodsQueryBo);
|
|
|
- if (!CollectionUtils.isEmpty(userExamGoodsVos)){
|
|
|
+ if (!CollectionUtils.isEmpty(userExamGoodsVos)) {
|
|
|
UserExamGoodsVo userExamGoodsVo = userExamGoodsVos.get(0);
|
|
|
UserExamGoodsSupplementAddBo userExamGoodsSupplementAddBo = new UserExamGoodsSupplementAddBo();
|
|
|
userExamGoodsSupplementAddBo.setGoodsId(goodsVo.getGoodsId());
|
|
|
@@ -447,17 +505,17 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
userExamGoodsSupplementService.insertByAddBo(userExamGoodsSupplementAddBo);
|
|
|
UserExamGoods userExamGoods = new UserExamGoods();
|
|
|
userExamGoods.setUserExamGoodsId(userExamGoodsVo.getUserExamGoodsId());
|
|
|
- userExamGoods.setDoNumber(userExamGoodsVo.getDoNumber()+goodsVo.getStudyCount());
|
|
|
+ userExamGoods.setDoNumber(userExamGoodsVo.getDoNumber() + goodsVo.getStudyCount());
|
|
|
userExamGoodsService.updateById(userExamGoods);
|
|
|
}
|
|
|
}
|
|
|
//增加考试次数
|
|
|
- if (goodsVo.getGoodsType().equals(3L)){
|
|
|
+ if (goodsVo.getGoodsType().equals(3)) {
|
|
|
UserExamGoodsQueryBo userExamGoodsQueryBo = new UserExamGoodsQueryBo();
|
|
|
userExamGoodsQueryBo.setUserId(order.getUserId());
|
|
|
userExamGoodsQueryBo.setGoodsId(goodsVo.getMakeGoodsId());
|
|
|
List<UserExamGoodsVo> userExamGoodsVos = userExamGoodsService.queryList(userExamGoodsQueryBo);
|
|
|
- if (!CollectionUtils.isEmpty(userExamGoodsVos)){
|
|
|
+ if (!CollectionUtils.isEmpty(userExamGoodsVos)) {
|
|
|
UserExamGoodsVo userExamGoodsVo = userExamGoodsVos.get(0);
|
|
|
UserExamGoodsSupplementAddBo userExamGoodsSupplementAddBo = new UserExamGoodsSupplementAddBo();
|
|
|
userExamGoodsSupplementAddBo.setGoodsId(goodsVo.getGoodsId());
|
|
|
@@ -467,7 +525,7 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
userExamGoodsSupplementService.insertByAddBo(userExamGoodsSupplementAddBo);
|
|
|
UserExamGoods userExamGoods = new UserExamGoods();
|
|
|
userExamGoods.setUserExamGoodsId(userExamGoodsVo.getUserExamGoodsId());
|
|
|
- userExamGoods.setExamNumber(userExamGoodsVo.getExamNumber()+goodsVo.getStudyCount());
|
|
|
+ userExamGoods.setExamNumber(userExamGoodsVo.getExamNumber() + goodsVo.getStudyCount());
|
|
|
userExamGoodsService.updateById(userExamGoods);
|
|
|
}
|
|
|
}
|
|
|
@@ -475,18 +533,19 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
|
|
|
//加入锁定班级
|
|
|
@Override
|
|
|
- public boolean joinLockGrade(String orderSn,Long goodsId,Long orderGoodsId){
|
|
|
+ public boolean joinLockGrade(String orderSn, Long goodsId, Long orderGoodsId) {
|
|
|
GoodsVo goodsVo = iGoodsService.queryById(goodsId);
|
|
|
- if (goodsVo.getGoodsType().equals(1L)){
|
|
|
+ if (goodsVo.getGoodsType().equals(1)) {
|
|
|
LambdaQueryWrapper<ClassGradeUserTemp> lqwLock = new LambdaQueryWrapper<>();
|
|
|
- lqwLock.eq(ClassGradeUserTemp::getOrderSn,orderSn);
|
|
|
- lqwLock.eq(ClassGradeUserTemp::getGoodsId,goodsId);
|
|
|
+ lqwLock.eq(ClassGradeUserTemp::getOrderSn, orderSn);
|
|
|
+ lqwLock.eq(ClassGradeUserTemp::getGoodsId, goodsId);
|
|
|
+ lqwLock.eq(ClassGradeUserTemp::getStatus, ClassGradeUserTemp.STATUS_LOCK);
|
|
|
ClassGradeUserTemp classGradeUserTemp = iClassGradeUserTempService.getOne(lqwLock);
|
|
|
- if(classGradeUserTemp!=null&&classGradeUserTemp.getStatus()==ClassGradeUserTemp.STATUS_LOCK){
|
|
|
+ if (classGradeUserTemp != null) {
|
|
|
classGradeUserTemp.setStatus(ClassGradeUserTemp.STATUS_USE); //
|
|
|
classGradeUserTemp.setUpdateTime(DateUtils.getNowTime());
|
|
|
iClassGradeUserTempService.updateById(classGradeUserTemp);//关闭锁定状态
|
|
|
- iOrderService.joinGrade(orderGoodsId,classGradeUserTemp.getGradeId(),classGradeUserTemp.getUserId());
|
|
|
+ iOrderService.joinGrade(orderGoodsId, classGradeUserTemp.getGradeId(), classGradeUserTemp.getUserId());
|
|
|
}
|
|
|
//记录消耗一次学习机会
|
|
|
StudyCountLog studyCountLog = new StudyCountLog();
|
|
|
@@ -509,8 +568,8 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, String> refund(String out_refund_no,String transaction_id, BigDecimal refund_fee, BigDecimal total_fee) {
|
|
|
- WxSmallConfig config = new WxSmallConfig(appid,mchid,key);
|
|
|
+ public Map<String, String> refund(String out_refund_no, String transaction_id, BigDecimal refund_fee, BigDecimal total_fee) {
|
|
|
+ WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
|
|
|
BigDecimal unit = new BigDecimal(100);
|
|
|
refund_fee = refund_fee.multiply(unit);
|
|
|
total_fee = total_fee.multiply(unit);
|
|
|
@@ -521,12 +580,12 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
data.put("transaction_id", transaction_id);
|
|
|
data.put("device_info", "");
|
|
|
data.put("fee_type", "CNY");
|
|
|
- data.put("refund_fee", refund_fee.intValue()+"");
|
|
|
- data.put("total_fee", total_fee.intValue()+"");
|
|
|
+ data.put("refund_fee", refund_fee.intValue() + "");
|
|
|
+ data.put("total_fee", total_fee.intValue() + "");
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
- result.put("appId",appid);
|
|
|
- result.put("nonceStr",WXPayUtil.generateNonceStr());
|
|
|
- result.put("signType","MD5");
|
|
|
+ result.put("appId", appid);
|
|
|
+ result.put("nonceStr", WXPayUtil.generateNonceStr());
|
|
|
+ result.put("signType", "MD5");
|
|
|
result.put("sign", WXPayUtil.generateSignature(result, key, WXPayConstants.SignType.MD5));
|
|
|
Map rMap = wxpay.refund(data);
|
|
|
System.out.println(rMap);
|