AdminWithDrp.java 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559
  1. package com.iamberry.wechat.handles.drp;
  2. import java.io.BufferedInputStream;
  3. import java.io.BufferedOutputStream;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.UnsupportedEncodingException;
  9. import java.net.URL;
  10. import java.net.URLDecoder;
  11. import java.net.URLEncoder;
  12. import java.util.ArrayList;
  13. import java.util.Date;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.zip.ZipEntry;
  18. import java.util.zip.ZipOutputStream;
  19. import javax.servlet.ServletContext;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import jxl.Sheet;
  23. import jxl.Workbook;
  24. import org.apache.commons.io.FileUtils;
  25. import org.apache.commons.lang.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.http.HttpHeaders;
  28. import org.springframework.http.HttpStatus;
  29. import org.springframework.http.MediaType;
  30. import org.springframework.http.ResponseEntity;
  31. import org.springframework.stereotype.Controller;
  32. import org.springframework.ui.Model;
  33. import org.springframework.ui.ModelMap;
  34. import org.springframework.web.bind.annotation.PathVariable;
  35. import org.springframework.web.bind.annotation.RequestBody;
  36. import org.springframework.web.bind.annotation.RequestMapping;
  37. import org.springframework.web.bind.annotation.RequestMethod;
  38. import org.springframework.web.bind.annotation.RequestParam;
  39. import org.springframework.web.bind.annotation.ResponseBody;
  40. import org.springframework.web.context.ContextLoader;
  41. import org.springframework.web.context.WebApplicationContext;
  42. import org.springframework.web.multipart.MultipartFile;
  43. import org.springframework.web.servlet.ModelAndView;
  44. import com.iamberry.wechat.core.entity.JsonBack;
  45. import com.iamberry.wechat.core.entity.Page;
  46. import com.iamberry.wechat.core.entity.PageBean;
  47. import com.iamberry.wechat.core.entity.ResultMsg;
  48. import com.iamberry.wechat.core.entity.banner.MessageDTO;
  49. import com.iamberry.wechat.core.entity.drp.ApplyPlaceLogs;
  50. import com.iamberry.wechat.core.entity.drp.ApplyUserInfo;
  51. import com.iamberry.wechat.core.entity.drp.PageBeanEarningLogs;
  52. import com.iamberry.wechat.core.entity.drp.PageBeanPlaceInfo;
  53. import com.iamberry.wechat.core.entity.drp.PageBeanPlaceLogs;
  54. import com.iamberry.wechat.core.entity.drp.PageBeanWithdraw;
  55. import com.iamberry.wechat.core.entity.drp.PlaceInfo;
  56. import com.iamberry.wechat.core.entity.drp.PlaceInfoBattleDto;
  57. import com.iamberry.wechat.core.entity.drp.PlaceLogs;
  58. import com.iamberry.wechat.core.entity.drp.PlaceRoleInfo;
  59. import com.iamberry.wechat.core.entity.drp.PlaceWithDrawalsLogs;
  60. import com.iamberry.wechat.core.entity.flow.TemplateInfo;
  61. import com.iamberry.wechat.core.entity.member.Member;
  62. import com.iamberry.wechat.face.drp.DrpRoleInfoService;
  63. import com.iamberry.wechat.face.drp.PlaceInfoService;
  64. import com.iamberry.wechat.face.drp.PlaceLogsService;
  65. import com.iamberry.wechat.face.drp.PlaceWithDrawalsLogsService;
  66. import com.iamberry.wechat.face.flow.TemplateInfoService;
  67. import com.iamberry.wechat.face.member.MemberService;
  68. import com.iamberry.wechat.face.qrcode.QrcodeService;
  69. import com.iamberry.wechat.face.reback.RebackStaticService;
  70. import com.iamberry.wechat.service.wechat.WeChatServiceImpl;
  71. import com.iamberry.wechat.tools.DateTimeUtil;
  72. import com.iamberry.wechat.tools.HttpClient431Util;
  73. import com.iamberry.wechat.tools.ImageUtils;
  74. import com.iamberry.wechat.tools.NameUtils;
  75. import com.iamberry.wechat.tools.ObjectExcelView;
  76. import com.iamberry.wechat.tools.ResultInfo;
  77. /**
  78. * @description 后台的分销管理
  79. * @author 欧阳明
  80. * @date 2016-4-21
  81. */
  82. @Deprecated
  83. @Controller
  84. @RequestMapping("/admin/drp")
  85. public class AdminWithDrp {
  86. @Autowired
  87. private PlaceInfoService placeInfoService;
  88. @Autowired
  89. private PlaceWithDrawalsLogsService placeWithDrawalsLogsService;
  90. @Autowired
  91. private PlaceLogsService placeLogsService;
  92. @Autowired
  93. private MemberService memberService;
  94. @Autowired
  95. private RebackStaticService rebackStaticService;
  96. @Autowired
  97. private QrcodeService qrcodeService;
  98. @Autowired
  99. private DrpRoleInfoService drpRoleInfoService;
  100. @Autowired
  101. private TemplateInfoService templateInfoService;
  102. @Autowired
  103. private WeChatServiceImpl weChatServiceImpl;
  104. /**
  105. * 后台-进入商户添加页面(在用)
  106. * @return
  107. */
  108. @RequestMapping("/addPlaceInfo")
  109. public String addPlaceInfo(HttpServletRequest request, Model model) {
  110. // 获取角色列表
  111. List<PlaceRoleInfo> roles = drpRoleInfoService.getDrpRoleList2();
  112. // 获取模板列表
  113. List<TemplateInfo> templates = templateInfoService.getSelectTemplateInfo();
  114. model.addAttribute("roles", roles);
  115. model.addAttribute("templates", templates);
  116. return "/admin/drp/addPlaceInfo";
  117. }
  118. /**
  119. * 后台-Drp分销增加页面
  120. *
  121. * @return
  122. */
  123. @RequestMapping("/addPlaceInfoBattle")
  124. public String addPlaceInfoBattle(HttpServletRequest request, Model model) {
  125. // 获取角色列表
  126. List<PlaceRoleInfo> roles = drpRoleInfoService.getDrpRoleList2();
  127. // 获取模板列表
  128. List<TemplateInfo> templates = templateInfoService.getSelectTemplateInfo();
  129. model.addAttribute("roles", roles);
  130. model.addAttribute("templates", templates);
  131. return "/admin/drp/addPlaceInfoBattle";
  132. }
  133. /**
  134. * 后台-Drp分销商预生成分销商
  135. * @return
  136. */
  137. @ResponseBody
  138. @RequestMapping("/addPlaceInfoAutoBattle")
  139. public Map<String, Object> PlaceInfoAddAutoBattle(HttpServletRequest request, PlaceInfoBattleDto placeInfoDto) {
  140. HashMap<String, Object> map = new HashMap<String, Object>();
  141. int count = placeInfoDto.getNum();
  142. if (count < 1) {
  143. map.put("state", "false");
  144. map.put("message", "批量生成必须大于10");
  145. }
  146. PlaceInfo placeInfo = new PlaceInfo();
  147. placeInfo.setTemplateId(placeInfoDto.getTemplateId());
  148. placeInfo.setHasQrcode(placeInfoDto.getHasQrcode());
  149. placeInfo.setRoleId(placeInfoDto.getRoleId());
  150. placeInfo.setPlacePid(placeInfoDto.getPlacePid());
  151. String timeBefore = "a" + new Date().getTime();
  152. int beginId = 0;
  153. for (int i = 0; i < count; i++) {
  154. placeInfo.setName(timeBefore + i);
  155. placeInfo.setUserName(timeBefore + i);
  156. placeInfo.setAddr("待定中");
  157. placeInfo.setTel("13828467890");
  158. placeInfo.setRemark("批量生成");
  159. Map<String, Object> map2 = new HashMap<String, Object>();
  160. try {
  161. map2 = addPlaceInfoDeal(placeInfo);
  162. } catch (Exception ex) {
  163. ex.printStackTrace();
  164. }
  165. if (i == 0) {
  166. beginId = ((PlaceInfo) map2.get("data")).getId();
  167. }
  168. }
  169. map.put("state", "true");
  170. map.put("message", "批量生成成功");
  171. map.put("id", beginId);
  172. return map;
  173. }
  174. /**
  175. * 后台-Drp预生成分销商修改
  176. *
  177. * @return
  178. */
  179. @RequestMapping("/advanceDownLoadPlaceInfos")
  180. public ModelAndView advanceDownLoadPlaceInfos(HttpServletRequest request) {
  181. String beginNumStr = request.getParameter("beginNum");
  182. String numstr = request.getParameter("num");
  183. Integer beginNum = null;
  184. Integer num = null;
  185. if (beginNumStr.equals("") || beginNumStr == null) {
  186. return null;
  187. }
  188. beginNum = Integer.valueOf(beginNumStr);
  189. // 准备model
  190. Map<String, Object> model = new HashMap<String, Object>();
  191. model.put("fileName", "分销商新增记录"); // 下载文件名称
  192. // 标题
  193. List<String> titles = new ArrayList<String>();
  194. titles.add("编号");
  195. titles.add("公司名");
  196. titles.add("用户名");
  197. titles.add("区域名");
  198. /*
  199. * titles.add("是否二维码"); titles.add("父级id"); titles.add("角色id");
  200. */
  201. titles.add("联系方式");
  202. titles.add("联系地址");
  203. titles.add("激活码");
  204. titles.add("备注");
  205. model.put("titles", titles);
  206. HashMap<String, Object> mapCondition = new HashMap<String, Object>();
  207. mapCondition.put("beginNum", beginNum);
  208. if (!numstr.equals("") && numstr != null) {
  209. num = Integer.valueOf(numstr);
  210. mapCondition.put("num", num);
  211. }
  212. List<PlaceInfo> placeList = placeInfoService.selectPlaceInfosForDownLoad(mapCondition);
  213. // 封装导出内容
  214. List<List<Object>> countexts = new ArrayList<List<Object>>();
  215. if (placeList != null && placeList.size() > 0) {
  216. for (PlaceInfo placeInfo : placeList) {
  217. List<Object> row = new ArrayList<Object>();
  218. row.add(placeInfo.getId());
  219. row.add(placeInfo.getName());
  220. row.add(placeInfo.getUserName());
  221. row.add(placeInfo.getAreaName());
  222. row.add(placeInfo.getTel());
  223. row.add(placeInfo.getAddr());
  224. row.add(placeInfo.getInitCode());
  225. row.add(placeInfo.getRemark());
  226. countexts.add(row);
  227. }
  228. }
  229. model.put("varList", countexts);
  230. ObjectExcelView erv = new ObjectExcelView();
  231. ModelAndView mv = new ModelAndView(erv, model);
  232. return mv;
  233. }
  234. /**
  235. * 后台-添加一个商户 提交(在用)
  236. * 添加一个和批量添加都用此方法
  237. * @return
  238. */
  239. @ResponseBody
  240. @RequestMapping("/addPlaceInfoDeal")
  241. public Map<String, Object> addPlaceInfoDeal(PlaceInfo placeInfo) {
  242. HashMap<String, Object> map = new HashMap<String, Object>();
  243. placeInfo.setStatus(1);
  244. //默认没完善个人信息 批量的时候添加的 须去掉
  245. if(placeInfo.getPlaceInfoStus() == null){
  246. placeInfo.setPlaceInfoStus(1);
  247. }
  248. int st = placeInfo.getHasQrcode();
  249. ResultMsg remsg = placeInfoService.addOne(placeInfo);
  250. if(!remsg.isStatus()){
  251. map.put("result", remsg.getResultCode());
  252. map.put("message", remsg.getMessage());
  253. return map;
  254. }
  255. placeInfo = (PlaceInfo) remsg.getData();
  256. if (st == 2) {
  257. qrcodeService.applyPlaceQrcodeUrl(placeInfo.getId());
  258. }
  259. if (remsg.getResultCode().equals(ResultInfo.SUCCESSCODE)) {
  260. map.put("result", ResultInfo.SUCCESSCODE);
  261. map.put("data", placeInfo);
  262. map.put("message", "操作成功,激活码是:" + placeInfo.getInitCode());
  263. } else {
  264. map.put("result", ResultInfo.ERRORCODE);
  265. map.put("message", NameUtils.getConfig("ERRORINFO"));
  266. }
  267. return map;
  268. }
  269. /**
  270. * 商户父节点搜索(根据商户名称)(在用 <一次查出了所有数据 待修改>)
  271. * @return
  272. * @throws UnsupportedEncodingException
  273. */
  274. @SuppressWarnings("unchecked")
  275. @ResponseBody
  276. //@RequestMapping("/searchPlaceInfoParent")
  277. @RequestMapping(value="/searchPlaceInfoParent",method = RequestMethod.POST)
  278. public Map<String, Object> searchPlaceInfoParent(HttpServletRequest request, String search, Integer roleId,Integer templateId)
  279. throws UnsupportedEncodingException {
  280. Map<String, Object> map = new HashMap<String, Object>();
  281. PlaceInfo placeInfo = new PlaceInfo();
  282. if (search == null || search.equals("")) {
  283. map.put("error", "参数错误异常");
  284. map.put("status", "false");
  285. return map;
  286. }
  287. if (roleId == null || roleId == 0) {
  288. map.put("error", "请先选择所属角色");
  289. map.put("status", "false");
  290. return map;
  291. }
  292. if (templateId == null || templateId == 0) {
  293. map.put("error", "请先选择模板");
  294. map.put("status", "false");
  295. return map;
  296. }
  297. if (roleId != null) {
  298. if(roleId == 47){//如果选择为合伙人或钻石会员则直接返回不查询
  299. return map;
  300. }
  301. if(roleId == 53){
  302. return map;
  303. }
  304. placeInfo.setRoleId(roleId);
  305. }
  306. if (templateId != null) {
  307. if(templateId == 24 ){
  308. if(roleId == 52){
  309. placeInfo.setTemplateId(templateId);
  310. }else{
  311. map.put("error", "模板与角色不匹配");
  312. map.put("status", "false");
  313. return map;
  314. }
  315. }else{
  316. placeInfo.setTemplateId(templateId);
  317. }
  318. }
  319. placeInfo.setName(search);
  320. map = placeInfoService.SearchPlaceInfo(placeInfo);
  321. return map;
  322. }
  323. /**
  324. * 用于修改页面增加角色或者模板的下拉列表
  325. * @author 欧阳明
  326. * @return
  327. */
  328. @ResponseBody
  329. @RequestMapping("/getSelectList")
  330. public List getSelectList(HttpServletRequest request) {
  331. int type = Integer.valueOf(request.getParameter("type"));
  332. if (type == 1) {
  333. // 获取角色列表
  334. List<PlaceRoleInfo> roles = drpRoleInfoService.getDrpRoleList2();
  335. return roles;
  336. } else {
  337. // 获取模板列表
  338. List<TemplateInfo> templates = templateInfoService.getSelectTemplateInfo();
  339. return templates;
  340. }
  341. }
  342. /**
  343. * 后台-Drp分销编辑页面
  344. * @return
  345. */
  346. @RequestMapping("/EditPlaceInfo")
  347. public String EditPlaceInfoPage(HttpServletRequest request, Model model) {
  348. int id = Integer.valueOf(request.getParameter("id"));
  349. PlaceInfo placeInfo = placeInfoService.getPlaceInfoById(id);
  350. if (placeInfo.getPlacePid() == 0) {
  351. placeInfo.setParentName(placeInfo.getName());
  352. } else {
  353. PlaceInfo parentPlaceInfo = placeInfoService.getPlaceInfoById(placeInfo.getPlacePid());
  354. placeInfo.setParentName(parentPlaceInfo.getName());
  355. }
  356. model.addAttribute("placeInfo", placeInfo);
  357. return "/admin/drp/editPlaceInfo";
  358. }
  359. /**
  360. * 后台-Drp分销编辑页面
  361. * @return
  362. */
  363. @ResponseBody
  364. @RequestMapping("/EditPlaceInfoSubmit")
  365. public Map EditPlaceInfoSubmit(PlaceInfo placeInfo) {
  366. int st = placeInfo.getHasQrcode();
  367. PlaceInfo orgin = placeInfoService.getPlaceInfoById(placeInfo.getId());
  368. if (orgin.getHasQrcode() == 1 && st == 2) {
  369. qrcodeService.applyPlaceQrcodeUrl(placeInfo.getId());
  370. }
  371. if (orgin.getHasQrcode() == 2 && st == 1) {
  372. qrcodeService.updateQRcodeStatusByUserOpenid(String.valueOf(orgin.getId()));
  373. }
  374. ResultMsg remsg = placeInfoService.update(placeInfo);
  375. HashMap map = new HashMap();
  376. if (remsg.getResultCode().equals(ResultInfo.SUCCESSCODE)) {
  377. map.put("result", ResultInfo.SUCCESSCODE);
  378. map.put("message", remsg.getMessage());
  379. } else {
  380. map.put("result", ResultInfo.ERRORCODE);
  381. map.put("message", NameUtils.getConfig("ERRORINFO"));
  382. }
  383. return map;
  384. }
  385. /**
  386. * 删除分销商-属于逻辑删除
  387. * @return
  388. */
  389. @ResponseBody
  390. @RequestMapping("/deletePlaceInfo")
  391. public Map deletePlaceInfo(HttpServletRequest request) {
  392. int id2 = Integer.valueOf(request.getParameter("id"));
  393. PlaceInfo placeInfo = new PlaceInfo();
  394. placeInfo.setId(id2);
  395. placeInfo.setStatus(2);
  396. ResultMsg remsg = placeInfoService.update(placeInfo);
  397. HashMap map = new HashMap();
  398. if (remsg.getResultCode().equals(ResultInfo.SUCCESSCODE)) {
  399. map.put("result", ResultInfo.SUCCESSCODE);
  400. map.put("message", remsg.getMessage());
  401. } else {
  402. map.put("result", ResultInfo.ERRORCODE);
  403. map.put("message", NameUtils.getConfig("ERRORINFO"));
  404. }
  405. return map;
  406. }
  407. /**
  408. * 后台-Drp分销绑定页面
  409. *
  410. * @return
  411. */
  412. @RequestMapping("/bindingPlaceInfo")
  413. public String bindingPlaceInfo(
  414. @RequestParam(value = "pageNO", defaultValue = "1", required = false) int pageNO,
  415. @RequestParam(value = "pageSize", defaultValue = "5", required = false) int pageSize,
  416. HttpServletRequest request,Model model) {
  417. String userInput = request.getParameter("userInput");
  418. Page page = new Page();
  419. if(userInput !=null && !userInput.equals("")){
  420. page.getParams().put("userInput", userInput);
  421. model.addAttribute("userInput", userInput);
  422. }
  423. page.setPageNo((pageNO - 1) * pageSize);
  424. int count = memberService.getCount();
  425. int pageCount = count % pageSize == 0 ? count / pageSize : count
  426. / pageSize + 1;
  427. page.setPageSize(pageSize);
  428. List<Member> memberList = memberService.getMemberByPage(page);
  429. model.addAttribute("memberList", memberList);
  430. model.addAttribute("pageNO", pageNO);
  431. model.addAttribute("pageSize", pageCount);
  432. model.addAttribute("url", "/admin/drp/bindingPlaceInfo?pageSize=" + pageSize
  433. + "&pageNO=");
  434. String initCode = request.getParameter("initCode");
  435. model.addAttribute("initCode", initCode);
  436. return "/admin/drp/bindingPlaceInfo";
  437. }
  438. /**
  439. * 后台-Drp分销绑定
  440. *
  441. * @return
  442. */
  443. @ResponseBody
  444. @RequestMapping("/bindingPlaceInfoSubmit")
  445. public Map bindingPlaceInfoSubmit(HttpServletRequest request,Model model) {
  446. String initCode = request.getParameter("initCode");
  447. String openId = request.getParameter("openId");
  448. HashMap map = new HashMap();
  449. if(initCode == null|| initCode.equals("") || openId == null || openId.equals("")){
  450. map.put("result", ResultInfo.ERRORCODE);
  451. }
  452. weChatServiceImpl.bulidPlace(initCode, openId);
  453. map.put("result", ResultInfo.SUCCESSCODE);
  454. return map;
  455. }
  456. /**
  457. * 后台-Drp分销管理主界面
  458. * @param pageNO
  459. * @param pageSize
  460. * @return
  461. */
  462. @RequestMapping("/index")
  463. public String index() {
  464. return "/admin/drp/placeInfolist";
  465. }
  466. /**
  467. * 分销商综合查询
  468. * @param str
  469. * @return
  470. */
  471. @ResponseBody
  472. @RequestMapping("/initTable")
  473. public Map initPlaceInfoTable2(@RequestBody PageBeanPlaceInfo tmp) throws Exception {
  474. if (tmp != null && tmp.getCondition().getUserNickname() != null
  475. && !"".equals(tmp.getCondition().getUserNickname())) {
  476. tmp.getCondition().setUserNickname(URLEncoder.encode(tmp.getCondition().getUserNickname(), "UTF-8"));
  477. }
  478. PageBean page = new PageBean();
  479. page.setCondition(tmp.getCondition());
  480. page.setPageNumber(tmp.getPageNumber());
  481. page.setPageSize(tmp.getPageSize());
  482. PlaceInfo pinfo = new PlaceInfo();
  483. if (page.getCondition() == null) {
  484. page.setCondition(pinfo);
  485. }
  486. Map map = placeInfoService.SearchPlaceInfoPage(page);
  487. page = (PageBean) map.get("page");
  488. return map;
  489. }
  490. // ===================================分销提现管理==========================================
  491. /**
  492. * 分销提现页面
  493. * @param str
  494. * @return
  495. */
  496. @RequestMapping("/initWithdraw")
  497. public String withdraw() {
  498. return "/admin/drp/withdrawlist";
  499. }
  500. @RequestMapping("/downLoadWithdraw")
  501. public ModelAndView downLoadWithdraw(HttpServletRequest request, PlaceWithDrawalsLogs tmp) {
  502. // 准备model
  503. Map<String, Object> model = new HashMap<String, Object>();
  504. model.put("fileName", "分销提现记录"); // 下载文件名称
  505. // 标题
  506. List<String> titles = new ArrayList<String>();
  507. titles.add("分销商");
  508. titles.add("角色");
  509. titles.add("金额");
  510. titles.add("收款人");
  511. titles.add("收款人联系方式");
  512. titles.add("收款人卡号");
  513. titles.add("所属银行");
  514. titles.add("申请状态");
  515. titles.add("创建时间");
  516. model.put("titles", titles);
  517. // 查询分销提现记录
  518. PageBean page = new PageBean();
  519. // page.setCondition(tmp.getCondition());
  520. PlaceWithDrawalsLogs pinfo = new PlaceWithDrawalsLogs();
  521. if (page.getCondition() == null) {
  522. page.setCondition(pinfo);
  523. }
  524. List<PlaceWithDrawalsLogs> placeList = placeWithDrawalsLogsService.selectAllMore(tmp);
  525. // 封装导出内容
  526. List<List<Object>> countexts = new ArrayList<List<Object>>();
  527. if (placeList != null && placeList.size() > 0) {
  528. for (PlaceWithDrawalsLogs drawalsLogs : placeList) {
  529. List<Object> row = new ArrayList<Object>();
  530. row.add(drawalsLogs.getName());
  531. row.add(drawalsLogs.getRoleName());
  532. row.add(drawalsLogs.getWithDrawalsNum());
  533. row.add(drawalsLogs.getWithDrawalsName());
  534. row.add(drawalsLogs.getTel());
  535. row.add(drawalsLogs.getAccountNo());
  536. row.add(drawalsLogs.getBankLocal());
  537. String status = "";
  538. switch (drawalsLogs.getStatus()) {
  539. case 1:
  540. status = "申请中";
  541. break;
  542. case 2:
  543. status = "申请成功";
  544. break;
  545. case 3:
  546. status = "申请失败";
  547. break;
  548. }
  549. row.add(status);
  550. if (drawalsLogs.getCreateDate() != null) {
  551. row.add(DateTimeUtil.format(drawalsLogs.getCreateDate(), NameUtils.getConfig("DATE_TIME_FORMAT")));
  552. }
  553. countexts.add(row);
  554. }
  555. }
  556. model.put("varList", countexts);
  557. ObjectExcelView erv = new ObjectExcelView();
  558. ModelAndView mv = new ModelAndView(erv, model);
  559. return mv;
  560. }
  561. /**
  562. * 分销提现管理
  563. *
  564. * @param str
  565. * @return
  566. */
  567. @ResponseBody
  568. @RequestMapping("/withdrawTable")
  569. public Map withdrawTable(@RequestBody PageBeanWithdraw tmp) {
  570. PageBean page = new PageBean();
  571. page.setCondition(tmp.getCondition());
  572. page.setPageNumber(tmp.getPageNumber());
  573. page.setPageSize(tmp.getPageSize());
  574. PlaceWithDrawalsLogs pinfo = new PlaceWithDrawalsLogs();
  575. if (page.getCondition() == null) {
  576. page.setCondition(pinfo);
  577. }
  578. Map map = placeWithDrawalsLogsService.HistoryRecordsManager(page);
  579. // page=(PageBean)map.get("page");
  580. return map;
  581. }
  582. /**
  583. * 进入提现处理页
  584. *
  585. * @param str
  586. * @return
  587. */
  588. @RequestMapping("/withdrawPaper")
  589. public String withdrawPaper(HttpServletRequest request, Model model) {
  590. int id = Integer.valueOf(request.getParameter("id"));
  591. PlaceWithDrawalsLogs placeWithDrawalsLogs = placeWithDrawalsLogsService.getOne(id);
  592. model.addAttribute("placeWithDrawalsLogs", placeWithDrawalsLogs);
  593. return "/admin/drp/withdrawPaper";
  594. }
  595. /**
  596. * 处理提现
  597. *
  598. * @param str
  599. * @return
  600. */
  601. @ResponseBody
  602. @RequestMapping("/dealWithdraw")
  603. public Map<String, String> dealWithdrawPaper(PlaceWithDrawalsLogs placeWithDrawalsLogs) {
  604. ResultMsg remsg = placeWithDrawalsLogsService.dealApply(placeWithDrawalsLogs);
  605. HashMap<String, String> map = new HashMap<String, String>();
  606. if (placeWithDrawalsLogs == null) {
  607. return map;
  608. }
  609. PlaceWithDrawalsLogs withDrawalsLogs = placeWithDrawalsLogsService.getOne(placeWithDrawalsLogs.getId());
  610. if (remsg.getResultCode().equals(ResultInfo.SUCCESSCODE)) {
  611. map.put("result", ResultInfo.SUCCESSCODE);
  612. map.put("message", remsg.getMessage());
  613. // 返现后给用户推送微信消息
  614. if (placeWithDrawalsLogs.getStatus() == 2) { // 审核通过
  615. if (withDrawalsLogs != null && StringUtils.isNotEmpty(withDrawalsLogs.getOpenid())
  616. && withDrawalsLogs.getWithDrawalsNum() > 0) {
  617. Member member = memberService.getMemberByUserOpenId(withDrawalsLogs.getOpenid());
  618. }
  619. } else if (placeWithDrawalsLogs.getStatus() == 3) { // 审核不通过
  620. if (withDrawalsLogs != null && StringUtils.isNotEmpty(withDrawalsLogs.getOpenid())
  621. && withDrawalsLogs.getWithDrawalsNum() > 0) {
  622. try {
  623. Member member = memberService.getMemberByUserOpenId(withDrawalsLogs.getOpenid());
  624. String temp = ResultInfo.INCOMEREMINDTEMP;
  625. temp = temp.replaceFirst("firstValueIamberry", ResultInfo.INCOMEREJECTMESSAGE)
  626. .replaceFirst("accountValueIamberry",
  627. URLDecoder.decode(member.getUserNickname(), "UTF-8"))
  628. .replaceFirst("timeValueIamberry",
  629. DateTimeUtil.format(new Date(), NameUtils.getConfig("DATE_TIME_FORMAT")))
  630. .replaceFirst("typeValueIamberry", "申请提现:"
  631. + new Double(withDrawalsLogs.getWithDrawalsNum() / 100.0).toString() + "元")
  632. .replaceFirst("remarkValueIamberry", ResultInfo.INTOSHOP);
  633. } catch (Exception e) {
  634. e.printStackTrace();
  635. }
  636. }
  637. }
  638. } else {
  639. map.put("result", ResultInfo.ERRORCODE);
  640. map.put("message", NameUtils.getConfig("ERRORINFO"));
  641. }
  642. return map;
  643. }
  644. // ===============================分销收支记录管理========================================
  645. /**
  646. * 现金记录页面
  647. *
  648. * @param str
  649. * @return
  650. */
  651. @RequestMapping("/initlogs")
  652. public String logs() {
  653. return "/admin/drp/placeLogslist";
  654. }
  655. /**
  656. * 初始化订单表格
  657. *
  658. * @param str
  659. * @return
  660. */
  661. @ResponseBody
  662. @RequestMapping("/logsTable")
  663. public Map orderTable(@RequestBody PageBeanPlaceLogs tmp) {
  664. PageBean page = new PageBean();
  665. page.setCondition(tmp.getCondition());
  666. page.setPageNumber(tmp.getPageNumber());
  667. page.setPageSize(tmp.getPageSize());
  668. PlaceLogs pLogs = new PlaceLogs();
  669. if (page.getCondition() == null) {
  670. page.setCondition(pLogs);
  671. }
  672. Map map = placeLogsService.SearchPlaceLogsPage(page);
  673. return map;
  674. }
  675. // =================================分销订单收入记录===================================
  676. /**
  677. * 分销订单收入记录
  678. *
  679. * @param str
  680. * @return
  681. */
  682. @RequestMapping("/initOrderlogs")
  683. public String initOrderlogs() {
  684. return "/admin/drp/orderEarningLogslist";
  685. }
  686. /**
  687. * 初始化订单表格
  688. *
  689. * @param str
  690. * @return
  691. */
  692. @ResponseBody
  693. @RequestMapping("/orderEarningTable")
  694. public Map orderEarningTable(@RequestBody PageBeanEarningLogs tmp) {
  695. PageBean page = new PageBean();
  696. page.setCondition(tmp.getCondition());
  697. page.setPageNumber(tmp.getPageNumber());
  698. page.setPageSize(tmp.getPageSize());
  699. // Map map=placeLogsService.searchDrpRecord(page);
  700. Map map = rebackStaticService.getSearchIncomeDetail(page);
  701. return map;
  702. }
  703. /**
  704. * 需要下载二维码的批量打包
  705. *
  706. * @param request
  707. * @param response
  708. * @return
  709. */
  710. @ResponseBody
  711. @RequestMapping(value = "/battle2w")
  712. public synchronized Map battle2w(HttpServletRequest request, HttpServletResponse response) {
  713. Map resultmap = new HashMap<String, String>();
  714. WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
  715. ServletContext servletContext = webApplicationContext.getServletContext();
  716. String realPath = servletContext.getRealPath(ResultInfo.QRCODE_IMAGE);
  717. String fileName = String.valueOf(new Date().getTime());
  718. try {
  719. String name = request.getParameter("name");
  720. String parentName = request.getParameter("supperName");
  721. String userName = request.getParameter("openid");
  722. PlaceInfo placeInfo = new PlaceInfo();
  723. placeInfo.setName(name);
  724. placeInfo.setUserName(userName);
  725. placeInfo.setParentName(parentName);
  726. List<PlaceInfo> placeList = placeInfoService.getPlaceId(placeInfo);
  727. ResponseEntity<byte[]> entity = null;
  728. if (placeList != null && placeList.size() > 0) {
  729. for (PlaceInfo place : placeList) {
  730. if (place.getQrcodeUrl() == null || "".equals(place.getQrcodeUrl())) {
  731. continue;
  732. }
  733. String url = place.getQrcodeUrl();
  734. String qrcode = realPath + "/" + place.getId() + "qrcode.png";
  735. // url =
  736. // "http://localhost:8080/iamberry/common/images/default_qrcode.png";
  737. Map<String, Object> map = this.selectSuperior(String.valueOf(place.getId()));
  738. String placeName = "";
  739. String imageName = String.valueOf(place.getId());
  740. if (map != null) {
  741. placeName = (String) map.get("name");
  742. imageName = (String) map.get("name");
  743. }
  744. String waterMark = realPath + "/" + imageName + ".png";
  745. File file = new File(waterMark);
  746. File files = new File(realPath);
  747. if (!files.exists()) {
  748. files.mkdir();
  749. }
  750. if (!file.exists()) {
  751. URL httpurl = new URL(url);
  752. org.apache.commons.io.FileUtils.copyURLToFile(httpurl, new File(qrcode));
  753. this.rwFile(servletContext.getRealPath(NameUtils.getConfig("WECHAT_DEFAULT_WATERMARK")),
  754. realPath, imageName);
  755. ImageUtils.press(waterMark, qrcode, placeName, -1, 170, 320, 250);
  756. }
  757. }
  758. /*
  759. * Task2wm tasks=new Task2wm(placeList,0,placeList.size());
  760. * ForkJoinPool pool=new ForkJoinPool(); pool.execute(tasks);
  761. * do{
  762. * System.out.println("active Thread:"+pool.getActiveThreadCount
  763. * ()); }while(!tasks.isDone()); pool.shutdown();
  764. */
  765. }
  766. String zipName = getZipPath(realPath, fileName, placeList);
  767. resultmap.put("status", "true");
  768. resultmap.put("fileName", fileName);
  769. resultmap.put("message", "success");
  770. } catch (Exception e) {
  771. e.printStackTrace();
  772. resultmap.put("status", "false");
  773. resultmap.put("fileName", fileName);
  774. resultmap.put("message", "fail");
  775. }
  776. return resultmap;
  777. }
  778. /**
  779. * 批量下载二维码
  780. *
  781. * @param request
  782. * @param response
  783. * @return
  784. */
  785. @RequestMapping(value = "/downLoadList")
  786. public synchronized ResponseEntity<byte[]> downLoadList(HttpServletRequest request, HttpServletResponse response) {
  787. String filePath = request.getServletContext().getRealPath(ResultInfo.QRCODE_IMAGE);
  788. String zipName = filePath + "/" + request.getParameter("zipName");
  789. String fileName = String.valueOf(new Date().getTime());
  790. ResponseEntity<byte[]> entity = null;
  791. // 创建HttpHeaders对象
  792. HttpHeaders headers = new HttpHeaders();
  793. // 创建一个响应吗
  794. HttpStatus httpStatus = HttpStatus.OK;
  795. // 创建对象
  796. try {
  797. headers.add("Content-Disposition",
  798. "attachment;filename=\"" + new String((fileName + ".zip").getBytes("UTF-8"), "ISO-8859-1") + "\"");
  799. // 添加一个头消息
  800. headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
  801. entity = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(new File(zipName)), headers, httpStatus);
  802. } catch (IOException e) {
  803. // TODO Auto-generated catch block
  804. e.printStackTrace();
  805. }
  806. // 手动释放资源
  807. return entity;
  808. }
  809. /**
  810. * 压缩文件方法
  811. *
  812. * @param zipPath
  813. * 压缩路径
  814. * @param fileName
  815. * 压缩后压缩包名称
  816. * @return
  817. * @throws Exception
  818. */
  819. public String getZipPath(String zipPath, String fileName, List<PlaceInfo> placeList) throws Exception {
  820. Map searchmap = new HashMap();
  821. for (PlaceInfo placeInfo : placeList) {
  822. searchmap.put(String.valueOf(placeInfo.getId()), placeInfo);
  823. }
  824. File sourceFile = new File(zipPath);
  825. FileInputStream fis = null;
  826. BufferedInputStream bis = null;
  827. FileOutputStream fos = null;
  828. ZipOutputStream zos = null;
  829. // 判断该压缩文件的目录是否存在
  830. if (sourceFile.exists() == false) {
  831. // System.out.println(">>>>>> 待压缩的文件目录:" + zipPath + " 不存在.
  832. // <<<<<<");
  833. return "";
  834. }
  835. try {
  836. File zipFile = new File(zipPath + "/" + fileName + ".zip");
  837. // 如果该压缩文件已经存在,则不再进行压缩
  838. if (zipFile.exists()) {
  839. // System.out.println(">>>>>> " + zipPath + " 目录下存在名字为:" +
  840. // fileName + ".zip" + " 打包文件. <<<<<<");
  841. return zipPath + "/" + fileName + ".zip";
  842. }
  843. File[] sourceFiles = sourceFile.listFiles();
  844. fos = new FileOutputStream(zipFile);
  845. zos = new ZipOutputStream(new BufferedOutputStream(fos));
  846. byte[] buffer = new byte[1024 * 10];
  847. if (null == sourceFiles || sourceFiles.length < 1) {
  848. // System.out.println(">>>>>> 待压缩的文件目录:" + zipPath + "
  849. // 里面不存在文件,无需压缩. <<<<<<");
  850. return "";
  851. }
  852. for (int i = 0; i < sourceFiles.length; i++) {
  853. String picName = sourceFiles[i].getName();
  854. // System.out.println("picName"+picName);
  855. String picNo = "";
  856. try {
  857. picNo = picName.substring(0, picName.indexOf("-"));
  858. } catch (Exception ex) {
  859. ex.printStackTrace();
  860. continue;
  861. }
  862. if (searchmap.get(picNo) == null) {
  863. continue;
  864. }
  865. if (!sourceFiles[i].getName().endsWith("qrcode.png")) {
  866. // 创建ZIP实体,并添加进压缩包
  867. ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName());
  868. zos.putNextEntry(zipEntry);
  869. // 读取待压缩的文件并写进压缩包里
  870. fis = new FileInputStream(sourceFiles[i]);
  871. bis = new BufferedInputStream(fis, 1024 * 10);
  872. int read = 0;
  873. while ((read = bis.read(buffer, 0, 1024 * 10)) != -1) {
  874. zos.write(buffer, 0, read);
  875. }
  876. searchmap.remove(picNo);
  877. }
  878. }
  879. } catch (Exception e) {
  880. e.printStackTrace();
  881. } finally {
  882. try {
  883. if (null != bis)
  884. bis.close();
  885. if (null != zos)
  886. zos.close();
  887. } catch (IOException e) {
  888. e.printStackTrace();
  889. throw new RuntimeException(e);
  890. }
  891. }
  892. return zipPath + "/" + fileName + ".zip";
  893. }
  894. /**
  895. * 分销商下载二维码功能
  896. *
  897. * @param request
  898. * @param url
  899. */
  900. @RequestMapping(value = "/downLoad")
  901. public synchronized ResponseEntity<byte[]> downLoad(HttpServletRequest request, HttpServletResponse response) {
  902. try {
  903. String openId = request.getParameter("openId");
  904. WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
  905. ServletContext servletContext = webApplicationContext.getServletContext();
  906. String realPath = servletContext.getRealPath(ResultInfo.QRCODE_IMAGE);
  907. String url = request.getParameter("url");
  908. String qrcode = realPath + "/" + openId + "qrcode.png";
  909. // url =
  910. // "http://localhost:8080/watero/common/images/default_qrcode.png";
  911. Map<String, Object> map = this.selectSuperior(openId);
  912. String name = "";
  913. String code = "";
  914. String imageName = openId;
  915. String imageCode = "";
  916. if (map != null) {
  917. name = (String) map.get("name");
  918. code = (String) map.get("code");
  919. imageName = (String) map.get("imageName");
  920. imageCode = (String) map.get("imageCode");
  921. }
  922. String waterMark = realPath + "/" + imageName + ".png";
  923. File file = new File(waterMark);
  924. File files = new File(realPath);
  925. if (!files.exists()) {
  926. files.mkdir();
  927. }
  928. if (!file.exists()) {
  929. HttpClient431Util.downloadFile(url, qrcode);
  930. this.rwFile(servletContext.getRealPath(NameUtils.getConfig("WECHAT_DEFAULT_WATERMARK")), realPath,
  931. imageName);
  932. ImageUtils.press(waterMark, qrcode, name, -1, 150, 320, 250);
  933. }
  934. if(code != null && !code.equals("")){
  935. ImageUtils.press(waterMark, qrcode, "门店激活码:"+code, -1, 180, 320, 250);
  936. }
  937. if(imageCode != null && !imageCode.equals("")){
  938. ImageUtils.press(waterMark, qrcode, "当前商户激活码:"+imageCode, -1, 210, 320, 250);
  939. }
  940. // 创建HttpHeaders对象
  941. HttpHeaders headers = new HttpHeaders();
  942. // 添加一个头消息
  943. headers.add("Content-Disposition",
  944. "attachment;filename=\"" + new String((imageName + ".png").getBytes("UTF-8"), "ISO-8859-1") + "\"");
  945. headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
  946. // 创建一个响应吗
  947. HttpStatus httpStatus = HttpStatus.OK;
  948. // 创建对象
  949. ResponseEntity<byte[]> entity = new ResponseEntity<byte[]>(
  950. FileUtils.readFileToByteArray(new File(waterMark)), headers, httpStatus);
  951. // 手动释放资源
  952. return entity;
  953. } catch (Exception e) {
  954. e.printStackTrace();
  955. }
  956. return null;
  957. }
  958. // 查询线下上级,拼接名称
  959. public Map<String, Object> selectSuperior(String openId) {
  960. if (null == openId || "".equals(openId)) {
  961. return null;
  962. }
  963. String imageName = "";
  964. Map<String, Object> map = new HashMap<String, Object>();
  965. PlaceInfo palceInfo1 = new PlaceInfo();
  966. palceInfo1.setId(Integer.parseInt(openId));
  967. StringBuffer name = new StringBuffer();
  968. PlaceInfo placeInfo = this.placeInfoService.getOnePlaceInfoByInitcode(palceInfo1);
  969. if (placeInfo == null) {
  970. return null;
  971. }
  972. imageName = openId + "-" + placeInfo.getName();
  973. map.put("imageName", imageName);
  974. map.put("imageCode", placeInfo.getInitCode());
  975. PlaceRoleInfo placeRoleInfo = new PlaceRoleInfo();
  976. PlaceInfo parentPlace = null;
  977. PlaceInfo superPlace = null;
  978. PlaceInfo threePlace = null;
  979. PlaceInfo fourPlace = null;
  980. PlaceInfo fivePlace = null;
  981. // 查询自己的角色信息
  982. placeRoleInfo.setRoleId(placeInfo.getRoleId());
  983. placeRoleInfo = drpRoleInfoService.selectDrpRoleInfo(placeRoleInfo);
  984. if (placeInfo != null && placeRoleInfo != null && placeInfo.getUserName() != null
  985. && placeRoleInfo.getRoleName() != null) {
  986. // System.out.println(placeInfo.getUserName()+" roleName:" +
  987. // placeRoleInfo.getRoleName());
  988. name.append(placeInfo.getUserName() + placeRoleInfo.getRoleName());
  989. // 查询第一级上级角色信息
  990. if (!"".equals(String.valueOf(placeInfo.getPlacePid()))) {
  991. parentPlace = this.placeInfoService.getPlaceInfoById(placeInfo.getPlacePid());
  992. if (null != parentPlace) {
  993. placeRoleInfo.setRoleId(parentPlace.getRoleId());
  994. placeRoleInfo = drpRoleInfoService.selectDrpRoleInfo(placeRoleInfo);
  995. name.insert(0, parentPlace.getUserName() + placeRoleInfo.getRoleName() + "—");
  996. map.put("code", parentPlace.getInitCode());
  997. map.put("name", name.toString());
  998. return map;
  999. }
  1000. }
  1001. // 查询第二级上级角色信息
  1002. if (null != parentPlace && !"".equals(String.valueOf(parentPlace.getPlacePid()))) {
  1003. superPlace = this.placeInfoService.getPlaceInfoById(parentPlace.getPlacePid());
  1004. if (null != superPlace) {
  1005. placeRoleInfo.setRoleId(superPlace.getRoleId());
  1006. placeRoleInfo = drpRoleInfoService.selectDrpRoleInfo(placeRoleInfo);
  1007. name.insert(0, superPlace.getUserName() + placeRoleInfo.getRoleName() + "—");
  1008. map.put("code", superPlace.getInitCode());
  1009. map.put("name", name.toString());
  1010. return map;
  1011. }
  1012. }
  1013. // 查询第三级上级角色信息
  1014. if (null != superPlace && !"".equals(String.valueOf(superPlace.getPlacePid()))) {
  1015. threePlace = this.placeInfoService.getPlaceInfoById(superPlace.getPlacePid());
  1016. if (null != threePlace) {
  1017. placeRoleInfo.setRoleId(threePlace.getRoleId());
  1018. placeRoleInfo = drpRoleInfoService.selectDrpRoleInfo(placeRoleInfo);
  1019. name.insert(0, threePlace.getUserName() + placeRoleInfo.getRoleName() + "—");
  1020. map.put("code", threePlace.getInitCode());
  1021. map.put("name", name.toString());
  1022. return map;
  1023. }
  1024. }
  1025. // 查询第四级上级角色信息
  1026. if (null != threePlace && !"".equals(String.valueOf(threePlace.getPlacePid()))) {
  1027. fourPlace = this.placeInfoService.getPlaceInfoById(threePlace.getPlacePid());
  1028. if (null != fourPlace) {
  1029. placeRoleInfo.setRoleId(fourPlace.getRoleId());
  1030. placeRoleInfo = drpRoleInfoService.selectDrpRoleInfo(placeRoleInfo);
  1031. name.insert(0, fourPlace.getUserName() + placeRoleInfo.getRoleName() + "—");
  1032. map.put("code", fourPlace.getInitCode());
  1033. map.put("name", name.toString());
  1034. return map;
  1035. }
  1036. }
  1037. // 查询第五级上级角色信息
  1038. if (null != fourPlace && !"".equals(String.valueOf(fourPlace.getPlacePid()))) {
  1039. fivePlace = this.placeInfoService.getPlaceInfoById(fourPlace.getPlacePid());
  1040. if (null != fivePlace) {
  1041. placeRoleInfo.setRoleId(fivePlace.getRoleId());
  1042. placeRoleInfo = drpRoleInfoService.selectDrpRoleInfo(placeRoleInfo);
  1043. name.insert(0, fivePlace.getUserName() + placeRoleInfo.getRoleName() + "—");
  1044. map.put("code", fivePlace.getInitCode());
  1045. map.put("name", name.toString());
  1046. return map;
  1047. }
  1048. }
  1049. map.put("name", name.toString());
  1050. return map;
  1051. }
  1052. return null;
  1053. }
  1054. // 从本地获取添加水印的背景图片
  1055. public void rwFile(String str1, String str2, String openId) {
  1056. try {
  1057. File f2 = new File(str2);
  1058. File f1 = new File(str1);
  1059. if (f2.exists()) {
  1060. FileInputStream fis = new FileInputStream(f1);
  1061. FileOutputStream fos = new FileOutputStream(f2 + "\\" + openId + ".png");
  1062. byte[] b = new byte[1024];
  1063. int i = fis.read(b);
  1064. while (i != -1) {
  1065. fos.write(b, 0, i);
  1066. i = fis.read(b);
  1067. }
  1068. fis.close();
  1069. fos.close();
  1070. }
  1071. } catch (Exception e) {
  1072. e.printStackTrace();
  1073. }
  1074. }
  1075. /**
  1076. * 分页查询分销角色表数据
  1077. *
  1078. * @param request
  1079. * @param response
  1080. * @param pageSize
  1081. * @param pageNO
  1082. * @return
  1083. * @throws Exception
  1084. */
  1085. @RequestMapping("/getDrpRoleList")
  1086. public ModelAndView getDrpRoleList(HttpServletRequest request,
  1087. @RequestParam(value = "pageSize", defaultValue = "6", required = false) Integer pageSize,
  1088. @RequestParam(value = "pageNO", defaultValue = "1", required = false) Integer pageNO) throws Exception {
  1089. ModelAndView mv = new ModelAndView("admin/drp/roleList");
  1090. String text = request.getParameter("text");
  1091. StringBuffer url = new StringBuffer("/admin/drp/getDrpRoleList?pageSize=" + pageSize);
  1092. PlaceRoleInfo drpRoleInfo = new PlaceRoleInfo();
  1093. if (null != text && !"".equals(text)) {
  1094. if (!request.getMethod().equalsIgnoreCase("post")) {
  1095. text = new String(text.getBytes("ISO-8859-1"), "UTF-8");
  1096. }
  1097. drpRoleInfo.setRoleName(text);
  1098. url.append("&text=" + text);
  1099. }
  1100. url.append("&pageNO=");
  1101. drpRoleInfo.getPage().setPageSize(pageSize);
  1102. drpRoleInfo.getPage().setPageNumber(pageNO);
  1103. drpRoleInfo.getPage().initRecordBegin();
  1104. List<PlaceRoleInfo> drpRoleList = drpRoleInfoService.getDrpRoleList(drpRoleInfo);
  1105. mv.addObject("text", text);
  1106. mv.addObject("drpRoleList", drpRoleList);
  1107. mv.addObject("pageNO", pageNO);
  1108. mv.addObject("url", url.toString());
  1109. mv.addObject("pageSize", drpRoleInfoService.selectDrpRoleCount(drpRoleInfo));
  1110. return mv;
  1111. }
  1112. /**
  1113. * 进入分销角色添加页面
  1114. *
  1115. * @param request
  1116. * @param drpRoleInfo
  1117. * @return
  1118. * @throws Exception
  1119. */
  1120. @RequestMapping("/addDrpRole")
  1121. public ModelAndView addDrpRole(HttpServletRequest request) throws Exception {
  1122. ModelAndView mv = new ModelAndView("admin/drp/addDrpRoleInfo");
  1123. return mv;
  1124. }
  1125. /**
  1126. * 添加角色信息
  1127. *
  1128. * @param request
  1129. * @param drpRoleInfo
  1130. * @return
  1131. * @throws Exception
  1132. */
  1133. @RequestMapping("/addDrpRoleInfo")
  1134. public ModelAndView addDrpRoleInfo(HttpServletRequest request, PlaceRoleInfo drpRoleInfo) throws Exception {
  1135. ModelAndView mv = new ModelAndView("admin/msg/msg");
  1136. Integer num = drpRoleInfoService.addDrpRoleInfo(drpRoleInfo);
  1137. if (num > 0) {
  1138. mv.addObject("msgObj", new MessageDTO(true, "恭喜您,操作成功", "分销角色已添加成功,刷新即可!"));
  1139. } else {
  1140. mv.addObject("msgObj", new MessageDTO(false, "对不起,操作有误", "对不起,您刚才的操作流程有误,请按规定填写数据!"));
  1141. }
  1142. return mv;
  1143. }
  1144. /**
  1145. * 跳转到修改分销角色信息页面
  1146. *
  1147. * @param request
  1148. * @param roleId
  1149. * @return
  1150. * @throws Exception
  1151. */
  1152. @RequestMapping("/updateDrpRole")
  1153. public ModelAndView updateDrpRole(HttpServletRequest request,
  1154. @RequestParam(value = "roleId", defaultValue = "", required = false) Integer roleId) throws Exception {
  1155. ModelAndView mv = new ModelAndView("admin/drp/updateDrpRoleInfo");
  1156. if ("".equals(roleId.toString())) {
  1157. return mv;
  1158. }
  1159. PlaceRoleInfo drpRoleInfo = new PlaceRoleInfo();
  1160. drpRoleInfo.setRoleId(roleId);
  1161. drpRoleInfo = drpRoleInfoService.selectDrpRoleInfo(drpRoleInfo);
  1162. mv.addObject("drpRoleInfo", drpRoleInfo);
  1163. return mv;
  1164. }
  1165. /**
  1166. * 修改分销角色数据
  1167. *
  1168. * @param request
  1169. * @param drpRoleInfo
  1170. * @return
  1171. * @throws Exception
  1172. */
  1173. @RequestMapping("/updateDrpRoleInfo")
  1174. public ModelAndView updateDrpRoleInfo(HttpServletRequest request, PlaceRoleInfo placeRoleInfo) throws Exception {
  1175. ModelAndView mv = new ModelAndView("admin/msg/msg");
  1176. if (null == placeRoleInfo.getRoleId() || "".equals(placeRoleInfo.getRoleId().toString())) {
  1177. mv.addObject("msgObj", new MessageDTO(false, "对不起,操作有误", "对不起,您刚才的操作流程有误,请按规定填写数据!"));
  1178. return mv;
  1179. }
  1180. Integer num = drpRoleInfoService.updateDrpRoleInfo(placeRoleInfo);
  1181. if (num > 0) {
  1182. mv.addObject("msgObj", new MessageDTO(true, "恭喜您,操作成功", "分销角色已修改成功,刷新即可!"));
  1183. } else {
  1184. mv.addObject("msgObj", new MessageDTO(false, "对不起,操作有误", "对不起,您刚才的操作流程有误,请按规定填写数据!"));
  1185. }
  1186. return mv;
  1187. }
  1188. /**
  1189. * 修改分销角色状态
  1190. *
  1191. * @param request
  1192. * @return
  1193. * @throws Exception
  1194. */
  1195. @ResponseBody
  1196. @RequestMapping("/updateDrpRoleStatus")
  1197. public String updateDrpRoleStatus(HttpServletRequest request) throws Exception {
  1198. String roleId = request.getParameter("roleId");
  1199. String roleStatus = request.getParameter("roleStatus");
  1200. if (null == roleId || "".equals(roleId)) {
  1201. return "{\"status\":\"修改失败!\"}";
  1202. }
  1203. if ("1".equals(roleStatus)) {
  1204. roleStatus = "2";
  1205. } else if ("2".equals(roleStatus)) {
  1206. roleStatus = "1";
  1207. } else {
  1208. return "{\"status\":\"修改失败!\"}";
  1209. }
  1210. PlaceRoleInfo placeRoleInfo = new PlaceRoleInfo();
  1211. placeRoleInfo.setRoleId(Integer.parseInt(roleId));
  1212. placeRoleInfo.setRoleStatus(Integer.parseInt(roleStatus));
  1213. Integer num = drpRoleInfoService.updateDrpRoleStatus(placeRoleInfo);
  1214. if (num > 0) {
  1215. return "{\"status\":\"修改成功!\"}";
  1216. } else {
  1217. return "{\"status\":\"修改失败!\"}";
  1218. }
  1219. }
  1220. /**
  1221. * 上传Excel 用于批量修改excel
  1222. *
  1223. * @param request
  1224. * @param response
  1225. */
  1226. @ResponseBody
  1227. @RequestMapping("/upLoadExcel")
  1228. public void upLoadExcel(@RequestParam(value = "file", required = false) MultipartFile file,
  1229. HttpServletRequest request, ModelMap model, HttpServletResponse response) throws Exception {
  1230. String path = request.getSession().getServletContext().getRealPath("/common/excelUpload");
  1231. String fileName = file.getOriginalFilename();
  1232. // System.out.println(path);
  1233. File targetFile = new File(path, fileName);
  1234. if (!targetFile.exists()) {
  1235. targetFile.mkdirs();
  1236. }
  1237. // 保存
  1238. try {
  1239. file.transferTo(targetFile);
  1240. List<PlaceInfo> placeInfos = readExcel(path + File.separator + fileName);
  1241. System.err.println(placeInfos);
  1242. int i = placeInfoService.batchUpdate(placeInfos);
  1243. targetFile.delete();
  1244. response.getWriter().write("<script>parent.msg('导入成功!')</script>");
  1245. } catch (Exception e) {
  1246. response.getWriter().write("<script>parent.msg('导入失败!')</script>");
  1247. e.printStackTrace();
  1248. }
  1249. }
  1250. // 通过路径读取excel表的数据
  1251. public List<PlaceInfo> readExcel(String pathname) {
  1252. List<PlaceInfo> placeInfos = new ArrayList<PlaceInfo>();
  1253. // String pathname="D:/Backup/Downloads/iamberry.xls";
  1254. List list = new ArrayList();
  1255. try {
  1256. Workbook rwb = Workbook.getWorkbook(new File(pathname));
  1257. Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet("iamberry-sheet")
  1258. int clos = rs.getColumns();// 得到所有的列
  1259. int rows = rs.getRows();// 得到所有的行
  1260. // System.out.println(clos+" rows:"+rows);
  1261. for (int i = 1; i < rows; i++) {
  1262. PlaceInfo placeInfo = new PlaceInfo();
  1263. for (int j = 0; j < clos; j++) {
  1264. placeInfo.setId(Integer.parseInt(rs.getCell(j, i).getContents()));
  1265. placeInfo.setName(rs.getCell(j + 1, i).getContents());
  1266. placeInfo.setUserName(rs.getCell(j + 2, i).getContents());
  1267. String areaName = rs.getCell(j + 3, i).getContents();
  1268. placeInfo.setAreaName(areaName.endsWith("") ? null : areaName);
  1269. /*
  1270. * placeInfo.setHasQrcode(Integer.parseInt(rs.getCell(j+4,
  1271. * i).getContents()));
  1272. * placeInfo.setPlacePid(Integer.parseInt(rs.getCell(j+5,
  1273. * i).getContents()));
  1274. * placeInfo.setRoleId(Integer.parseInt(rs.getCell(j+6,
  1275. * i).getContents()));
  1276. */
  1277. placeInfo.setTel(rs.getCell(j + 4, i).getContents());
  1278. placeInfo.setAddr(rs.getCell(j + 5, i).getContents());
  1279. placeInfo.setRemark(rs.getCell(j + 7, i).getContents());
  1280. // System.out.println(placeInfo.toString());
  1281. break;
  1282. }
  1283. placeInfos.add(placeInfo);
  1284. }
  1285. rwb.close();
  1286. } catch (Exception e) {
  1287. e.printStackTrace();
  1288. }
  1289. return placeInfos;
  1290. }
  1291. /**
  1292. * 上传Excel 用于批量添加excel
  1293. *
  1294. * @param request
  1295. * @param response
  1296. */
  1297. @ResponseBody
  1298. @RequestMapping("/addLoadExcel")
  1299. public void addLoadExcel(@RequestParam(value = "file2", required = false) MultipartFile file,
  1300. HttpServletRequest request, ModelMap model, HttpServletResponse response) throws Exception {
  1301. String path = request.getSession().getServletContext().getRealPath("/common/excelUpload");
  1302. String fileName = file.getOriginalFilename();
  1303. // System.out.println(path);
  1304. File targetFile = new File(path, fileName);
  1305. if (!targetFile.exists()) {
  1306. targetFile.mkdirs();
  1307. }
  1308. // 保存
  1309. try {
  1310. file.transferTo(targetFile);
  1311. boolean msg = readExcel2(path + File.separator + fileName);
  1312. if(msg){
  1313. targetFile.delete();
  1314. response.getWriter().write("<script>parent.msg('导入成功!')</script>");
  1315. }else{
  1316. response.getWriter().write("<script>parent.msg('导入失败!')</script>");
  1317. }
  1318. } catch (Exception e) {
  1319. response.getWriter().write("<script>parent.msg('导入失败!')</script>");
  1320. e.printStackTrace();
  1321. }
  1322. }
  1323. // 通过路径读取excel表的数据
  1324. public boolean readExcel2(String pathname) {
  1325. List<PlaceInfo> placeInfos = new ArrayList<PlaceInfo>();
  1326. try {
  1327. Workbook rwb = Workbook.getWorkbook(new File(pathname));
  1328. Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet("iamberry-sheet")
  1329. int clos = rs.getColumns();// 得到所有的列
  1330. int rows = rs.getRows();// 得到所有的行
  1331. String partnerId = "";//合夥人id
  1332. Integer storeId = 0;//門店id
  1333. partnerId = rs.getCell(0, 0).getContents();//得到合夥人id
  1334. for (int i = 1; i < rows; i++) {
  1335. PlaceInfo placeInfo = new PlaceInfo();
  1336. for (int j = 0; j < clos; j++) {
  1337. //获取某一列所有数据
  1338. //获取一列的第一格数据判断是否是门店或vip会员
  1339. String isStoresMembers = rs.getCell(j, i).getContents();
  1340. String name = rs.getCell(j+1, i).getContents();//门店名称/vip会员名称
  1341. //如果第二格为空这表示此行无数据并不在往后取数据
  1342. if(name == null || name.equals("")){
  1343. break;
  1344. }
  1345. String nickName = rs.getCell(j+2, i).getContents();//门店姓名/vip会员姓名
  1346. String tel = rs.getCell(j+3, i).getContents();//门店手机号/vip会员手机号
  1347. Integer isPerfect = Integer.valueOf(rs.getCell(j+4, i).getContents());//是否已完善信息
  1348. String city = rs.getCell(j+5, i).getContents();//门店地址/vip会员地址
  1349. String note = rs.getCell(j+6, i).getContents();//门店备注/vip会员备注
  1350. //如果不为空表示为门店、反之为vip会员
  1351. placeInfo.setName(name);
  1352. placeInfo.setUserName(nickName);
  1353. placeInfo.setAddr(city);
  1354. placeInfo.setTemplateId(23);
  1355. placeInfo.setTel(tel);
  1356. placeInfo.setStatus(1);
  1357. placeInfo.setCreateDate(new Date());
  1358. placeInfo.setRemark(note);
  1359. placeInfo.setPlaceInfoStus(isPerfect);
  1360. if(isStoresMembers != null&& !isStoresMembers.equals("")){
  1361. //完善门店信息
  1362. placeInfo.setPlacePid(Integer.valueOf(partnerId));
  1363. placeInfo.setHasQrcode(1);// 1表示没有二维码
  1364. placeInfo.setRoleId(48);
  1365. Map<String, Object> msgMap = addPlaceInfoDeal(placeInfo);//添加门店
  1366. PlaceInfo Info = (PlaceInfo) msgMap.get("data");
  1367. storeId = Info.getId();//保存门店id为全局变量
  1368. }else{//vip会员
  1369. placeInfo.setPlacePid(storeId);//门店id
  1370. placeInfo.setHasQrcode(2);// 2表示有二维码
  1371. placeInfo.setRoleId(51);
  1372. addPlaceInfoDeal(placeInfo);//添加vip会员
  1373. }
  1374. break;
  1375. }
  1376. }
  1377. rwb.close();
  1378. } catch (Exception e) {
  1379. e.printStackTrace();
  1380. }
  1381. return true;
  1382. }
  1383. /**
  1384. * list view
  1385. *
  1386. * @return
  1387. */
  1388. @RequestMapping("/apply/list")
  1389. public ModelAndView list(@RequestParam(value = "pageNO", defaultValue = "1") Integer pageNO,
  1390. @RequestParam(value = "pageSize", required = false) Integer pageSize, HttpServletRequest request) {
  1391. ModelAndView mv = new ModelAndView("admin/drp/applyList");
  1392. // 分页查找
  1393. List<ApplyPlaceLogs> news = placeInfoService.selectApplyPlaceLogs(pageNO, 10);
  1394. mv.addObject("list", news);
  1395. // 是否已经get过pageSize了?
  1396. if (pageSize == null) {
  1397. pageSize = placeInfoService.getCount(10);
  1398. }
  1399. // 分页数据
  1400. mv.addObject("pageNO", pageNO);
  1401. mv.addObject("pageSize", pageSize);
  1402. mv.addObject("url",
  1403. new StringBuilder(StringUtils.replace(request.getRequestURI(), request.getContextPath(), ""))
  1404. .append("?pageSize=").append(pageSize).append("&pageNO="));
  1405. return mv;
  1406. }
  1407. /**
  1408. * 审核操作
  1409. *
  1410. * @return
  1411. */
  1412. @RequestMapping(value = "/apply/{id}/{status}", method = RequestMethod.POST)
  1413. @ResponseBody
  1414. public JsonBack updatePlaceInfo(@PathVariable("id") Integer id, @PathVariable("status") Integer status) {
  1415. JsonBack back = new JsonBack();
  1416. if (status == 2 || status == 3) {
  1417. back.setSuccess(placeInfoService.handlerApplyLogs(id, status));
  1418. } else {
  1419. back.setSuccess(false);
  1420. back.setResponseData("状态不对!");
  1421. }
  1422. return back;
  1423. }
  1424. /**
  1425. * 分页查询我要代理申请记录
  1426. *
  1427. * @param request
  1428. * @param response
  1429. * @param pageSize
  1430. * @param pageNO
  1431. * @return
  1432. * @throws Exception
  1433. */
  1434. @RequestMapping("/applyAgentList")
  1435. public ModelAndView applyAgentList(HttpServletRequest request,
  1436. @RequestParam(value = "pageSize", defaultValue = "6", required = false) Integer pageSize,
  1437. @RequestParam(value = "pageNO", defaultValue = "1", required = false) Integer pageNO) throws Exception {
  1438. ModelAndView mv = new ModelAndView("admin/drp/applyAgentList");
  1439. String text = request.getParameter("text");
  1440. StringBuffer url = new StringBuffer("/admin/drp/applyAgentList?pageSize=" + pageSize);
  1441. ApplyUserInfo applyUserInfo = new ApplyUserInfo();
  1442. if (null != text && !"".equals(text)) {
  1443. if (!request.getMethod().equalsIgnoreCase("post")) {
  1444. text = new String(text.getBytes("ISO-8859-1"), "UTF-8");
  1445. }
  1446. applyUserInfo.setUserName(text);
  1447. url.append("&text=" + text);
  1448. }
  1449. url.append("&pageNO=");
  1450. applyUserInfo.getPage().setPageSize(pageSize);
  1451. applyUserInfo.getPage().setPageNumber(pageNO);
  1452. applyUserInfo.getPage().initRecordBegin();
  1453. List<ApplyUserInfo> applyUserList = placeInfoService.getApplyAgentList(applyUserInfo);
  1454. mv.addObject("text", text);
  1455. mv.addObject("applyUserList", applyUserList);
  1456. mv.addObject("pageNO", pageNO);
  1457. mv.addObject("url", url.toString());
  1458. mv.addObject("pageSize", placeInfoService.getApplyAgentCount(applyUserInfo));
  1459. return mv;
  1460. }
  1461. }