package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.cloudPayment.example.BalanceAcctExample;
|
import com.stylefeng.guns.modular.cloudPayment.example.WithdrawalExample;
|
import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq;
|
import com.stylefeng.guns.modular.cloudPayment.req.WithdrawalReq;
|
import com.stylefeng.guns.modular.system.controller.util.Base64Util;
|
import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal;
|
import com.stylefeng.guns.modular.system.model.User;
|
import com.stylefeng.guns.modular.system.service.ITEnterpriseWithdrawalService;
|
import com.stylefeng.guns.modular.system.service.IUserService;
|
import com.unionpay.upyzt.exception.UpyztException;
|
import com.unionpay.upyzt.resp.BalanceAcctListResp;
|
import com.unionpay.upyzt.resp.BalanceAcctResp;
|
import com.unionpay.upyzt.resp.WithdrawalResp;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import com.stylefeng.guns.core.log.LogObjectHolder;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import com.stylefeng.guns.modular.system.model.TCompanyWithdraw;
|
import com.stylefeng.guns.modular.system.service.ITCompanyWithdrawService;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 控制器
|
*
|
* @author fengshuonan
|
* @Date 2023-03-17 14:18:09
|
*/
|
@Controller
|
@RequestMapping("/tCompanyWithdraw")
|
public class TCompanyWithdrawController extends BaseController {
|
|
private String PREFIX = "/system/tCompanyWithdraw/";
|
|
@Autowired
|
private ITCompanyWithdrawService tCompanyWithdrawService;
|
|
@Resource
|
private ITEnterpriseWithdrawalService enterpriseWithdrawalService;
|
|
/**
|
* 跳转到首页
|
*/
|
@RequestMapping("")
|
public String index(Model model) {
|
Integer id = ShiroKit.getUser().getObjectId();
|
List<TEnterpriseWithdrawal> companyId = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", id));
|
if(companyId.size()>0){
|
try {
|
BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
|
balanceAcctReq.setMchId(companyId.get(0).getMchId());
|
BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
|
Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount();
|
String money = settledAmount.toString();
|
model.addAttribute("money",new BigDecimal(money).divide(new BigDecimal(100)).toString());
|
} catch (UpyztException e) {
|
e.printStackTrace();
|
model.addAttribute("money",0);
|
}
|
|
}else {
|
model.addAttribute("money",0);
|
}
|
return PREFIX + "tCompanyWithdraw.html";
|
}
|
|
/**
|
* 跳转到添加
|
*/
|
@RequestMapping("/tCompanyWithdraw_add")
|
public String tCompanyWithdrawAdd() {
|
return PREFIX + "tCompanyWithdraw_add.html";
|
}
|
|
/**
|
* 跳转到修改
|
*/
|
@RequestMapping("/tCompanyWithdraw_update/{tCompanyWithdrawId}")
|
public String tCompanyWithdrawUpdate(@PathVariable Integer tCompanyWithdrawId, Model model) {
|
TCompanyWithdraw tCompanyWithdraw = tCompanyWithdrawService.selectById(tCompanyWithdrawId);
|
model.addAttribute("item",tCompanyWithdraw);
|
LogObjectHolder.me().set(tCompanyWithdraw);
|
return PREFIX + "tCompanyWithdraw_edit.html";
|
}
|
@Autowired
|
private IUserService userService;
|
/**
|
* 获取列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String createTime,Integer state) {
|
Integer id = ShiroKit.getUser().getObjectId();
|
EntityWrapper<TCompanyWithdraw> withdrawEntityWrapper = new EntityWrapper<>();
|
String sTime=null;
|
String eTime=null;
|
if(ToolUtil.isNotEmpty(state)){
|
withdrawEntityWrapper.eq("status",state);
|
}
|
withdrawEntityWrapper.eq("companyId",id);
|
if(ToolUtil.isNotEmpty(createTime)){
|
sTime=createTime.split(" - ")[0]+" 00:00:01";
|
eTime=createTime.split(" - ")[1]+" 23:59:59";
|
withdrawEntityWrapper.between("createTime",sTime,eTime);
|
}
|
List<TCompanyWithdraw> tCompanyWithdraws = tCompanyWithdrawService.selectList(withdrawEntityWrapper);
|
for (TCompanyWithdraw tCompanyWithdraw : tCompanyWithdraws) {
|
Integer createId = tCompanyWithdraw.getCreateId();
|
User user = userService.selectById(createId);
|
tCompanyWithdraw.setCreateUserName(user.getName());
|
}
|
return tCompanyWithdraws;
|
}
|
|
/**
|
* 新增
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
|
public Object add(Double money,String type,String remark) {
|
List<TEnterpriseWithdrawal> companyId = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", ShiroKit.getUser().getObjectId()));
|
if(companyId.size()>0){
|
try {
|
BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
|
balanceAcctReq.setMchId(companyId.get(0).getMchId());
|
BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
|
Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount();
|
if(settledAmount<money){
|
return "5001";
|
}
|
} catch (UpyztException e) {
|
e.printStackTrace();
|
}
|
|
}
|
TCompanyWithdraw tCompanyWithdraw = new TCompanyWithdraw();
|
tCompanyWithdraw.setWithdrawMoney(new BigDecimal(money));
|
tCompanyWithdraw.setCompanyId(ShiroKit.getUser().getObjectId());
|
tCompanyWithdraw.setCreateId(ShiroKit.getUser().getId());
|
tCompanyWithdraw.setCreateTime(new Date());
|
if("提现".equals(type)){
|
tCompanyWithdraw.setType(1);
|
}
|
tCompanyWithdraw.setRemark(remark);
|
tCompanyWithdraw.setStatus(0);
|
// TODO 创建提现 需要回调进行提现状态查询
|
|
try {
|
WithdrawalReq withdrawalReq = new WithdrawalReq();
|
if(companyId.size()>0){
|
TEnterpriseWithdrawal enterpriseWithdrawal = companyId.get(0);
|
withdrawalReq.setOutOrderNo(ToolUtil.getRandomString(32));
|
int total = new BigDecimal(money).multiply(new BigDecimal(100)).intValue();
|
withdrawalReq.setAmount(total);
|
withdrawalReq.setBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId());
|
withdrawalReq.setBankAcctNo(enterpriseWithdrawal.getBankAccount());
|
withdrawalReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode()));
|
|
}
|
WithdrawalResp withdrawalResp = WithdrawalExample.create(withdrawalReq);
|
|
System.out.println("公司添加提现:"+withdrawalResp);
|
tCompanyWithdraw.setWithdrawId(withdrawalResp.getWithdrawalId());
|
|
} catch (UpyztException e) {
|
e.printStackTrace();
|
System.out.println("公司添加提现失败:"+e.getIssue());
|
}
|
tCompanyWithdrawService.insert(tCompanyWithdraw);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 删除
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer tCompanyWithdrawId) {
|
tCompanyWithdrawService.deleteById(tCompanyWithdrawId);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TCompanyWithdraw tCompanyWithdraw) {
|
tCompanyWithdrawService.updateById(tCompanyWithdraw);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 详情
|
*/
|
@RequestMapping(value = "/detail/{tCompanyWithdrawId}")
|
@ResponseBody
|
public Object detail(@PathVariable("tCompanyWithdrawId") Integer tCompanyWithdrawId) {
|
return tCompanyWithdrawService.selectById(tCompanyWithdrawId);
|
}
|
}
|