MerchantServiceImpl.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. package com.poteviohealth.ym.ipos.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.alibaba.fastjson.TypeReference;
  5. import com.poteviohealth.cgp.common.facade.cache.CacheService;
  6. import com.poteviohealth.cgp.common.filter.TokenContext;
  7. import com.poteviohealth.cgp.common.integrated.OperatorIdParams;
  8. import com.poteviohealth.cgp.common.integrated.customer.CustomerFeignClient;
  9. import com.poteviohealth.cgp.common.integrated.partner.PartnerFeignClient;
  10. import com.poteviohealth.cgp.common.model.VaultsResponse;
  11. import com.poteviohealth.ym.ipos.common.Basic;
  12. import com.poteviohealth.ym.ipos.model.BasicConfiguration;
  13. import com.poteviohealth.ym.ipos.model.back.BaseBack;
  14. import com.poteviohealth.ym.ipos.model.merchant.*;
  15. import com.poteviohealth.ym.ipos.model.merchant.back.ImageListBack;
  16. import com.poteviohealth.ym.ipos.model.merchant.back.PictureBack;
  17. import com.poteviohealth.ym.ipos.model.merchant.back.UserBack;
  18. import com.poteviohealth.ym.ipos.model.merchant.back.UserSearchBack;
  19. import com.poteviohealth.ym.ipos.model.merchant.detail.*;
  20. import com.poteviohealth.ym.ipos.model.merchant.dto.ImageDto;
  21. import com.poteviohealth.ym.ipos.model.merchant.dto.ImageListDto;
  22. import com.poteviohealth.ym.ipos.model.merchant.dto.UserDto;
  23. import com.poteviohealth.ym.ipos.model.payment.dto.BindDto;
  24. import com.poteviohealth.ym.ipos.service.IAreaService;
  25. import com.poteviohealth.ym.ipos.service.IMerchantService;
  26. import com.poteviohealth.ym.ipos.service.IPaymentService;
  27. import com.poteviohealth.ym.ipos.utils.YmUtil;
  28. import lombok.extern.log4j.Log4j2;
  29. import org.apache.commons.lang3.StringUtils;
  30. import org.springframework.stereotype.Service;
  31. import javax.annotation.Resource;
  32. import java.math.BigDecimal;
  33. import java.util.List;
  34. import java.util.stream.Collectors;
  35. /**
  36. * 商户入驻接口实现
  37. * @author Qin
  38. */
  39. @Service
  40. @Log4j2
  41. public class MerchantServiceImpl implements IMerchantService {
  42. @Resource
  43. private PartnerFeignClient partnerFeignClient;
  44. @Resource
  45. private CustomerFeignClient customerFeignClient;
  46. @Resource
  47. private IAreaService areaService;
  48. @Resource
  49. private IPaymentService paymentService;
  50. @Resource
  51. private CacheService cacheService;
  52. /**
  53. * 上传图片
  54. * @param dto
  55. * @return
  56. */
  57. @Override
  58. public VaultsResponse<String> merchantPicture(ImageDto dto){
  59. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  60. Picture p = new Picture();
  61. p.setSystem_id(bc.getSystemId());
  62. p.setIsspid(bc.getPid());
  63. PictureDetail detail = new PictureDetail();
  64. detail.setType(dto.getType());
  65. detail.setImage_name(dto.getName());
  66. detail.setImage_content(dto.getBase64Str());
  67. p.setMerchant_picture_request(detail);
  68. PictureBack back = null;
  69. try {
  70. back = (PictureBack) YmUtil.resultBack(p,new PictureBack());
  71. } catch (IllegalAccessException e) {
  72. e.printStackTrace();
  73. return VaultsResponse.failed(e.getMessage());
  74. }
  75. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  76. return VaultsResponse.success(back.getId());
  77. }
  78. return VaultsResponse.failed(back.getResult().getComment());
  79. }
  80. /**
  81. * 商户新增/修改开户入驻
  82. * @param dto
  83. * @return
  84. */
  85. @Override
  86. public VaultsResponse merchantCreateOpen(UserDto dto) {
  87. BasicConfiguration basicConfig = Basic.getSystemParameter(TokenContext.cureOperatorId());
  88. dto.setRemained_amt(dto.getRemained_amt()*100);
  89. VaultsResponse<UserSearchBack> vaultsResponse = this.merchantQuery(dto.getPhone(),null);
  90. if(!vaultsResponse.validate()){
  91. log.info("UserSearchBack==="+vaultsResponse);
  92. return vaultsResponse;
  93. }
  94. UserSearchBack searchBack = vaultsResponse.getData();
  95. Integer status = 0;
  96. if(searchBack != null){
  97. status = Integer.parseInt(searchBack.getIncoming_status());
  98. }
  99. if(StringUtils.isEmpty(dto.getIncoming_status())){
  100. dto.setIncoming_status(status.toString());
  101. }
  102. if(StringUtils.isEmpty(dto.getMerchant_id())){
  103. if(searchBack != null){
  104. dto.setMerchant_id(searchBack.getMerchant_id());
  105. //return VaultsResponse.failed("手机号码已被注册");
  106. }
  107. //添加商户
  108. VaultsResponse<String> createVault = this.merchantCreate(dto);
  109. if(!createVault.validate()){
  110. log.info("createVault==="+createVault);
  111. return createVault;
  112. }
  113. dto.setMerchant_id(createVault.getData());
  114. }else{
  115. if(searchBack != null && !searchBack.getMerchant_id().equals(dto.getMerchant_id())){
  116. return VaultsResponse.failed("手机号码已被注册");
  117. }
  118. }
  119. if(dto.getIncoming_status().equals("2")){
  120. //修改开户/入驻信息
  121. VaultsResponse<String> indvmodifyVault = this.modifyVault(dto);
  122. if(!indvmodifyVault.validate()){
  123. log.info("indvmodifyVault==="+indvmodifyVault);
  124. return indvmodifyVault;
  125. }
  126. VaultsResponse<String> openModifyVault = this.merchantOpenModify(dto);
  127. VaultsResponse<String> stringVault = updateMerchantId(dto.getId(), dto.getSourceId(), dto.getMerchant_id(),2,dto.getRemained_amt(),basicConfig.getCode(),dto.getProportion());
  128. if(!stringVault.validate()){
  129. log.info("stringVault==="+stringVault);
  130. return stringVault;
  131. }
  132. if(dto.getSourceId().equals(1)){
  133. BindDto bd = new BindDto();
  134. bd.setAppId(stringVault.getData());
  135. bd.setPosId(basicConfig.getCode());
  136. bd.setStoreId(dto.getId().toString());
  137. bd.setName("("+basicConfig.getCode()+")"+dto.getMerchant_short_name());
  138. //修改门店信息
  139. if(!dto.getMerchant_short_name().equals(searchBack.getBase_merchant_short_name())){
  140. VaultsResponse changeVr = paymentService.changeBindPos(bd);
  141. if(!changeVr.validate()){
  142. return changeVr;
  143. }
  144. }
  145. //终端绑定交易
  146. return paymentService.bindPos(bd);
  147. }
  148. log.info("openModifyVault==="+openModifyVault);
  149. return openModifyVault;
  150. }else{
  151. if(dto.getIncoming_status().equals("0") || dto.getIncoming_status().equals("-1")){
  152. //未开户或开户失败时
  153. if(dto.getType().equals("3")){
  154. //个人
  155. VaultsResponse<String> indvregisterVault = this.merchantIndvregister(dto);
  156. if(!indvregisterVault.validate()){
  157. log.info("indvregisterVault==="+indvregisterVault);
  158. return indvregisterVault;
  159. }
  160. }else{
  161. //商户
  162. VaultsResponse<String> entregisterVault = this.merchantEntregister(dto);
  163. if(!entregisterVault.validate()){
  164. log.info("entregisterVault==="+entregisterVault);
  165. return entregisterVault;
  166. }
  167. }
  168. updateMerchantId(dto.getId(), dto.getSourceId(), dto.getMerchant_id(),3,dto.getRemained_amt(),basicConfig.getCode(),dto.getProportion());
  169. }else{
  170. VaultsResponse<String> indvmodifyVault = this.modifyVault(dto);
  171. if(!indvmodifyVault.validate()){
  172. log.info("indvmodifyVault==="+indvmodifyVault);
  173. return indvmodifyVault;
  174. }
  175. }
  176. //入驻
  177. VaultsResponse<String> openVault = this.merchantOpen(dto);
  178. if(!openVault.validate()){
  179. log.info("openVault==="+openVault);
  180. return openVault;
  181. }
  182. // if(status != 2){
  183. VaultsResponse<String> stringVault = updateMerchantId(dto.getId(), dto.getSourceId(), dto.getMerchant_id(),2,dto.getRemained_amt(),basicConfig.getCode(),dto.getProportion());
  184. if(!stringVault.validate()){
  185. log.info("stringVault==="+stringVault);
  186. return stringVault;
  187. }
  188. if(dto.getSourceId().equals(1)){
  189. //终端绑定交易
  190. BindDto bd = new BindDto();
  191. bd.setAppId(stringVault.getData());
  192. bd.setPosId(basicConfig.getCode());
  193. bd.setStoreId(dto.getId().toString());
  194. bd.setName("("+basicConfig.getCode()+")"+dto.getMerchant_short_name());
  195. return paymentService.bindPos(bd);
  196. }
  197. // }
  198. }
  199. return VaultsResponse.success();
  200. }
  201. private VaultsResponse<String> modifyVault(UserDto dto) {
  202. //修改开户信息
  203. if(dto.getType().equals("3")){
  204. //个人
  205. VaultsResponse<String> indvmodifyVault = this.merchantIndvmodify(dto);
  206. if(!indvmodifyVault.validate()){
  207. return indvmodifyVault;
  208. }
  209. }else{
  210. //商户
  211. VaultsResponse<String> entmodifyVault = this.merchantEntmodify(dto);
  212. if(!entmodifyVault.validate()){
  213. return entmodifyVault;
  214. }
  215. }
  216. return VaultsResponse.success();
  217. }
  218. /**
  219. * 添加分账商户
  220. * @param dto
  221. * @return
  222. */
  223. private VaultsResponse merchantCreate(UserDto dto) {
  224. User user = new User();
  225. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  226. user.setSystem_id(bc.getSystemId());
  227. user.setIsspid(bc.getPid());
  228. UserDetail detail = new UserDetail();
  229. detail.setType(dto.getType());
  230. detail.setMerchant_short_name(dto.getMerchant_short_name());
  231. detail.setMerchant_name(dto.getMerchant_name());
  232. detail.setPhone(dto.getPhone());
  233. user.setMerchant_create_request(detail);
  234. UserBack back = null;
  235. try {
  236. back = (UserBack) YmUtil.resultBack(user,new UserBack());
  237. } catch (IllegalAccessException e) {
  238. e.printStackTrace();
  239. return VaultsResponse.failed(e.getMessage());
  240. }
  241. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  242. VaultsResponse vaultsResponse = updateMerchantId(dto.getId(), dto.getSourceId(), back.getMerchant_id(),0,dto.getRemained_amt(),bc.getCode(),dto.getProportion());
  243. if(!vaultsResponse.validate()){
  244. return vaultsResponse;
  245. }
  246. return VaultsResponse.success(back.getMerchant_id());
  247. }
  248. return VaultsResponse.failed(back.getResult().getComment());
  249. }
  250. private VaultsResponse updateMerchantId(Integer id, Integer source, String merchantId, Integer status, Long remainedAmt, String code, BigDecimal proportion) {
  251. VaultsResponse vaultsResponse;
  252. OperatorIdParams operatorIdParams = new OperatorIdParams();
  253. operatorIdParams.setOperatorId(TokenContext.cureOperatorId());
  254. operatorIdParams.setId(id.toString());
  255. operatorIdParams.setMerchantId(merchantId);
  256. operatorIdParams.setSource(source);
  257. operatorIdParams.setStatus(status);
  258. operatorIdParams.setCode(code);
  259. operatorIdParams.setRemainedAmt(remainedAmt);
  260. if(source.equals(3)){
  261. vaultsResponse = customerFeignClient.updateMerchantId(operatorIdParams);
  262. }else{
  263. if(proportion != null){
  264. operatorIdParams.setProportion(proportion.divide(new BigDecimal(100.0)));
  265. }
  266. vaultsResponse = partnerFeignClient.updateMerchantId(operatorIdParams);
  267. }
  268. return vaultsResponse;
  269. }
  270. /**
  271. * 个人分账商户开户
  272. * @param dto
  273. * @return
  274. */
  275. private VaultsResponse merchantIndvregister(UserDto dto){
  276. IndvregisterAdd iAdd = new IndvregisterAdd();
  277. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  278. iAdd.setSystem_id(bc.getSystemId());
  279. iAdd.setIsspid(bc.getPid());
  280. IndvregisterAddDetail detail = new IndvregisterAddDetail();
  281. detail.setMerchant_id(dto.getMerchant_id());
  282. detail.setIdentity_begin_date(dto.getIdentity_begin_date());
  283. if(StringUtils.isNotEmpty(dto.getIdentity_end_date())){
  284. detail.setIdentity_end_date(dto.getIdentity_end_date());
  285. }
  286. detail.setIdentity_validity_type(dto.getIdentity_validity_type());
  287. detail.setContact_phone(dto.getContact_phone());
  288. detail.setCert_photo_a(this.merchantPicture(dto.getCert_photo_a()).getData());
  289. detail.setCert_photo_b(this.merchantPicture(dto.getCert_photo_b()).getData());
  290. detail.setLegal_name(dto.getLegal_name());
  291. detail.setIdentity_no(dto.getIdentity_no());
  292. detail.setMerchant_name(dto.getMerchant_name());
  293. //detail.setIdentity_type(dto.getIdentity_type());
  294. iAdd.setMerchant_indvregister_request(detail);
  295. BaseBack back = null;
  296. try {
  297. back = (BaseBack) YmUtil.resultBack(iAdd,new BaseBack());
  298. } catch (IllegalAccessException e) {
  299. e.printStackTrace();
  300. return VaultsResponse.failed(e.getMessage());
  301. }
  302. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  303. return VaultsResponse.success();
  304. }
  305. return VaultsResponse.failed(back.getResult().getComment());
  306. }
  307. /**
  308. * 个人分账商户修改
  309. * @param dto
  310. * @return
  311. */
  312. private VaultsResponse merchantIndvmodify(UserDto dto){
  313. IndvregisterUpdate iUpdate = new IndvregisterUpdate();
  314. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  315. iUpdate.setSystem_id(bc.getSystemId());
  316. iUpdate.setIsspid(bc.getPid());
  317. IndvregisterUpdateDetail iUpdateDetail = new IndvregisterUpdateDetail();
  318. iUpdateDetail.setMerchant_id(dto.getMerchant_id());
  319. iUpdateDetail.setIdentity_begin_date(dto.getIdentity_begin_date());
  320. if(StringUtils.isNotEmpty(dto.getIdentity_end_date())){
  321. iUpdateDetail.setIdentity_end_date(dto.getIdentity_end_date());
  322. }
  323. iUpdateDetail.setIdentity_validity_type(dto.getIdentity_validity_type());
  324. iUpdateDetail.setContact_phone(dto.getContact_phone());
  325. if(StringUtils.isEmpty(dto.getCert_photo_a().getBase64Str())){
  326. for (ImageListDto imageListDto : dto.getImage_list()) {
  327. if(imageListDto.getFile_type().equals("01")){
  328. iUpdateDetail.setCert_photo_a(imageListDto.getFile_id());
  329. break;
  330. }
  331. }
  332. }else{
  333. iUpdateDetail.setCert_photo_a(this.merchantPicture(dto.getCert_photo_a()).getData());
  334. }
  335. if(StringUtils.isEmpty(dto.getCert_photo_b().getBase64Str())){
  336. for (ImageListDto imageListDto : dto.getImage_list()) {
  337. if(imageListDto.getFile_type().equals("02")){
  338. iUpdateDetail.setCert_photo_b(imageListDto.getFile_id());
  339. break;
  340. }
  341. }
  342. }else{
  343. iUpdateDetail.setCert_photo_b(this.merchantPicture(dto.getCert_photo_b()).getData());
  344. }
  345. iUpdate.setMerchant_indvmodify_request(iUpdateDetail);
  346. BaseBack back = null;
  347. try {
  348. back = (BaseBack) YmUtil.resultBack(iUpdate,new BaseBack());
  349. } catch (IllegalAccessException e) {
  350. e.printStackTrace();
  351. return VaultsResponse.failed(e.getMessage());
  352. }
  353. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  354. return VaultsResponse.success();
  355. }
  356. return VaultsResponse.failed(back.getResult().getComment());
  357. }
  358. /**
  359. * 企业分账商户开户
  360. * @param dto
  361. * @return
  362. */
  363. private VaultsResponse merchantEntregister(UserDto dto){
  364. EntregisterAdd iAdd = new EntregisterAdd();
  365. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  366. iAdd.setSystem_id(bc.getSystemId());
  367. iAdd.setIsspid(bc.getPid());
  368. EntregisterAddDetail detail = new EntregisterAddDetail();
  369. detail.setMerchant_id(dto.getMerchant_id());
  370. detail.setLicense_begin_date(dto.getLicense_begin_date());
  371. if(StringUtils.isNotEmpty(dto.getLicense_end_date())){
  372. detail.setLicense_end_date(dto.getLicense_end_date());
  373. }
  374. detail.setLicense_validity_type(dto.getLicense_validity_type());
  375. List<String> areaList = areaService.getAreaCode(dto.getLicense_area());
  376. detail.setLicense_province_code(areaList.get(0));
  377. detail.setLicense_city_code(areaList.get(1));
  378. detail.setLicense_area_code(areaList.get(2));
  379. detail.setLicense_address(dto.getLicense_address());
  380. detail.setLegal_name(dto.getLegal_name());
  381. detail.setIdentity_no(dto.getIdentity_no());
  382. detail.setIdentity_begin_date(dto.getIdentity_begin_date());
  383. if(StringUtils.isNotEmpty(dto.getIdentity_end_date())){
  384. detail.setIdentity_end_date(dto.getIdentity_end_date());
  385. }
  386. detail.setIdentity_validity_type(dto.getIdentity_validity_type());
  387. detail.setContact_name(dto.getContact_name());
  388. detail.setContact_phone(dto.getContact_phone());
  389. detail.setLicense_photo(this.merchantPicture(dto.getLicense_photo()).getData());
  390. detail.setCert_photo_a(this.merchantPicture(dto.getCert_photo_a()).getData());
  391. detail.setCert_photo_b(this.merchantPicture(dto.getCert_photo_b()).getData());
  392. detail.setMerchant_name(dto.getMerchant_name());
  393. detail.setLicense_code(dto.getLicense_code());
  394. //detail.setIdentity_type(dto.getIdentity_type());
  395. iAdd.setMerchant_entregister_request(detail);
  396. BaseBack back = null;
  397. try {
  398. back = (BaseBack) YmUtil.resultBack(iAdd,new BaseBack());
  399. } catch (IllegalAccessException e) {
  400. e.printStackTrace();
  401. return VaultsResponse.failed(e.getMessage());
  402. }
  403. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  404. return VaultsResponse.success();
  405. }
  406. return VaultsResponse.failed(back.getResult().getComment());
  407. }
  408. /**
  409. * 企业分账商户修改
  410. * @param dto
  411. * @return
  412. */
  413. private VaultsResponse merchantEntmodify(UserDto dto){
  414. EntregisterUpdate iUpdate = new EntregisterUpdate();
  415. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  416. iUpdate.setSystem_id(bc.getSystemId());
  417. iUpdate.setIsspid(bc.getPid());
  418. EntregisterUpdateDetail iUpdateDetail = new EntregisterUpdateDetail();
  419. iUpdateDetail.setMerchant_id(dto.getMerchant_id());
  420. iUpdateDetail.setLicense_begin_date(dto.getLicense_begin_date());
  421. if(StringUtils.isNotEmpty(dto.getLicense_end_date())){
  422. iUpdateDetail.setLicense_end_date(dto.getLicense_end_date());
  423. }
  424. iUpdateDetail.setLicense_validity_type(dto.getLicense_validity_type());
  425. List<String> areaList = areaService.getAreaCode(dto.getLicense_area());
  426. iUpdateDetail.setLicense_province_code(areaList.get(0));
  427. iUpdateDetail.setLicense_city_code(areaList.get(1));
  428. iUpdateDetail.setLicense_area_code(areaList.get(2));
  429. iUpdateDetail.setLicense_address(dto.getLicense_address());
  430. iUpdateDetail.setLegal_name(dto.getLegal_name());
  431. iUpdateDetail.setIdentity_no(dto.getIdentity_no());
  432. iUpdateDetail.setIdentity_begin_date(dto.getIdentity_begin_date());
  433. if(StringUtils.isNotEmpty(dto.getIdentity_end_date())){
  434. iUpdateDetail.setIdentity_end_date(dto.getIdentity_end_date());
  435. }
  436. iUpdateDetail.setIdentity_validity_type(dto.getIdentity_validity_type());
  437. iUpdateDetail.setContact_name(dto.getContact_name());
  438. iUpdateDetail.setContact_phone(dto.getContact_phone());
  439. if(StringUtils.isEmpty(dto.getLicense_photo().getBase64Str())){
  440. for (ImageListDto imageListDto : dto.getImage_list()) {
  441. if(imageListDto.getFile_type().equals("03")){
  442. iUpdateDetail.setLicense_photo(imageListDto.getFile_id());
  443. break;
  444. }
  445. }
  446. }else{
  447. iUpdateDetail.setLicense_photo(this.merchantPicture(dto.getLicense_photo()).getData());
  448. }
  449. if(StringUtils.isEmpty(dto.getCert_photo_a().getBase64Str())){
  450. for (ImageListDto imageListDto : dto.getImage_list()) {
  451. if(imageListDto.getFile_type().equals("01")){
  452. iUpdateDetail.setCert_photo_a(imageListDto.getFile_id());
  453. break;
  454. }
  455. }
  456. }else{
  457. iUpdateDetail.setCert_photo_a(this.merchantPicture(dto.getCert_photo_a()).getData());
  458. }
  459. if(StringUtils.isEmpty(dto.getCert_photo_b().getBase64Str())){
  460. for (ImageListDto imageListDto : dto.getImage_list()) {
  461. if(imageListDto.getFile_type().equals("02")){
  462. iUpdateDetail.setCert_photo_b(imageListDto.getFile_id());
  463. break;
  464. }
  465. }
  466. }else{
  467. iUpdateDetail.setCert_photo_b(this.merchantPicture(dto.getCert_photo_b()).getData());
  468. }
  469. iUpdate.setMerchant_entmodify_request(iUpdateDetail);
  470. BaseBack back = null;
  471. try {
  472. back = (BaseBack) YmUtil.resultBack(iUpdate,new BaseBack());
  473. } catch (IllegalAccessException e) {
  474. e.printStackTrace();
  475. return VaultsResponse.failed(e.getMessage());
  476. }
  477. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  478. return VaultsResponse.success();
  479. }
  480. return VaultsResponse.failed(back.getResult().getComment());
  481. }
  482. /**
  483. * 分账商户业务入驻
  484. * @param dto
  485. * @return
  486. */
  487. private VaultsResponse merchantOpen(UserDto dto){
  488. OpenAdd openAdd = new OpenAdd();
  489. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  490. openAdd.setSystem_id(bc.getSystemId());
  491. openAdd.setIsspid(bc.getPid());
  492. openAdd.setMerchant_open_request(this.fill(dto));
  493. BaseBack back = null;
  494. try {
  495. back = (BaseBack) YmUtil.resultBack(openAdd,new BaseBack());
  496. } catch (IllegalAccessException e) {
  497. e.printStackTrace();
  498. return VaultsResponse.failed(e.getMessage());
  499. }
  500. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  501. return VaultsResponse.success(back);
  502. }else if(YmUtil.ERROR.equals(back.getResult().getId())){
  503. return VaultsResponse.failed(back.getResult().getComment());
  504. }
  505. return VaultsResponse.failed();
  506. }
  507. /**
  508. * 入驻数据填充
  509. * @param dto
  510. * @return
  511. */
  512. private OpenDetail fill(UserDto dto){
  513. OpenDetail detail = new OpenDetail();
  514. detail.setMerchant_id(dto.getMerchant_id());
  515. detail.setSettle_type(dto.getSettle_type());
  516. /* detail.setSettlement_way(dto.getSettlement_way());
  517. detail.setWithdraw_way(dto.getWithdraw_way());*/
  518. detail.setCard_no(dto.getCard_no());
  519. detail.setParent_bank_name(dto.getParent_bank_name());
  520. detail.setParent_bank_code(dto.getParent_bank_code());
  521. List<String> areaList = areaService.getAreaCode(dto.getBank_area());
  522. detail.setProvince(areaList.get(0));
  523. detail.setCity(areaList.get(1));
  524. detail.setBranch_bank_code(dto.getBranch_bank_code());
  525. detail.setBranch_bank_name(dto.getBranch_bank_name());
  526. if(StringUtils.isEmpty(dto.getSettle_photo_a().getBase64Str())){
  527. for (ImageListDto imageListDto : dto.getImage_list()) {
  528. if(imageListDto.getFile_type().equals("13")){
  529. detail.setSettle_photo_a(imageListDto.getFile_id());
  530. break;
  531. }
  532. }
  533. }else{
  534. detail.setSettle_photo_a(this.merchantPicture(dto.getSettle_photo_a()).getData());
  535. }
  536. if(StringUtils.isEmpty(dto.getSettle_photo_b().getBase64Str())){
  537. for (ImageListDto imageListDto : dto.getImage_list()) {
  538. if(imageListDto.getFile_type().equals("14")){
  539. detail.setSettle_photo_b(imageListDto.getFile_id());
  540. break;
  541. }
  542. }
  543. }else{
  544. detail.setSettle_photo_b(this.merchantPicture(dto.getSettle_photo_b()).getData());
  545. }
  546. detail.setRemained_amt(dto.getRemained_amt());
  547. detail.setSettle_abstract(dto.getSettle_abstract());
  548. return detail;
  549. }
  550. /**
  551. * 分账商户业务入驻修改
  552. * @param dto
  553. * @return
  554. */
  555. private VaultsResponse merchantOpenModify(UserDto dto){
  556. OpenUpdate openUpdate = new OpenUpdate();
  557. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  558. openUpdate.setSystem_id(bc.getSystemId());
  559. openUpdate.setIsspid(bc.getPid());
  560. openUpdate.setMerchant_openmodify_request(this.fill(dto));
  561. BaseBack back = null;
  562. try {
  563. back = (BaseBack) YmUtil.resultBack(openUpdate,new BaseBack());
  564. } catch (IllegalAccessException e) {
  565. e.printStackTrace();
  566. return VaultsResponse.failed(e.getMessage());
  567. }
  568. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  569. return VaultsResponse.success(back);
  570. }
  571. return VaultsResponse.failed();
  572. }
  573. /**
  574. * 分账商户查询
  575. * @param phone
  576. * @param merchantId
  577. * @return
  578. */
  579. @Override
  580. public VaultsResponse<UserSearchBack> merchantQuery(String phone, String merchantId){
  581. UserSearch userSearch = new UserSearch();
  582. BasicConfiguration bc = Basic.getSystemParameter(TokenContext.cureOperatorId());
  583. userSearch.setSystem_id(bc.getSystemId());
  584. userSearch.setIsspid(bc.getPid());
  585. UserSearchDetail detail = new UserSearchDetail();
  586. detail.setPhone(phone);
  587. detail.setMerchant_id(merchantId);
  588. userSearch.setMerchant_query_request(detail);
  589. UserSearchBack back = null;
  590. try {
  591. String val = (String) YmUtil.resultBack(userSearch,new UserSearchBack());
  592. JSONObject jsonObject = new JSONObject(JSON.parseObject(val));
  593. if(val.contains("image_list")){
  594. List<ImageListBack> list = jsonObject.getJSONArray("image_list").stream().map(item -> JSON.parseObject(item.toString(), new TypeReference<ImageListBack>() {})).collect(Collectors.toList());
  595. jsonObject.put("image_list",list);
  596. }
  597. back = JSONObject.toJavaObject(jsonObject, UserSearchBack.class);
  598. if(cacheService.exists("supplier_pro")){
  599. back.setProportion(new BigDecimal(cacheService.get("supplier_pro")).multiply(new BigDecimal(100)));
  600. }
  601. } catch (IllegalAccessException e) {
  602. e.printStackTrace();
  603. return VaultsResponse.failed(e.getMessage());
  604. }
  605. if(YmUtil.SUCCESS.equals(back.getResult().getId())){
  606. return VaultsResponse.success(back);
  607. }else if("9990".equals(back.getResult().getId())){
  608. return VaultsResponse.success(null);
  609. }
  610. return VaultsResponse.failed();
  611. }
  612. }