package com.stylefeng.guns.modular.system.controller.general; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.baomidou.mybatisplus.plugins.Page; import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.common.constant.factory.PageFactory; import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.util.DateUtil; import com.stylefeng.guns.core.util.ExcelExportUtil; import com.stylefeng.guns.core.util.SinataUtil; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.model.TDriver; import com.stylefeng.guns.modular.system.model.TPubWithdrawal; import com.stylefeng.guns.modular.system.model.TSystemNotice; import com.stylefeng.guns.modular.system.model.TUser; import com.stylefeng.guns.modular.system.service.ITDriverService; import com.stylefeng.guns.modular.system.service.ITPubWithdrawalService; import com.stylefeng.guns.modular.system.service.ITSystemNoticeService; import com.stylefeng.guns.modular.system.service.ITUserService; import com.stylefeng.guns.modular.system.util.HttpRequestUtil; import com.stylefeng.guns.modular.system.util.PushURL; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.util.alipay.AlipayUtils; import com.stylefeng.guns.modular.system.util.alipay.UUIDUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat; import java.util.*; /** * 提现列表控制器 * * @author fengshuonan * @Date 2020-06-09 09:30:59 */ @Controller @RequestMapping("/tPubWithdrawal") public class TPubWithdrawalController extends BaseController { private String PREFIX = "/system/tPubWithdrawal/"; @Autowired private ITPubWithdrawalService tPubWithdrawalService; @Autowired private ITUserService userService; @Autowired private ITSystemNoticeService tSystemNoticeService; @Autowired private ITDriverService driverService; /** * 跳转到提现列表首页 */ @RequestMapping("") public String index() { return PREFIX + "tPubWithdrawal.html"; } /** * 跳转到查看详情 */ @RequestMapping("/lookDetail/{id}/{type}") public String lookDetail(@PathVariable Integer id, @PathVariable Integer type, Model model) { TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id); String str = ""; if (1 == type){ str = tPubWithdrawal.getRemark(); } model.addAttribute("str",str); return "/system/tComplaint/lookDetail.html"; } /** * 跳转到立即处理页面 * ----------改为批量 */ @RequestMapping("/tPubWithdrawal_immediately/{tPubWithdrawalIds}") public String tPubWithdrawalUpdate(@PathVariable String tPubWithdrawalIds, Model model) { model.addAttribute("tPubWithdrawalIds",tPubWithdrawalIds); return PREFIX + "tPubWithdrawal_immediately.html"; } /** * 获取提现列表列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String insertTime, String name, Integer withdrawalType, Integer userType, Integer type, Integer state) { String beginTime = null; String endTime = null; if (SinataUtil.isNotEmpty(insertTime)){ String[] timeArray = insertTime.split(" - "); beginTime = timeArray[0]; endTime = timeArray[1]; } Page> page = new PageFactory>().defaultPage(); if (ShiroKit.getUser().getRoleType() != 1){ page.setRecords(null); }else{ page.setRecords(tPubWithdrawalService.getWithdrawalList(page,beginTime,endTime,name,withdrawalType,userType,type,state)); } return super.packForBT(page); } /** * 新增提现列表 */ @RequestMapping(value = "/add") @ResponseBody public Object add(TPubWithdrawal tPubWithdrawal) { tPubWithdrawalService.insert(tPubWithdrawal); return SUCCESS_TIP; } /** * 立即处理操作 */ @RequestMapping(value = "/immediately") @ResponseBody public Object immediately(@RequestParam Integer id,@RequestParam Integer state,@RequestParam String remark) throws AlipayApiException { TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id); if (SinataUtil.isNotEmpty(tPubWithdrawal)){ // tPubWithdrawal.setState(state); //调用接口修改状态 tPubWithdrawal.setRemark(remark); tPubWithdrawal.setHandleTime(new Date()); Integer stateObj = 1; if (2 == state){ //同意提现 stateObj = 1; // 支付宝提现 String certNo = ""; if (tPubWithdrawal.getUserType()==1){ TUser tUser = userService.selectById(tPubWithdrawal.getUserId()); certNo = tUser.getIdCard(); }else{ TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId()); certNo = tDriver.getIdCard(); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); String s = AlipayUtils.aliWithdrawal(code, tPubWithdrawal.getMoney() + "", tPubWithdrawal.getCode(), certNo); JSONObject res = JSONObject.parseObject(s); JSONObject alipayFundTransUniTransferResponse = res.getJSONObject("alipay_fund_trans_uni_transfer_response"); if (alipayFundTransUniTransferResponse!=null){ if (alipayFundTransUniTransferResponse.getString("status").equals("Success")){ String string = alipayFundTransUniTransferResponse.getString("order_id"); tPubWithdrawal.setOrderNumber(string); }else{ return ResultUtil.error("提现失败:"+alipayFundTransUniTransferResponse.getString("msg")); } } System.err.println("支付宝提现返回信息"+s); tPubWithdrawal.setOutOrderNo(code); tPubWithdrawalService.updateById(tPubWithdrawal); }else if (3 == state){ //拒绝提现 stateObj = 2; } // Map map = new HashMap<>(); // map.put("id", String.valueOf(tPubWithdrawal.getId())); // map.put("state", String.valueOf(stateObj)); // String result = HttpRequestUtil.postRequest(PushURL.withdraw_auth_url, map); // System.out.println("提现审核接口 :【recordId="+tPubWithdrawal.getId().toString()+"】,调用接口:"+result); //增加系统消息 TSystemNotice notice = new TSystemNotice(); notice.setType(2); notice.setUserType(tPubWithdrawal.getUserType()); notice.setContent("提现处理结果:【"+remark+"】。"); notice.setUserId(tPubWithdrawal.getUserId()); notice.setInsertTime(new Date()); notice.setRead(1); tSystemNoticeService.insert(notice); } return SUCCESS_TIP; } /** * 修改提现列表 */ @RequestMapping(value = "/update") @ResponseBody public Object update(TPubWithdrawal tPubWithdrawal) { tPubWithdrawalService.updateById(tPubWithdrawal); return SUCCESS_TIP; } /** * 提现列表详情 */ @RequestMapping(value = "/detail/{tPubWithdrawalId}") @ResponseBody public Object detail(@PathVariable("tPubWithdrawalId") Integer tPubWithdrawalId) { return tPubWithdrawalService.selectById(tPubWithdrawalId); } /** * 提现列表导出 * @author yxh * @date 2021/4/7 15:59 * @param insertTime * @param name * @param withdrawalType * @param userType * @param type * @param state */ @RequestMapping(value = "/downloadList",method = RequestMethod.GET) public void downloadList(String insertTime, String name, Integer withdrawalType, Integer userType, Integer type, Integer state, HttpServletRequest request, HttpServletResponse response){ String start = null; String end = null; if(ToolUtil.isNotEmpty(insertTime)){ start = insertTime.split(" - ")[0]; end = insertTime.split(" - ")[1]; } List> list =tPubWithdrawalService.getWithdrawalListNoPage(start,end,name,withdrawalType,userType,type,state); // 表格数据 List> dataList = new ArrayList<>(); // 表头行 List shellList = new ArrayList(); shellList.add("申请时间"); shellList.add("提现人"); shellList.add("银行卡号"); shellList.add("开户行"); shellList.add("提现方式"); shellList.add("账户类型"); shellList.add("提现类型"); shellList.add("账户余额"); shellList.add("提现金额"); shellList.add("联系人"); shellList.add("联系电话"); shellList.add("备注"); shellList.add("状态"); dataList.add(shellList); for (Map map : list) { //数据行 shellList = new ArrayList(); if(SinataUtil.isNotEmpty(map.get("applyTime"))){ shellList.add(map.get("applyTime").toString()); }else{ shellList.add("-"); } if(SinataUtil.isNotEmpty(map.get("name"))){ shellList.add(map.get("name").toString()); }else{ shellList.add("-"); } if(SinataUtil.isNotEmpty(map.get("code"))){ shellList.add(map.get("code").toString()); }else{ shellList.add("-"); } if(SinataUtil.isNotEmpty(map.get("bankName"))){ shellList.add(map.get("bankName").toString()); }else{ shellList.add("-"); } //withdrawalType if(SinataUtil.isNotEmpty(map.get("withdrawalType"))){ switch (map.get("withdrawalType").toString()){ case "1": shellList.add("银行卡"); break; case "2": shellList.add("线下"); break; default: shellList.add("-"); } }else{ shellList.add("-"); } //userType if(SinataUtil.isNotEmpty(map.get("userType"))){ switch (map.get("userType").toString()){ case "1": shellList.add("用户"); break; case "2": shellList.add("司机"); break; default: shellList.add("-"); } }else{ shellList.add("-"); } //type if(SinataUtil.isNotEmpty(map.get("type"))){ switch (map.get("type").toString()){ case "1": shellList.add("活动收入提现"); break; case "2": shellList.add("业务收入提现"); break; default: shellList.add("-"); } }else{ shellList.add("-"); } //balance if(SinataUtil.isNotEmpty(map.get("balance"))){ shellList.add(map.get("balance").toString()); }else{ shellList.add("-"); } //money if(SinataUtil.isNotEmpty(map.get("money"))){ shellList.add(map.get("money").toString()); }else{ shellList.add("-"); } //userName if(SinataUtil.isNotEmpty(map.get("userName"))){ shellList.add(map.get("userName").toString()); }else{ shellList.add("-"); } //userPhone if(SinataUtil.isNotEmpty(map.get("userPhone"))){ shellList.add(map.get("userPhone").toString()); }else{ shellList.add("-"); } //remark if(SinataUtil.isNotEmpty(map.get("remark"))){ shellList.add(map.get("remark").toString()); }else{ shellList.add("-"); } //state if(SinataUtil.isNotEmpty(map.get("state"))){ switch (map.get("state").toString()){ case "1": shellList.add("待处理"); break; case "2": shellList.add("成功"); break; case "3": shellList.add("失败"); break; default: shellList.add("-"); } }else{ shellList.add("-"); } dataList.add(shellList); } try { // 调用工具类进行导出 ExcelExportUtil.easySheet("提现导出记录"+ DateUtil.formatDate(new Date(), "YYYYMMddHHmmss"), "提现导出记录", dataList,request, response); } catch (Exception e) { e.printStackTrace(); } } }