| | |
| | | package com.stylefeng.guns.modular.system.controller.general; |
| | | |
| | | import cn.hutool.core.codec.Base64; |
| | | import cn.hutool.core.util.ZipUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.http.server.HttpServerResponse; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.base.tips.SuccessTip; |
| | | import com.stylefeng.guns.core.common.constant.state.ManagerStatus; |
| | | import com.stylefeng.guns.core.exception.GunsException; |
| | | import com.stylefeng.guns.core.exception.ServiceExceptionEnum; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.shiro.ShiroUser; |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TAgentResp; |
| | | import com.stylefeng.guns.modular.system.controller.util.ExcelUtil; |
| | | import com.stylefeng.guns.modular.system.controller.util.UUIDUtil; |
| | | import com.stylefeng.guns.modular.system.enums.OrderStateEnum; |
| | | import com.stylefeng.guns.modular.system.enums.PayStatusEnum; |
| | | import com.stylefeng.guns.modular.system.enums.UserTypeEnum; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.util.MallBook.model.*; |
| | | import com.stylefeng.guns.modular.system.util.MallBook.util.TrhRequest; |
| | | import com.stylefeng.guns.modular.system.util.RedisUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.hdf.extractor.TC; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.*; |
| | | 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 org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.OutputStream; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.net.InetAddress; |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | * @Date 2023-02-20 09:18:08 |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/tAgent") |
| | | @RequestMapping("") |
| | | public class TAgentController extends BaseController { |
| | | |
| | | private String PREFIX = "/system/tAgent/"; |
| | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | @Autowired |
| | | private ISettlementRecordService settlementRecordService; |
| | | |
| | | @Autowired |
| | | private IRechargeRecordService rechargeRecordService; |
| | | |
| | | @Autowired |
| | | private ITSystemConfigService systemConfigService; |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath; |
| | | |
| | | |
| | | /** |
| | | * 跳转到首页 |
| | | */ |
| | | @RequestMapping("") |
| | | @RequestMapping("/tAgent") |
| | | public String index(Model model) { |
| | | model.addAttribute("userType", Objects.requireNonNull(ShiroKit.getUser()).getRoleType()); |
| | | return PREFIX + "tAgent.html"; |
| | |
| | | /** |
| | | * 跳转到添加 |
| | | */ |
| | | @RequestMapping("/tAgent_add") |
| | | @RequestMapping("/tAgent/tAgent_add") |
| | | public String tAgentAdd() { |
| | | return PREFIX + "tAgent_add.html"; |
| | | } |
| | |
| | | /** |
| | | * 跳转到修改 |
| | | */ |
| | | @RequestMapping("/tAgent_update/{tAgentId}") |
| | | @RequestMapping("/tAgent/tAgent_update/{tAgentId}") |
| | | public String tAgentUpdate(@PathVariable Integer tAgentId, Model model) { |
| | | TAgent tAgent = tAgentService.selectById(tAgentId); |
| | | model.addAttribute("item",tAgent); |
| | |
| | | /** |
| | | * 跳转详情页面 |
| | | */ |
| | | @RequestMapping("/agentDetail") |
| | | @RequestMapping("/tAgent/agentDetail") |
| | | public String agentDetail(Integer agentId, Model model) { |
| | | tAgentService.detail(agentId,model); |
| | | return PREFIX + "tAgentDetail.html"; |
| | |
| | | /** |
| | | * 跳转区域页面 |
| | | */ |
| | | @RequestMapping("/areaDetail") |
| | | @RequestMapping("/tAgent/areaDetail") |
| | | public String areaDetail(String area,String areaId,Model model) { |
| | | // String[] split1 = areaId.split("/"); |
| | | // List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0)); |
| | | // model.addAttribute("provinceList",tRegions); |
| | | //// List<Integer> provinceIds = tRegions.stream().map(TRegion::getId).collect(Collectors.toList()); |
| | | //// // 查询市 |
| | | //// List<TRegion> tRegions1 = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", split1[0])); |
| | | //// model.addAttribute("cityList",tRegions1); |
| | | //// |
| | | //// // 查询区 |
| | | //// List<Integer> cityIds = tRegions1.stream().map(TRegion::getId).collect(Collectors.toList()); |
| | | //// List<TRegion> tRegions2 = tRegionService.selectList(new EntityWrapper<TRegion>().in("parent_id", cityIds)); |
| | | //// model.addAttribute("districtList",tRegions2); |
| | | // |
| | | // if(StringUtils.hasLength(area) && StringUtils.hasLength(areaId)){ |
| | | // String[] split = area.split("/"); |
| | | // model.addAttribute("provinceName",split[0]); |
| | | // model.addAttribute("cityName",split[1]); |
| | | // if(split.length>2){ |
| | | // model.addAttribute("districtName",split[2]); |
| | | // }else { |
| | | // model.addAttribute("districtName",""); |
| | | // } |
| | | // |
| | | // model.addAttribute("provinceId",split1[0]); |
| | | // model.addAttribute("cityId",split1[1]); |
| | | // if(split1.length>2) { |
| | | // model.addAttribute("districtId", split1[2]); |
| | | // }else { |
| | | // model.addAttribute("districtId", ""); |
| | | // } |
| | | // |
| | | // List<TRegion> tRegions1 = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", split1[0])); |
| | | // model.addAttribute("cityList",tRegions1); |
| | | // |
| | | // // 查询区 |
| | | // List<TRegion> tRegions2 = tRegionService.selectList(new EntityWrapper<TRegion>().in("parent_id", split1[1])); |
| | | // model.addAttribute("districtList",tRegions2); |
| | | // }else { |
| | | // model.addAttribute("cityList",new ArrayList<>()); |
| | | // model.addAttribute("districtList",new ArrayList<>()); |
| | | // |
| | | // model.addAttribute("provinceName",""); |
| | | // model.addAttribute("cityName",""); |
| | | // model.addAttribute("districtName",""); |
| | | // |
| | | // model.addAttribute("provinceId",""); |
| | | // model.addAttribute("cityId",""); |
| | | // model.addAttribute("districtId", ""); |
| | | // } |
| | | String[] split1 = areaId.split("/"); |
| | | List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0)); |
| | | model.addAttribute("province",tRegions); |
| | | List<Integer> provinceIds = tRegions.stream().map(TRegion::getId).collect(Collectors.toList()); |
| | | model.addAttribute("provinceList",tRegions); |
| | | // List<Integer> provinceIds = tRegions.stream().map(TRegion::getId).collect(Collectors.toList()); |
| | | // 查询市 |
| | | List<TRegion> tRegions1 = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", split1[0])); |
| | | model.addAttribute("cityList",tRegions1); |
| | |
| | | /** |
| | | * 获取列表 |
| | | */ |
| | | @RequestMapping(value = "/list") |
| | | @RequestMapping(value = "/tAgent/list") |
| | | @ResponseBody |
| | | public Object list(String principal,String principalPhone,String createTime,Integer status) { |
| | | EntityWrapper<TAgent> wrapper = tAgentService.getAgentWrapper(principal,principalPhone,createTime,status); |
| | |
| | | /** |
| | | * 获取列表 |
| | | */ |
| | | @RequestMapping(value = "/list-back") |
| | | @RequestMapping(value = "/tAgent/list-back") |
| | | @ResponseBody |
| | | public Object listBack(String condition) { |
| | | return tAgentService.selectList(null); |
| | |
| | | /** |
| | | * 新增 |
| | | */ |
| | | @RequestMapping(value = "/add") |
| | | @RequestMapping(value = "/tAgent/add") |
| | | @ResponseBody |
| | | @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW) |
| | | public Object add(TAgent tAgent) { |
| | | |
| | | String[] split1 = tAgent.getArea().split("/"); |
| | | |
| | | int count = tAgentService.selectCount(new EntityWrapper<TAgent>().eq("provinceName", split1[0]).eq("cityName",split1[1])); |
| | | // int count = tAgentService.selectCount(new EntityWrapper<TAgent>() |
| | | // .eq("provinceName", split1[0]) |
| | | // .eq("cityName",split1[1]) |
| | | // .eq("districtName",sp)); |
| | | int count = tAgentService.selectCount(new EntityWrapper<TAgent>() |
| | | .eq("merchantName", tAgent.getMerchantName())); |
| | | if(count>0){ |
| | | return new SuccessTip(500,"该代理商已存在!"); |
| | | } |
| | |
| | | user.setSex(1); |
| | | userService.insert(user); |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | registeredMerchant(tAgent); |
| | | } |
| | | }).start(); |
| | | |
| | | return SUCCESS_TIP; |
| | | } |
| | | |
| | | |
| | | |
| | | public void registeredMerchant(TAgent tAgent){ |
| | | if(tAgent.getUserType() == 0){ |
| | | Register registerVO = new Register(); |
| | | registerVO.setMerUserId("agent_" + tAgent.getId()); |
| | | registerVO.setPhone(tAgent.getPrincipalPhone()); |
| | | registerVO.setUserType("0"); |
| | | registerVO.setUserName(tAgent.getMerchantName()); |
| | | registerVO.setCertId(tAgent.getMerchantIDCode()); |
| | | registerVO.setNotifyUrl(callbackPath + "/base/tAgent/microenterpriseCallback"); |
| | | TrhRequest<Register> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(registerVO, Register.SERVICE_CODE); |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | tAgent.setMerchantStatus(2); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("注册代理商子商户失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | tAgent.setMerchantStatus(0); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("注册代理商子商户处理中"); |
| | | } |
| | | if("1".equals(status)){ |
| | | String userId = jsonObject.getString("userId"); |
| | | tAgent.setMerchantNumber(userId); |
| | | tAgent.setMerchantStatus(1); |
| | | tAgentService.updateById(tAgent); |
| | | |
| | | BindAccount bindAccount = new BindAccount(); |
| | | bindAccount.setUserId(tAgent.getMerchantNumber()); |
| | | bindAccount.setCertId(tAgent.getMerchantIDCode()); |
| | | bindAccount.setCardName(tAgent.getCardName()); |
| | | bindAccount.setCardNo(tAgent.getCardNo()); |
| | | bindAccount.setBankAcctType(tAgent.getBankAcctType().toString()); |
| | | bindAccount.setPhone(tAgent.getPhone()); |
| | | TrhRequest<BindAccount> request1 = new TrhRequest(); |
| | | InterfaceResponse execute1 = request1.execute(bindAccount, BindAccount.SERVICE_CODE); |
| | | if("0000".equals(execute1.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute1.getResult()); |
| | | String status1 = jsonObject1.getString("status"); |
| | | if("2".equals(status1)){ |
| | | tAgent.setBankStatus(2); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户失败" ); |
| | | } |
| | | if("1".equals(status1)){ |
| | | tAgent.setBankStatus(1); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户成功"); |
| | | } |
| | | if("0".equals(status1)){ |
| | | tAgent.setBankStatus(0); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户处理中"); |
| | | } |
| | | }else{ |
| | | System.err.println("绑定结算账户失败:" + execute.getMsg()); |
| | | } |
| | | } |
| | | }else{ |
| | | System.err.println("注册代理商子商户异常:" + execute.getMsg()); |
| | | } |
| | | }else{ |
| | | Register registerVO = new Register(); |
| | | registerVO.setMerUserId("agent_" + tAgent.getId()); |
| | | registerVO.setPhone(tAgent.getPrincipalPhone()); |
| | | registerVO.setUserType(tAgent.getUserType().toString()); |
| | | registerVO.setUserName(tAgent.getMerchantName()); |
| | | registerVO.setCertId(tAgent.getMerchantIDCode()); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | registerVO.setCertIdExpires(sdf.format(tAgent.getCertIdExpires())); |
| | | registerVO.setBusinessScope(tAgent.getBusinessScope()); |
| | | registerVO.setSocialCreditCode(tAgent.getSocialCreditCode()); |
| | | registerVO.setSocialCreditCodeExpires(sdf.format(tAgent.getSocialCreditCodeExpires())); |
| | | registerVO.setLegalPhone(tAgent.getLegalPhone()); |
| | | registerVO.setLegalPerson(tAgent.getLegalPerson()); |
| | | registerVO.setAddress(tAgent.getAddress()); |
| | | registerVO.setProvCode(tAgent.getProvCodeEnterprise()); |
| | | registerVO.setAreaCode(tAgent.getAreaCodeEnterprise()); |
| | | registerVO.setFileNo(tAgent.getFileNo()); |
| | | registerVO.setNotifyUrl(callbackPath + "/base/tAgent/microenterpriseCallback"); |
| | | registerVO.setParameter1(tAgent.getId().toString()); |
| | | |
| | | TrhRequest<Register> request = new TrhRequest(); |
| | | InterfaceResponse response = request.execute(registerVO, Register.SERVICE_CODE); |
| | | if("0000".equals(response.getCode())){ |
| | | JSONObject jsonObject = JSON.parseObject(response.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | tAgent.setMerchantStatus(2); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("注册代理商子商户失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | tAgent.setMerchantStatus(0); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("注册代理商子商户处理中"); |
| | | } |
| | | if("1".equals(status)){ |
| | | String userId = jsonObject.getString("userId"); |
| | | tAgent.setMerchantNumber(userId); |
| | | tAgent.setMerchantStatus(1); |
| | | tAgentService.updateById(tAgent); |
| | | |
| | | //开始绑定结算账户 |
| | | BindAccount bindAccount = new BindAccount(); |
| | | bindAccount.setUserId(tAgent.getMerchantNumber()); |
| | | bindAccount.setCertId(tAgent.getMerchantIDCode()); |
| | | bindAccount.setCardName(tAgent.getCardName()); |
| | | bindAccount.setCardNo(tAgent.getCardNo()); |
| | | bindAccount.setBankAcctType(tAgent.getBankAcctType().toString()); |
| | | bindAccount.setPhone(tAgent.getPhone()); |
| | | bindAccount.setBankCode(tAgent.getBankCode()); |
| | | bindAccount.setProvCode(tAgent.getProvCodeBank()); |
| | | bindAccount.setAreaCode(tAgent.getAreaCodeBank()); |
| | | TrhRequest<BindAccount> request1 = new TrhRequest(); |
| | | InterfaceResponse execute = request1.execute(bindAccount, BindAccount.SERVICE_CODE); |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.getResult()); |
| | | String status1 = jsonObject1.getString("status"); |
| | | if("2".equals(status1)){ |
| | | tAgent.setBankStatus(2); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户失败" ); |
| | | } |
| | | if("1".equals(status1)){ |
| | | tAgent.setBankStatus(1); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户成功"); |
| | | } |
| | | if("0".equals(status1)){ |
| | | tAgent.setBankStatus(0); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户处理中"); |
| | | } |
| | | }else{ |
| | | System.err.println("绑定结算账户失败:" + execute.getMsg()); |
| | | } |
| | | |
| | | } |
| | | }else{ |
| | | System.err.println("注册代理商子商户异常:" + response.getMsg()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 注册商户回调 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/tAgent/microenterpriseCallback") |
| | | public void microenterpriseCallback(@RequestBody InterfaceResponse interfaceResponse, HttpServletResponse response){ |
| | | try { |
| | | if("0000".equals(interfaceResponse.getCode())) { |
| | | JSONObject jsonObject = JSON.parseObject(interfaceResponse.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | String parameter1 = jsonObject.getString("parameter1"); |
| | | TAgent tAgent = tAgentService.selectById(parameter1); |
| | | if ("2".equals(status)) { |
| | | tAgent.setMerchantStatus(2); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("注册代理商子商户失败"); |
| | | } |
| | | if ("0".equals(status)) { |
| | | tAgent.setMerchantStatus(0); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("注册代理商子商户处理中"); |
| | | } |
| | | if ("1".equals(status)) { |
| | | String userId = jsonObject.getString("userId"); |
| | | tAgent.setMerchantNumber(userId); |
| | | tAgent.setMerchantStatus(1); |
| | | tAgentService.updateById(tAgent); |
| | | |
| | | //开始绑定结算账户 |
| | | BindAccount bindAccount = new BindAccount(); |
| | | bindAccount.setUserId(tAgent.getMerchantNumber()); |
| | | bindAccount.setCertId(tAgent.getMerchantIDCode()); |
| | | bindAccount.setCardName(tAgent.getCardName()); |
| | | bindAccount.setCardNo(tAgent.getCardNo()); |
| | | bindAccount.setBankAcctType(tAgent.getBankAcctType().toString()); |
| | | bindAccount.setPhone(tAgent.getPhone()); |
| | | bindAccount.setBankCode(tAgent.getBankCode()); |
| | | bindAccount.setProvCode(tAgent.getProvCodeBank()); |
| | | bindAccount.setAreaCode(tAgent.getAreaCodeBank()); |
| | | TrhRequest<BindAccount> request1 = new TrhRequest(); |
| | | InterfaceResponse execute = request1.execute(bindAccount, BindAccount.SERVICE_CODE); |
| | | if ("0000".equals(execute.getCode())) { |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.getResult()); |
| | | String status1 = jsonObject1.getString("status"); |
| | | if ("2".equals(status1)) { |
| | | tAgent.setBankStatus(2); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户失败"); |
| | | } |
| | | if ("1".equals(status1)) { |
| | | tAgent.setBankStatus(1); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户成功"); |
| | | } |
| | | if ("0".equals(status1)) { |
| | | tAgent.setBankStatus(0); |
| | | tAgentService.updateById(tAgent); |
| | | System.err.println("绑定结算账户处理中"); |
| | | } |
| | | } else { |
| | | System.err.println("绑定结算账户失败:" + execute.getMsg()); |
| | | } |
| | | response.setStatus(200); |
| | | PrintWriter out = response.getWriter(); |
| | | out.print("OK"); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 删除 |
| | | */ |
| | | @RequestMapping(value = "/delete") |
| | | @RequestMapping(value = "/tAgent/delete") |
| | | @ResponseBody |
| | | public Object delete(@RequestParam Integer tAgentId) { |
| | | tAgentService.deleteById(tAgentId); |
| | |
| | | /** |
| | | * 修改用户状态 |
| | | */ |
| | | @RequestMapping(value = "/update-status") |
| | | @RequestMapping(value = "/tAgent/update-status") |
| | | @ResponseBody |
| | | public Object updateStatus(Integer id,Integer status) { |
| | | TAgent tAgent = tAgentService.selectById(id); |
| | |
| | | /** |
| | | * 修改 |
| | | */ |
| | | @RequestMapping(value = "/update") |
| | | @RequestMapping(value = "/tAgent/update") |
| | | @ResponseBody |
| | | public Object update(TAgent tAgent) { |
| | | tAgent.setPrincipal(tAgent.getPrincipal().replace(" ","")); |
| | |
| | | /** |
| | | * 详情 |
| | | */ |
| | | @RequestMapping(value = "/detail/{tAgentId}") |
| | | @RequestMapping(value = "/tAgent/detail/{tAgentId}") |
| | | @ResponseBody |
| | | public Object detail(@PathVariable("tAgentId") Integer tAgentId) { |
| | | return tAgentService.selectById(tAgentId); |
| | |
| | | |
| | | |
| | | @ApiOperation(value = "省市区查询",notes="省市区查询") |
| | | @RequestMapping(value = "/area") |
| | | @RequestMapping(value = "/tAgent/area") |
| | | @ResponseBody |
| | | public Object area() { |
| | | return tRegionService.getAreaList(); |
| | | } |
| | | |
| | | @ApiOperation(value = "省查询",notes="省查询") |
| | | @RequestMapping(value = "/areaProvince") |
| | | @RequestMapping(value = "/tAgent/areaProvince") |
| | | @ResponseBody |
| | | public Object areaProvince(Model model) { |
| | | return tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0)); |
| | | } |
| | | |
| | | @ApiOperation(value = "市区查询",notes="市区查询") |
| | | @RequestMapping(value = "/areaCity") |
| | | @RequestMapping(value = "/tAgent/areaCity") |
| | | @ResponseBody |
| | | public Object areaCity(Integer parentId) { |
| | | return tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id",parentId)); |
| | |
| | | |
| | | |
| | | @ApiOperation(value = "导出代理商列表",notes="导出代理商列表") |
| | | @RequestMapping(value = "/export") |
| | | @RequestMapping(value = "/tAgent/export") |
| | | @ResponseBody |
| | | public void export(String principal,String principalPhone,Integer status,String createTime, HttpServletResponse response) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping(value = "/tAgent/uploadFile") |
| | | public String uploadFile(MultipartFile file){ |
| | | File srcFile = null; |
| | | String originalFilename = file.getOriginalFilename(); |
| | | String substring = originalFilename.substring(originalFilename.lastIndexOf(".")); |
| | | String fileName = ""; |
| | | try { |
| | | fileName = UUIDUtil.getRandomCode(28) + ".png"; |
| | | srcFile = multipartFileToFile(file, fileName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | ImageUpload imageUpload = new ImageUpload(); |
| | | imageUpload.setMerUserId("33567678901213221"); |
| | | File zip = ZipUtil.zip(srcFile); |
| | | imageUpload.setName(zip.getName()); |
| | | imageUpload.setFile(Base64.encode(zip)); |
| | | TrhRequest<ImageUpload> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(imageUpload, ImageUpload.SERVICE_CODE); |
| | | if(execute.getCode().equals("0000")){ |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | return jsonObject.getString("fileNo"); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | public File multipartFileToFile(MultipartFile file, String fileName) throws Exception { |
| | | File toFile = null; |
| | | if (file.equals("") || file.getSize() <= 0) { |
| | | file = null; |
| | | } else { |
| | | InputStream ins = null; |
| | | ins = file.getInputStream(); |
| | | toFile = new File("D:\\logs\\" + fileName); |
| | | inputStreamToFile(ins, toFile); |
| | | ins.close(); |
| | | } |
| | | return toFile; |
| | | |
| | | } |
| | | |
| | | |
| | | private static void inputStreamToFile(InputStream ins, File file) { |
| | | try { |
| | | OutputStream os = new FileOutputStream(file); |
| | | int bytesRead = 0; |
| | | byte[] buffer = new byte[8192]; |
| | | while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { |
| | | os.write(buffer, 0, bytesRead); |
| | | } |
| | | os.close(); |
| | | ins.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 跳转到企业信息页 |
| | | * @return |
| | | */ |
| | | @GetMapping("/tAgent/showEnterprisePage") |
| | | public String showEnterprisePage(Model model){ |
| | | ShiroUser user = ShiroKit.getUser(); |
| | | Integer objectId = user.getObjectId(); |
| | | Integer roleType = user.getRoleType(); |
| | | User user1 = userService.selectById(user.getId()); |
| | | TAgent tAgent = new TAgent(); |
| | | if(roleType == 1){//平台 |
| | | tAgent.setPrincipal(user1.getName()); |
| | | tAgent.setPrincipalPhone(user1.getPhone()); |
| | | tAgent.setEmail(user1.getEmail()); |
| | | tAgent.setMerchantNumber("553021440975"); |
| | | } |
| | | if(roleType == 3){//代理商 |
| | | tAgent = tAgentService.selectById(objectId); |
| | | } |
| | | model.addAttribute("roleType", roleType); |
| | | model.addAttribute("item", tAgent); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | model.addAttribute("socialCreditCodeExpires", roleType == 1 ? "" :Objects.isNull(tAgent.getSocialCreditCodeExpires())?"": sdf.format(tAgent.getSocialCreditCodeExpires())); |
| | | model.addAttribute("certIdExpires", roleType == 1 ? "" : null == tAgent.getCertIdExpires() ? "" : sdf.format(tAgent.getCertIdExpires())); |
| | | Wrapper<SettlementRecord> settlementRecordWrapper = new EntityWrapper<SettlementRecord>().eq("type", roleType == 1 ? 1 : 2); |
| | | if(roleType == 2){ |
| | | settlementRecordWrapper.eq("objectId", objectId); |
| | | } |
| | | List<SettlementRecord> settlementRecords = settlementRecordService.selectList(settlementRecordWrapper.isNotNull("arrivalTime").orderBy("insertTime desc")); |
| | | model.addAttribute("settlementRecords", settlementRecords); |
| | | |
| | | QueryBalance queryBalance = new QueryBalance(); |
| | | queryBalance.setUserId(tAgent.getMerchantNumber()); |
| | | TrhRequest<QueryBalance> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(queryBalance, QueryBalance.SERVICE_CODE); |
| | | model.addAttribute("balance", 0); |
| | | model.addAttribute("marketingAmount", 0); |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | model.addAttribute("balance", jsonObject.getDoubleValue("settledAmount") / 100); |
| | | if(roleType == 1){ |
| | | Double amount = rechargeRecordService.querSumSurplusDividedAmount(4); |
| | | model.addAttribute("marketingAmount", amount); |
| | | } |
| | | } |
| | | return PREFIX + "enterprisePage.html"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 提现申请 |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/tAgent/withdrawCash") |
| | | public ResultUtil withdrawCash(){ |
| | | ShiroUser user = ShiroKit.getUser(); |
| | | Integer objectId = user.getObjectId(); |
| | | Integer roleType = user.getRoleType(); |
| | | User user1 = userService.selectById(user.getId()); |
| | | TAgent tAgent = new TAgent(); |
| | | if(roleType == 1){//平台 |
| | | tAgent.setLegalPerson(user1.getName()); |
| | | tAgent.setLegalPhone(user1.getPhone()); |
| | | tAgent.setEmail(user1.getEmail()); |
| | | tAgent.setMerchantNumber("553021440975"); |
| | | } |
| | | if(roleType == 3){//代理商 |
| | | tAgent = tAgentService.selectById(objectId); |
| | | } |
| | | QueryBalance queryBalance = new QueryBalance(); |
| | | queryBalance.setUserId(tAgent.getMerchantNumber()); |
| | | TrhRequest<QueryBalance> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(queryBalance, QueryBalance.SERVICE_CODE); |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | Integer settledAmount = jsonObject.getInteger("settledAmount"); |
| | | if(0 == settledAmount){ |
| | | return ResultUtil.error("余额不足"); |
| | | } |
| | | SettlementRecord settlementRecord = new SettlementRecord(); |
| | | settlementRecord.setType(roleType == 1 ? 1 : 2); |
| | | if(roleType == 3){ |
| | | settlementRecord.setObjectId(tAgent.getId()); |
| | | } |
| | | settlementRecord.setAmount(Double.valueOf(settledAmount) / 100); |
| | | settlementRecord.setInsertTime(new Date()); |
| | | settlementRecordService.insert(settlementRecord); |
| | | |
| | | |
| | | Withdraw withdraw = new Withdraw(); |
| | | withdraw.setUserId(tAgent.getMerchantNumber()); |
| | | withdraw.setAmount(String.valueOf(settledAmount)); |
| | | withdraw.setOrderName("账户余额提现"); |
| | | withdraw.setRemark("账户余额提现"); |
| | | withdraw.setNotifyUrl(callbackPath + "/base/tAgent/withdrawCashCallback"); |
| | | withdraw.setParameter1(settlementRecord.getId().toString()); |
| | | TrhRequest<Withdraw> request1 = new TrhRequest(); |
| | | InterfaceResponse execute1 = request1.execute(withdraw, Withdraw.SERVICE_CODE);//结算(提现) |
| | | if("0000".equals(execute1.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute1.getResult()); |
| | | String merOrderId1 = jsonObject1.getString("merOrderId"); |
| | | Integer status = jsonObject1.getInteger("status");//0:待处理;1:成功;2:失败 |
| | | if(0 == status){ |
| | | return ResultUtil.error("申请处理中"); |
| | | } |
| | | if(1 == status){ |
| | | settlementRecord.setOrderNumber(merOrderId1); |
| | | settlementRecord.setArrivalTime(new Date()); |
| | | settlementRecordService.updateById(settlementRecord); |
| | | return ResultUtil.success(); |
| | | } |
| | | if(2 == status){ |
| | | return ResultUtil.error("结算接口异常【提现】:" + jsonObject1.getString("statusMsg")); |
| | | } |
| | | }else{ |
| | | return ResultUtil.error("结算接口异常【提现】:" + execute.getMsg()); |
| | | } |
| | | |
| | | }else{ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | return ResultUtil.error("未知异常"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 提现回调 |
| | | * @param interfaceResponse |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/tAgent/withdrawCashCallback") |
| | | public void withdrawCashCallback(@RequestBody InterfaceResponse interfaceResponse, HttpServletResponse response) { |
| | | try { |
| | | if("0000".equals(interfaceResponse.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(interfaceResponse.getResult()); |
| | | String merOrderId1 = jsonObject1.getString("merOrderId"); |
| | | Integer status = jsonObject1.getInteger("status");//0:待处理;1:成功;2:失败 |
| | | if(1 == status){ |
| | | String parameter1 = jsonObject1.getString("parameter1"); |
| | | SettlementRecord settlementRecord = settlementRecordService.selectById(parameter1); |
| | | settlementRecord.setOrderNumber(merOrderId1); |
| | | settlementRecord.setArrivalTime(new Date()); |
| | | settlementRecordService.updateById(settlementRecord); |
| | | response.setStatus(200); |
| | | PrintWriter out = response.getWriter(); |
| | | out.print("OK"); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | if(2 == status){ |
| | | System.err.println("结算接口异常【提现】:" + jsonObject1.getString("statusMsg")); |
| | | } |
| | | }else{ |
| | | System.err.println("结算接口异常【提现】:" + interfaceResponse.getMsg()); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 充值补贴金额 |
| | | * @param amount |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/tAgent/accountRecharge") |
| | | public ResultUtil accountRecharge(Double amount){ |
| | | try { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + UUIDUtil.getNumberRandom(3); |
| | | RechargeRecord rechargeRecord = new RechargeRecord(); |
| | | rechargeRecord.setCode(out_trade_no); |
| | | rechargeRecord.setType(4); |
| | | rechargeRecord.setAmount(amount); |
| | | rechargeRecord.setPayType(2); |
| | | rechargeRecord.setPayStatus(1); |
| | | rechargeRecord.setCreateTime(new Date()); |
| | | rechargeRecordService.insert(rechargeRecord); |
| | | |
| | | Deposit deposit = new Deposit(); |
| | | deposit.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue())); |
| | | deposit.setOrderName("补贴充值"); |
| | | deposit.setPayType("ALI_CB"); |
| | | deposit.setTerminalIp(InetAddress.getLocalHost().getHostAddress()); |
| | | deposit.setFrontUrl(callbackPath + "/base/tAgent/accountRechargeCallback"); |
| | | deposit.setNotifyUrl(callbackPath + "/base/tAgent/accountRechargeCallback"); |
| | | deposit.setParameter1(rechargeRecord.getId().toString()); |
| | | TrhRequest<Deposit> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(deposit, Deposit.SERVICE_CODE); |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | Integer status = jsonObject.getInteger("status"); |
| | | if(2 == status){ |
| | | return ResultUtil.error("支付异常"); |
| | | } |
| | | String merOrderId = jsonObject.getString("merOrderId"); |
| | | String payCode = jsonObject.getString("payCode"); |
| | | if(ToolUtil.isNotEmpty(payCode)){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10){ |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | RechargeRecord rechargeRecord1 = rechargeRecordService.selectById(rechargeRecord.getId()); |
| | | if(rechargeRecord1.getPayStatus() != 1){ |
| | | return; |
| | | } |
| | | QueryOrder queryOrder = new QueryOrder(); |
| | | queryOrder.setOriginalMerOrderId(merOrderId); |
| | | /** |
| | | * 1:支付查询 2:退款查询 3:确认收货查询 4:结算查询 5:充值查询 6:转账查询 7:异步分账查询(必填) 字段长度最长:1位 |
| | | */ |
| | | queryOrder.setQueryType("5"); |
| | | TrhRequest<QueryOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute1 = request.execute(queryOrder, QueryOrder.SERVICE_CODE); |
| | | if("0000".equals(execute1.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute1.getResult()); |
| | | String status1 = jsonObject1.getString("status"); |
| | | if("0".equals(status1)){//待处理 |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | if("1".equals(status1)){//成功 |
| | | String merOrderId = jsonObject1.getString("merOrderId"); |
| | | rechargeRecord1.setPayTime(new Date()); |
| | | rechargeRecord1.setPayStatus(2); |
| | | rechargeRecord1.setOrderNumber(merOrderId); |
| | | rechargeRecord1.setSurplusDividedAmount(rechargeRecord1.getAmount()); |
| | | rechargeRecordService.updateById(rechargeRecord1); |
| | | break; |
| | | } |
| | | if("2".equals(status1) || 10 == num){//失败 |
| | | rechargeRecordService.deleteById(rechargeRecord1.getId()); |
| | | break; |
| | | } |
| | | }else{ |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | return ResultUtil.success(payCode); |
| | | }else{ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 补贴金额充值回调 |
| | | * @param interfaceResponse |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/tAgent/accountRechargeCallback") |
| | | public void accountRechargeCallback(@RequestBody InterfaceResponse interfaceResponse, HttpServletResponse response){ |
| | | try { |
| | | if("0000".equals(interfaceResponse.getCode())){ |
| | | JSONObject jsonObject = JSON.parseObject(interfaceResponse.getResult()); |
| | | Integer status = jsonObject.getInteger("status"); |
| | | if(2 == status){ |
| | | System.err.println("支付异常"); |
| | | return; |
| | | } |
| | | if(1 == status){ |
| | | String parameter1 = jsonObject.getString("parameter1"); |
| | | RechargeRecord rechargeRecord = rechargeRecordService.selectById(parameter1); |
| | | rechargeRecord.setPayStatus(2); |
| | | rechargeRecord.setPayTime(new Date()); |
| | | rechargeRecord.setOrderNumber(jsonObject.getString("merOrderId")); |
| | | rechargeRecord.setSurplusDividedAmount(rechargeRecord.getAmount()); |
| | | rechargeRecordService.updateById(rechargeRecord); |
| | | response.setStatus(200); |
| | | PrintWriter out = response.getWriter(); |
| | | out.print("OK"); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | }else{ |
| | | System.err.println(interfaceResponse.getMsg()); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |