package com.hollywood.applet.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.hollywood.applet.service.*;
|
import com.hollywood.common.model.TPerformerActivityUser;
|
import com.hollywood.common.model.TUser;
|
import com.hollywood.common.model.TVipPurchaseRecord;
|
import com.hollywood.common.utils.PayMoneyUtil;
|
import io.swagger.annotations.Api;
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
import org.checkerframework.checker.units.qual.A;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.PrintWriter;
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import java.time.LocalTime;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
@Slf4j
|
@RestController
|
@RequestMapping("/base")
|
public class CallBackController {
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
@Autowired
|
private TScriptService scriptService;
|
@Autowired
|
private TShortPlayService shortPlayService;
|
@Autowired
|
private TPerformerActivityUserService performerActivityUserService;
|
@Autowired
|
private TVipPurchaseRecordService vipPurchaseRecordService;
|
@Autowired
|
private TUserService userService;
|
|
@ResponseBody
|
@PostMapping("/script/wxcallback")
|
public void weChatScriptCallback(HttpServletRequest request, HttpServletResponse response) {
|
try {
|
Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
|
if (null != map) {
|
String code = map.get("out_trade_no");
|
String transaction_id = map.get("transaction_id");
|
String result = map.get("result");
|
scriptService.wxcallback(code, transaction_id);
|
PrintWriter out = response.getWriter();
|
out.write("success");
|
out.flush();
|
out.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
@ResponseBody
|
@PostMapping("/short/wxcallback")
|
public void weChatShortCallback(HttpServletRequest request, HttpServletResponse response) {
|
try {
|
Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
|
if (null != map) {
|
String code = map.get("out_trade_no");
|
String transaction_id = map.get("transaction_id");
|
String result = map.get("result");
|
shortPlayService.wxcallback(code, transaction_id);
|
PrintWriter out = response.getWriter();
|
out.write(result);
|
out.flush();
|
out.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
@ResponseBody
|
@PostMapping("/performance/wxcallback")
|
public void weChatPerformanceCallback(HttpServletRequest request, HttpServletResponse response) {
|
try {
|
Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
|
if (null != map) {
|
String code = map.get("out_trade_no");
|
String transaction_id = map.get("transaction_id");
|
String result = map.get("result");
|
// shortPlayService.wxcallback(code, transaction_id);
|
|
TPerformerActivityUser one = performerActivityUserService.getOne(Wrappers.lambdaQuery(TPerformerActivityUser.class).eq(TPerformerActivityUser::getCode, code));
|
if (one.getIsPay()==1){
|
one.setIsPay(2);
|
one.setOrderNum(transaction_id);
|
}
|
performerActivityUserService.updateById(one);
|
PrintWriter out = response.getWriter();
|
out.write("success");
|
out.flush();
|
out.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/vip/wxcallback")
|
public void weChatVipCallback(HttpServletRequest request, HttpServletResponse response) {
|
try {
|
Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
|
if (null != map) {
|
String code = map.get("out_trade_no");
|
String transaction_id = map.get("transaction_id");
|
String result = map.get("result");
|
TVipPurchaseRecord one = vipPurchaseRecordService.getOne(Wrappers.lambdaQuery(TVipPurchaseRecord.class).eq(TVipPurchaseRecord::getCode, code));
|
if (one.getIsPay()==1){
|
one.setIsPay(2);
|
one.setOrderNum(transaction_id);
|
TUser byId = userService.getById(one.getUserId());
|
|
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime firstVipTime = byId.getFirstVipTime();
|
if (firstVipTime==null){
|
byId.setFirstVipTime(now);
|
}
|
Integer purchaseCount = one.getPurchaseCount();
|
LocalDateTime endTime = byId.getEndTime();
|
if (endTime==null||endTime.isBefore(now)){
|
byId.setEndTime(now.plusDays(purchaseCount* 31L));
|
}else {
|
byId.setEndTime(byId.getEndTime().plusDays(purchaseCount*31L));
|
}
|
userService.updateById(byId);
|
}
|
vipPurchaseRecordService.updateById(one);
|
PrintWriter out = response.getWriter();
|
out.write("success");
|
out.flush();
|
out.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/vip/aliPaymentCourseCallback")
|
public void aliVipCallback(HttpServletRequest request, HttpServletResponse response) {
|
try {
|
Map<String, String> map = payMoneyUtil.alipayCallback(request);
|
if (null != map) {
|
String code = map.get("out_trade_no");
|
String trade_no = map.get("trade_no");
|
TVipPurchaseRecord one = vipPurchaseRecordService.getOne(Wrappers.lambdaQuery(TVipPurchaseRecord.class).eq(TVipPurchaseRecord::getCode, code));
|
if (one.getIsPay()==1){
|
one.setIsPay(2);
|
one.setOrderNum(trade_no);
|
TUser byId = userService.getById(one.getUserId());
|
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime firstVipTime = byId.getFirstVipTime();
|
if (firstVipTime==null){
|
byId.setFirstVipTime(now);
|
}
|
Integer purchaseCount = one.getPurchaseCount();
|
LocalDateTime endTime = byId.getEndTime();
|
if (endTime==null||endTime.isBefore(now)){
|
byId.setEndTime(now.plusDays(purchaseCount* 31L));
|
}else {
|
byId.setEndTime(byId.getEndTime().plusDays(purchaseCount*31L));
|
}
|
byId.setVipType(one.getVipType());
|
byId.setHasPay(byId.getHasPay()==null? BigDecimal.valueOf(one.getPayMoney()) :byId.getHasPay().add(BigDecimal.valueOf(one.getPayMoney())));
|
userService.updateById(byId);
|
}
|
vipPurchaseRecordService.updateById(one);
|
PrintWriter out = response.getWriter();
|
out.write("success");
|
out.flush();
|
out.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
@ResponseBody
|
@PostMapping("/performance/aliPaymentCourseCallback")
|
public void aliPerformanceCallback(HttpServletRequest request, HttpServletResponse response) {
|
try {
|
Map<String, String> map = payMoneyUtil.alipayCallback(request);
|
if (null != map) {
|
String code = map.get("out_trade_no");
|
String trade_no = map.get("trade_no");
|
TPerformerActivityUser one = performerActivityUserService.getOne(Wrappers.lambdaQuery(TPerformerActivityUser.class).eq(TPerformerActivityUser::getCode, code));
|
if (one.getIsPay()==1){
|
one.setIsPay(2);
|
one.setOrderNum(trade_no);
|
}
|
TUser byId = userService.getById(one.getUserId());
|
byId.setHasPay(byId.getHasPay()==null? one.getMoney() :byId.getHasPay().add(one.getMoney()));
|
userService.updateById(byId);
|
|
performerActivityUserService.updateById(one);
|
PrintWriter out = response.getWriter();
|
out.write("success");
|
out.flush();
|
out.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/script/alicallback")
|
public void aliScriptCallback(HttpServletRequest request, HttpServletResponse response){
|
try {
|
Map<String, String> map = payMoneyUtil.alipayCallback(request);
|
if(null != map){
|
String code = map.get("out_trade_no");
|
String trade_no = map.get("trade_no");
|
scriptService.alicallback(code,trade_no);
|
PrintWriter out = response.getWriter();
|
out.write("success");
|
out.flush();
|
out.close();
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/short/alicallback")
|
public void aliShortCallback(HttpServletRequest request, HttpServletResponse response){
|
try {
|
Map<String, String> map = payMoneyUtil.alipayCallback(request);
|
if(null != map){
|
String code = map.get("out_trade_no");
|
String trade_no = map.get("trade_no");
|
shortPlayService.alicallback(code,trade_no);
|
PrintWriter out = response.getWriter();
|
out.write("success");
|
out.flush();
|
out.close();
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
}
|