package com.ibeetl.admin.console.api;
|
|
import com.ibeetl.admin.console.model.ItemModel;
|
import com.ibeetl.admin.console.model.MoneyModel;
|
import com.ibeetl.admin.console.model.UserAccountModel;
|
import com.ibeetl.admin.console.model.UserModel;
|
import com.ibeetl.admin.console.service.CuserConsoleService;
|
import com.ibeetl.admin.console.service.FunctionConsoleService;
|
import com.ibeetl.admin.console.service.MoneyConsoleService;
|
import com.ibeetl.admin.console.service.SettingConsoleService;
|
import com.ibeetl.admin.console.service.pay.PayService;
|
import com.ibeetl.admin.console.service.pay.utils.WechatpayUtil;
|
import com.ibeetl.admin.console.service.pay.utils.entity.ResultEntity;
|
import com.ibeetl.admin.console.service.pay.utils.entity.TransfersDto;
|
import com.ibeetl.admin.console.util.PreventManyCommit;
|
import com.ibeetl.admin.console.util.UserLock;
|
import com.ibeetl.admin.core.annotation.Function;
|
import com.ibeetl.admin.core.gen.MavenProjectTarget;
|
import com.ibeetl.admin.core.web.JsonResult;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import java.sql.SQLOutput;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* 微信提现
|
*/
|
@RestController
|
@Configuration
|
@Api(value = "微信提现接口类")
|
public class PayApi {
|
|
private static final String MODEL = "/admin/wx/pay";
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
@Autowired
|
CuserConsoleService service;
|
@Autowired
|
MoneyConsoleService moneyConsoleService;
|
@Autowired
|
CuserConsoleService cuserConsoleService;
|
@Autowired
|
PayService payService;
|
@Autowired
|
SettingConsoleService settingConsoleService;
|
@Autowired
|
FunctionConsoleService functionConsoleService;
|
|
@Value("${wx.app.url}")
|
String TRANS_URL;
|
@Value("${wx.app.key}")
|
String APP_KEY;
|
@Value("${wx.path}")
|
String CERT_PATH;
|
@Value("${wx.appid}")
|
String APP_ID;
|
@Value("${wx.mchid}")
|
String MCH_ID;
|
@Value("${wx.name}")
|
String MCH_NAME;
|
@Value("${wx.create.ip}")
|
String CREATE_IP;
|
@Value("${wx.appid.app}")
|
String APP_ID_APP;
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
@PostMapping(MODEL + "/wxPay.do")
|
@ResponseBody
|
@ApiOperation(value = "微信提现接口", notes = "test: 仅0有正确返回")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType = "query", name = "userId", value = "用户Id", required = true, dataType = "String"),
|
@ApiImplicitParam(paramType = "query", name = "payOrderId", value = "提现申请订单Id", required = true, dataType = "String"),
|
@ApiImplicitParam(paramType = "query", name = "otherUserId", value = "非普通用户Id", required = true, dataType = "String")
|
})
|
public JsonResult<String> wxPay(@RequestBody TransfersDto dto) {
|
Map<String,Object> result = new HashMap<>();
|
MoneyModel moneyModel = new MoneyModel();
|
String payOrderId = dto.getPayOrderId();
|
if (StringUtils.isEmpty(dto.getPayOrderId())) {
|
|
return JsonResult.fail("payOrderId不能为空");
|
} else {
|
moneyModel = getMoneyModel(dto.getPayOrderId());
|
String desc ="";
|
if(null!=dto.getOtherUserId()&&!"".equals(dto.getOtherUserId())){
|
desc = checkMoneyModel(moneyModel, dto.getOtherUserId());
|
}else{
|
desc = checkMoneyModel(moneyModel, dto.getUserId());
|
}
|
if (!"0".equals(desc)) {
|
return JsonResult.fail(desc);
|
}
|
}
|
|
//查询用户openId
|
String openId = "";
|
UserModel userModel = new UserModel();
|
UserModel userModelAccount = new UserModel();
|
if(null!=dto.getOtherUserId()&&!"".equals(dto.getOtherUserId())){
|
//if(dto.getOtherUserId().equals(dto.getUserId())){
|
dto.setMch_appid(APP_ID_APP);
|
//}
|
userModelAccount = service.queryUserOtherInfoById(dto.getOtherUserId());
|
userModel = service.queryUserOtherInfoById(dto.getOtherUserId());
|
System.out.println("============otherUserId="+dto.getOtherUserId());
|
}else{
|
userModel = service.queryUserById(dto.getUserId());
|
dto.setMch_appid(APP_ID);
|
}
|
System.out.println("APPID========="+APP_ID);
|
log.info("appid==="+APP_ID);
|
if (userModel == null) {
|
moneyModel.setUnpassReason("用户不存在");
|
moneyConsoleService.updateMoney(moneyModel);
|
return JsonResult.fail( "用户不存在");
|
}
|
//查询用户账户是否能提现
|
UserAccountModel userAccount = new UserAccountModel();
|
if(null!=dto.getOtherUserId()&&!"".equals(dto.getOtherUserId())){
|
userAccount = getUserAccount(moneyModel, userModelAccount);
|
|
}else{
|
userAccount = getUserAccount(moneyModel, userModel);
|
|
}
|
String oldMoney = String.valueOf(userAccount.getMoney());
|
|
if (null != userAccount.getErrorType() && !"".equals(userAccount.getErrorType())) {
|
return JsonResult.fail(userAccount.getErrorType());
|
} else {
|
// 审核通过
|
moneyModel.setStatus("2");
|
moneyModel.setPayFlag("0");
|
moneyConsoleService.updateMoney(moneyModel);
|
}
|
openId = userModel.getOpenId();
|
String mobilePhone = userModel.getMobilePhone();
|
if (!"".equals(openId)) {
|
dto.setOpenid(openId);
|
dto.setMchid(MCH_ID);
|
dto.setAppkey(APP_KEY);
|
dto.setSpbill_create_ip(CREATE_IP);
|
dto.setMch_name("湖南小棕熊环保科技有限责任公司");
|
dto.setDesc("企业付款到零钱");
|
if(null!=dto.getOtherUserId()&&!"".equals(dto.getOtherUserId())){
|
dto.setUserId(dto.getOtherUserId());
|
|
}
|
//自动转为以分为单位
|
dto.setAmount(Double.parseDouble(moneyModel.getMoney()));
|
dto.setPayOrderId(payOrderId);
|
result = payService.sendWxPay(TRANS_URL, CERT_PATH, dto, userAccount,mobilePhone,oldMoney);
|
}
|
if("0".equals(result.get("code").toString())){
|
return JsonResult.success(result.get("data").toString());
|
|
}else{
|
return JsonResult.fail(result.get("data").toString());
|
|
}
|
}
|
|
/**
|
* 查询提现申请记录
|
*
|
* @param payOrderId
|
* @return
|
*/
|
private MoneyModel getMoneyModel(String payOrderId) {
|
MoneyModel moneyModel = new MoneyModel();
|
moneyModel.setPayOrderId(payOrderId);
|
moneyModel = moneyConsoleService.queryMoney(moneyModel);
|
moneyModel.setStatus("3");
|
moneyModel.setPayFlag("3");
|
moneyModel.setExamineTime(sdf.format(new Date()));
|
return moneyModel;
|
}
|
|
/**
|
* @param model
|
* @return
|
*/
|
private String checkMoneyModel(MoneyModel model, String userId) {
|
if (!model.getCreateUserId().equals(userId)) {
|
model.setUnpassReason("userId和支付订单里面的userId不一致");
|
moneyConsoleService.updateMoney(model);
|
return "userId和支付订单里面的userId不一致";
|
}
|
if (StringUtils.isEmpty(model.getCreateUserId())) {
|
model.setUnpassReason("用户ID不能为空");
|
moneyConsoleService.updateMoney(model);
|
return "用户ID不能为空";
|
}
|
if (StringUtils.isEmpty(model.getMoney())) {
|
model.setUnpassReason("金钱不能为空");
|
moneyConsoleService.updateMoney(model);
|
return "金钱不能为空";
|
}
|
if (Double.parseDouble(model.getMoney()) <=0.3) {
|
model.setUnpassReason("金额不能等于或小于0.3");
|
moneyConsoleService.updateMoney(model);
|
return "金额不能等于或小于1";
|
}
|
return "0";
|
}
|
|
private UserAccountModel getUserAccount(MoneyModel moneyModel, UserModel userModel) {
|
UserAccountModel model = new UserAccountModel();
|
|
// 查询用户账号表
|
UserAccountModel userAccountModel = cuserConsoleService.queryAccountInfo(userModel.getUserId(), userModel.getMobilePhone());
|
if (userAccountModel == null) {
|
moneyModel.setUnpassReason("此用户未查询到账户信息");
|
moneyConsoleService.updateMoney(moneyModel);
|
model.setErrorType("此用户未查询到账户信息");
|
return model;
|
}
|
if (userAccountModel.getDelFlag().equals("1")) {
|
moneyModel.setUnpassReason("账户信息已删除");
|
moneyConsoleService.updateMoney(moneyModel);
|
model.setErrorType("账户信息已删除");
|
return model;
|
}
|
if (userAccountModel.getMoney() < Double.parseDouble(moneyModel.getMoney())) {
|
moneyModel.setUnpassReason("可提现金额不足");
|
moneyConsoleService.updateMoney(moneyModel);
|
model.setErrorType("可提现金额不足");
|
return model;
|
}
|
if (!userModel.getOpenId().equals(moneyModel.getOpenId())) {
|
moneyModel.setUnpassReason("用户和支付的openId不一致");
|
moneyConsoleService.updateMoney(moneyModel);
|
model.setErrorType("用户和支付的openId不一致");
|
return model;
|
}
|
return userAccountModel;
|
}
|
|
@PostMapping(MODEL + "/queryPayInfoDetail.json")
|
@ResponseBody
|
Map<String, Object> queryPayInfoDetail(String payOrderId){
|
return payService.queryPayInfoDetail(payOrderId);
|
}
|
|
// 回收员类别页面
|
@GetMapping(MODEL + "/queryPayInfo.do")
|
ModelAndView queryPayInfo(String payOrderId) {
|
ModelAndView view = new ModelAndView("/admin/money/payInfoDetail.html");
|
view.addObject("payOrderId", payOrderId);
|
return view;
|
}
|
|
/**
|
* 更新
|
* @param payOrderId
|
* @param userId
|
* @param unpassReason
|
* @return
|
*/
|
@PostMapping(MODEL + "/addReason.json")
|
@ResponseBody
|
int addReason(String payOrderId,String userId,String unpassReason){
|
|
return payService.addReason(payOrderId,userId,unpassReason);
|
}
|
|
|
|
@PostMapping(MODEL + "/quotaList.json")
|
@ResponseBody
|
Map<String, Object> quotaList(MoneyModel moneyModel,String page,String limit){
|
moneyModel.setPayType("7");
|
return moneyConsoleService.queryMoneyList(moneyModel,page,limit);
|
}
|
|
@PostMapping(MODEL + "/quota.json")
|
@ResponseBody
|
public JsonResult<String> quota(TransfersDto dto) {
|
Map<String, Object> result = new HashMap<>();
|
MoneyModel moneyModel = new MoneyModel();
|
moneyModel.setPayOrderId(dto.getPayOrderId());
|
moneyModel = moneyConsoleService.queryMoney(moneyModel);
|
//
|
UserModel userModel = service.queryRecoveryById(dto.getUserId(),"2");
|
if(null!=userModel){
|
UserAccountModel userAccountModel = cuserConsoleService.queryAccountInfo(moneyModel.getCreateUserId(), userModel.getMobilePhone());
|
if (userAccountModel == null) {
|
return JsonResult.success("此用户未查询到账户信息");
|
}else{
|
settingConsoleService.updateOverdrawPriceByUserId(userAccountModel.getAccountId(),moneyModel.getMoney());
|
//修改申请状态
|
moneyModel.setStatus("2");
|
moneyModel.setUnpassReason("审核通过");
|
moneyConsoleService.updateMoney(moneyModel);
|
return JsonResult.success("完成审核");
|
}
|
}else{
|
return JsonResult.success("查不到对应的回收员");
|
}
|
}
|
|
@PostMapping(MODEL + "/wxPayCancel.json")
|
@ResponseBody
|
@ApiOperation(value="资金管理-提现申请(拒绝)", notes="test: 仅0有正确返回")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType="query", name = "payOrderId", value = "提现申请Id", required = true, dataType = "String"),
|
@ApiImplicitParam(paramType="query", name = "userId", value = "用户Id", required = true, dataType = "String"),
|
@ApiImplicitParam(paramType="query", name = "unpassReason", value = "未通过原因", required = true, dataType = "String")
|
|
})
|
public JsonResult<String> wxPayCancel(@RequestBody TransfersDto dto) {
|
Map<String, Object> result = new HashMap<>();
|
MoneyModel moneyModel = new MoneyModel();
|
moneyModel.setPayOrderId(dto.getPayOrderId());
|
moneyModel = moneyConsoleService.queryMoney(moneyModel);
|
moneyModel.setStatus("3");
|
moneyModel.setUnpassReason(dto.getUnpassReason());
|
functionConsoleService.updateMoney(moneyModel);
|
return JsonResult.success("完成审核");
|
}
|
|
|
}
|