当前位置:   article > 正文

java版Spring Cloud+Mybatis 微服务商城 b2b2c商城 直播商城 小程序商城 多商家入驻商城 APP商城源码 聚合支付商城_开源微服务多商户商城

开源微服务多商户商城

1. 平台简介

一个全新覆盖全行业,以直播、短视频带货,商家实体VR全景体验,多营销模式,分销分佣,多商家入驻,多端支持的大型新零售电商平台。

2. 平台清单

系统管理平台 + 商家端(PC+手机) + 消费端微服务 + 消费端(小程序/APP/公众号/H5) + 消息提醒

3. 平台模式

B2B2C多商家入驻通用版本: 标准多商户入驻+二级分销体系+满减、满送、优惠券、组合销售、平台礼包等营销活动)

B2B2C多商家入驻直播/短视频带货版本: 标准多商户入驻+直播、短视频带货+二级分销体系+满减、满送、优惠券、组合销售、平台礼包等营销活动

B2B2C多商家入驻VR全景版本: 标准多商户入驻+二级分销体系+满减、满送、优惠券、组合销售、平台礼包等营销活动)

4. 涉及营销方案

一、一县一特(一个县城,一个特色,集本地特产、特色、名胜、小吃、文化为一体的营销方案)

二、短距离配送(外卖、生鲜水果配送,解决1.5公里配送问题,接入第三方代跑腿服务)

三、酒店行业(酒店商家入驻,根据定位,可针对附近酒店,不同城酒店进行线上预定、下线核销等,参考去哪儿网酒店业务)

四、VR全景(商家入驻后,可以进行VR全景拍摄,VR店铺体验,全新购物方式,通过虚拟现实技术,线上线下打通,实现全新O2O,深度场景体验,感受另一个大千世界,让用户足不出户完美购物。通过VR让您的店铺曝光率更高,让天下没有难销的商品)

五、线下套餐体验(针对于实体行业,用户线上消费后生成核销码,用户到实体店铺体验套餐,可凭借核销码进行体验项目)

六、旅游业(周边游、本地游、异地游等,旅游景区和VR全景结合,用户足不出户先感受一下旅游项目、旅游攻略等,可线上订票、预定等)

七、供应求购(简易供应链供应、求购模式)

八、社交资讯(用户发布文章,可进行带货)

九、社交动态(个人信息、动态、视频,如:文字+图片、文字+视频,可进行带货;粉丝、关注、分享等)

十、异业联盟(不同行业的联盟销售,如:在某餐饮店面消费后可送附近健身卡优惠券,凭借优惠券可进行线下体验)

十一、一键代发营销(商家选择平台商品后放入自己店面销售,用户购买后商家可获取特殊分润提成,商家不需要发货,由平台厂家直接发货,并支持本店面自提)

十二、秒杀(通用方案)

十三、拼团(仿拼多多)

十四、限时折扣(通用方案,在活动时间范围内会员享受折扣价格)

十五、积分商城(纯积分兑换、积分+现金兑换)

十六、限时折扣(通用方案,在活动时间范围内会员享受折扣价格)

十七、活动商品(平台发布活动商品,如:可以进行0元领取,领取需要进行用户拉新,拉新后可进行现金奖励等)

5. 使用技术

开发工具:Idea、Eclipse

WEB容器:Tomcat、Jboss、Weblogic、webSphere

JDK版本:1.8+

系统支持:Docker、Window、Linux

数据库/数据源:MySQL、Alibaba Druid

服务框架:Spring Cloud、Spring Boot2、Mybatis、前后端分离、分布式、微服务

分布式中间件:RabbitMQ、Redis、ElasticSearch、OSS

前端架构:VUE、Uniapp、H5、CSS3

构建方式:Maven、Jenkins

涉及技术:Eureka、Config、Zuul、OAuth2、Security、OSS、Turbine、Zipkin、Feign、Monitor、Stream、ElasticSearch、Redis、RabbitMQ等

支持终端:小程序、APP(IOS/Android)、公众号、H5

6. 架构设计&思想

分布式、微服务、云架构、模块化、服务化、原子化、持续集成、中间件集成、云服务集成

7. 技术架构图

 

8. 微服务清单

honghu-activity:活动、honghu-advert:广告、honghu-brand: 品牌

honghu-cms: 内容发布、honghu-collect: 我的收藏、honghu-common: 系统通用服务

honghu-coupon: 优惠券、honghu-distribution: 分销、honghu-file: 文件

honghu-free: 试用、honghu-goodsc-lass: 商品分类、honghu-goods: 商品

honghu-group: 团购、honghu-home: 首页、honghu-integral: 积分商城

honghu-member: 会员、honghu-message: 消息、honghu-operate: 运营

honghu-order: 订单、honghu-pay: 支付、honghu-pin: 拼团

honghu-search: 搜索、honghu-social: 社交电商

honghu-sso: 单点登录、honghu-store: 店铺

@源码地址来源: https://minglisoft.cn/honghu/business.html

 

 

8. 演示截图

 

 

 

 

 

 

 

 

 

  

9. 相关源码

@源码地址来源: https://minglisoft.cn/honghu/business.html
  1. package com.honghu.cloud.controller;
  2. import java.math.BigDecimal;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.servlet.http.HttpServletRequest;
  9. import org.apache.http.HttpResponse;
  10. import org.apache.http.client.methods.HttpPost;
  11. import org.apache.http.entity.StringEntity;
  12. import org.apache.http.impl.client.DefaultHttpClient;
  13. import org.apache.http.util.EntityUtils;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.CrossOrigin;
  18. import org.springframework.web.bind.annotation.RequestBody;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestMethod;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import com.alibaba.fastjson.JSON;
  23. import com.alibaba.fastjson.JSONException;
  24. import com.google.common.collect.Lists;
  25. import com.google.common.collect.Maps;
  26. import com.honghu.cloud.bean.DaDaAppConfig;
  27. import com.honghu.cloud.bean.DaDaService;
  28. import com.honghu.cloud.bean.DadaApiResponse;
  29. import com.honghu.cloud.bean.ShopAddModel;
  30. import com.honghu.cloud.bean.Store;
  31. import com.honghu.cloud.code.ResponseCode;
  32. import com.honghu.cloud.dto.AreaDto;
  33. import com.honghu.cloud.dto.CouponInfoDto;
  34. import com.honghu.cloud.dto.EvaluateDto;
  35. import com.honghu.cloud.dto.ExpressCompanyCommonDto;
  36. import com.honghu.cloud.dto.ExpressCompanyDto;
  37. import com.honghu.cloud.dto.ExpressInfoDto;
  38. import com.honghu.cloud.dto.GoodsDto;
  39. import com.honghu.cloud.dto.MessageDto;
  40. import com.honghu.cloud.dto.OrderFormDto;
  41. import com.honghu.cloud.dto.OrderFormLogDto;
  42. import com.honghu.cloud.dto.RefundApplyFormDto;
  43. import com.honghu.cloud.dto.ReturnGoodsLogDto;
  44. import com.honghu.cloud.dto.ShipAddressDto;
  45. import com.honghu.cloud.dto.SysConfigDto;
  46. import com.honghu.cloud.dto.TransInfoDto;
  47. import com.honghu.cloud.dto.UserDto;
  48. import com.honghu.cloud.feign.AreaFeignClient;
  49. import com.honghu.cloud.feign.CouponInfoFeignClient;
  50. import com.honghu.cloud.feign.EvaluateFeignClient;
  51. import com.honghu.cloud.feign.ExpressCompanyCommonFeignClient;
  52. import com.honghu.cloud.feign.ExpressCompanyFeignClient;
  53. import com.honghu.cloud.feign.ExpressInfoFeignClient;
  54. import com.honghu.cloud.feign.GoodsFeignClient;
  55. import com.honghu.cloud.feign.MessageFeignClient;
  56. import com.honghu.cloud.feign.ModularClassFeignClient;
  57. import com.honghu.cloud.feign.MsgToolsFeignClient;
  58. import com.honghu.cloud.feign.OrderFormFeignClient;
  59. import com.honghu.cloud.feign.OrderFormLogFeignClient;
  60. import com.honghu.cloud.feign.OrderFormToolsFeignClient;
  61. import com.honghu.cloud.feign.RefundApplyFormFeignClient;
  62. import com.honghu.cloud.feign.ReturnGoodsLogFeignClient;
  63. import com.honghu.cloud.feign.ShipAddressFeignClient;
  64. import com.honghu.cloud.feign.ShipToolsFeignClient;
  65. import com.honghu.cloud.feign.SysConfigFeignClient;
  66. import com.honghu.cloud.feign.UserFeignClient;
  67. import com.honghu.cloud.service.IStoreService;
  68. import com.honghu.cloud.tools.DadaRequestClient;
  69. import com.honghu.cloud.tools.JSONUtil;
  70. import com.honghu.cloud.tools.QueryTools;
  71. import com.honghu.cloud.tools.SecurityUserHolder;
  72. import com.honghu.cloud.utils.CommUtil;
  73. import com.honghu.cloud.utils.StringUtils;
  74. import com.honghu.cloud.utils.tools.Md5Encrypt;
  75. import lombok.extern.slf4j.Slf4j;
  76. import net.sf.json.JSONObject;
  77. @CrossOrigin(origins = "*", maxAge = 3600)
  78. @Slf4j
  79. @RestController
  80. @RequestMapping(value = "/applet/storeOrder")
  81. public class AppletStoreOrderController {
  82. private final Logger logger = LoggerFactory.getLogger(AppletStoreOrderController.class);
  83. @Autowired
  84. private IStoreService storeService;
  85. @Autowired
  86. private OrderFormFeignClient orderFormFeignClient;
  87. @Autowired
  88. private UserFeignClient userFeignClient;
  89. @Autowired
  90. private GoodsFeignClient goodsFeignClient;
  91. @Autowired
  92. private QueryTools queryTools;
  93. @Autowired
  94. private RefundApplyFormFeignClient refundapplyformfeignclient;
  95. @Autowired
  96. private MessageFeignClient messagefeignclient;
  97. @Autowired
  98. private ReturnGoodsLogFeignClient returnGoodsLogFeignClient;
  99. @Autowired
  100. private ShipToolsFeignClient shipToolsFeignClient;
  101. @Autowired
  102. private OrderFormToolsFeignClient orderFormToolsFeignClient;
  103. @Autowired
  104. private OrderFormLogFeignClient orderFormLogFeignClient;
  105. @Autowired
  106. private MsgToolsFeignClient msgToolsFeignClient;
  107. @Autowired
  108. private ExpressCompanyCommonFeignClient companyCommonFeignClient;
  109. @Autowired
  110. private ShipAddressFeignClient shipAddressFeignClient;
  111. @Autowired
  112. private SysConfigFeignClient sysConfigFeignClient;
  113. @Autowired
  114. private ExpressInfoFeignClient expressInfoFeignClient;
  115. @Autowired
  116. private EvaluateFeignClient evaluateFeignClient;
  117. @Autowired
  118. private ExpressCompanyFeignClient expressCompanyFeignClient;
  119. @Autowired
  120. private ExpressCompanyCommonFeignClient expressCompanyCommonFeignClient;
  121. @Autowired
  122. private AreaFeignClient areaFeignClient;
  123. @Autowired
  124. private ModularClassFeignClient modularClassFeignClient;
  125. @Autowired
  126. private CouponInfoFeignClient couponInfoFeignClient;
  127. /**
  128. * 卖家订单列表
  129. * @param request
  130. * @param response
  131. * @param currentPage
  132. * @param order_status
  133. * @param order_id
  134. * @param beginTime
  135. * @param endTime
  136. * @param buyer_userName
  137. * @return
  138. */
  139. @RequestMapping( value = { "/order" } , method = RequestMethod.POST)
  140. public Map<String,Object> order(HttpServletRequest request,
  141. @RequestBody JSONObject json) {
  142. String currentPage = json.optString("currentPage");
  143. String order_status = json.optString("order_status");
  144. String order_id = json.optString("order_id");
  145. /*String beginTime = json.optString("beginTime");
  146. String endTime = json.optString("endTime");*/
  147. String order_id_userName = json.optString("order_id_userName");
  148. Map<String,Object> maps= this.queryTools.getParams(currentPage,"addTime", "desc");
  149. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  150. if(user == null){
  151. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  152. }
  153. if (user.getParent_id()!=null) {
  154. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  155. }
  156. if(user.getStore_id() == null){
  157. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  158. }
  159. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  160. .getStore_id()));
  161. if(store != null){
  162. maps.put("store_id", store.getId());
  163. }else{
  164. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  165. }
  166. /* maps.put("order_cat_no", 2);
  167. */ Map<String, Object> map = Maps.newHashMap();
  168. if (!CommUtil.null2String(order_status).equals("")) {
  169. if (order_status.equals("order_submit")) {//代付款
  170. maps.put("order_status1", Integer.valueOf(10));
  171. maps.put("order_status2", Integer.valueOf(16));
  172. }
  173. if (order_status.equals("order_pay")) { //代发货
  174. maps.put("order_status1", Integer.valueOf(20));
  175. maps.put("order_status2", Integer.valueOf(14));
  176. }
  177. if (order_status.equals("order_shipping")) {//待收货 已发货
  178. //maps.put("order_status", Integer.valueOf(30));
  179. maps.put("order_status_0", Integer.valueOf(30));
  180. maps.put("order_status_1", Integer.valueOf(31));
  181. maps.put("order_status_2", Integer.valueOf(32));
  182. }
  183. if (order_status.equals("order_evaluate")) {// 已收货 待评价
  184. maps.put("order_status", Integer.valueOf(40));
  185. }
  186. if (order_status.equals("order_finish")) { //评论完
  187. maps.put("order_status", Integer.valueOf(50));
  188. }
  189. if (order_status.equals("order_cancel")) {//订单取消
  190. maps.put("order_status", Integer.valueOf(0));
  191. }
  192. if (order_status.equals("order_refund")) {//退款中
  193. maps.put("order_status", Integer.valueOf(21));
  194. }
  195. }
  196. if (!CommUtil.null2String(order_id).equals("")) {
  197. maps.put("order_id_like", order_id);
  198. }
  199. /*if (!CommUtil.null2String(beginTime).equals("")) {
  200. maps.put("add_Time_more_than_equal", CommUtil.formatDate(beginTime));
  201. map.put("beginTime", beginTime);
  202. }
  203. if (!CommUtil.null2String(endTime).equals("")) {
  204. String ends = endTime + " 23:59:59";
  205. maps.put("add_Time_less_than_equal", CommUtil.formatDate(ends,"yyyy-MM-dd hh:mm:ss"));
  206. map.put("endTime", endTime);
  207. }*/
  208. if (!CommUtil.null2String(order_id_userName).equals("")) {
  209. maps.put("order_id_userName", order_id_userName);
  210. }
  211. Map<String, Object> list = this.orderFormFeignClient.list(maps);
  212. map.putAll(list);
  213. /*map.put("list", list);*/
  214. map.put("order_id", order_id);
  215. map.put("order_status", order_status == null ? "all" : order_status);
  216. return ResponseCode.buildSuccessMap(map);
  217. }
  218. /**
  219. * 卖家订单
  220. * @param request
  221. * @param response
  222. * @param currentPage
  223. * @param order_status
  224. * @param order_id
  225. * @param beginTime
  226. * @param endTime
  227. * @param buyer_userName
  228. * @return
  229. */
  230. @RequestMapping( value = { "/orderHome" } , method = RequestMethod.POST)
  231. public Map<String,Object> orderHome(HttpServletRequest request) {
  232. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  233. if(user == null){
  234. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  235. }
  236. if (user.getParent_id()!=null) {
  237. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  238. }
  239. if(user.getStore_id() == null){
  240. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  241. }
  242. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  243. .getStore_id()));
  244. if(store == null){
  245. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  246. }
  247. Map<String, Object> map = Maps.newHashMap();
  248. map.put("store_id", store.getId());
  249. //代付款1
  250. map.put("order_status1", Integer.valueOf(10));
  251. map.put("order_status2", Integer.valueOf(16));
  252. Integer order_submit = this.orderFormFeignClient.selectCount(map);
  253. //代发货1
  254. map.clear();
  255. map.put("store_id", store.getId());
  256. map.put("order_status", Integer.valueOf(20));
  257. Integer order_pay = this.orderFormFeignClient.selectCount(map);
  258. //待收货 已发货 1
  259. map.clear();
  260. map.put("store_id", store.getId());
  261. map.put("order_status", Integer.valueOf(30));
  262. Integer order_shipping = this.orderFormFeignClient.selectCount(map);
  263. // 已收货 待评价1
  264. map.clear();
  265. map.put("store_id", store.getId());
  266. map.put("order_status", Integer.valueOf(40));
  267. Integer order_evaluate = this.orderFormFeignClient.selectCount(map);
  268. //退款中1
  269. map.clear();
  270. map.put("store_id", store.getId());
  271. map.put("refundStatus", 1);
  272. Integer order_refund = this.orderFormFeignClient.selectCount(map);
  273. map.put("selectCount_refund", order_refund);
  274. map.clear();
  275. map.put("store_id", user.getStore_id());
  276. int selectCount = this.returnGoodsLogFeignClient.selectCount(map);
  277. if(order_refund == null){
  278. order_refund = 0;
  279. }
  280. order_refund = order_refund + selectCount;
  281. map.clear();
  282. map.put("order_submit", order_submit);
  283. map.put("order_pay", order_pay);
  284. map.put("order_shipping", order_shipping);
  285. map.put("order_evaluate", order_evaluate);
  286. map.put("order_refund", order_refund);
  287. return ResponseCode.buildSuccessMap(map);
  288. }
  289. /**订单详情
  290. * @param request
  291. * @param json
  292. * @return
  293. */
  294. @RequestMapping(value = { "/order_view" } , method = RequestMethod.POST)
  295. public Map<String , Object> order_view(HttpServletRequest request,
  296. @RequestBody JSONObject json) {
  297. String id = json.optString("id");
  298. OrderFormDto obj = this.orderFormFeignClient
  299. .selectByPrimaryKey(CommUtil.null2Long(id));
  300. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  301. .getCurrentUser(request).getId());
  302. if(user == null){
  303. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  304. }
  305. if (user.getParent_id()!=null) {
  306. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  307. }
  308. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  309. .getStore_id()));
  310. if(store == null){
  311. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  312. }
  313. if(user.getStore_id() == null){
  314. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  315. }
  316. if (user.getStore_id().equals(store.getId())) {
  317. Map<String , Object> maps = Maps.newHashMap();
  318. if(obj.getOrder_status() == 10){
  319. SysConfigDto sys = this.sysConfigFeignClient.getSysConfig();
  320. Integer auto_order_cancel = sys.getAuto_order_cancel();
  321. Date addTime = obj.getAddTime();
  322. Date date = new Date();
  323. /*System.out.println(((addTime.getTime() - date.getTime()) / (24 * 60 * 60 * 1000))/ 365 + "年");
  324. System.out.println((addTime.getTime() - date.getTime()) / (24 * 60 * 60 * 1000) + "天");
  325. System.out.println((((addTime.getTime() - date.getTime()) / (60 * 60 * 1000)) % 24) + "小时");
  326. System.out.println((((addTime.getTime() - date.getTime()) / 1000) % 60) + "分钟");
  327. System.out.println(((addTime.getTime() - date.getTime()) / (60 * 1000)) % 60 + "秒");*/
  328. maps.put("obj", obj);
  329. maps.put("second", (((addTime.getTime() - date.getTime()) / 1000)) + auto_order_cancel*60*60);
  330. }
  331. maps.put("obj", obj);
  332. return ResponseCode.buildSuccessMap(maps);
  333. } else {
  334. return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
  335. }
  336. }
  337. /**
  338. * 卖家取消订单
  339. * @param request
  340. * @param response
  341. * @param id
  342. * @param currentPage
  343. * @return
  344. */
  345. @RequestMapping(value ={ "/order_cancel" } ,method = RequestMethod.POST)
  346. public Map<String , Object> order_cancel(HttpServletRequest request , @RequestBody JSONObject jsonv) {
  347. String id = jsonv.optString("id");
  348. if (SecurityUserHolder.getCurrentUserId(request)==null) {
  349. return ResponseCode.buildCodeMap("1111", "userid为空", null);
  350. }
  351. UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  352. OrderFormDto obj = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  353. if(seller == null){
  354. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  355. }
  356. if (seller.getParent_id()!=null) {
  357. seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
  358. }
  359. //user = user.getParent_id() == null ? user : user.getParent();
  360. if(seller.getStore_id() == null){
  361. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  362. }
  363. //System.out.println("---------user--getStore_id-------------"+seller
  364. //.getStore_id());
  365. Store store = this.storeService.selectByPrimaryKey(seller
  366. .getStore_id());
  367. //System.out.println("---------user---------------"+seller.getId());
  368. //System.out.println("------------obj-------------"+obj.getId());
  369. //System.out.println("---------seller---------------"+seller.getStore_id());
  370. if(store == null){
  371. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  372. }
  373. System.out.println("-----------store--------------"+store.getId());
  374. if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
  375. return ResponseCode.buildSuccessMap(obj);
  376. } else {
  377. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  378. }
  379. }
  380. /**
  381. * 卖家取消订单保存
  382. * @param request
  383. * @param response
  384. * @param id
  385. * @param currentPage
  386. * @return
  387. */
  388. @RequestMapping(value ={ "/order_cancel_save" } ,method = RequestMethod.POST)
  389. public Map<String , Object> order_cancel_save(HttpServletRequest request , @RequestBody JSONObject jsonv) {
  390. String id = jsonv.optString("id");
  391. String state_info = jsonv.optString("state_info");
  392. String other_state_info = jsonv.optString("other_state_info");
  393. UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  394. OrderFormDto obj = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  395. if(seller == null){
  396. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  397. }
  398. if (seller.getParent_id()!=null) {
  399. seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
  400. }
  401. //user = user.getParent_id() == null ? user : user.getParent();
  402. if(seller.getStore_id() == null){
  403. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  404. }
  405. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(seller
  406. .getStore_id()));
  407. if(store == null){
  408. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  409. }
  410. Date nowDate = new Date();
  411. if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
  412. obj.setOrder_status(0);
  413. if ((obj.getCoupon_info() != null)
  414. && (!"".equals(obj.getCoupon_info()))) {
  415. Map m = JSON.parseObject(obj.getCoupon_info());
  416. CouponInfoDto cpInfo = this.couponInfoFeignClient.selectByPrimaryKey(CommUtil
  417. .null2Long(m.get("couponinfo_id")));
  418. if (cpInfo != null) {
  419. if (nowDate.before(cpInfo.getEndDate())) {
  420. cpInfo.setStatus(0);
  421. } else {
  422. cpInfo.setStatus(-1);
  423. }
  424. }
  425. }
  426. orderFormFeignClient.updateById(obj);
  427. OrderFormLogDto ofl = new OrderFormLogDto();
  428. ofl.setAddTime(new Date());
  429. ofl.setLog_info("取消订单");
  430. ofl.setLog_user_id(seller.getId());
  431. ofl.setLog_user_name(seller.getUserName());
  432. ofl.setOf_id(obj.getId());
  433. if (state_info.equals("其他原因")) {
  434. ofl.setState_info(other_state_info);
  435. } else {
  436. ofl.setState_info(state_info);
  437. }
  438. this.orderFormLogFeignClient.saveEntity(ofl);
  439. /* UserDto buyer = this.userFeignClient.selectByPrimaryKey(CommUtil.null2Long(obj
  440. .getUser_id()));
  441. Map<String, Object> map = Maps.newHashMap();
  442. map.put("buyer_id", buyer.getId().toString());
  443. map.put("seller_id", store.getUser_id());
  444. map.put("order_id", obj.getId());
  445. String json = JSON.toJSONString(map);*/
  446. /*if (obj.getOrder_form() == 0) {
  447. try {
  448. this.msgToolsFeignClient.sendEmailCharge(CommUtil.getURL(request),
  449. "email_tobuyer_order_cancel_notify", buyer.getEmail(),
  450. json, null, obj.getStore_id());
  451. this.msgToolsFeignClient.sendSmsCharge(CommUtil.getURL(request),
  452. "sms_tobuyer_order_cancel_notify", buyer.getMobile(),
  453. json, null, obj.getStore_id());
  454. } catch (Exception e) {
  455. // TODO Auto-generated catch block
  456. e.printStackTrace();
  457. }
  458. } else {
  459. try {
  460. this.msgToolsFeignClient.sendEmailFree(CommUtil.getURL(request),
  461. "email_tobuyer_order_cancel_notify", buyer.getEmail(),
  462. json, null);
  463. this.msgToolsFeignClient.sendSmsFree(CommUtil.getURL(request),
  464. "sms_tobuyer_order_cancel_notify", buyer.getMobile(),
  465. json, null);
  466. } catch (Exception e) {
  467. // TODO Auto-generated catch block
  468. e.printStackTrace();
  469. }
  470. }*/
  471. return ResponseCode.buildSuccessMap(null);
  472. } else {
  473. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  474. }
  475. }
  476. /**
  477. * 订单退款申请单
  478. * @param request
  479. * @param response
  480. * @param currentPage
  481. * @param orderBy
  482. * @param orderType
  483. * @param status
  484. * @return
  485. */
  486. @RequestMapping(value = { "/refund_apply_form" } , method = RequestMethod.POST)
  487. public Map<String,Object> refund_apply_form(HttpServletRequest request,
  488. @RequestBody JSONObject json) {
  489. String currentPage = json.optString("currentPage");
  490. String orderType = json.optString("orderType");
  491. String orderBy = json.optString("orderBy");
  492. //状态 0:待审核 5:审核拒绝 10:审核通过待退款 15:已退款
  493. String refundStatus = json.optString("refundStatus");
  494. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  495. if(user == null){
  496. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  497. }
  498. if (user.getParent_id()!=null) {
  499. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  500. }
  501. if(user.getStore_id() == null){
  502. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  503. }
  504. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  505. .getStore_id()));
  506. Map<String,Object> maps= this.queryTools.getParams(currentPage, orderBy, orderType);
  507. if ((refundStatus == null) || (refundStatus.equals(""))) {
  508. maps.put("refundStatus", CommUtil.null2Int(Integer.valueOf(0)));
  509. } else {
  510. maps.put("refundStatus", CommUtil.null2Int(Integer.valueOf(refundStatus)));
  511. }
  512. if(store != null){
  513. maps.put("store_id", store.getId());
  514. }else{
  515. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  516. }
  517. Map<String, Object> data = this.orderFormFeignClient.refundApplyFormList(maps);
  518. data.put("refundStatus", refundStatus);
  519. return ResponseCode.buildSuccessMap(data);
  520. }
  521. /**
  522. * 订单退款申请单详情
  523. * @param request
  524. * @param response
  525. * @param order_id
  526. * @return
  527. */
  528. @RequestMapping(value = { "/refund_orderform_view" } , method = RequestMethod.POST)
  529. public Map<String,Object> refund_orderform_view(HttpServletRequest request, @RequestBody JSONObject json) {
  530. Map<Object, Object> map = Maps.newHashMap();
  531. map.put("reason","");
  532. if (StringUtils.isBlank(json.optString("order_id"))) {
  533. return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
  534. }
  535. String apply_from_id = json.optString("apply_from_id");
  536. if (StringUtils.isBlank(apply_from_id)) {
  537. return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
  538. }
  539. OrderFormDto obj = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(json.optString("order_id")));
  540. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj.getStore_id()));
  541. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  542. if(user == null){
  543. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  544. }
  545. if (user.getParent_id()!=null) {
  546. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  547. }
  548. RefundApplyFormDto RefundApplyFormDto = refundapplyformfeignclient.selectByPrimaryKey(CommUtil.null2Long(apply_from_id));
  549. if(RefundApplyFormDto!=null){
  550. map.put("reason",RefundApplyFormDto.getReturn_content()); //退款原因
  551. }
  552. //user = user.getParent_id() == null ? user : user.getParent();
  553. if(user.getStore_id() == null){
  554. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  555. }
  556. if(store == null){
  557. return ResponseCode.buildReturnMap(ResponseCode.REQUEST_FORBIDDEN, null);
  558. }
  559. if(!user.getStore_id().equals(store.getId()) ||store.getStore_status()!=15){ //验证是否是当前商家 , 并且正常营业
  560. return ResponseCode.buildReturnMap(ResponseCode.REQUEST_FORBIDDEN, null);
  561. }
  562. if (obj != null) {
  563. String temp = obj.getSpecial_invoice();
  564. if ((temp != null) && (!"".equals(temp))) {
  565. Map of_va = JSON.parseObject(temp);
  566. map.put("of_va", of_va);
  567. }
  568. }
  569. map.put("obj", obj);
  570. String queryExInfo = this.queryExInfo(obj.getExpress_info(), "express_company_name");
  571. map.put("store", store);
  572. map.put("express_company_name", queryExInfo);
  573. //map.put("express_company_name", this.orderFormTools.queryExInfo(obj.getExpress_info(), "express_company_name"));
  574. ReturnGoodsLogDto returnGoodsLogDto = returnGoodsLogFeignClient.selectByOrderId(obj.getId());
  575. map.put("returnGoodsLogDto", returnGoodsLogDto);
  576. return ResponseCode.buildSuccessMap(map);
  577. }
  578. public String queryExInfo(String json, String key) {
  579. Map<String, Object> map = Maps.newHashMap();
  580. if ((json != null) && (!json.equals(""))) {
  581. map = JSON.parseObject(json);
  582. }
  583. return CommUtil.null2String(map.get(key));
  584. }
  585. /**
  586. * 订单退款申请单审核
  587. * @param request
  588. * @param result
  589. * @param apply_form_id
  590. * @param currentPage
  591. * @return
  592. */
  593. @RequestMapping({ "/refund_audit" })
  594. public Map<String, Object> refund_audit(HttpServletRequest request, @RequestBody JSONObject json) {
  595. UserDto user = SecurityUserHolder.getCurrentUser(request);
  596. Store store = null ;
  597. if(user == null){
  598. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  599. }
  600. if (user.getParent_id()!=null) {
  601. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  602. }
  603. store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  604. .getStore_id()));
  605. if(store == null){
  606. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  607. }
  608. RefundApplyFormDto refundApplyForm = this.refundapplyformfeignclient
  609. .selectByPrimaryKey(CommUtil.null2Long(json.optString("apply_from_id")));
  610. //TODO
  611. //Store store = (user.getParent() == null ? user : user.getParent()).getStore();
  612. if ((store != null) && (store.getId().toString().equals(refundApplyForm.getStore_id()))&&refundApplyForm.getOrder_form_id()!=null) {
  613. OrderFormDto orderForm = this.orderFormFeignClient.selectByPrimaryKey(refundApplyForm.getOrder_form_id());
  614. refundApplyForm.setAudit_date(new Date());
  615. refundApplyForm.setAudit_user_name(user.getUserName());
  616. if (StringUtils.isNotBlank(json.optString("result"))) {
  617. refundApplyForm.setStatus(10);
  618. this.refundapplyformfeignclient.updateById(refundApplyForm);
  619. orderForm.setOrder_status(22);
  620. this.orderFormFeignClient.updateById(orderForm);
  621. MessageDto msg = new MessageDto();
  622. String msg_content = "您订单号为:" + orderForm.getOrder_id() + "的订单退款申请已通过,我们会尽快将" + "退款金额打入您的预存款中。";
  623. msg.setAddTime(new Date());
  624. msg.setStatus(0);
  625. msg.setType(0);
  626. msg.setContent(msg_content);
  627. //msg.setFromu(user);
  628. //msg.setToUser(this.userFeignClient.selectByPrimaryKey(CommUtil.null2Long(orderForm.getUser_id())));
  629. msg.setFromUser_id(user.getId());
  630. msg.setToUser_id(CommUtil.null2Long(orderForm.getUser_id()));
  631. this.messagefeignclient.saveEntity(msg);
  632. } else {
  633. refundApplyForm.setStatus(5);
  634. this.refundapplyformfeignclient.updateById(refundApplyForm);
  635. orderForm.setOrder_status(20);
  636. this.orderFormFeignClient.updateById(orderForm);
  637. MessageDto msg = new MessageDto();
  638. String msg_content = "您订单号为:" + orderForm.getOrder_id() + "的订单退款申请未通过。";
  639. msg.setAddTime(new Date());
  640. msg.setStatus(0);
  641. msg.setType(0);
  642. msg.setContent(msg_content);
  643. msg.setFromUser(user);
  644. msg.setToUser_id(CommUtil.null2Long(orderForm.getUser_id()));
  645. this.messagefeignclient.saveEntity(msg);
  646. }
  647. }else {
  648. //店铺不存在, 或者登录用户不为该订单商铺
  649. return ResponseCode.buildReturnMap(ResponseCode.REQUEST_FORBIDDEN, null);
  650. }
  651. return ResponseCode.buildSuccessMap(null);
  652. }
  653. /**
  654. * 退货列表
  655. * @param request
  656. * @param response
  657. * @param currentPage
  658. * @param orderBy
  659. * @param orderType
  660. * @param name
  661. * @param user_name
  662. * @param return_service_id
  663. * @return
  664. */
  665. @RequestMapping(value = { "/return" } , method = RequestMethod.POST)
  666. public Map<String, Object> seller_return(HttpServletRequest request,@RequestBody JSONObject json) {
  667. String currentPage = json.optString("currentPage");
  668. String orderBy = json.optString("orderBy");
  669. String orderType = json.optString("orderType");
  670. String name = json.optString("name");
  671. String user_name = json.optString("user_name");
  672. String return_service_id = json.optString("return_service_id");
  673. Map<String,Object> maps= this.queryTools.getParams(currentPage, "addTime", "desc");
  674. maps.put("goods_type", 1);
  675. if ((user_name != null) && (!user_name.equals(""))) {
  676. maps.put("user_name", user_name);
  677. }
  678. if ((name != null) && (!name.equals(""))) {
  679. maps.put("goods_name_like", name);
  680. }
  681. if ((return_service_id != null) && (!return_service_id.equals(""))) {
  682. maps.put("return_service_id", return_service_id);
  683. }
  684. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  685. if(user == null){
  686. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  687. }
  688. if (user.getParent_id()!=null) {
  689. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  690. }
  691. //user = user.getParent_id() == null ? user : user.getParent();
  692. if(user.getStore_id() == null){
  693. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  694. }
  695. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  696. .getStore_id()));
  697. if(store != null){
  698. maps.put("store_id", store.getId());
  699. }else{
  700. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  701. }
  702. maps.put("store_id", user.getStore_id());
  703. Map<String , Object> data = this.returnGoodsLogFeignClient.list(maps);
  704. data.put("name", name);
  705. data.put("user_name", user_name);
  706. data.put("return_service_id", return_service_id);
  707. data.put("store", store);
  708. return ResponseCode.buildSuccessMap(data);
  709. }
  710. /**
  711. * 退货详情数据
  712. * @param request
  713. * @param response
  714. * @param currentPage
  715. * @param id
  716. * @return
  717. */
  718. @RequestMapping(value = { "/return_check" } , method = RequestMethod.POST)
  719. public Map<String, Object> return_check(HttpServletRequest request,
  720. @RequestBody JSONObject json) {
  721. String id = json.optString("id");
  722. ReturnGoodsLogDto obj = this.returnGoodsLogFeignClient.selectByPrimaryKey(CommUtil
  723. .null2Long(id));
  724. Map<String, Object> map = Maps.newHashMap();
  725. if (obj.getGoods_return_status().equals("7")) {
  726. TransInfoDto transInfo = this.shipToolsFeignClient.query_Ordership_getData(CommUtil.null2String(obj.getId()));
  727. map.put("transInfo", transInfo);
  728. Map<String, Object> mapa = JSON.parseObject(obj
  729. .getReturn_express_info());
  730. //物流名称
  731. map.put("express_company_name",mapa.get("express_company_name"));
  732. }
  733. map.put("obj", obj);
  734. return ResponseCode.buildSuccessMap(map);
  735. }
  736. /**
  737. * 退货订单 审核or拒绝
  738. * @param request
  739. * @param id
  740. * @param goods_return_status
  741. * @param self_address
  742. */
  743. @RequestMapping( value = { "/return_check_save" } , method = RequestMethod.POST)
  744. public Map<String , Object> return_check_saveEntity(HttpServletRequest request,@RequestBody JSONObject jsonv) {
  745. String id = jsonv.optString("id");
  746. /*String currentPage = jsonv.optString("currentPage");*/
  747. /*String cmd = jsonv.optString("cmd");*/
  748. // 退货商品状态 -2为超过退货时间未能输入退货物流 -1为申请被拒绝 1为可以退货 5为退货申请中 6为审核通过可进行退货 7为退货中 10为退货完成,等待退款,11为平台退款完成
  749. String goods_return_status = jsonv.optString("goods_return_status");
  750. // 收货时向买家发送的收货地址,买家通过此将货物发送给卖家
  751. String self_address = jsonv.optString("self_address");
  752. UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  753. // UserDto seller = this.userFeignClient.selectByPrimaryKey(445L);
  754. if(seller == null){
  755. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  756. }
  757. if (seller.getParent_id()!=null) {
  758. seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
  759. }
  760. //user = user.getParent_id() == null ? user : user.getParent();
  761. if(seller.getStore_id() == null){
  762. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  763. }
  764. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(seller
  765. .getStore_id()));
  766. // Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(62));
  767. if(store == null){
  768. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  769. }
  770. ReturnGoodsLogDto obj = this.returnGoodsLogFeignClient.selectByPrimaryKey(Long.valueOf(Long.parseLong(id)));
  771. String message = "审核为未通过";
  772. String code = "10001";
  773. if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
  774. obj.setGoods_return_status(goods_return_status);
  775. obj.setSelf_address(self_address);
  776. obj.setRefund_time(new Date()); //审核时间
  777. this.returnGoodsLogFeignClient.updateById(obj);
  778. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getUser_id());
  779. String msg_content =null;
  780. if (goods_return_status.equals("6")) {
  781. message = "审核通过";
  782. code = "10000";
  783. msg_content = "退货申请审核通过,请在'退货/退款'-'查看返修/退换记录'中提交退货物流信息。";
  784. } else {
  785. /* OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(Long.valueOf(obj.getReturn_order_id()));
  786. of.setOrder_status(18); //申请未通过, 用户取消退款确认收货/人工仲裁
  787. this.orderFormFeignClient.updateById(of);*/
  788. message = "提交成功";
  789. code = "10000";
  790. msg_content = "订单号:" + obj.getReturn_service_id()
  791. + "退货申请审核未通过,请在'退货/退款'-'查看返修/退换记录'中提交退货物流信息。";
  792. }
  793. MessageDto msg = new MessageDto();
  794. msg.setAddTime(new Date());
  795. msg.setStatus(0);
  796. msg.setType(0);
  797. msg.setContent(msg_content);
  798. msg.setFromUser(SecurityUserHolder.getCurrentUser(request));
  799. msg.setToUser(user);
  800. this.messagefeignclient.saveEntity(msg);
  801. } else {
  802. message = "信息有误";
  803. code = "10001";
  804. }
  805. return ResponseCode.buildCodeMap(code,message, null);
  806. }
  807. /**
  808. * 确认退货收货
  809. * @param request
  810. * @param response
  811. * @param id
  812. * @return
  813. */
  814. @RequestMapping( value = { "/return_confirm" } , method = RequestMethod.POST)
  815. public Map<String , Object> return_confirm(HttpServletRequest request , @RequestBody JSONObject jsonv) {
  816. String id = jsonv.optString("id");
  817. UserDto seller = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  818. ReturnGoodsLogDto obj = this.returnGoodsLogFeignClient.selectByPrimaryKey(Long.valueOf(Long.parseLong(id)));
  819. if(seller == null){
  820. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  821. }
  822. if (seller.getParent_id()!=null) {
  823. seller = this.userFeignClient.selectByPrimaryKey(seller.getParent_id());
  824. }
  825. //user = user.getParent_id() == null ? user : user.getParent();
  826. if(seller.getStore_id() == null){
  827. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  828. }
  829. // Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(seller
  830. // .getStore_id()));
  831. Store store = this.storeService.selectByPrimaryKey(seller.getStore_id());
  832. if(store == null){
  833. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  834. }
  835. if ((seller.getStore_id() != null)&& (CommUtil.null2String(obj.getStore_id()).equals(seller.getStore_id().toString()))) {
  836. obj.setGoods_return_status("10");
  837. this.returnGoodsLogFeignClient.updateById(obj);
  838. }
  839. return ResponseCode.buildSuccessMap(null);
  840. }
  841. /**
  842. * 卖家调整订单费用
  843. * @param request
  844. * @param response
  845. * @param id
  846. * @param currentPage
  847. * @return
  848. */
  849. @RequestMapping(value = { "/order_fee" } , method = RequestMethod.POST)
  850. public Map<String , Object> order_fee(HttpServletRequest request,
  851. @RequestBody JSONObject json) {
  852. String id = json.optString("id");
  853. OrderFormDto obj = this.orderFormFeignClient
  854. .selectByPrimaryKey(CommUtil.null2Long(id));
  855. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  856. .getCurrentUser(request).getId());
  857. if(user == null){
  858. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  859. }
  860. if (user.getParent_id()!=null) {
  861. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  862. }
  863. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  864. .getStore_id()));
  865. if(store == null){
  866. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  867. }
  868. //user = user.getParent_id() == null ? user : user.getParent();
  869. if(user.getStore_id() == null){
  870. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  871. }
  872. if (user.getStore_id().equals(store.getId())) {
  873. return ResponseCode.buildSuccessMap(obj);
  874. } else {
  875. return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
  876. }
  877. }
  878. /**
  879. * 卖家调整订单费用保存
  880. * @param request
  881. * @param response
  882. * @param id
  883. * @param currentPage
  884. * @param goods_amount
  885. * @param ship_price
  886. * @param totalPrice
  887. * @return
  888. * @throws Exception
  889. */
  890. @RequestMapping( value = { "/order_fee_save" } , method = RequestMethod.POST)
  891. public Map<String, Object> order_fee_saveEntity(HttpServletRequest request,@RequestBody JSONObject jsonv)
  892. {
  893. String id = jsonv.optString("id");
  894. String goods_amount = jsonv.optString("goods_amount"); //商品总价格
  895. String ship_price = jsonv.optString("ship_price"); // 配送价格
  896. String totalPrice = jsonv.optString("totalPrice"); // 订单总价格
  897. OrderFormDto obj = this.orderFormFeignClient
  898. .selectByPrimaryKey(CommUtil.null2Long(id));
  899. if (CommUtil.null2Double(obj.getCommission_amount()) <= CommUtil
  900. .null2Double(goods_amount)) {
  901. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  902. .getCurrentUser(request).getId());
  903. if(user == null){
  904. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  905. }
  906. if (user.getParent_id()!=null) {
  907. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  908. }
  909. if(user.getStore_id() == null){
  910. return ResponseCode.buildReturnMap(ResponseCode.FAILURE,null);
  911. }
  912. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  913. .getStore_id()));
  914. if(store == null){
  915. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE,null);
  916. }
  917. //user = user.getParent_id() == null ? user : user.getParent();
  918. if (user.getStore_id().toString().equals(store.getId().toString())) {
  919. obj.setGoods_amount(BigDecimal.valueOf(CommUtil
  920. .null2Double(goods_amount)));
  921. obj.setShip_price(BigDecimal.valueOf(CommUtil
  922. .null2Double(ship_price)));
  923. obj.setTotalPrice(BigDecimal.valueOf(CommUtil
  924. .null2Double(totalPrice)));
  925. obj.setOperation_price_count(obj.getOperation_price_count() + 1);
  926. this.orderFormFeignClient.updateById(obj);
  927. OrderFormLogDto ofl = new OrderFormLogDto();
  928. ofl.setAddTime(new Date());
  929. ofl.setLog_info("调整订单费用");
  930. ofl.setState_info("调整订单总金额为:" + totalPrice + ",调整运费金额为:"
  931. + ship_price);
  932. ofl.setLog_user_id(SecurityUserHolder.getCurrentUser(request).getId());
  933. ofl.setLog_user_name(SecurityUserHolder.getCurrentUser(request)
  934. .getUserName());
  935. ofl.setOf_id(obj.getId());
  936. this.orderFormLogFeignClient.saveEntity(ofl);
  937. /* UserDto buyer = this.userFeignClient.selectByPrimaryKey(CommUtil.null2Long(obj
  938. .getUser_id()));
  939. Map<String, Object> map = Maps.newHashMap();
  940. map.put("buyer_id", buyer.getId().toString());
  941. map.put("seller_id", store.getUser_id());
  942. map.put("order_id", obj.getId());
  943. String json = JSON.toJSONString(map);
  944. if (obj.getOrder_form() == 0) {
  945. this.msgToolsFeignClient.sendEmailCharge(CommUtil.getURL(request),
  946. "email_tobuyer_order_update_fee_notify",
  947. buyer.getEmail(), json, null, obj.getStore_id());
  948. this.msgToolsFeignClient.sendSmsCharge(CommUtil.getURL(request),
  949. "sms_tobuyer_order_fee_notify", buyer.getMobile(),
  950. json, null, obj.getStore_id());
  951. } else {
  952. this.msgToolsFeignClient.sendEmailFree(CommUtil.getURL(request),
  953. "email_tobuyer_order_update_fee_notify",
  954. buyer.getEmail(), json, null);
  955. this.msgToolsFeignClient.sendSmsFree(CommUtil.getURL(request),
  956. "sms_tobuyer_order_fee_notify", buyer.getMobile(),
  957. json, null);
  958. }*/
  959. }else{
  960. return ResponseCode.buildReturnMap(ResponseCode.FAILURE,null);
  961. }
  962. }else{
  963. return ResponseCode.buildReturnMap(ResponseCode.FAILURE,null);
  964. }
  965. return ResponseCode.buildSuccessMap(null);
  966. }
  967. /**
  968. * 卖家发货
  969. * @param request
  970. * @param response
  971. * @param id
  972. * @param currentPage
  973. * @param page_status
  974. * @return
  975. */
  976. @RequestMapping(value = { "/order_shipping" } , method = RequestMethod.POST)
  977. public Map<String, Object> order_shipping(HttpServletRequest request,@RequestBody JSONObject json) {
  978. String id = json.optString("id");
  979. String page_status = json.optString("page_status");
  980. OrderFormDto obj = this.orderFormFeignClient
  981. .selectByPrimaryKey(CommUtil.null2Long(id));
  982. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  983. .getCurrentUser(request).getId());
  984. if(user == null){
  985. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  986. }
  987. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  988. .getStore_id()));
  989. if (user.getParent_id()!=null) {
  990. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  991. }
  992. Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  993. .getStore_id()));
  994. if(store1 == null ||store == null){
  995. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  996. }
  997. //user = user.getParent_id() == null ? user : user.getParent();
  998. if(user.getStore_id() == null){
  999. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1000. }
  1001. Map<String, Object> map = Maps.newHashMap();
  1002. if (user.getStore_id().equals(store.getId())) {
  1003. map.put("obj", obj);
  1004. List<GoodsDto> list_goods = queryOfGoods(obj);
  1005. List<GoodsDto> deliveryGoods = Lists.newArrayList();
  1006. boolean physicalGoods = false;
  1007. for (GoodsDto g : list_goods) {
  1008. if (g.getGoods_choice_type() == 1) {
  1009. deliveryGoods.add(g);
  1010. } else {
  1011. physicalGoods = true;
  1012. }
  1013. }
  1014. Map<String, Object> params = Maps.newHashMap();
  1015. params.put("ecc_type", Integer.valueOf(0));
  1016. params.put("ecc_store_id", store.getId());
  1017. List<ExpressCompanyCommonDto> eccs = this.companyCommonFeignClient.queryPages(params);
  1018. params.clear();
  1019. params.put("sa_type", Integer.valueOf(0));
  1020. params.put("sa_user_id", user.getId());
  1021. params.put("orderBy", "obj.sa_default desc,obj.sa_sequence");
  1022. params.put("orderType", "asc");
  1023. List<ShipAddressDto> shipAddrs = this.shipAddressFeignClient.queryPages(params);
  1024. map.put("eccs", eccs);
  1025. map.put("shipAddrs", shipAddrs);
  1026. map.put("physicalGoods", Boolean.valueOf(physicalGoods));
  1027. map.put("deliveryGoods", deliveryGoods);
  1028. map.put("page_status", page_status);
  1029. //用改方法查询虚拟商品的数量
  1030. /*map.put("queryOfGoodsCount", this.queryOfGoodsCount);*/
  1031. } else {
  1032. return ResponseCode.buildEnumMap(ResponseCode.PARAM_ERROR, null);
  1033. }
  1034. return ResponseCode.buildSuccessMap(map);
  1035. }
  1036. /**
  1037. * 根据订单id和商品id查询该商品在该订单中的数量
  1038. * @param order_id
  1039. * @param goods_id
  1040. * @return
  1041. */
  1042. public int queryOfGoodsCount(String order_id, String goods_id) {
  1043. int count = 0;
  1044. OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil
  1045. .null2Long(order_id));
  1046. List<Map> map_list = this.orderFormToolsFeignClient.queryGoodsInfo(of.getGoods_info());
  1047. for (Map map : map_list) {
  1048. if (CommUtil.null2String(map.get("goods_id")).equals(goods_id)) {
  1049. count = CommUtil.null2Int(map.get("goods_count"));
  1050. break;
  1051. }
  1052. }
  1053. if ((count == 0)
  1054. && (!CommUtil.null2String(of.getChild_order_detail())
  1055. .equals(""))) { // 主订单无数量信息,继续从子订单中查询
  1056. List<Map> maps = this.orderFormToolsFeignClient.queryGoodsInfo(of.getChild_order_detail());
  1057. for (Map map : maps) {
  1058. OrderFormDto child_order = this.orderFormFeignClient
  1059. .selectByPrimaryKey(CommUtil.null2Long(map
  1060. .get("order_id")));
  1061. map_list.clear();
  1062. map_list = this.orderFormToolsFeignClient.queryGoodsInfo(child_order.getGoods_info());
  1063. for (Map map1 : map_list) {
  1064. if (CommUtil.null2String(map1.get("goods_id")).equals(
  1065. goods_id)) {
  1066. count = CommUtil.null2Int(map1.get("goods_count"));
  1067. break;
  1068. }
  1069. }
  1070. }
  1071. }
  1072. return count;
  1073. }
  1074. /**
  1075. * 根据订单id查询该订单中所有商品,包括子订单中的商品
  1076. * @param main_order
  1077. * @return
  1078. */
  1079. public List<GoodsDto> queryOfGoods(OrderFormDto main_order) {
  1080. List<Map> map_list =this.orderFormToolsFeignClient.queryGoodsInfo(main_order.getGoods_info());
  1081. List<GoodsDto> goods_list = Lists.newArrayList();
  1082. for (Map map : map_list) {
  1083. GoodsDto goods = this.goodsFeignClient.selectByPrimaryKey(CommUtil
  1084. .null2Long(map.get("goods_id")));
  1085. if(goods != null){
  1086. goods_list.add(goods);
  1087. }
  1088. }
  1089. if (!CommUtil.null2String(main_order.getChild_order_detail())
  1090. .equals("")) {
  1091. List<Map> maps = this.orderFormToolsFeignClient.queryGoodsInfo(main_order.getChild_order_detail());
  1092. for (Map<String, Object> map : maps) {
  1093. OrderFormDto child_order = this.orderFormFeignClient
  1094. .selectByPrimaryKey(CommUtil.null2Long(map
  1095. .get("order_id")));
  1096. map_list.clear();
  1097. map_list =this.orderFormToolsFeignClient.queryGoodsInfo(child_order.getGoods_info());
  1098. for (Map map1 : map_list) {
  1099. GoodsDto good = this.goodsFeignClient.selectByPrimaryKey(CommUtil
  1100. .null2Long(map1.get("goods_id")));
  1101. goods_list.add(good);
  1102. }
  1103. }
  1104. }
  1105. return goods_list;
  1106. }
  1107. /**
  1108. * 卖家修改物流
  1109. * @param request
  1110. * @param response
  1111. * @param id
  1112. * @param currentPage
  1113. * @return
  1114. */
  1115. @RequestMapping(value = { "/order_shipping_code" } , method = RequestMethod.POST)
  1116. public Map<String , Object> order_shipping_code(HttpServletRequest request,@RequestBody JSONObject json) {
  1117. String id = json.optString("id");
  1118. OrderFormDto obj = this.orderFormFeignClient
  1119. .selectByPrimaryKey(CommUtil.null2Long(id));
  1120. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1121. .getCurrentUser(request).getId());
  1122. if(user == null){
  1123. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  1124. }
  1125. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  1126. .getStore_id()));
  1127. if (user.getParent_id()!=null) {
  1128. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1129. }
  1130. //user = user.getParent_id() == null ? user : user.getParent();
  1131. if(user.getStore_id() == null){
  1132. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1133. }
  1134. Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1135. .getStore_id()));
  1136. if(store1 == null || store == null){
  1137. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1138. }
  1139. if (user.getStore_id().equals(store.getId())) {
  1140. return ResponseCode.buildSuccessMap(obj);
  1141. } else {
  1142. return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
  1143. }
  1144. }
  1145. /**
  1146. * 卖家修改物流保存
  1147. * @param request
  1148. * @param response
  1149. * @param id
  1150. * @param currentPage
  1151. * @param shipCode
  1152. * @param state_info
  1153. * @return
  1154. */
  1155. @RequestMapping(value = { "/order_shipping_code_save" } , method = RequestMethod.POST)
  1156. public Map<String , Object> order_shipping_code_saveEntity(HttpServletRequest request,@RequestBody JSONObject json) {
  1157. String id = json.optString("id");
  1158. String shipCode = json.optString("shipCode");
  1159. String state_info = json.optString("state_info");
  1160. OrderFormDto obj = this.orderFormFeignClient
  1161. .selectByPrimaryKey(CommUtil.null2Long(id));
  1162. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1163. .getCurrentUser(request).getId());
  1164. if(user == null){
  1165. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  1166. }
  1167. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  1168. .getStore_id()));
  1169. if (user.getParent_id()!=null) {
  1170. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1171. }
  1172. Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1173. .getStore_id()));
  1174. if(store1 == null || store == null){
  1175. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1176. }
  1177. //user = user.getParent_id() == null ? user : user.getParent();
  1178. if(user.getStore_id() == null){
  1179. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1180. }
  1181. Map<String, Object> map = Maps.newHashMap();
  1182. if (user.getStore_id().equals(store.getId())) {
  1183. obj.setShipCode(shipCode);
  1184. this.orderFormFeignClient.updateById(obj);
  1185. OrderFormLogDto ofl = new OrderFormLogDto();
  1186. ofl.setAddTime(new Date());
  1187. ofl.setLog_info("修改物流信息");
  1188. ofl.setState_info(state_info);
  1189. ofl.setLog_user_id(SecurityUserHolder.getCurrentUser(request).getId());
  1190. ofl.setLog_user_name(SecurityUserHolder.getCurrentUser(request)
  1191. .getUserName());
  1192. ofl.setOf(obj);
  1193. this.orderFormLogFeignClient.saveEntity(ofl);
  1194. if (this.sysConfigFeignClient.getSysConfig().getKuaidi_type() == 1) {
  1195. JSONObject info = new JSONObject();
  1196. Map express_map = JSON.parseObject(obj.getExpress_info());
  1197. info.put("company", CommUtil.null2String(express_map
  1198. .get("express_company_mark")));
  1199. info.put("number", obj.getShipCode());
  1200. info.put("from", CommUtil.null2String(obj.getShip_addr()));
  1201. info.put("to", obj.getReceiver_area());
  1202. info.put("key", this.sysConfigFeignClient.getSysConfig()
  1203. .getKuaidi_id2());
  1204. JSONObject param_info = new JSONObject();
  1205. param_info.put("callbackurl", CommUtil.getURL(request)
  1206. + "/kuaidi_callback?order_id=" + obj.getId()
  1207. + "&orderType=0");
  1208. param_info.put("salt",
  1209. Md5Encrypt.md5(CommUtil.null2String(obj.getId()))
  1210. .substring(0, 16));
  1211. info.put("parameters", param_info);
  1212. try {
  1213. String result = Post(
  1214. "http://highapi.kuaidi.com/openapi-receive.html",
  1215. info.toString());
  1216. Map remap = JSON.parseObject(result);
  1217. if ("success".equals(CommUtil.null2String(remap
  1218. .get("message")))) {
  1219. ExpressInfoDto ei = new ExpressInfoDto();
  1220. ei.setAddTime(new Date());
  1221. ei.setOrder_id(obj.getId());
  1222. ei.setOrder_express_id(obj.getShipCode());
  1223. ei.setOrder_type(0);
  1224. Map ec_map = JSON.parseObject(CommUtil.null2String(obj
  1225. .getExpress_info()));
  1226. if (ec_map != null) {
  1227. ei.setOrder_express_name(CommUtil
  1228. .null2String(ec_map
  1229. .get("express_company_name")));
  1230. }
  1231. this.expressInfoFeignClient.saveEntity(ei);
  1232. System.out.println("订阅成功");
  1233. } else {
  1234. System.out.println("订阅失败");
  1235. }
  1236. } catch (JSONException e) {
  1237. e.printStackTrace();
  1238. }
  1239. }
  1240. }
  1241. return ResponseCode.buildSuccessMap(null);
  1242. }
  1243. /**
  1244. * 快递Post请求
  1245. * @param url
  1246. * @param param
  1247. * @return
  1248. */
  1249. @SuppressWarnings("resource")
  1250. public static String Post(String url, String param) {
  1251. try {
  1252. DefaultHttpClient httpClient = new DefaultHttpClient();
  1253. HttpPost method = new HttpPost(url);
  1254. StringEntity entity = new StringEntity(param, "utf-8");// 解决中文乱码问题
  1255. entity.setContentEncoding("UTF-8");
  1256. entity.setContentType("application/json");
  1257. method.setEntity(entity);
  1258. HttpResponse result = httpClient.execute(method);
  1259. // 请求结束,返回结果
  1260. return EntityUtils.toString(result.getEntity());
  1261. } catch (Exception e) {
  1262. e.printStackTrace();
  1263. throw new RuntimeException(e.getMessage());
  1264. }
  1265. }
  1266. /**
  1267. * 卖家物流详情
  1268. * @param request
  1269. * @param response
  1270. * @param id
  1271. * @return
  1272. */
  1273. @RequestMapping( value = { "/ship_view" } , method = RequestMethod.POST)
  1274. public Map<String , Object> order_ship_view(HttpServletRequest request,@RequestBody JSONObject json) {
  1275. String id = json.optString("id");
  1276. OrderFormDto obj = this.orderFormFeignClient
  1277. .selectByPrimaryKey(CommUtil.null2Long(id));
  1278. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1279. .getCurrentUser(request).getId());
  1280. if(user == null){
  1281. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  1282. }
  1283. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  1284. .getStore_id()));
  1285. if (user.getParent_id()!=null) {
  1286. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1287. }
  1288. Store store1 = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1289. .getStore_id()));
  1290. if(store1 == null || store == null){
  1291. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1292. }
  1293. //user = user.getParent_id() == null ? user : user.getParent();
  1294. if(user.getStore_id() == null){
  1295. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1296. }
  1297. Map<String, Object> map = Maps.newHashMap();
  1298. if (user.getStore_id().equals(store.getId())) {
  1299. map.put("obj", obj);
  1300. TransInfoDto transInfo = this.shipToolsFeignClient
  1301. .query_Ordership_getData(CommUtil.null2String(obj.getId()));
  1302. map.put("transInfo", transInfo);
  1303. return ResponseCode.buildSuccessMap(map);
  1304. } else {
  1305. return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
  1306. }
  1307. }
  1308. /**
  1309. * 商品评价列表
  1310. * @param request
  1311. * @param response
  1312. * @param currentPage
  1313. * @param orderBy
  1314. * @param orderType
  1315. * @param status
  1316. * @return
  1317. */
  1318. @RequestMapping({ "/evaluate_list" })
  1319. public Map<String , Object> evaluate_list(HttpServletRequest request,@RequestBody JSONObject json) {
  1320. String currentPage = json.getString("currentPage");
  1321. String orderBy = json.getString("orderBy");
  1322. String orderType = json.getString("orderType");
  1323. String status = json.getString("status");
  1324. String evaluate_buyer_val = json.getString("evaluate_buyer_val");
  1325. Map<String,Object> maps= this.queryTools.getParams(currentPage, orderBy, orderType);
  1326. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  1327. if(user == null){
  1328. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  1329. }
  1330. if (user.getParent_id()!=null) {
  1331. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1332. }
  1333. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1334. .getStore_id()));
  1335. if(store == null){
  1336. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1337. }
  1338. maps.put("evaluate_goods_goods_store_id", store.getId());
  1339. maps.put("evaluate_status", 0);
  1340. maps.put("evaluate_type", "goods");
  1341. if ("yes".equals(status)) {
  1342. maps.put("reply_status", 1);
  1343. maps.put("status", status);
  1344. }
  1345. if ("no".equals(status)) {
  1346. maps.put("reply_status", 0);
  1347. maps.put("status", status);
  1348. }
  1349. //买家评价,评价类型,1为好评,0为中评,-1为差评
  1350. if(StringUtils.isNotBlank(evaluate_buyer_val)){
  1351. maps.put("evaluate_buyer_val", evaluate_buyer_val);
  1352. }
  1353. Map<String, Object> map = this.evaluateFeignClient.list(maps);
  1354. map.put("status", status);
  1355. return ResponseCode.buildSuccessMap(map);
  1356. }
  1357. /**
  1358. * 商品评价内容查看
  1359. * @param request
  1360. * @param response
  1361. * @param id
  1362. * @return
  1363. */
  1364. @RequestMapping( value = { "/evaluate_info" } ,method = RequestMethod.POST)
  1365. public Map<String , Object> evaluate_info(HttpServletRequest request,@RequestBody JSONObject json) {
  1366. String id = json.optString("id");
  1367. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1368. .getCurrentUser(request).getId());
  1369. if(user == null){
  1370. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  1371. }
  1372. if (user.getParent_id()!=null) {
  1373. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1374. }
  1375. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1376. .getStore_id()));
  1377. if(store == null){
  1378. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1379. }
  1380. EvaluateDto evl = this.evaluateFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1381. //TODO
  1382. if (evl != null){
  1383. OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(evl.getOf_id());
  1384. UserDto euser = userFeignClient.selectByPrimaryKey(evl.getEvaluate_user_id());
  1385. if((of.getStore_id().equals(user.getStore_id()+""))) {
  1386. /*mv.addObject("evl", evl);*/
  1387. /*mv.addObject("imageTools", this.imageTools);*/
  1388. Map<String , Object> maps = Maps.newHashMap();
  1389. maps.put("evl", evl);
  1390. maps.put("euser", euser);
  1391. return ResponseCode.buildSuccessMap(maps);
  1392. } else {
  1393. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1394. }
  1395. }else{
  1396. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1397. }
  1398. }
  1399. /**
  1400. * 商品评价内容回复
  1401. * @param request
  1402. * @param response
  1403. * @param id
  1404. * @param reply
  1405. */
  1406. @RequestMapping( value = { "/evaluate_reply_save" } , method = RequestMethod.POST)
  1407. public Map<String, Object> evaluate_reply_saveEntity(HttpServletRequest request,@RequestBody JSONObject json) {
  1408. String id = json.optString("id");
  1409. String reply = json.optString("reply");
  1410. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  1411. if(user == null){
  1412. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  1413. }
  1414. if (user.getParent_id()!=null) {
  1415. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1416. }
  1417. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1418. .getStore_id()));
  1419. if(store == null){
  1420. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1421. }
  1422. EvaluateDto evl = this.evaluateFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1423. if (evl != null){
  1424. OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(evl.getOf_id());
  1425. if((of.getStore_id().equals(user.getStore_id()+""))) {
  1426. /*mv.addObject("evl", evl);*/
  1427. /*mv.addObject("imageTools", this.imageTools);*/
  1428. evl.setReply(reply);
  1429. evl.setReply_status(1);
  1430. this.evaluateFeignClient.updateById(evl);
  1431. return ResponseCode.buildSuccessMap(evl);
  1432. } else {
  1433. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1434. }
  1435. }else{
  1436. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1437. }
  1438. }
  1439. /**
  1440. * 常用快递公司
  1441. * @param request
  1442. * @param response
  1443. * @param currentPage
  1444. * @param orderBy
  1445. * @param orderType
  1446. * @return
  1447. */
  1448. @RequestMapping(value = { "/ecc_set" } ,method = RequestMethod.POST)
  1449. public Map<String , Object> ecc_set(HttpServletRequest request) {
  1450. Map<String, Object> params = Maps.newHashMap();
  1451. /*List<ExpressCompanyDto> ecs = this.expressCompanyFeignClient.queryPageList(params);*/
  1452. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1453. .getCurrentUser(request).getId());
  1454. if(user == null){
  1455. return ResponseCode.buildEnumMap(ResponseCode.TOKEN_EXPIRE, null);
  1456. }
  1457. if (user.getParent_id()!=null) {
  1458. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1459. }
  1460. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1461. .getStore_id()));
  1462. if(store == null){
  1463. return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE, null);
  1464. }
  1465. List<ExpressCompanyCommonDto> eccs = Lists.newArrayList();
  1466. if ((store != null) && (user.getUserRole().indexOf("SELLER") >= 0)) {
  1467. params.put("ecc_type", Integer.valueOf(0));
  1468. params.put("ecc_store_id", store.getId());
  1469. eccs = this.expressCompanyCommonFeignClient.queryPages(params);
  1470. }
  1471. /*mv.addObject("ecs", ecs);
  1472. mv.addObject("transportTools", this.transportTools);*/
  1473. return ResponseCode.buildSuccessMap(eccs);
  1474. }
  1475. // public int query_common_ec(HttpServletRequest request,String id) {
  1476. // int ret = 0;
  1477. // if (!CommUtil.null2String(id).equals("")) {
  1478. // Map<String, Object> params = Maps.newHashMap();
  1479. // UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1480. // .getCurrentUser(request).getId());
  1481. // if(user == null){
  1482. // return ret;
  1483. // }
  1484. // if (user.getParent_id()!=null) {
  1485. // user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1486. // }
  1487. // Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1488. // .getStore_id()));
  1489. // if(store == null){
  1490. // return ret;
  1491. // }
  1492. // List<ExpressCompanyCommonDto> eccs = Lists.newArrayList();
  1493. // if ((store != null) && (user.getUserRole().indexOf("SELLER") >= 0)) {
  1494. // params.put("ecc_type", Integer.valueOf(0));
  1495. // params.put("ecc_store_id", store.getId());
  1496. // eccs = this.expressCompanyCommon.queryPageList(params);
  1497. //
  1498. // for (ExpressCompanyCommonDto ecc : eccs) {
  1499. // if (ecc.getEcc_ec_id().equals(CommUtil.null2Long(id))) {
  1500. // ret = 1;
  1501. // }
  1502. // }
  1503. // } else {
  1504. // params.put("ecc_type", Integer.valueOf(1));
  1505. // eccs = this.expressCompanyCommon.queryPageList(params);
  1506. //
  1507. // for (ExpressCompanyCommonDto ecc : eccs) {
  1508. // if (ecc.getEcc_ec_id().equals(CommUtil.null2Long(id))) {
  1509. // ret = 1;
  1510. // }
  1511. // }
  1512. // }
  1513. // }
  1514. // return ret;
  1515. // }
  1516. /**
  1517. * 常用快递公司删除
  1518. * @param request
  1519. * @param response
  1520. * @param id
  1521. * @param currentPage
  1522. * @return
  1523. */
  1524. @RequestMapping(value = { "/ecc_delete" } , method = RequestMethod.POST)
  1525. public Map<String, Object> ecc_deleteById(HttpServletRequest request,@RequestBody JSONObject json) {
  1526. String id = json.optString("id");
  1527. ExpressCompanyCommonDto ecc = this.expressCompanyCommonFeignClient
  1528. .selectByPrimaryKey(CommUtil.null2Long(id));
  1529. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1530. .getCurrentUser(request).getId());
  1531. if(user == null){
  1532. return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
  1533. }
  1534. if (user.getParent_id()!=null) {
  1535. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1536. }
  1537. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1538. .getStore_id()));
  1539. if(store == null){
  1540. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1541. }
  1542. if (ecc.getEcc_store_id().equals(store.getId())) {
  1543. this.expressCompanyCommonFeignClient.deleteById(CommUtil.null2Long(id));
  1544. return ResponseCode.buildSuccessMap(null);
  1545. }else{
  1546. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1547. }
  1548. }
  1549. /**
  1550. * 所有未选择的常用快递公司
  1551. * @param request
  1552. * @param response
  1553. * @param id
  1554. * @param currentPage
  1555. * @return
  1556. */
  1557. @RequestMapping(value = { "/ecc_saveEntityView" } , method = RequestMethod.POST)
  1558. public Map<String, Object> ecc_saveEntityView(HttpServletRequest request,@RequestBody JSONObject json) {
  1559. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1560. .getCurrentUser(request).getId());
  1561. if(user == null){
  1562. return ResponseCode.buildEnumMap( ResponseCode.TOKEN_EXPIRE, null);
  1563. }
  1564. if (user.getParent_id()!=null) {
  1565. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1566. }
  1567. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1568. .getStore_id()));
  1569. if(store == null){
  1570. return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE,null);
  1571. }
  1572. Map<String, Object> params = Maps.newHashMap();
  1573. params.put("company_status", Integer.valueOf(0));
  1574. params.put("orderBy", "company_sequence");
  1575. params.put("orderType", "asc");
  1576. List<ExpressCompanyDto> excs = this.expressCompanyFeignClient.queryPages(params);
  1577. List<ExpressCompanyCommonDto> eccs = Lists.newArrayList();
  1578. List<ExpressCompanyDto> execs = Lists.newArrayList();
  1579. if ((store != null) && (user.getUserRole().indexOf("SELLER") >= 0)) {
  1580. params.clear();
  1581. params.put("ecc_type", Integer.valueOf(0));
  1582. params.put("ecc_store_id", store.getId());
  1583. eccs = this.expressCompanyCommonFeignClient.queryPages(params);
  1584. for (ExpressCompanyDto exc : excs) {
  1585. int i= 0;
  1586. for (ExpressCompanyCommonDto ecc : eccs) {
  1587. if (ecc.getEcc_ec_id().equals(CommUtil.null2Long(exc.getId()))) {
  1588. i=1;
  1589. break;
  1590. }
  1591. }
  1592. if(i == 0){
  1593. execs.add(exc);
  1594. }
  1595. }
  1596. }
  1597. return ResponseCode.buildSuccessMap(execs);
  1598. }
  1599. /**
  1600. * 常用快递公司添加
  1601. * @param request
  1602. * @param response
  1603. * @param id
  1604. * @param currentPage
  1605. * @return
  1606. */
  1607. @RequestMapping(value = { "/ecc_saveEntity" } , method = RequestMethod.POST)
  1608. public Map<String, Object> ecc_saveEntity(HttpServletRequest request,@RequestBody JSONObject json) {
  1609. String ids = json.optString("ids");
  1610. String[] ec_ids= null;
  1611. if(ids != null){
  1612. ec_ids = ids.split(",");
  1613. }
  1614. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1615. .getCurrentUser(request).getId());
  1616. if(user == null){
  1617. return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
  1618. }
  1619. if (user.getParent_id()!=null) {
  1620. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1621. }
  1622. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1623. .getStore_id()));
  1624. if(store == null){
  1625. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1626. }
  1627. for (String ec_id : ec_ids) {
  1628. if (!CommUtil.null2String(ec_id).equals("")) {
  1629. ExpressCompanyDto ec = this.expressCompanyFeignClient.selectByPrimaryKey(CommUtil.null2Long(ec_id));
  1630. ExpressCompanyCommonDto ecc = new ExpressCompanyCommonDto();
  1631. ecc.setAddTime(new Date());
  1632. ecc.setEcc_code(ec.getCompany_mark());
  1633. ecc.setEcc_ec_id(ec.getId());
  1634. ecc.setEcc_name(ec.getCompany_name());
  1635. ecc.setEcc_store_id(store.getId());
  1636. ecc.setEcc_template(ec.getCompany_template());
  1637. ecc.setEcc_template_heigh(ec.getCompany_template_heigh());
  1638. ecc.setEcc_template_width(ec.getCompany_template_width());
  1639. ecc.setEcc_template_offset(ec.getCompany_template_offset());
  1640. ecc.setEcc_type(0);
  1641. ecc.setEcc_ec_type(ec.getCompany_type());
  1642. this.expressCompanyCommonFeignClient.saveEntity(ecc);
  1643. }
  1644. }
  1645. return ResponseCode.buildSuccessMap(null);
  1646. }
  1647. /**
  1648. * 发货地址列表
  1649. * @param request
  1650. * @param response
  1651. * @param currentPage
  1652. * @param orderBy
  1653. * @param orderType
  1654. * @return
  1655. */
  1656. @RequestMapping(value = { "/ship_address" } ,method = RequestMethod.POST)
  1657. public Map<String,Object> ship_address(HttpServletRequest request,@RequestBody JSONObject json) {
  1658. String currentPage = json.optString("currentPage");
  1659. String orderBy = json.optString("orderBy");
  1660. String orderType = json.optString("orderType");
  1661. Map<String,Object> maps= this.queryTools.getParams(currentPage, orderBy, orderType);
  1662. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
  1663. List<Long> sa_user_ids = Lists.newArrayList();
  1664. sa_user_ids.add(user.getId());
  1665. if(user!=null && user.getParent_id()!=null){
  1666. UserDto userParent = this.userFeignClient.selectByPrimaryKey(user.getParent().getId());
  1667. sa_user_ids.add(userParent.getId());
  1668. List<UserDto> childs = userParent.getChilds();
  1669. for (UserDto uc : childs) {
  1670. sa_user_ids.add(uc.getId());
  1671. }
  1672. }
  1673. if(user!=null && user.getChilds()!=null && user.getChilds().size()>0){
  1674. List<UserDto> childs = user.getChilds();
  1675. for (UserDto uc : childs) {
  1676. sa_user_ids.add(uc.getId());
  1677. }
  1678. }
  1679. maps.put("sa_type", 0);
  1680. maps.put("sa_user_ids", sa_user_ids);
  1681. Map<String, Object> data = this.shipAddressFeignClient.list(maps);
  1682. HashMap<Object, Object> result = new HashMap<>();
  1683. result.put("data", data);
  1684. Store store = storeService.selectByPrimaryKey(user.getStore_id());
  1685. if (store!=null) {
  1686. List<Map> ms_list = Lists.newArrayList();
  1687. if (store.getStore_service_info() != null) {
  1688. ms_list = JSON.parseArray(store.getStore_service_info(),Map.class);
  1689. }
  1690. result.put("ms_list", ms_list);
  1691. if (store.getMc_id()!=null&&store.getMc_id()==22) {
  1692. result.put("scenic", 1); //为景点商品
  1693. }else{
  1694. result.put("scenic", 0); //普通商品
  1695. }
  1696. }
  1697. return ResponseCode.buildSuccessMap(result);
  1698. }
  1699. /**
  1700. * 新增发货地址的地区
  1701. * @param request
  1702. * @param response
  1703. * @param currentPage
  1704. * @return
  1705. */
  1706. @RequestMapping(value = { "/ship_address_add" } , method = RequestMethod.POST)
  1707. public Map<String , Object> ship_address_add(HttpServletRequest request, @RequestBody JSONObject json) {
  1708. String parent_id = json.optString("parent_id");
  1709. Map<String, Object> maps = Maps.newHashMap();
  1710. if(StringUtils.isNotBlank(parent_id)){
  1711. maps.put("parent_id", parent_id);
  1712. }else{
  1713. maps.put("parent_id", -1);
  1714. }
  1715. /*List<AreaDto> areas = this.areaFeignClient.queryPageList(maps);*/
  1716. List<AreaDto> areas = this.areaFeignClient.queryPages(maps);
  1717. return ResponseCode.buildSuccessMap(areas);
  1718. }
  1719. /**
  1720. * 编辑发货地址
  1721. * @param request
  1722. * @param response
  1723. * @param id
  1724. * @param currentPage
  1725. * @return
  1726. */
  1727. @RequestMapping(value = { "/ship_address_edit" } , method = RequestMethod.POST)
  1728. public Map<String , Object> ship_address_edit(HttpServletRequest request,@RequestBody JSONObject json) {
  1729. String id = json.optString("id");
  1730. ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(CommUtil
  1731. .null2Long(id));
  1732. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1733. .getCurrentUser(request).getId());
  1734. if(user == null){
  1735. return ResponseCode.buildEnumMap(ResponseCode.TOKEN_EXPIRE,null);
  1736. }
  1737. if (user.getParent_id()!=null) {
  1738. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1739. }
  1740. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1741. .getStore_id()));
  1742. if(store == null){
  1743. return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE,null);
  1744. }
  1745. if ((obj != null) && (obj.getSa_user_id().equals(user.getId()))) {
  1746. Map<String, Object> maps = Maps.newHashMap();
  1747. AreaDto sa_area = this.areaFeignClient.selectByPrimaryKeyFullParent(obj.getSa_area_id());
  1748. obj.setSa_area_name(sa_area.getParent().getParent().getAreaName()+sa_area.getParent().getAreaName()+sa_area.getAreaName());
  1749. maps.put("obj", obj);
  1750. return ResponseCode.buildSuccessMap(maps);
  1751. } else {
  1752. return ResponseCode.buildEnumMap(ResponseCode.PARAM_ERROR, null);
  1753. }
  1754. }
  1755. /**
  1756. * 保存发货地址
  1757. * @param request
  1758. * @param response
  1759. * @param id
  1760. * @param currentPage
  1761. */
  1762. @RequestMapping( value = { "/ship_address_save" } ,method = RequestMethod.POST)
  1763. public Map<String , Object> ship_address_saveEntity(HttpServletRequest request,@RequestBody ShipAddressDto shipaddress) {
  1764. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1765. .getCurrentUser(request).getId());
  1766. if(user == null){
  1767. return ResponseCode.buildEnumMap(ResponseCode.TOKEN_EXPIRE,null);
  1768. }
  1769. if (user.getParent_id()!=null) {
  1770. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1771. }
  1772. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1773. .getStore_id()));
  1774. if(store == null){
  1775. return ResponseCode.buildEnumMap(ResponseCode.NOTSTORE,null);
  1776. }
  1777. if(shipaddress == null){
  1778. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1779. }
  1780. if (StringUtils.isBlank(shipaddress.getId()+"")) {
  1781. shipaddress.setAddTime(new Date());
  1782. shipaddress.setDeleteStatus(0);
  1783. } else {
  1784. ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(shipaddress.getId());
  1785. shipaddress.setAddTime(obj.getAddTime());
  1786. shipaddress.setDeleteStatus(obj.getDeleteStatus());
  1787. }
  1788. //判断是不是第一个发货地址 如果是则设置成默认的
  1789. Map< String , Object> maps = Maps.newHashMap();
  1790. List<Long> sa_user_ids = Lists.newArrayList();
  1791. sa_user_ids.add(user.getId());
  1792. if(user!=null && user.getParent_id()!=null){
  1793. UserDto userParent = this.userFeignClient.selectByPrimaryKey(user.getParent().getId());
  1794. sa_user_ids.add(userParent.getId());
  1795. List<UserDto> childs = userParent.getChilds();
  1796. for (UserDto uc : childs) {
  1797. sa_user_ids.add(uc.getId());
  1798. }
  1799. }
  1800. if(user!=null && user.getChilds()!=null && user.getChilds().size()>0){
  1801. List<UserDto> childs = user.getChilds();
  1802. for (UserDto uc : childs) {
  1803. sa_user_ids.add(uc.getId());
  1804. }
  1805. }
  1806. maps.put("sa_type", 0);
  1807. maps.put("sa_user_ids", sa_user_ids);
  1808. List<ShipAddressDto> queryPages = this.shipAddressFeignClient.queryPages(maps);
  1809. if(queryPages.size()>0){
  1810. shipaddress.setSa_default(0);
  1811. }else{
  1812. shipaddress.setSa_default(1);
  1813. }
  1814. shipaddress.setStore_id(store.getId());
  1815. shipaddress.setSa_type(0);
  1816. shipaddress.setSa_user_id(SecurityUserHolder.getCurrentUser(request).getId());
  1817. shipaddress.setSa_user_name(SecurityUserHolder.getCurrentUser(request)
  1818. .getUsername());
  1819. // 根据行业 决定是否需要创建达达门店
  1820. if (modularClassFeignClient.selectByPrimaryKey(store.getMc_id()).isTimely()) { // 若为附近配送,
  1821. SysConfigDto sysConfig = sysConfigFeignClient.getSysConfig();
  1822. if (sysConfig.getDada_appkey()!=null&& sysConfig.getDada_appsecret()!=null) {
  1823. // 1.初始化配置(isOnline表示是否测试环境)
  1824. DaDaAppConfig appConfig = new DaDaAppConfig(store.getSource_id() + "", sysConfig.getDada_appkey(), sysConfig.getDada_appsecret());
  1825. // 2.初始化model
  1826. ShopAddModel shopAddModel = new ShopAddModel();
  1827. if (StringUtils.isBlank(shipaddress.getId()+"")) { //不存在走更新
  1828. // 根据实际信息来填写门店地址
  1829. String order_suffix = CommUtil.formatTime("yyyyMMddHHmmss", new Date());
  1830. shopAddModel.setOriginShopId(order_suffix + store.getId()); // 门店编码,可自定义,但必须唯一;若不填写,则系统自动生成
  1831. shipaddress.setShop_no(order_suffix + store.getId()); // 保存门店编码
  1832. }else{
  1833. shopAddModel.setOriginShopId(shipaddress.getShop_no());
  1834. }
  1835. shopAddModel.setStationName(shipaddress.getSa_name()); // 门店名称
  1836. shopAddModel.setBusiness(13); // 业务类型, 13 水果生鲜
  1837. AreaDto area = areaFeignClient.selectByPrimaryKeyFullParent(shipaddress.getSa_area_id());
  1838. // shipaddress
  1839. shopAddModel.setCityName(area.getParent().getAreaName()); // 城市名称
  1840. shopAddModel.setAreaName(area.getAreaName()); // 区域名称
  1841. shopAddModel.setStationAddress(shipaddress.getSa_addr()); // 详细地址
  1842. shopAddModel.setLng(BigDecimal.valueOf(shipaddress.getSa_lng())); // 经纬度
  1843. shopAddModel.setLat(BigDecimal.valueOf(shipaddress.getSa_lat()));
  1844. shopAddModel.setContactName(shipaddress.getSa_user());
  1845. shopAddModel.setPhone(shipaddress.getSa_telephone());
  1846. // 3.初始化service (门店新增比较特殊,是一个批量新增接口)
  1847. List<ShopAddModel> shopAddList = new ArrayList<ShopAddModel>();
  1848. shopAddList.add(shopAddModel);
  1849. String dadaUrl = null;
  1850. if (StringUtils.isBlank(shipaddress.getId()+"")) {
  1851. dadaUrl = "/api/shop/add";
  1852. } else {
  1853. // 更新门店信息
  1854. dadaUrl = "/api/shop/update";
  1855. }
  1856. DaDaService shopAddService = new DaDaService(dadaUrl, JSONUtil.toJson(shopAddList));
  1857. // 4.初始化客户端
  1858. DadaRequestClient dadaClient = new DadaRequestClient(shopAddService, appConfig);
  1859. DadaApiResponse callRpc = dadaClient.callRpc();
  1860. if (callRpc.getCode() != 0) { // 不成功 ,返回错误信息
  1861. return ResponseCode.buildCodeMap("100", callRpc.getMsg(), null);
  1862. }
  1863. }
  1864. }
  1865. if (StringUtils.isBlank(shipaddress.getId()+"")) {
  1866. this.shipAddressFeignClient.saveEntity(shipaddress);
  1867. } else {
  1868. this.shipAddressFeignClient.updateById(shipaddress);
  1869. }
  1870. return ResponseCode.buildSuccessMap(null);
  1871. }
  1872. /**
  1873. * 发货地址删除
  1874. * @param request
  1875. * @param response
  1876. * @param mulitId
  1877. * @param currentPage
  1878. * @return
  1879. */
  1880. @RequestMapping(value = { "/ship_address_del" } , method = RequestMethod.POST)
  1881. public Map<String , Object> ship_address_del(HttpServletRequest request,@RequestBody JSONObject json) {
  1882. String id = json.optString("id");
  1883. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1884. .getCurrentUser(request).getId());
  1885. if(user == null){
  1886. return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
  1887. }
  1888. if (user.getParent_id()!=null) {
  1889. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1890. }
  1891. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1892. .getStore_id()));
  1893. if(store == null){
  1894. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1895. }
  1896. if (StringUtils.isNotBlank(id)) {
  1897. ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(CommUtil
  1898. .null2Long(id));
  1899. if ((obj != null) && (obj.getSa_type() == 0)
  1900. && (obj.getSa_user_id().equals(user.getId()))) {
  1901. this.shipAddressFeignClient.deleteById(obj.getId());
  1902. }
  1903. }
  1904. return ResponseCode.buildSuccessMap(null);
  1905. }
  1906. /**
  1907. * 设置默认发货地址
  1908. * @param request
  1909. * @param response
  1910. * @param id
  1911. * @param currentPage
  1912. * @return
  1913. */
  1914. @RequestMapping( value = { "/ship_address_default" } , method = RequestMethod.POST)
  1915. public Map<String , Object> ship_address_default(HttpServletRequest request, @RequestBody JSONObject json) {
  1916. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1917. .getCurrentUser(request).getId());
  1918. if(user == null){
  1919. return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
  1920. }
  1921. if (user.getParent_id()!=null) {
  1922. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1923. }
  1924. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
  1925. .getStore_id()));
  1926. if(store == null){
  1927. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1928. }
  1929. Map<String, Object> params = Maps.newHashMap();
  1930. params.put("sa_default", Integer.valueOf(1));
  1931. params.put("sa_user_id", user.getId());
  1932. List<ShipAddressDto> sa_list = this.shipAddressFeignClient.queryPages(params);
  1933. for (ShipAddressDto sa : sa_list) {
  1934. sa.setSa_default(0);
  1935. this.shipAddressFeignClient.updateById(sa);
  1936. }
  1937. String id = json.optString("id");
  1938. ShipAddressDto obj = this.shipAddressFeignClient.selectByPrimaryKey(CommUtil
  1939. .null2Long(id));
  1940. if (obj.getSa_user_id().equals(user.getId())) {
  1941. obj.setSa_default(1);
  1942. this.shipAddressFeignClient.updateById(obj);
  1943. }
  1944. return ResponseCode.buildSuccessMap(null);
  1945. }
  1946. /**
  1947. * 设置修改收货地址
  1948. * @param request
  1949. * @param response
  1950. * @param id
  1951. * @param currentPage
  1952. * @return
  1953. */
  1954. @RequestMapping(value = { "/upShippingAddress" } , method = RequestMethod.POST)
  1955. public Map<String , Object> upShippingAddress(HttpServletRequest request,
  1956. @RequestBody JSONObject json) {
  1957. String id = json.optString("id");
  1958. OrderFormDto obj = this.orderFormFeignClient
  1959. .selectByPrimaryKey(CommUtil.null2Long(id));
  1960. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  1961. .getCurrentUser(request).getId());
  1962. if(user == null){
  1963. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  1964. }
  1965. if (user.getParent_id()!=null) {
  1966. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  1967. }
  1968. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  1969. .getStore_id()));
  1970. if(store == null){
  1971. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  1972. }
  1973. //user = user.getParent_id() == null ? user : user.getParent();
  1974. if(user.getStore_id() == null){
  1975. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  1976. }
  1977. if (user.getStore_id().equals(store.getId())) {
  1978. return ResponseCode.buildSuccessMap(obj);
  1979. } else {
  1980. return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
  1981. }
  1982. }
  1983. /**
  1984. * 设置修改收货地址保存
  1985. * @param request
  1986. * @param response
  1987. * @param id
  1988. * @param currentPage
  1989. * @return
  1990. */
  1991. @RequestMapping(value = { "/upShippingAddress_save" } , method = RequestMethod.POST)
  1992. public Map<String , Object> upShippingAddress_save(HttpServletRequest request,
  1993. @RequestBody JSONObject json) {
  1994. String id = json.optString("id");
  1995. String receiver_name = json.optString("receiver_name");// 收货人姓名,确认订单后,将买家的收货地址所有信息添加到订单中,该订单与买家收货地址没有任何关联
  1996. String receiver_area = json.optString("receiver_area");// 收货人地区,例如:福建省厦门市海沧区
  1997. String receiver_area_info = json.optString("receiver_area_info");// 收货人详细地址,例如:凌空二街56-1号,4单元21
  1998. //String receiver_zip = json.optString("receiver_zip");// 收货人邮政编码
  1999. String receiver_telephone = json.optString("receiver_telephone");// 收货人联系电话
  2000. String receiver_mobile = json.optString("receiver_mobile");// 收货人手机号码
  2001. String lat = json.optString("lat");// 经纬度
  2002. String lng = json.optString("lng");//
  2003. OrderFormDto obj = this.orderFormFeignClient
  2004. .selectByPrimaryKey(CommUtil.null2Long(id));
  2005. if(obj == null){
  2006. return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
  2007. }
  2008. UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
  2009. .getCurrentUser(request).getId());
  2010. if(user == null){
  2011. return ResponseCode.buildReturnMap(ResponseCode.USER_DOES_NOT_EXIST, null);
  2012. }
  2013. if (user.getParent_id()!=null) {
  2014. user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
  2015. }
  2016. Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(obj
  2017. .getStore_id()));
  2018. if(store == null){
  2019. return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
  2020. }
  2021. //user = user.getParent_id() == null ? user : user.getParent();
  2022. if(user.getStore_id() == null){
  2023. return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
  2024. }
  2025. if (CommUtil.null2String(user.getStore_id()).equals(CommUtil.null2String(store.getId()))) {
  2026. obj.setReceiver_Name(receiver_name);
  2027. obj.setReceiver_area(receiver_area);
  2028. obj.setReceiver_area_info(receiver_area_info);
  2029. //obj.setReceiver_zip(receiver_zip);
  2030. obj.setReceiver_telephone(receiver_telephone);
  2031. obj.setReceiver_mobile(receiver_mobile);
  2032. if (StringUtils.isNotBlank(lat)&&StringUtils.isNotBlank(lng)) {
  2033. obj.setUser_lat(CommUtil.null2Double(lat));
  2034. obj.setUser_lng(CommUtil.null2Double(lng));
  2035. }
  2036. orderFormFeignClient.updateById(obj);
  2037. return ResponseCode.buildSuccessMap(obj);
  2038. } else {
  2039. return ResponseCode.buildEnumMap(ResponseCode.FAILURE, null);
  2040. }
  2041. }
  2042. }
  1. package com.honghu.cloud.controller;
  2. import java.io.BufferedReader;
  3. import java.io.ByteArrayInputStream;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9. import java.io.PrintWriter;
  10. import java.math.BigDecimal;
  11. import java.net.HttpURLConnection;
  12. import java.net.URL;
  13. import java.net.URLEncoder;
  14. import java.text.SimpleDateFormat;
  15. import java.util.Date;
  16. import java.util.Enumeration;
  17. import java.util.HashMap;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. import java.util.Map;
  21. import javax.servlet.http.HttpServletRequest;
  22. import javax.servlet.http.HttpServletResponse;
  23. import org.apache.commons.lang.StringUtils;
  24. import org.jdom.Document;
  25. import org.jdom.Element;
  26. import org.jdom.JDOMException;
  27. import org.jdom.input.SAXBuilder;
  28. import org.slf4j.Logger;
  29. import org.slf4j.LoggerFactory;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.web.bind.annotation.RequestBody;
  32. import org.springframework.web.bind.annotation.RequestMapping;
  33. import org.springframework.web.bind.annotation.RequestMethod;
  34. import org.springframework.web.bind.annotation.RestController;
  35. import com.alibaba.fastjson.JSON;
  36. import com.google.common.collect.Lists;
  37. import com.google.common.collect.Maps;
  38. import com.honghu.cloud.bean.GoldLog;
  39. import com.honghu.cloud.bean.GoldRecord;
  40. import com.honghu.cloud.bean.Payment;
  41. import com.honghu.cloud.bean.PlatformPay;
  42. import com.honghu.cloud.bean.PlatformPayFlow;
  43. import com.honghu.cloud.code.ResponseCode;
  44. import com.honghu.cloud.dto.CloudPurchaseOrderDto;
  45. import com.honghu.cloud.dto.DistributionSettingDto;
  46. import com.honghu.cloud.dto.IntegralGoodsDto;
  47. import com.honghu.cloud.dto.IntegralGoodsOrderDto;
  48. import com.honghu.cloud.dto.MessageDto;
  49. import com.honghu.cloud.dto.OrderFormDto;
  50. import com.honghu.cloud.dto.PredepositDto;
  51. import com.honghu.cloud.dto.PredepositLogDto;
  52. import com.honghu.cloud.dto.RushOrderformDto;
  53. import com.honghu.cloud.dto.StoreDto;
  54. import com.honghu.cloud.dto.SysConfigDto;
  55. import com.honghu.cloud.dto.SysConfigExtendDto;
  56. import com.honghu.cloud.dto.UserDto;
  57. import com.honghu.cloud.feign.AgentProfitFeignClient;
  58. import com.honghu.cloud.feign.CloudPurchaseOrderFeignClient;
  59. import com.honghu.cloud.feign.DistributionOrderFeignClient;
  60. import com.honghu.cloud.feign.DistributionProfitFeignClient;
  61. import com.honghu.cloud.feign.DistributionSettingFeignClient;
  62. import com.honghu.cloud.feign.HandleOrderFormFeignClient;
  63. import com.honghu.cloud.feign.IntegralGoodsFeignClient;
  64. import com.honghu.cloud.feign.IntegralGoodsOrderFeignClient;
  65. import com.honghu.cloud.feign.JiguangPushFeignClient;
  66. import com.honghu.cloud.feign.LiveOrderFeignClient;
  67. import com.honghu.cloud.feign.MessageFeignClient;
  68. import com.honghu.cloud.feign.OrderFormFeignClient;
  69. import com.honghu.cloud.feign.OrderFormToolsFeignClient;
  70. import com.honghu.cloud.feign.PinPayRecordFeignClient;
  71. import com.honghu.cloud.feign.PredepositFeignClient;
  72. import com.honghu.cloud.feign.PredepositLogFeignClient;
  73. import com.honghu.cloud.feign.RushOrderFormFeignClient;
  74. import com.honghu.cloud.feign.StoreFeignClient;
  75. import com.honghu.cloud.feign.SysConfigFeignClient;
  76. import com.honghu.cloud.feign.SysconrigExtendFeignClient;
  77. import com.honghu.cloud.feign.TXTemplateFeignClient;
  78. import com.honghu.cloud.feign.UserFeignClient;
  79. import com.honghu.cloud.pay.alipay.services.AlipayService;
  80. import com.honghu.cloud.pay.alipay.util.AlipayUtil;
  81. import com.honghu.cloud.pay.bill.util.MD5Util;
  82. import com.honghu.cloud.pay.tenpay.RequestHandler;
  83. import com.honghu.cloud.pay.tenpay.ResponseHandler;
  84. import com.honghu.cloud.pay.tenpay.util.Sha1Util;
  85. import com.honghu.cloud.pay.tenpay.util.TenpayUtil;
  86. import com.honghu.cloud.pay.unionpay.acp.sdk.SDKUtil;
  87. import com.honghu.cloud.service.IGoldLogService;
  88. import com.honghu.cloud.service.IGoldRecordService;
  89. import com.honghu.cloud.service.IPaymentService;
  90. import com.honghu.cloud.service.IPlatformPayFlowService;
  91. import com.honghu.cloud.service.IPlatformPayService;
  92. import com.honghu.cloud.tools.AccessTokenTools;
  93. import com.honghu.cloud.tools.SecurityUserHolder;
  94. import com.honghu.cloud.tools.qrcode.QRCodeUtil;
  95. import com.honghu.cloud.utils.CommUtil;
  96. import com.honghu.cloud.utils.tools.Md5Encrypt;
  97. import lombok.extern.log4j.Log4j;
  98. import net.sf.json.JSONObject;
  99. /**
  100. *
  101. * <p>
  102. * Title: HongHuPayViewAction.java
  103. * </p>
  104. *
  105. * <p>
  106. * Description:在线支付回调控制器,处理系统支持的所有支付方式回调业务处理,包括支付宝、财付通、快钱、paypal、网银在线
  107. * </p>
  108. *
  109. * <p>
  110. * Copyright: Copyright (c) 2015
  111. * </p>
  112. *
  113. * <p>
  114. * Company: www.minglisoft.cn
  115. * </p>
  116. *
  117. * @author honghu
  118. *
  119. * @date 2014-5-25
  120. *
  121. * @version honghu_b2b2c v8.0 2016版
  122. */
  123. @SuppressWarnings({ "unchecked", "rawtypes", "unused" })
  124. @RestController
  125. @Log4j
  126. @RequestMapping(value = "/pay")
  127. public class PayController {
  128. private static final Logger logger = LoggerFactory.getLogger(PayController.class);
  129. @Autowired
  130. private SysConfigFeignClient sysConfigFeignClient;
  131. @Autowired
  132. private OrderFormFeignClient orderFormFeignClient;
  133. @Autowired
  134. private PredepositLogFeignClient predepositLogFeignClient;
  135. @Autowired
  136. private PredepositFeignClient predepositFeignClient;
  137. @Autowired
  138. private IPaymentService paymentService;
  139. @Autowired
  140. private CloudPurchaseOrderFeignClient cloudPurchaseOrderFeignClient;
  141. @Autowired
  142. private IntegralGoodsOrderFeignClient integralGoodsOrderFeignClient;
  143. @Autowired
  144. private RushOrderFormFeignClient rushOrderFormFeignClient;
  145. @Autowired
  146. private UserFeignClient userFeignClient;
  147. @Autowired
  148. private IGoldRecordService goldRecordService;
  149. @Autowired
  150. private IGoldLogService goldLogService;
  151. @Autowired
  152. private HandleOrderFormFeignClient handleOrderFormFeignClient;
  153. @Autowired
  154. private OrderFormToolsFeignClient orderFormToolsFeignClient;
  155. @Autowired
  156. private IntegralGoodsFeignClient integralGoodsFeignClient;
  157. @Autowired
  158. private PinPayRecordFeignClient pinPayRecordFeignClient;
  159. @Autowired
  160. private DistributionOrderFeignClient distributionOrderFeignClient;
  161. @Autowired
  162. private SysconrigExtendFeignClient sysconrigExtendFeignClient;
  163. @Autowired
  164. private IPlatformPayService platformPayService;
  165. @Autowired
  166. private IPlatformPayFlowService platformPayFlowService;
  167. @Autowired
  168. private StoreFeignClient storeFeignClient;
  169. @Autowired
  170. private LiveOrderFeignClient liveOrderFeignClient;
  171. @Autowired
  172. private MessageFeignClient messageFeignClient;
  173. @Autowired
  174. private DistributionProfitFeignClient distributionProfitFeignClient;
  175. @Autowired
  176. private DistributionSettingFeignClient distributionSettingFeignClient;
  177. @Autowired
  178. private AgentProfitFeignClient agentProfitFeignClient;
  179. @Autowired
  180. private TXTemplateFeignClient tXTemplateFeignClient;
  181. @Autowired
  182. private JiguangPushFeignClient jiguangPushFeignClient;
  183. @Autowired
  184. private AccessTokenTools accessTokenTools;
  185. @Autowired
  186. private AlipayService alipayService;
  187. /* @Value("${notify.url}")
  188. private String notify_url;
  189. */
  190. /**
  191. * 移动端订单支付详情
  192. *
  193. * @param request
  194. * @param response
  195. * @param payType
  196. * @param order_id
  197. * @param order_type
  198. * @param pay_password
  199. * @return
  200. */
  201. @RequestMapping(value = "/order_pay", method = RequestMethod.POST)
  202. public Map<String, Object> order_pay(HttpServletRequest request, HttpServletResponse response,@RequestBody JSONObject json) {
  203. String order_type = json.optString("order_type");
  204. String payType = json.optString("payType");
  205. Long order_id = json.optLong("order_id");
  206. UserDto user = SecurityUserHolder.getCurrentUser(request);
  207. Map<String, Object> result = new HashMap<String, Object>();
  208. if ("cloudpurchase".equals(order_type)) {
  209. CloudPurchaseOrderDto order = cloudPurchaseOrderFeignClient
  210. .selectByPrimaryKey(CommUtil.null2Long(order_id));
  211. if (order != null) {
  212. if ((order.getUser_id().equals(user.getId())) && (order.getStatus() == 0)) {
  213. if ("wx_pay".equals(payType)) {
  214. try {
  215. // TODO
  216. // 微信支付
  217. return ResponseCode
  218. .buildSuccessMap(wx_pay1(request, response, order_id, payType, order_type));
  219. } catch (Exception e) {
  220. log.error(e.toString());
  221. return ResponseCode.buildCodeMap("20008", "支付方式错误!", null);
  222. }
  223. }
  224. if ("wxh5_pay".equals(payType)) {
  225. try {
  226. // TODO
  227. // 微信支付
  228. return ResponseCode
  229. .buildSuccessMap(wxh5_pay(request, response, order_id, payType, order_type));
  230. } catch (Exception e) {
  231. log.error(e.toString());
  232. return ResponseCode.buildCodeMap("20008", "支付方式错误!", null);
  233. }
  234. }
  235. if (payType.equals("balance")) {
  236. double order_total_price = CommUtil.null2Double(Integer.valueOf(order.getPrice()));
  237. result.put("order_total_price", Double.valueOf(order_total_price));
  238. result.put("type", order_type);
  239. result.put("order_id", order_id);
  240. return ResponseCode.buildCodeMap("20009", "余额支付!", null);
  241. }
  242. result.put("type", "cloudpurchase");
  243. result.put("order_id", order.getId());
  244. result.put("url", CommUtil.getURL(request));
  245. Map<String, Object> params = Maps.newHashMap();
  246. params.put("mark", payType);
  247. List<Payment> payments = paymentService.queryPageList(params);
  248. if (payments.size() > 0) {
  249. Payment payment = payments.get(0);
  250. result.put("payment_id", payment.getId());
  251. }
  252. return ResponseCode.buildSuccessMap(result);
  253. }
  254. }
  255. return ResponseCode.buildCodeMap("20010", "订单中商品已被删除,请重新下单", null);
  256. }
  257. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  258. Map<Boolean, Object> map_verify = orderFormToolsFeignClient.orderForm_verify(order, user.getId());
  259. Iterator iterator = map_verify.keySet().iterator();
  260. while (iterator.hasNext()) {
  261. Boolean verify_result = (Boolean) iterator.next();
  262. if (!verify_result.booleanValue()) {
  263. return ResponseCode.buildFailMap("", map_verify.get(verify_result));
  264. }
  265. }
  266. int order_status = orderFormToolsFeignClient.query_order_status(CommUtil.null2String(order_id));
  267. if (order_status == 10) {
  268. if ((payType == null) || ("".equals(CommUtil.null2String(payType)))) {
  269. return ResponseCode.buildCodeMap("20011", "支付方式错误", null);
  270. }
  271. Map<String, Object> params = Maps.newHashMap();
  272. params.put("mark", payType);
  273. List<Payment> payments = paymentService.queryPageList(params);
  274. if (payments.size() > 0) {
  275. Payment payment = payments.get(0);
  276. order.setPayment_id(payment.getId());
  277. order.setPayment_mark(payment.getMark());
  278. order.setPayment_name(payment.getName());
  279. }
  280. order.setPayType("online");
  281. orderFormFeignClient.updateById(order);
  282. if (payType.equals("balance")) {
  283. double order_total_price = orderFormToolsFeignClient
  284. .query_order_pay_price(CommUtil.null2String(order_id));
  285. result.put("order_total_price", order_total_price);
  286. result.put("user", user);
  287. } else {
  288. result.put("payType", payType);
  289. result.put("url", CommUtil.getURL(request));
  290. // mv.addObject("payTools", this.payTools);
  291. String type = "goods";
  292. if (order.getOrder_cat() == 2) {
  293. type = "group";
  294. }
  295. result.put("type", type);
  296. result.put("payment_id", order.getPayment_id());
  297. if ("wx_pay".equals(payType)) {
  298. try {
  299. // TODO
  300. // 微信支付
  301. return ResponseCode.buildSuccessMap(wx_pay1(request, response, order_id, payType, order_type));
  302. } catch (Exception e) {
  303. log.error(e.toString());
  304. return ResponseCode.buildCodeMap("20011", "支付方式错误", null);
  305. }
  306. }
  307. }
  308. result.put("order", order);
  309. result.put("order_id", order.getId());
  310. result.put("user", user);
  311. }
  312. if (order_status == 11) {
  313. if (payType.equals("balance")) {
  314. double order_total_price = orderFormToolsFeignClient
  315. .query_order_pay_price(CommUtil.null2String(order_id));
  316. result.put("order_total_price", order_total_price);
  317. result.put("user", user);
  318. } else {
  319. result.put("payType", payType);
  320. result.put("url", CommUtil.getURL(request));
  321. // mv.addObject("payTools", this.payTools);
  322. String type = "goods";
  323. result.put("type", type);
  324. result.put("payment_id", order.getPayment_id());
  325. if ("wx_pay".equals(payType)) {
  326. try {
  327. // TODO
  328. // 微信支付
  329. return ResponseCode.buildSuccessMap(wx_pay1(request, response, order_id, payType, order_type));
  330. } catch (Exception e) {
  331. log.error(e.toString());
  332. return ResponseCode.buildCodeMap("20011", "支付方式错误", null);
  333. }
  334. }
  335. }
  336. result.put("order", order);
  337. result.put("order_id", order.getId());
  338. result.put("user", user);
  339. }
  340. return ResponseCode.buildSuccessMap(result);
  341. }
  342. /**
  343. * 手机订单货到付款
  344. *
  345. * @param request
  346. * @param response
  347. * @param order_id
  348. * @param pay_msg
  349. * @param pay_session
  350. * @return
  351. * @throws Exception
  352. */
  353. @RequestMapping({ "/order_pay_payafter" })
  354. public Map<String, Object> order_pay_payafter(HttpServletRequest request, HttpServletResponse response,
  355. @RequestBody JSONObject json) throws Exception {
  356. String pay_session = json.optString("pay_session");
  357. String pay_msg = json.optString("pay_msg");
  358. String order_id = json.optString("order_id");
  359. Map<String, Object> result = new HashMap<String, Object>();
  360. String pay_session1 = CommUtil.null2String(request.getSession(false).getAttribute("pay_session"));
  361. if (pay_session1.equals(pay_session)) {
  362. OrderFormDto order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  363. boolean exist = orderFormToolsFeignClient.verify_goods_exist(order);
  364. if (!exist) {
  365. return ResponseCode.buildFailMap("订单中商品已被删除,请重新下单", null);
  366. }
  367. boolean inventory_very = orderFormToolsFeignClient.verify_goods_Inventory(order);
  368. if (!inventory_very) {
  369. return ResponseCode.buildFailMap("订单中商品库存不足,请重新下单", null);
  370. }
  371. boolean ret = handleOrderFormFeignClient.payByPayafter(order, CommUtil.getURL(request), pay_msg);
  372. if (ret) {
  373. orderFormToolsFeignClient.updateGoodsInventory(order);
  374. }
  375. request.getSession(false).removeAttribute("pay_session");
  376. result.put("op_title", "货到付款提交成功,等待发货");
  377. result.put("url", CommUtil.getURL(request) + "/buyer/order_list");
  378. } else {
  379. return ResponseCode.buildFailMap("订单已经支付,禁止重复支付", null);
  380. }
  381. return ResponseCode.buildSuccessMap(result);
  382. }
  383. /**
  384. * 支付宝在线支付成功回调控制
  385. *
  386. * @param request
  387. * @param response
  388. * @return
  389. * @throws Exception
  390. *//*
  391. @RequestMapping({ "/aplipay_return" })
  392. public Map<String, Object> aplipay_return(HttpServletRequest request, HttpServletResponse response)
  393. throws Exception {
  394. Map<String, Object> resultMap = new HashMap<String, Object>();
  395. System.out.println("pc_alipay_return");
  396. String trade_no = request.getParameter("trade_no");
  397. String[] order_nos = request.getParameter("out_trade_no").split("-");
  398. String total_fee = request.getParameter("price");
  399. String subject = request.getParameter("subject");
  400. String order_no = order_nos[2];
  401. String type = CommUtil.null2String(request.getParameter("body")).trim();
  402. String trade_status = request.getParameter("trade_status");
  403. OrderFormDto main_order = null;
  404. PredepositDto obj = null;
  405. GoldRecord gold = null;
  406. IntegralGoodsOrderDto ig_order = null;
  407. CloudPurchaseOrderDto cp_order = null;
  408. if (type.equals("goods")) {
  409. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  410. }
  411. if (type.equals("cash")) {
  412. obj = predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  413. }
  414. if (type.equals("gold")) {
  415. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(order_no));
  416. }
  417. if (type.equals("integral")) {
  418. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  419. }
  420. if (type.equals("group")) {
  421. main_order = orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  422. }
  423. if (type.equals("cloudpurchase")) {
  424. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  425. }
  426. Map<String, String> params = Maps.newHashMap();
  427. Map requestParams = request.getParameterMap();
  428. for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
  429. String name = (String) iter.next();
  430. String[] values = (String[]) requestParams.get(name);
  431. String valueStr = "";
  432. for (int i = 0; i < values.length; i++) {
  433. valueStr = valueStr + values[i] + ",";
  434. }
  435. params.put(name, valueStr);
  436. }
  437. AlipayConfig config = new AlipayConfig();
  438. Payment payment = null;
  439. if ((type.equals("goods")) || (type.equals("group"))) {
  440. payment = this.paymentService.selectByPrimaryKey(main_order.getPayment_id());
  441. config.setKey(payment.getSafeKey());
  442. config.setPartner(payment.getPartner());
  443. config.setSeller_email(payment.getSeller_email());
  444. }
  445. if ((type.equals("cash")) || (type.equals("gold")) || (type.equals("integral"))
  446. || (type.equals("cloudpurchase"))) {
  447. Map q_params = Maps.newHashMap();
  448. q_params.put("install", Boolean.valueOf(true));
  449. if (type.equals("cash")) {
  450. q_params.put("mark", obj.getPd_payment());
  451. }
  452. if (type.equals("gold")) {
  453. q_params.put("mark", gold.getGold_payment());
  454. }
  455. if (type.equals("integral")) {
  456. q_params.put("mark", ig_order.getIgo_payment());
  457. }
  458. if (type.equals("cloudpurchase")) {
  459. q_params.put("mark", cp_order.getPayment());
  460. }
  461. List<Payment> payments = this.paymentService.queryPageList(q_params);
  462. config.setKey(((Payment) payments.get(0)).getSafeKey());
  463. config.setPartner(((Payment) payments.get(0)).getPartner());
  464. config.setSeller_email(((Payment) payments.get(0)).getSeller_email());
  465. }
  466. config.setNotify_url(CommUtil.getURL(request) + "/alipay_notify");
  467. config.setReturn_url(CommUtil.getURL(request) + "/aplipay_return");
  468. boolean verify_result = AlipayNotify.verify(config, params);
  469. if (verify_result) {
  470. if (((type.equals("goods")) || (type.equals("group"))) && ((trade_status.equals("WAIT_SELLER_SEND_GOODS"))
  471. || (trade_status.equals("TRADE_FINISHED")) || (trade_status.equals("TRADE_SUCCESS")))) {
  472. boolean flag = this.handleOrderFormFeignClient.payByOnline(main_order, trade_no,
  473. CommUtil.getURL(request));
  474. if (flag) {
  475. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  476. }
  477. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  478. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  479. resultMap.put("all_price", Double.valueOf(this.orderFormToolsFeignClient
  480. .query_order_pay_price(CommUtil.null2String(main_order.getId()))));
  481. resultMap.put("obj", main_order);
  482. }
  483. if ((type.equals("cash")) && ((trade_status.equals("WAIT_SELLER_SEND_GOODS"))
  484. || (trade_status.equals("TRADE_FINISHED")) || (trade_status.equals("TRADE_SUCCESS")))) {
  485. if (obj.getPd_pay_status() != 2) {
  486. obj.setPd_status(1);
  487. obj.setPd_pay_status(2);
  488. this.predepositFeignClient.updateById(obj);
  489. UserDto user = userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  490. user.setAvailableBalance(
  491. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  492. userFeignClient.updateById(user);
  493. PredepositLogDto log = new PredepositLogDto();
  494. log.setAddTime(new Date());
  495. log.setPd_log_amount(obj.getPd_amount());
  496. log.setPd_log_user(obj.getPd_user());
  497. log.setPd_op_type("充值");
  498. log.setPd_type("可用预存款");
  499. log.setPd_log_info("支付宝在线支付");
  500. this.predepositLogFeignClient.saveEntity(log);
  501. }
  502. resultMap.put("op_title", "恭喜您,成功充值" + obj.getPd_amount() + "元");
  503. resultMap.put("url", CommUtil.getURL(request) + "/buyer/predeposit_list");
  504. }
  505. if ((type.equals("gold")) && ((trade_status.equals("WAIT_SELLER_SEND_GOODS"))
  506. || (trade_status.equals("TRADE_FINISHED")) || (trade_status.equals("TRADE_SUCCESS")))) {
  507. if (gold.getGold_pay_status() != 2) {
  508. gold.setGold_status(1);
  509. gold.setGold_pay_status(2);
  510. this.goldRecordService.updateById(gold);
  511. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  512. user.setGold(user.getGold() + gold.getGold_count());
  513. this.userFeignClient.updateById(user);
  514. GoldLog log = new GoldLog();
  515. log.setAddTime(new Date());
  516. log.setGl_payment(gold.getGold_payment());
  517. log.setGl_content("支付宝在线支付");
  518. log.setGl_money(gold.getGold_money());
  519. log.setGl_count(gold.getGold_count());
  520. log.setGl_type(0);
  521. log.setGl_user(gold.getGold_user());
  522. log.setGr(gold);
  523. this.goldLogService.saveEntity(log);
  524. }
  525. resultMap.put("op_title", "兑换" + gold.getGold_count() + "金币成功");
  526. resultMap.put("url", CommUtil.getURL(request) + "/seller/gold_record_list");
  527. }
  528. if ((type.equals("integral")) && ((trade_status.equals("WAIT_SELLER_SEND_GOODS"))
  529. || (trade_status.equals("TRADE_FINISHED")) || (trade_status.equals("TRADE_SUCCESS")))) {
  530. if (ig_order.getIgo_status() < 20) {
  531. ig_order.setIgo_status(20);
  532. ig_order.setIgo_pay_time(new Date());
  533. ig_order.setIgo_payment("alipay");
  534. this.integralGoodsOrderFeignClient.updateById(ig_order);
  535. List<Map> ig_maps = this.orderFormToolsFeignClient
  536. .query_integral_goodsinfo(ig_order.getGoods_info());
  537. for (Map map : ig_maps) {
  538. IntegralGoodsDto goods = this.integralGoodsFeignClient
  539. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  540. goods.setIg_goods_count(
  541. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  542. goods.setIg_exchange_count(
  543. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  544. this.integralGoodsFeignClient.updateById(goods);
  545. }
  546. }
  547. resultMap.put("obj", ig_order);
  548. }
  549. if (type.equals("cloudpurchase")) {
  550. if (cp_order.getStatus() < 5) {
  551. cp_order.setStatus(5);
  552. cp_order.setPayTime(new Date());
  553. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  554. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  555. }
  556. resultMap.put("op_title", "预付款支付成功!");
  557. resultMap.put("url", CommUtil.getURL(request) + "/buyer/cloudbuy_order");
  558. }
  559. } else {
  560. resultMap.put("op_title", "支付回调失败");
  561. resultMap.put("url", CommUtil.getURL(request) + "/index");
  562. }
  563. return resultMap;
  564. }*/
  565. /**
  566. * 支付宝异步通知
  567. *
  568. * @param request
  569. * @param response
  570. * @throws Exception
  571. */
  572. @RequestMapping({ "/alipay_notify" })
  573. public void alipay_notify(HttpServletRequest request, HttpServletResponse response) throws Exception {
  574. /*
  575. https://xx/receive_notify.htm?notify_type=trade_status_sync&notify_id=91722adff935e8cfa58b3aabf4dead6ibe
  576. &notify_time=2017-02-16 21:46:15&sign_type=RSA2
  577. &sign=xxxxxxxxxxxxxxx&app_id=2088102146225135&trade_no=2013112011001004330000121536&out_trade_no=6823789339978248&out_biz_no=85478536823789339978248
  578. &buyer_logon_id=159****5620&seller_id=2088102146225135&trans_currency=USD&seller_email=aa@mail.sa.com&total_amount=120.88
  579. &buyer_id=2088202954065786&settle_currency=USD&settle_amount=88.88&pay_currency=CNY&pay_amount=580.04&settle_trans_rate=1
  580. &trans_pay_rate=6.5261&trade_status=TRADE_SUCCESS&invoice_amount=88.88&receipt_amount=88.88&point_amount=88.88&refund_fee=10.23
  581. &buyer_pay_amount=88.88&subject=Iphone6 16G&body=Iphone6 16G&gmt_create=2014-11-27 15:45:57&gmt_payment=2014-11-27 15:45:57
  582. &gmt_refund=2014-11-27 14:15:57&gmt_close=2014-11-27 17:45:57&fund_bill_list="[{\"amount\":\"10000.00\",\"fundChannel\":\"ALIPAYACCOUNT\"}]"&voucher_detail_list="[{\"id\":\"20170307000730026487005X1M6V\",\"name\":\"全仓5折优惠券\"}]"
  583. &discount_goods_detail="[{\"goodsId\":\"STANDARD1026181538\",\"goodsName\":\"雪碧\",\"discountAmount\":\"10.00\"}]"
  584. &refund_preset_paytool_list=[{"amount":"1.00","assert_type_code":"HEMA"}]&charge_amount=8.88&charge_flags=bluesea_1
  585. &settlement_id=2018101610032004620239146945&advance_amount=11.11&current_seller_received_amount=88.88&seller_received_total_amount=88.88
  586. &total_from_seller_fee=88.88&ff_current_period=1&notify_action_type=payByAccountAction/closeTradeAction/reverseAction/finishFPAction/confirmDisburseAction/financingReceiptAction
  587. &discount_amount=88.88&mdiscount_amount=88.88&unfreeze_amount=18.18&auth_trade_pay_mode=CREDIT_PREAUTH_PAY
  588. &passback_params=merchantBizType%3d3C%26merchantBizNo%3d2016010101111&hb_fq_pay_info={"USER_INSTALL_NUM":"3"}&receipt_currency_type=DC
  589. */
  590. //获取支付宝POST过来反馈信息
  591. Map<String, String> params = new HashMap<String, String>();
  592. Map requestParams = request.getParameterMap();
  593. for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
  594. String name = (String) iter.next();
  595. String[] values = (String[]) requestParams.get(name);
  596. String valueStr = "";
  597. for (int i = 0; i < values.length; i++) {
  598. valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
  599. }
  600. //乱码解决,这段代码在出现乱码时使用。
  601. //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
  602. params.put(name, valueStr);
  603. }
  604. //String sign = request.getParameter("sign");
  605. String passbackParamsUnCode = request.getParameter("passback_params");
  606. String passbackParams = java.net.URLDecoder.decode(passbackParamsUnCode);
  607. String[] attachs = passbackParams.split("_");
  608. String type = attachs[3];
  609. //支付方式 因为付方式是"alipay_app" 形式 故pay_type为attachs[4]+"_"+attachs[5]
  610. String pay_type = attachs[4] + "_" + attachs[5];
  611. System.out.println("返回的pay_type:" + pay_type);
  612. Map<String, Object> pay_type_params = Maps.newHashMap();
  613. pay_type_params.put("mark", pay_type);
  614. List<Payment> payments = this.paymentService.queryPageList(pay_type_params);
  615. log.info("----异步通知参数 开始 ------");
  616. log.info(params.toString());
  617. log.info("----异步通知参数 结束 ------");
  618. if (null == payments || payments.size() < 1) {
  619. log.error("支付异步通知失败");
  620. response.setContentType("text/plain");
  621. response.setHeader("Cache-Control", "no-cache");
  622. response.setCharacterEncoding("UTF-8");
  623. try {
  624. PrintWriter writer = response.getWriter();
  625. writer.print("fail");
  626. } catch (IOException e) {
  627. log.error(e.toString());
  628. }
  629. return;
  630. }
  631. Payment payment = payments.get(0);
  632. //
  633. if (AlipayUtil.validateSign(params, payment.getApp_public_key())) {
  634. log.info("回調验签成功");
  635. afterNotifyOrderHandling_alipay(request, payment, type, attachs);
  636. response.setContentType("text/plain");
  637. response.setHeader("Cache-Control", "no-cache");
  638. response.setCharacterEncoding("UTF-8");
  639. try {
  640. PrintWriter writer = response.getWriter();
  641. writer.print("success");
  642. } catch (IOException e) {
  643. log.error(e.toString());
  644. }
  645. } else {
  646. log.info("回調验签失败");
  647. response.setContentType("text/plain");
  648. response.setHeader("Cache-Control", "no-cache");
  649. response.setCharacterEncoding("UTF-8");
  650. try {
  651. PrintWriter writer = response.getWriter();
  652. writer.print("fail");
  653. } catch (IOException e) {
  654. log.error(e.toString());
  655. }
  656. }
  657. }
  658. /**
  659. * 快钱在线支付回调处理控制
  660. *
  661. * @param request
  662. * @param response
  663. * @return
  664. * @throws Exception
  665. */
  666. @RequestMapping({ "/bill_return" })
  667. public Map<String, Object> bill_return(HttpServletRequest request, HttpServletResponse response) throws Exception {
  668. Map<String, Object> resultMap = new HashMap<String, Object>();
  669. String ext1 = request.getParameter("ext1").trim();
  670. String ext2 = CommUtil.null2String(request.getParameter("ext2").trim());
  671. OrderFormDto order = null;
  672. PredepositDto obj = null;
  673. GoldRecord gold = null;
  674. IntegralGoodsOrderDto ig_order = null;
  675. CloudPurchaseOrderDto cp_order = null;
  676. if ((ext2.equals("goods")) || (ext2.equals("group"))) {
  677. order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  678. }
  679. if (ext2.equals("cash")) {
  680. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  681. }
  682. if (ext2.equals("gold")) {
  683. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(ext1));
  684. }
  685. if (ext2.equals("integral")) {
  686. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  687. }
  688. if (ext2.equals("cloudpurchase")) {
  689. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  690. }
  691. String merchantAcctId = request.getParameter("merchantAcctId").trim();
  692. String key = "";
  693. Payment payment = null;
  694. if ((ext2.equals("goods")) || (ext2.equals("group"))) {
  695. payment = this.paymentService.selectByPrimaryKey(order.getPayment_id());
  696. key = payment.getRmbKey();
  697. }
  698. if ((ext2.equals("cash")) || (ext2.equals("gold")) || (ext2.equals("integral"))
  699. || (ext2.equals("cloudpurchase"))) {
  700. Map q_params = Maps.newHashMap();
  701. q_params.put("install", Boolean.valueOf(true));
  702. if (ext2.equals("cash")) {
  703. q_params.put("mark", obj.getPd_payment());
  704. }
  705. if (ext2.equals("gold")) {
  706. q_params.put("mark", gold.getGold_payment());
  707. }
  708. if (ext2.equals("integral")) {
  709. q_params.put("mark", ig_order.getIgo_payment());
  710. }
  711. if (ext2.equals("cloudpurchase")) {
  712. q_params.put("mark", cp_order.getPayment());
  713. }
  714. List<Payment> payments = this.paymentService.queryPageList(q_params);
  715. key = ((Payment) payments.get(0)).getRmbKey();
  716. }
  717. String version = request.getParameter("version").trim();
  718. String language = request.getParameter("language").trim();
  719. String signType = request.getParameter("signType").trim();
  720. String payType = request.getParameter("payType").trim();
  721. String bankId = request.getParameter("bankId").trim();
  722. String orderId = request.getParameter("orderId").trim();
  723. String orderTime = request.getParameter("orderTime").trim();
  724. String orderAmount = request.getParameter("orderAmount").trim();
  725. String dealId = request.getParameter("dealId").trim();
  726. String bankDealId = request.getParameter("bankDealId").trim();
  727. String dealTime = request.getParameter("dealTime").trim();
  728. String payAmount = request.getParameter("payAmount").trim();
  729. String fee = request.getParameter("fee").trim();
  730. String payResult = request.getParameter("payResult").trim();
  731. String errCode = request.getParameter("errCode").trim();
  732. String signMsg = request.getParameter("signMsg").trim();
  733. String merchantSignMsgVal = "";
  734. merchantSignMsgVal = appendParam(merchantSignMsgVal, "merchantAcctId", merchantAcctId);
  735. merchantSignMsgVal = appendParam(merchantSignMsgVal, "version", version);
  736. merchantSignMsgVal = appendParam(merchantSignMsgVal, "language", language);
  737. merchantSignMsgVal = appendParam(merchantSignMsgVal, "signType", signType);
  738. merchantSignMsgVal = appendParam(merchantSignMsgVal, "payType", payType);
  739. merchantSignMsgVal = appendParam(merchantSignMsgVal, "bankId", bankId);
  740. merchantSignMsgVal = appendParam(merchantSignMsgVal, "orderId", orderId);
  741. merchantSignMsgVal = appendParam(merchantSignMsgVal, "orderTime", orderTime);
  742. merchantSignMsgVal = appendParam(merchantSignMsgVal, "orderAmount", orderAmount);
  743. merchantSignMsgVal = appendParam(merchantSignMsgVal, "dealId", dealId);
  744. merchantSignMsgVal = appendParam(merchantSignMsgVal, "bankDealId", bankDealId);
  745. merchantSignMsgVal = appendParam(merchantSignMsgVal, "dealTime", dealTime);
  746. merchantSignMsgVal = appendParam(merchantSignMsgVal, "payAmount", payAmount);
  747. merchantSignMsgVal = appendParam(merchantSignMsgVal, "fee", fee);
  748. merchantSignMsgVal = appendParam(merchantSignMsgVal, "ext1", ext1);
  749. merchantSignMsgVal = appendParam(merchantSignMsgVal, "ext2", ext2);
  750. merchantSignMsgVal = appendParam(merchantSignMsgVal, "payResult", payResult);
  751. merchantSignMsgVal = appendParam(merchantSignMsgVal, "errCode", errCode);
  752. merchantSignMsgVal = appendParam(merchantSignMsgVal, "key", key);
  753. String merchantSignMsg = MD5Util.md5Hex(merchantSignMsgVal.getBytes("utf-8")).toUpperCase();
  754. if (signMsg.toUpperCase().equals(merchantSignMsg.toUpperCase())) {
  755. switch (Integer.parseInt(payResult)) {
  756. case 10:
  757. if ((ext2.equals("goods")) || (ext2.equals("group"))) {
  758. boolean flag = this.handleOrderFormFeignClient.payByOnline(order, "", CommUtil.getURL(request));
  759. if (flag) {
  760. this.orderFormToolsFeignClient.updateGoodsInventory(order);
  761. }
  762. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), order,
  763. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  764. resultMap.put("all_price", Double.valueOf(
  765. this.orderFormToolsFeignClient.query_order_pay_price(CommUtil.null2String(order.getId()))));
  766. resultMap.put("obj", order);
  767. }
  768. if (ext2.equals("cash")) {
  769. if (obj.getPd_pay_status() < 2) {
  770. obj.setPd_status(1);
  771. obj.setPd_pay_status(2);
  772. this.predepositFeignClient.updateById(obj);
  773. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  774. user.setAvailableBalance(
  775. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  776. this.userFeignClient.updateById(user);
  777. PredepositLogDto log = new PredepositLogDto();
  778. log.setAddTime(new Date());
  779. log.setPd_log_amount(obj.getPd_amount());
  780. log.setPd_log_user(obj.getPd_user());
  781. log.setPd_op_type("充值");
  782. log.setPd_type("可用预存款");
  783. log.setPd_log_info("快钱在线支付");
  784. this.predepositLogFeignClient.saveEntity(log);
  785. }
  786. resultMap.put("op_title", "充值" + obj.getPd_amount() + "成功");
  787. resultMap.put("url", CommUtil.getURL(request) + "/buyer/predeposit_list");
  788. }
  789. if (ext2.equals("gold")) {
  790. if (gold.getGold_pay_status() < 2) {
  791. gold.setGold_status(1);
  792. gold.setGold_pay_status(2);
  793. this.goldRecordService.updateById(gold);
  794. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  795. user.setGold(user.getGold() + gold.getGold_count());
  796. this.userFeignClient.updateById(user);
  797. GoldLog log = new GoldLog();
  798. log.setAddTime(new Date());
  799. log.setGl_payment(gold.getGold_payment());
  800. log.setGl_content("快钱在线支付");
  801. log.setGl_money(gold.getGold_money());
  802. log.setGl_count(gold.getGold_count());
  803. log.setGl_type(0);
  804. log.setGl_user(gold.getGold_user());
  805. log.setGr(gold);
  806. this.goldLogService.saveEntity(log);
  807. }
  808. resultMap.put("op_title", "兑换" + gold.getGold_count() + "金币成功");
  809. resultMap.put("url", CommUtil.getURL(request) + "/seller/gold_record_list");
  810. }
  811. if (ext2.equals("integral")) {
  812. if (ig_order.getIgo_status() < 20) {
  813. ig_order.setIgo_status(20);
  814. ig_order.setIgo_pay_time(new Date());
  815. ig_order.setIgo_payment("bill");
  816. this.integralGoodsOrderFeignClient.updateById(ig_order);
  817. List<Map> ig_maps = this.orderFormToolsFeignClient
  818. .query_integral_goodsinfo(ig_order.getGoods_info());
  819. for (Map map : ig_maps) {
  820. IntegralGoodsDto goods = this.integralGoodsFeignClient
  821. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  822. goods.setIg_goods_count(
  823. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  824. goods.setIg_exchange_count(
  825. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  826. this.integralGoodsFeignClient.updateById(goods);
  827. }
  828. }
  829. resultMap.put("obj", ig_order);
  830. }
  831. if (!ext2.equals("cloudpurchase")) {
  832. break;
  833. }
  834. if (cp_order.getStatus() < 5) {
  835. cp_order.setStatus(5);
  836. cp_order.setPayTime(new Date());
  837. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  838. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  839. }
  840. resultMap.put("op_title", "预付款支付成功!");
  841. resultMap.put("url", CommUtil.getURL(request) + "/buyer/cloudbuy_order");
  842. break;
  843. default:
  844. resultMap.put("op_title", "快钱支付失败!");
  845. resultMap.put("url", CommUtil.getURL(request) + "/index");
  846. break;
  847. }
  848. } else {
  849. resultMap.put("op_title", "快钱支付失败!");
  850. resultMap.put("url", CommUtil.getURL(request) + "/index");
  851. }
  852. return resultMap;
  853. }
  854. public String appendParam(String returnStr, String paramId, String paramValue) {
  855. if (!returnStr.equals("")) {
  856. if (!paramValue.equals("")) {
  857. returnStr = returnStr + "&" + paramId + "=" + paramValue;
  858. }
  859. } else if (!paramValue.equals("")) {
  860. returnStr = paramId + "=" + paramValue;
  861. }
  862. return returnStr;
  863. }
  864. /**
  865. * 快钱异步回调处理,如果同步回调出错,异步回调会弥补该功能
  866. *
  867. * @param request
  868. * @param response
  869. * @throws Exception
  870. */
  871. @RequestMapping({ "/bill_notify_return" })
  872. public void bill_notify_return(HttpServletRequest request, HttpServletResponse response) throws Exception {
  873. int rtnOK = 0;
  874. String ext1 = request.getParameter("ext1").trim();
  875. String ext2 = CommUtil.null2String(request.getParameter("ext2").trim());
  876. OrderFormDto order = null;
  877. PredepositDto obj = null;
  878. GoldRecord gold = null;
  879. IntegralGoodsOrderDto ig_order = null;
  880. CloudPurchaseOrderDto cp_order = null;
  881. if ((ext2.equals("goods")) || (ext2.equals("group"))) {
  882. order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  883. }
  884. if (ext2.equals("cash")) {
  885. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  886. }
  887. if (ext2.equals("gold")) {
  888. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(ext1));
  889. }
  890. if (ext2.equals("integral")) {
  891. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  892. }
  893. if (ext2.equals("cloudpurchase")) {
  894. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(ext1));
  895. }
  896. String merchantAcctId = request.getParameter("merchantAcctId").trim();
  897. String key = "";
  898. Payment payment = null;
  899. if ((ext2.equals("goods")) || (ext2.equals("group"))) {
  900. payment = this.paymentService.selectByPrimaryKey(order.getPayment_id());
  901. key = payment.getRmbKey();
  902. }
  903. if ((ext2.equals("cash")) || (ext2.equals("gold")) || (ext2.equals("integral"))
  904. || (ext2.equals("cloudpurchase"))) {
  905. Map q_params = Maps.newHashMap();
  906. q_params.put("install", Boolean.valueOf(true));
  907. if (ext2.equals("cash")) {
  908. q_params.put("mark", obj.getPd_payment());
  909. }
  910. if (ext2.equals("gold")) {
  911. q_params.put("mark", gold.getGold_payment());
  912. }
  913. if (ext2.equals("integral")) {
  914. q_params.put("mark", ig_order.getIgo_payment());
  915. }
  916. if (ext2.equals("cloudpurchase")) {
  917. q_params.put("mark", cp_order.getPayment());
  918. }
  919. List<Payment> payments = this.paymentService.queryPageList(q_params);
  920. key = ((Payment) payments.get(0)).getRmbKey();
  921. }
  922. String version = request.getParameter("version").trim();
  923. String language = request.getParameter("language").trim();
  924. String signType = request.getParameter("signType").trim();
  925. String payType = request.getParameter("payType").trim();
  926. String bankId = request.getParameter("bankId").trim();
  927. String orderId = request.getParameter("orderId").trim();
  928. String orderTime = request.getParameter("orderTime").trim();
  929. String orderAmount = request.getParameter("orderAmount").trim();
  930. String dealId = request.getParameter("dealId").trim();
  931. String bankDealId = request.getParameter("bankDealId").trim();
  932. String dealTime = request.getParameter("dealTime").trim();
  933. String payAmount = request.getParameter("payAmount").trim();
  934. String fee = request.getParameter("fee").trim();
  935. String payResult = request.getParameter("payResult").trim();
  936. String errCode = request.getParameter("errCode").trim();
  937. String signMsg = request.getParameter("signMsg").trim();
  938. String merchantSignMsgVal = "";
  939. merchantSignMsgVal = appendParam(merchantSignMsgVal, "merchantAcctId", merchantAcctId);
  940. merchantSignMsgVal = appendParam(merchantSignMsgVal, "version", version);
  941. merchantSignMsgVal = appendParam(merchantSignMsgVal, "language", language);
  942. merchantSignMsgVal = appendParam(merchantSignMsgVal, "signType", signType);
  943. merchantSignMsgVal = appendParam(merchantSignMsgVal, "payType", payType);
  944. merchantSignMsgVal = appendParam(merchantSignMsgVal, "bankId", bankId);
  945. merchantSignMsgVal = appendParam(merchantSignMsgVal, "orderId", orderId);
  946. merchantSignMsgVal = appendParam(merchantSignMsgVal, "orderTime", orderTime);
  947. merchantSignMsgVal = appendParam(merchantSignMsgVal, "orderAmount", orderAmount);
  948. merchantSignMsgVal = appendParam(merchantSignMsgVal, "dealId", dealId);
  949. merchantSignMsgVal = appendParam(merchantSignMsgVal, "bankDealId", bankDealId);
  950. merchantSignMsgVal = appendParam(merchantSignMsgVal, "dealTime", dealTime);
  951. merchantSignMsgVal = appendParam(merchantSignMsgVal, "payAmount", payAmount);
  952. merchantSignMsgVal = appendParam(merchantSignMsgVal, "fee", fee);
  953. merchantSignMsgVal = appendParam(merchantSignMsgVal, "ext1", ext1);
  954. merchantSignMsgVal = appendParam(merchantSignMsgVal, "ext2", ext2);
  955. merchantSignMsgVal = appendParam(merchantSignMsgVal, "payResult", payResult);
  956. merchantSignMsgVal = appendParam(merchantSignMsgVal, "errCode", errCode);
  957. merchantSignMsgVal = appendParam(merchantSignMsgVal, "key", key);
  958. String merchantSignMsg = MD5Util.md5Hex(merchantSignMsgVal.getBytes("utf-8")).toUpperCase();
  959. if (signMsg.toUpperCase().equals(merchantSignMsg.toUpperCase())) {
  960. switch (Integer.parseInt(payResult)) {
  961. case 10:
  962. if ((ext2.equals("goods")) || (ext2.equals("group"))) {
  963. boolean flag = this.handleOrderFormFeignClient.payByOnline(order, dealId, CommUtil.getURL(request));
  964. if (flag) {
  965. this.orderFormToolsFeignClient.updateGoodsInventory(order);
  966. }
  967. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), order,
  968. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  969. rtnOK = 1;
  970. }
  971. if (ext2.equals("cash")) {
  972. if (obj.getPd_pay_status() < 2) {
  973. obj.setPd_status(1);
  974. obj.setPd_pay_status(2);
  975. this.predepositFeignClient.updateById(obj);
  976. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  977. user.setAvailableBalance(
  978. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  979. this.userFeignClient.updateById(user);
  980. PredepositLogDto log = new PredepositLogDto();
  981. log.setAddTime(new Date());
  982. log.setPd_log_amount(obj.getPd_amount());
  983. log.setPd_log_user(obj.getPd_user());
  984. log.setPd_op_type("充值");
  985. log.setPd_type("可用预存款");
  986. log.setPd_log_info("快钱在线支付");
  987. this.predepositLogFeignClient.saveEntity(log);
  988. }
  989. rtnOK = 1;
  990. }
  991. if (ext2.equals("gold")) {
  992. if (gold.getGold_pay_status() < 2) {
  993. gold.setGold_status(1);
  994. gold.setGold_pay_status(2);
  995. this.goldRecordService.updateById(gold);
  996. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  997. user.setGold(user.getGold() + gold.getGold_count());
  998. this.userFeignClient.updateById(user);
  999. GoldLog log = new GoldLog();
  1000. log.setAddTime(new Date());
  1001. log.setGl_payment(gold.getGold_payment());
  1002. log.setGl_content("快钱在线支付");
  1003. log.setGl_money(gold.getGold_money());
  1004. log.setGl_count(gold.getGold_count());
  1005. log.setGl_type(0);
  1006. log.setGl_user(gold.getGold_user());
  1007. log.setGr(gold);
  1008. this.goldLogService.saveEntity(log);
  1009. }
  1010. rtnOK = 1;
  1011. }
  1012. if (ext2.equals("integral")) {
  1013. if (ig_order.getIgo_status() < 20) {
  1014. ig_order.setIgo_status(20);
  1015. ig_order.setIgo_pay_time(new Date());
  1016. ig_order.setIgo_payment("bill");
  1017. this.integralGoodsOrderFeignClient.updateById(ig_order);
  1018. List<Map> ig_maps = this.orderFormToolsFeignClient
  1019. .query_integral_goodsinfo(ig_order.getGoods_info());
  1020. for (Map map : ig_maps) {
  1021. IntegralGoodsDto goods = this.integralGoodsFeignClient
  1022. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  1023. goods.setIg_goods_count(
  1024. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  1025. goods.setIg_exchange_count(
  1026. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  1027. this.integralGoodsFeignClient.updateById(goods);
  1028. }
  1029. }
  1030. rtnOK = 1;
  1031. }
  1032. if (ext2.equals("cloudpurchase")) {
  1033. if (cp_order.getStatus() < 5) {
  1034. cp_order.setStatus(5);
  1035. cp_order.setPayTime(new Date());
  1036. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  1037. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  1038. }
  1039. rtnOK = 1;
  1040. }
  1041. break;
  1042. }
  1043. }
  1044. response.setContentType("text/plain");
  1045. response.setHeader("Cache-Control", "no-cache");
  1046. response.setCharacterEncoding("UTF-8");
  1047. try {
  1048. PrintWriter writer = response.getWriter();
  1049. writer.print(rtnOK);
  1050. } catch (IOException e) {
  1051. log.error(e.toString());
  1052. }
  1053. }
  1054. /**
  1055. * 财付通支付
  1056. *
  1057. * @param request
  1058. * @param response
  1059. * @param id
  1060. * @param type
  1061. * @param payment_id
  1062. * @throws IOException
  1063. */
  1064. @RequestMapping({ "/tenpay" })
  1065. public void tenpay(HttpServletRequest request, HttpServletResponse response,@RequestBody JSONObject json) throws IOException {
  1066. String payment_id = json.optString("payment_id");
  1067. String type = json.optString("type");
  1068. String id = json.optString("id");
  1069. boolean submit = true;
  1070. OrderFormDto of = null;
  1071. PredepositDto obj = null;
  1072. GoldRecord gold = null;
  1073. IntegralGoodsOrderDto ig_order = null;
  1074. CloudPurchaseOrderDto cp_order = null;
  1075. if ((type.equals("goods")) || (type.equals("group"))) {
  1076. of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1077. if (of.getOrder_status() >= 20) {
  1078. submit = false;
  1079. }
  1080. }
  1081. if (type.equals("cash")) {
  1082. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1083. if (obj.getPd_pay_status() >= 2) {
  1084. submit = false;
  1085. }
  1086. }
  1087. if (type.equals("gold")) {
  1088. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(id));
  1089. if (gold.getGold_pay_status() >= 2) {
  1090. submit = false;
  1091. }
  1092. }
  1093. if (type.equals("integral")) {
  1094. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1095. if (ig_order.getIgo_status() >= 20) {
  1096. submit = false;
  1097. }
  1098. }
  1099. if (type.equals("cloudpurchase")) {
  1100. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1101. }
  1102. if (submit) {
  1103. String order_price = "";
  1104. if ((type.equals("goods")) || (type.equals("gruop"))) {
  1105. order_price = CommUtil.null2String(of.getTotalPrice());
  1106. }
  1107. if (type.equals("cash")) {
  1108. order_price = CommUtil.null2String(obj.getPd_amount());
  1109. }
  1110. if (type.equals("gold")) {
  1111. order_price = CommUtil.null2String(Integer.valueOf(gold.getGold_money()));
  1112. }
  1113. if (type.equals("integral")) {
  1114. order_price = CommUtil.null2String(ig_order.getIgo_trans_fee());
  1115. }
  1116. if (type.equals("cloudpurchase")) {
  1117. order_price = CommUtil.null2String(Integer.valueOf(cp_order.getPrice()));
  1118. }
  1119. double total_fee = CommUtil.null2Double(order_price) * 100.0D;
  1120. int fee = (int) total_fee;
  1121. String product_name = "";
  1122. if ((type.equals("goods")) || (type.equals("group"))) {
  1123. product_name = of.getOrder_id();
  1124. }
  1125. if (type.equals("cash")) {
  1126. product_name = obj.getPd_sn();
  1127. }
  1128. if (type.equals("gold")) {
  1129. product_name = gold.getGold_sn();
  1130. }
  1131. if (type.equals("integral")) {
  1132. product_name = ig_order.getIgo_order_sn();
  1133. }
  1134. if (type.equals("cloudpurchase")) {
  1135. product_name = cp_order.getOdrdersn();
  1136. }
  1137. String remarkexplain = "";
  1138. if ((type.equals("goods")) || (type.equals("group"))) {
  1139. remarkexplain = of.getMsg();
  1140. }
  1141. if (type.equals("cash")) {
  1142. remarkexplain = obj.getPd_remittance_info();
  1143. }
  1144. if (type.equals("gold")) {
  1145. remarkexplain = gold.getGold_exchange_info();
  1146. }
  1147. if (type.equals("integral")) {
  1148. remarkexplain = ig_order.getIgo_msg();
  1149. }
  1150. if (type.equals("cloudpurchase")) {
  1151. product_name = cp_order.getIgo_order_sn();
  1152. }
  1153. String attach = "";
  1154. if ((type.equals("goods")) || (type.equals("group"))) {
  1155. attach = type + "," + of.getId().toString();
  1156. }
  1157. if (type.equals("cash")) {
  1158. attach = type + "," + obj.getId().toString();
  1159. }
  1160. if (type.equals("gold")) {
  1161. attach = type + "," + gold.getId().toString();
  1162. }
  1163. if (type.equals("integral")) {
  1164. attach = type + "," + ig_order.getId().toString();
  1165. }
  1166. if (type.equals("cloudpurchase")) {
  1167. attach = type + "," + cp_order.getId().toString();
  1168. }
  1169. String desc = "商品:" + product_name;
  1170. String out_trade_no = "";
  1171. if ((type.equals("goods")) || (type.equals("group"))) {
  1172. out_trade_no = of.getOrder_id();
  1173. }
  1174. if (type.endsWith("cash")) {
  1175. out_trade_no = obj.getPd_sn();
  1176. }
  1177. if (type.endsWith("gold")) {
  1178. out_trade_no = gold.getGold_sn();
  1179. }
  1180. if (type.equals("integral")) {
  1181. out_trade_no = ig_order.getIgo_order_sn();
  1182. }
  1183. if (type.equals("cloudpurchase")) {
  1184. out_trade_no = cp_order.getOdrdersn();
  1185. }
  1186. Payment payment = this.paymentService.selectByPrimaryKey(CommUtil.null2Long(payment_id));
  1187. if (payment == null) {
  1188. payment = new Payment();
  1189. }
  1190. String trade_mode = CommUtil.null2String(Integer.valueOf(payment.getTrade_mode()));
  1191. String currTime = TenpayUtil.getCurrTime();
  1192. RequestHandler reqHandler = new RequestHandler(request, response);
  1193. reqHandler.init();
  1194. reqHandler.setKey(payment.getTenpay_key());
  1195. reqHandler.setGateUrl("https://gw.tenpay.com/gateway/pay");
  1196. reqHandler.setParameter("partner", payment.getTenpay_partner());
  1197. reqHandler.setParameter("out_trade_no", out_trade_no);
  1198. reqHandler.setParameter("total_fee", String.valueOf(fee));
  1199. reqHandler.setParameter("return_url", CommUtil.getURL(request) + "/tenpay_return");
  1200. reqHandler.setParameter("notify_url", CommUtil.getURL(request) + "/tenpay_notify");
  1201. reqHandler.setParameter("body", desc);
  1202. reqHandler.setParameter("bank_type", "DEFAULT");
  1203. reqHandler.setParameter("spbill_create_ip", request.getRemoteAddr());
  1204. reqHandler.setParameter("fee_type", "1");
  1205. reqHandler.setParameter("subject", desc);
  1206. reqHandler.setParameter("sign_type", "MD5");
  1207. reqHandler.setParameter("service_version", "1.0");
  1208. reqHandler.setParameter("input_charset", "UTF-8");
  1209. reqHandler.setParameter("sign_key_index", "1");
  1210. reqHandler.setParameter("attach", attach);
  1211. reqHandler.setParameter("product_fee", "");
  1212. reqHandler.setParameter("transport_fee", "0");
  1213. reqHandler.setParameter("time_start", currTime);
  1214. reqHandler.setParameter("time_expire", "");
  1215. reqHandler.setParameter("buyer_id", "");
  1216. reqHandler.setParameter("goods_tag", "");
  1217. reqHandler.setParameter("trade_mode", trade_mode);
  1218. reqHandler.setParameter("transport_desc", "");
  1219. reqHandler.setParameter("trans_type", "1");
  1220. reqHandler.setParameter("agentid", "");
  1221. reqHandler.setParameter("agent_type", "");
  1222. reqHandler.setParameter("seller_id", "");
  1223. String requestUrl = reqHandler.getRequestURL();
  1224. response.sendRedirect(requestUrl);
  1225. } else {
  1226. response.getWriter().write("该订单已经完成支付!");
  1227. }
  1228. }
  1229. /**
  1230. * 财付通在线支付回调控制
  1231. *
  1232. * @param request
  1233. * @param response
  1234. * @return
  1235. * @throws Exception
  1236. */
  1237. @RequestMapping({ "/tenpay_return" })
  1238. public Map<String, Object> tenpay_return(HttpServletRequest request, HttpServletResponse response)
  1239. throws Exception {
  1240. Map<String, Object> resultMap = new HashMap<String, Object>();
  1241. ResponseHandler resHandler = new ResponseHandler(request, response);
  1242. String[] attachs = request.getParameter("attach").split(",");
  1243. String out_trade_no = resHandler.getParameter("out_trade_no");
  1244. OrderFormDto order = null;
  1245. PredepositDto obj = null;
  1246. GoldRecord gold = null;
  1247. IntegralGoodsOrderDto ig_order = null;
  1248. CloudPurchaseOrderDto cp_order = null;
  1249. if (attachs[0].equals("cloudpurchase")) {
  1250. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[1]));
  1251. Map q_params = Maps.newHashMap();
  1252. q_params.put("install", Boolean.valueOf(true));
  1253. q_params.put("mark", cp_order.getPayment());
  1254. List<Payment> payments = this.paymentService.queryPageList(q_params);
  1255. resHandler.setKey(((Payment) payments.get(0)).getTenpay_key());
  1256. }
  1257. if (attachs[0].equals("integral")) {
  1258. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[1]));
  1259. Map q_params = Maps.newHashMap();
  1260. q_params.put("install", Boolean.valueOf(true));
  1261. q_params.put("mark", ig_order.getIgo_payment());
  1262. List<Payment> payments = this.paymentService.queryPageList(q_params);
  1263. resHandler.setKey(((Payment) payments.get(0)).getTenpay_key());
  1264. }
  1265. if (attachs[0].equals("cash")) {
  1266. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[1]));
  1267. Map q_params = Maps.newHashMap();
  1268. q_params.put("install", Boolean.valueOf(true));
  1269. q_params.put("mark", obj.getPd_payment());
  1270. List<Payment> payments = this.paymentService.queryPageList(q_params);
  1271. resHandler.setKey(((Payment) payments.get(0)).getTenpay_key());
  1272. }
  1273. if (attachs[0].equals("gold")) {
  1274. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(attachs[1]));
  1275. Map q_params = Maps.newHashMap();
  1276. q_params.put("install", Boolean.valueOf(true));
  1277. q_params.put("mark", gold.getGold_payment());
  1278. List<Payment> payments = this.paymentService.queryPageList(q_params);
  1279. resHandler.setKey(((Payment) payments.get(0)).getTenpay_key());
  1280. }
  1281. Payment payment = null;
  1282. if ((attachs[0].equals("goods")) || (attachs[0].equals("group"))) {
  1283. order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[1]));
  1284. payment = this.paymentService.selectByPrimaryKey(order.getPayment_id());
  1285. resHandler.setKey(payment.getTenpay_key());
  1286. }
  1287. if (resHandler.isTenpaySign()) {
  1288. String notify_id = resHandler.getParameter("notify_id");
  1289. String transaction_id = resHandler.getParameter("transaction_id");
  1290. String total_fee = resHandler.getParameter("total_fee");
  1291. String discount = resHandler.getParameter("discount");
  1292. String trade_state = resHandler.getParameter("trade_state");
  1293. String trade_mode = resHandler.getParameter("trade_mode");
  1294. if ("1".equals(trade_mode)) {
  1295. if ("0".equals(trade_state)) {
  1296. if (attachs[0].equals("cash")) {
  1297. obj.setPd_status(1);
  1298. obj.setPd_pay_status(2);
  1299. this.predepositFeignClient.updateById(obj);
  1300. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  1301. user.setAvailableBalance(
  1302. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  1303. this.userFeignClient.updateById(user);
  1304. resultMap.put("op_title", "充值" + obj.getPd_amount() + "成功");
  1305. resultMap.put("url", CommUtil.getURL(request) + "/buyer/predeposit_list");
  1306. }
  1307. if ((attachs[0].equals("goods")) || (attachs[0].equals("group"))) {
  1308. boolean flag = this.handleOrderFormFeignClient.payByOnline(order, transaction_id,
  1309. CommUtil.getURL(request));
  1310. if (flag) {
  1311. this.orderFormToolsFeignClient.updateGoodsInventory(order);
  1312. }
  1313. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), order,
  1314. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  1315. resultMap.put("all_price", Double.valueOf(this.orderFormToolsFeignClient
  1316. .query_order_pay_price(CommUtil.null2String(order.getId()))));
  1317. resultMap.put("obj", order);
  1318. }
  1319. if (attachs[0].equals("gold")) {
  1320. gold.setGold_status(1);
  1321. gold.setGold_pay_status(2);
  1322. this.goldRecordService.updateById(gold);
  1323. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  1324. user.setGold(user.getGold() + gold.getGold_count());
  1325. this.userFeignClient.updateById(user);
  1326. GoldLog log = new GoldLog();
  1327. log.setAddTime(new Date());
  1328. log.setGl_payment(gold.getGold_payment());
  1329. log.setGl_content("财付通及时到账支付");
  1330. log.setGl_money(gold.getGold_money());
  1331. log.setGl_count(gold.getGold_count());
  1332. log.setGl_type(0);
  1333. log.setGl_user(gold.getGold_user());
  1334. log.setGr(gold);
  1335. this.goldLogService.saveEntity(log);
  1336. resultMap.put("op_title", "兑换" + gold.getGold_count() + "金币成功");
  1337. resultMap.put("url", CommUtil.getURL(request) + "/seller/gold_record_list");
  1338. }
  1339. if (attachs[0].equals("integral")) {
  1340. ig_order.setIgo_status(20);
  1341. ig_order.setIgo_pay_time(new Date());
  1342. ig_order.setIgo_payment("bill");
  1343. this.integralGoodsOrderFeignClient.updateById(ig_order);
  1344. List<Map> ig_maps = this.orderFormToolsFeignClient
  1345. .query_integral_goodsinfo(ig_order.getGoods_info());
  1346. for (Map map : ig_maps) {
  1347. IntegralGoodsDto goods = this.integralGoodsFeignClient
  1348. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  1349. goods.setIg_goods_count(
  1350. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  1351. goods.setIg_exchange_count(
  1352. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  1353. this.integralGoodsFeignClient.updateById(goods);
  1354. }
  1355. resultMap.put("obj", ig_order);
  1356. }
  1357. if (attachs[0].equals("cloudpurchase")) {
  1358. if (cp_order.getStatus() < 5) {
  1359. cp_order.setStatus(5);
  1360. cp_order.setPayTime(new Date());
  1361. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  1362. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  1363. }
  1364. resultMap.put("op_title", "预付款支付成功!");
  1365. resultMap.put("url", CommUtil.getURL(request) + "/buyer/cloudbuy_order");
  1366. }
  1367. } else {
  1368. resultMap.put("op_title", "财付通支付失败!");
  1369. resultMap.put("url", CommUtil.getURL(request) + "/index");
  1370. }
  1371. } else if ("2".equals(trade_mode)) {
  1372. if ("0".equals(trade_state)) {
  1373. if (attachs[0].equals("cash")) {
  1374. obj.setPd_status(1);
  1375. obj.setPd_pay_status(2);
  1376. this.predepositFeignClient.updateById(obj);
  1377. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  1378. user.setAvailableBalance(
  1379. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  1380. this.userFeignClient.updateById(user);
  1381. PredepositLogDto log = new PredepositLogDto();
  1382. log.setAddTime(new Date());
  1383. log.setPd_log_amount(obj.getPd_amount());
  1384. log.setPd_log_user(obj.getPd_user());
  1385. log.setPd_op_type("充值");
  1386. log.setPd_type("可用预存款");
  1387. log.setPd_log_info("财付通中介担保付款");
  1388. this.predepositLogFeignClient.saveEntity(log);
  1389. resultMap.put("op_title", "充值" + obj.getPd_amount() + "成功");
  1390. resultMap.put("url", CommUtil.getURL(request) + "/buyer/predeposit_list");
  1391. }
  1392. if (attachs[0].equals("goods")) {
  1393. boolean flag = this.handleOrderFormFeignClient.payByOnline(order, transaction_id,
  1394. CommUtil.getURL(request));
  1395. if (flag) {
  1396. this.orderFormToolsFeignClient.updateGoodsInventory(order);
  1397. }
  1398. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), order,
  1399. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  1400. resultMap.put("all_price", Double.valueOf(this.orderFormToolsFeignClient
  1401. .query_order_pay_price(CommUtil.null2String(order.getId()))));
  1402. resultMap.put("obj", order);
  1403. }
  1404. if (attachs[0].equals("gold")) {
  1405. gold.setGold_status(1);
  1406. gold.setGold_pay_status(2);
  1407. this.goldRecordService.updateById(gold);
  1408. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  1409. user.setGold(user.getGold() + gold.getGold_count());
  1410. this.userFeignClient.updateById(user);
  1411. GoldLog log = new GoldLog();
  1412. log.setAddTime(new Date());
  1413. log.setGl_payment(gold.getGold_payment());
  1414. log.setGl_content("财付通中介担保付款成功");
  1415. log.setGl_money(gold.getGold_money());
  1416. log.setGl_count(gold.getGold_count());
  1417. log.setGl_type(0);
  1418. log.setGl_user(gold.getGold_user());
  1419. log.setGr(gold);
  1420. this.goldLogService.saveEntity(log);
  1421. resultMap.put("op_title", "兑换" + gold.getGold_count() + "金币成功");
  1422. resultMap.put("url", CommUtil.getURL(request) + "/seller/gold_record_list");
  1423. }
  1424. if (attachs[0].equals("integral")) {
  1425. ig_order.setIgo_status(20);
  1426. ig_order.setIgo_pay_time(new Date());
  1427. ig_order.setIgo_payment("bill");
  1428. this.integralGoodsOrderFeignClient.updateById(ig_order);
  1429. List<Map> ig_maps = this.orderFormToolsFeignClient
  1430. .query_integral_goodsinfo(ig_order.getGoods_info());
  1431. for (Map map : ig_maps) {
  1432. IntegralGoodsDto goods = this.integralGoodsFeignClient
  1433. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  1434. goods.setIg_goods_count(
  1435. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  1436. goods.setIg_exchange_count(
  1437. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  1438. this.integralGoodsFeignClient.updateById(goods);
  1439. }
  1440. resultMap.put("obj", ig_order);
  1441. }
  1442. if (attachs[0].equals("cloudpurchase")) {
  1443. if (cp_order.getStatus() < 5) {
  1444. cp_order.setStatus(5);
  1445. cp_order.setPayTime(new Date());
  1446. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  1447. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  1448. }
  1449. resultMap.put("op_title", "预付款支付成功!");
  1450. resultMap.put("url", CommUtil.getURL(request) + "/buyer/cloudbuy_order");
  1451. }
  1452. } else {
  1453. resultMap.put("op_title", "财付通支付失败!");
  1454. resultMap.put("url", CommUtil.getURL(request) + "/index");
  1455. }
  1456. }
  1457. } else {
  1458. resultMap.put("op_title", "财付通认证签名失败!");
  1459. resultMap.put("url", CommUtil.getURL(request) + "/index");
  1460. }
  1461. return resultMap;
  1462. }
  1463. /**
  1464. * 网银在线回调函数
  1465. *
  1466. * @param request
  1467. * @param response
  1468. * @return
  1469. * @throws Exception
  1470. */
  1471. @RequestMapping({ "/chinabank_return" })
  1472. public Map<String, Object> chinabank_return(HttpServletRequest request, HttpServletResponse response)
  1473. throws Exception {
  1474. Map<String, Object> resultMap = new HashMap<String, Object>();
  1475. String remark1 = request.getParameter("remark1");
  1476. String remark2 = CommUtil.null2String(request.getParameter("remark2"));
  1477. OrderFormDto order = null;
  1478. PredepositDto obj = null;
  1479. GoldRecord gold = null;
  1480. IntegralGoodsOrderDto ig_order = null;
  1481. CloudPurchaseOrderDto cp_order = null;
  1482. if ((remark2.equals("goods")) || (remark2.equals("group"))) {
  1483. order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1.trim()));
  1484. }
  1485. if (remark2.equals("cash")) {
  1486. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1487. }
  1488. if (remark2.equals("gold")) {
  1489. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1490. }
  1491. if (remark2.equals("integral")) {
  1492. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1493. }
  1494. if (remark2.equals("cloudpurchase")) {
  1495. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1496. }
  1497. String key = "";
  1498. Payment payment = null;
  1499. if ((remark2.equals("goods")) || (remark2.equals("group"))) {
  1500. payment = this.paymentService.selectByPrimaryKey(order.getPayment_id());
  1501. key = payment.getChinabank_key();
  1502. }
  1503. if ((remark2.equals("cash")) || (remark2.equals("gold")) || (remark2.equals("integral"))
  1504. || (remark2.equals("cloudpurchase"))) {
  1505. Map q_params = Maps.newHashMap();
  1506. q_params.put("install", Boolean.valueOf(true));
  1507. if (remark2.equals("cash")) {
  1508. q_params.put("mark", obj.getPd_payment());
  1509. }
  1510. if (remark2.equals("gold")) {
  1511. q_params.put("mark", gold.getGold_payment());
  1512. }
  1513. if (remark2.equals("integral")) {
  1514. q_params.put("mark", ig_order.getIgo_payment());
  1515. }
  1516. if (remark2.equals("cloudpurchase")) {
  1517. q_params.put("mark", cp_order.getPayment());
  1518. }
  1519. List<Payment> payments = this.paymentService.queryPageList(q_params);
  1520. key = ((Payment) payments.get(0)).getChinabank_key();
  1521. }
  1522. String v_oid = request.getParameter("v_oid");
  1523. String v_pmode = request.getParameter("v_pmode");
  1524. String v_pstatus = request.getParameter("v_pstatus");
  1525. String v_pstring = request.getParameter("v_pstring");
  1526. String v_amount = request.getParameter("v_amount");
  1527. String v_moneytype = request.getParameter("v_moneytype");
  1528. String v_md5str = request.getParameter("v_md5str");
  1529. String text = v_oid + v_pstatus + v_amount + v_moneytype + key;
  1530. String v_md5text = Md5Encrypt.md5(text).toUpperCase();
  1531. if (v_md5str.equals(v_md5text)) {
  1532. if ("20".equals(v_pstatus)) {
  1533. if ((remark2.equals("goods")) || (remark2.equals("group"))) {
  1534. boolean flag = this.handleOrderFormFeignClient.payByOnline(order, v_oid, CommUtil.getURL(request));
  1535. if (flag) {
  1536. this.orderFormToolsFeignClient.updateGoodsInventory(order);
  1537. }
  1538. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), order,
  1539. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  1540. resultMap.put("all_price", Double.valueOf(
  1541. this.orderFormToolsFeignClient.query_order_pay_price(CommUtil.null2String(order.getId()))));
  1542. resultMap.put("obj", order);
  1543. }
  1544. if (remark2.endsWith("cash")) {
  1545. obj.setPd_status(1);
  1546. obj.setPd_pay_status(2);
  1547. this.predepositFeignClient.updateById(obj);
  1548. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  1549. user.setAvailableBalance(
  1550. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  1551. this.userFeignClient.updateById(user);
  1552. PredepositLogDto log = new PredepositLogDto();
  1553. log.setAddTime(new Date());
  1554. log.setPd_log_amount(obj.getPd_amount());
  1555. log.setPd_log_user(obj.getPd_user());
  1556. log.setPd_op_type("充值");
  1557. log.setPd_type("可用预存款");
  1558. log.setPd_log_info("网银在线支付");
  1559. this.predepositLogFeignClient.saveEntity(log);
  1560. resultMap.put("op_title", "充值" + obj.getPd_amount() + "成功");
  1561. resultMap.put("url", CommUtil.getURL(request) + "/buyer/predeposit_list");
  1562. }
  1563. if (remark2.equals("gold")) {
  1564. gold.setGold_status(1);
  1565. gold.setGold_pay_status(2);
  1566. this.goldRecordService.updateById(gold);
  1567. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  1568. user.setGold(user.getGold() + gold.getGold_count());
  1569. this.userFeignClient.updateById(user);
  1570. GoldLog log = new GoldLog();
  1571. log.setAddTime(new Date());
  1572. log.setGl_payment(gold.getGold_payment());
  1573. log.setGl_content("网银在线支付");
  1574. log.setGl_money(gold.getGold_money());
  1575. log.setGl_count(gold.getGold_count());
  1576. log.setGl_type(0);
  1577. log.setGl_user(gold.getGold_user());
  1578. log.setGr(gold);
  1579. this.goldLogService.saveEntity(log);
  1580. resultMap.put("op_title", "兑换" + gold.getGold_count() + "金币成功");
  1581. resultMap.put("url", CommUtil.getURL(request) + "/seller/gold_record_list");
  1582. }
  1583. if (remark2.equals("integral")) {
  1584. ig_order.setIgo_status(20);
  1585. ig_order.setIgo_pay_time(new Date());
  1586. ig_order.setIgo_payment("bill");
  1587. this.integralGoodsOrderFeignClient.updateById(ig_order);
  1588. List<Map> ig_maps = this.orderFormToolsFeignClient
  1589. .query_integral_goodsinfo(ig_order.getGoods_info());
  1590. for (Map map : ig_maps) {
  1591. IntegralGoodsDto goods = this.integralGoodsFeignClient
  1592. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  1593. goods.setIg_goods_count(
  1594. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  1595. goods.setIg_exchange_count(
  1596. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  1597. this.integralGoodsFeignClient.updateById(goods);
  1598. }
  1599. resultMap.put("obj", ig_order);
  1600. }
  1601. if (remark2.equals("cloudpurchase")) {
  1602. if (cp_order.getStatus() < 5) {
  1603. cp_order.setStatus(5);
  1604. cp_order.setPayTime(new Date());
  1605. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  1606. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  1607. }
  1608. resultMap.put("op_title", "预付款支付成功!");
  1609. resultMap.put("url", CommUtil.getURL(request) + "/buyer/cloudbuy_order");
  1610. }
  1611. }
  1612. } else {
  1613. resultMap.put("op_title", "网银在线支付失败!");
  1614. resultMap.put("url", CommUtil.getURL(request) + "/index");
  1615. }
  1616. return resultMap;
  1617. }
  1618. /**
  1619. * paypal回调方法,paypal支付成功了后,调用该方法进行后续处理
  1620. *
  1621. * @param request
  1622. * @param response
  1623. * @return
  1624. * @throws Exception
  1625. */
  1626. @SuppressWarnings("deprecation")
  1627. @RequestMapping({ "/paypal_return" })
  1628. public Map<String, Object> paypal_return(HttpServletRequest request, HttpServletResponse response)
  1629. throws Exception {
  1630. Map<String, Object> resultMap = new HashMap<String, Object>();
  1631. Enumeration en = request.getParameterNames();
  1632. String str = "cmd=_notify-validate";
  1633. while (en.hasMoreElements()) {
  1634. String paramName = (String) en.nextElement();
  1635. String paramValue = request.getParameter(paramName);
  1636. str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
  1637. }
  1638. String[] customs = request.getParameter("custom").split(",");
  1639. String remark1 = customs[0];
  1640. String remark2 = customs[1];
  1641. String item_name = request.getParameter("item_name");
  1642. String txnId = request.getParameter("txn_id");
  1643. OrderFormDto order = null;
  1644. PredepositDto obj = null;
  1645. GoldRecord gold = null;
  1646. IntegralGoodsOrderDto ig_order = null;
  1647. CloudPurchaseOrderDto cp_order = null;
  1648. Payment payment = null;
  1649. if ((remark2.equals("goods")) || (remark2.equals("group"))) {
  1650. order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1.trim()));
  1651. payment = this.paymentService.selectByPrimaryKey(order.getPayment_id());
  1652. }
  1653. if (remark2.equals("cash")) {
  1654. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1655. }
  1656. if (remark2.equals("gold")) {
  1657. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1658. }
  1659. if (remark2.equals("integral")) {
  1660. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1661. }
  1662. if (remark2.equals("cloudpurchase")) {
  1663. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(remark1));
  1664. }
  1665. String txn_id = request.getParameter("txn_id");
  1666. String itemName = request.getParameter("item_name");
  1667. String paymentStatus = request.getParameter("payment_status");
  1668. String paymentAmount = request.getParameter("mc_gross");
  1669. String paymentCurrency = request.getParameter("mc_currency");
  1670. String receiverEmail = request.getParameter("receiver_email");
  1671. String payerEmail = request.getParameter("payer_email");
  1672. if ((paymentStatus.equals("Completed")) || (paymentStatus.equals("Pending"))) {
  1673. if (((remark2.equals("goods")) || (remark2.equals("group"))) && (order.getOrder_status() < 20)) {
  1674. if (CommUtil.null2String(order.getTotalPrice()).equals(paymentAmount)) {
  1675. boolean flag = this.handleOrderFormFeignClient.payByOnline(order, txnId, CommUtil.getURL(request));
  1676. if (flag) {
  1677. this.orderFormToolsFeignClient.updateGoodsInventory(order);
  1678. }
  1679. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), order,
  1680. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  1681. resultMap.put("all_price", Double.valueOf(
  1682. this.orderFormToolsFeignClient.query_order_pay_price(CommUtil.null2String(order.getId()))));
  1683. resultMap.put("obj", order);
  1684. }
  1685. }
  1686. if (remark2.endsWith("cash")) {
  1687. if (obj.getPd_pay_status() < 2) {
  1688. obj.setPd_status(1);
  1689. obj.setPd_pay_status(2);
  1690. this.predepositFeignClient.updateById(obj);
  1691. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  1692. user.setAvailableBalance(
  1693. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  1694. this.userFeignClient.updateById(user);
  1695. PredepositLogDto log = new PredepositLogDto();
  1696. log.setAddTime(new Date());
  1697. log.setPd_log_amount(obj.getPd_amount());
  1698. log.setPd_log_user(obj.getPd_user());
  1699. log.setPd_op_type("充值");
  1700. log.setPd_type("可用预存款");
  1701. log.setPd_log_info("Paypal在线支付");
  1702. this.predepositLogFeignClient.saveEntity(log);
  1703. }
  1704. resultMap.put("op_title", "成功充值:" + obj.getPd_amount());
  1705. resultMap.put("url", CommUtil.getURL(request) + "/buyer/predeposit_list");
  1706. }
  1707. if (remark2.equals("gold")) {
  1708. if (gold.getGold_pay_status() < 2) {
  1709. gold.setGold_status(1);
  1710. gold.setGold_pay_status(2);
  1711. this.goldRecordService.updateById(gold);
  1712. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  1713. user.setGold(user.getGold() + gold.getGold_count());
  1714. this.userFeignClient.updateById(user);
  1715. GoldLog log = new GoldLog();
  1716. log.setAddTime(new Date());
  1717. log.setGl_payment(gold.getGold_payment());
  1718. log.setGl_content("Paypal");
  1719. log.setGl_money(gold.getGold_money());
  1720. log.setGl_count(gold.getGold_count());
  1721. log.setGl_type(0);
  1722. log.setGl_user(gold.getGold_user());
  1723. log.setGr(gold);
  1724. this.goldLogService.saveEntity(log);
  1725. }
  1726. resultMap.put("op_title", "成功充值金币:" + gold.getGold_count());
  1727. resultMap.put("url", CommUtil.getURL(request) + "/seller/gold_record_list");
  1728. }
  1729. if (remark2.equals("integral")) {
  1730. if (ig_order.getIgo_status() < 20) {
  1731. ig_order.setIgo_status(20);
  1732. ig_order.setIgo_pay_time(new Date());
  1733. ig_order.setIgo_payment("paypal");
  1734. this.integralGoodsOrderFeignClient.updateById(ig_order);
  1735. List<Map> ig_maps = this.orderFormToolsFeignClient
  1736. .query_integral_goodsinfo(ig_order.getGoods_info());
  1737. for (Map map : ig_maps) {
  1738. IntegralGoodsDto goods = this.integralGoodsFeignClient
  1739. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  1740. goods.setIg_goods_count(
  1741. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  1742. goods.setIg_exchange_count(
  1743. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  1744. this.integralGoodsFeignClient.updateById(goods);
  1745. }
  1746. }
  1747. resultMap.put("obj", ig_order);
  1748. }
  1749. if (remark2.equals("cloudpurchase")) {
  1750. if (cp_order.getStatus() < 5) {
  1751. cp_order.setStatus(5);
  1752. cp_order.setPayTime(new Date());
  1753. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  1754. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  1755. }
  1756. resultMap.put("op_title", "预付款支付成功!");
  1757. resultMap.put("url", CommUtil.getURL(request) + "/buyer/cloudbuy_order");
  1758. }
  1759. } else {
  1760. resultMap.put("op_title", "Paypal支付失败");
  1761. resultMap.put("url", CommUtil.getURL(request) + "/index");
  1762. }
  1763. return resultMap;
  1764. }
  1765. public Map<String, Object> wx_pay1(HttpServletRequest request, HttpServletResponse response, Long id,
  1766. String pay_type, String order_type) throws Exception {
  1767. Map<String, Object> resultMap = new HashMap<String, Object>();
  1768. RequestHandler reqHandler = new RequestHandler(request, response);
  1769. List<Payment> payments = Lists.newArrayList();
  1770. Map<String, Object> params = Maps.newHashMap();
  1771. //TODO
  1772. pay_type="wx_miniprogram";
  1773. params.put("mark", pay_type);
  1774. payments = this.paymentService.queryPageList(params);
  1775. Payment payment = null;
  1776. if (payments.size() > 0) {
  1777. payment = (Payment) payments.get(0);
  1778. }
  1779. String body = "";
  1780. String attach = "";
  1781. String out_trade_no = "";
  1782. double total_fee = 0.0D;
  1783. boolean submit = true;
  1784. OrderFormDto of = null;
  1785. PredepositDto pd = null;
  1786. GoldRecord gold = null;
  1787. IntegralGoodsOrderDto ig_order = null;
  1788. CloudPurchaseOrderDto cp_order = null;
  1789. if ((order_type.equals("goods")) || (order_type.equals("group"))) {
  1790. of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1791. if (of.getOrder_status() >= 20) {
  1792. submit = false;
  1793. } else {
  1794. body = of.getOrder_id();
  1795. attach = of.getId() + "_" + of.getOrder_id() + "_" + of.getUser_id() + "_" + order_type +"_"+pay_type;
  1796. out_trade_no = of.getOrder_id();
  1797. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  1798. resultMap.put("obj", of);
  1799. }
  1800. }
  1801. if (order_type.equals("cash")) {
  1802. pd = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1803. if (pd.getPd_pay_status() >= 2) {
  1804. submit = false;
  1805. } else {
  1806. body = pd.getPd_sn();
  1807. attach = pd.getId() + "_" + pd.getPd_sn() + "_" + pd.getPd_user().getId() + "_" + order_type+"_"+pay_type;
  1808. out_trade_no = pd.getPd_sn();
  1809. total_fee = Double.valueOf(pd.getPd_amount().toString()).doubleValue() * 100.0D;
  1810. resultMap.put("obj", pd);
  1811. }
  1812. }
  1813. if (order_type.equals("gold")) {
  1814. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(id));
  1815. if (gold.getGold_pay_status() >= 2) {
  1816. submit = false;
  1817. } else {
  1818. body = gold.getGold_sn();
  1819. attach = gold.getId() + "_" + gold.getGold_sn() + "_" + gold.getGold_user().getId() + "_" + order_type+"_"+pay_type;
  1820. out_trade_no = gold.getGold_sn();
  1821. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  1822. resultMap.put("obj", gold);
  1823. }
  1824. }
  1825. if (order_type.equals("integral")) {
  1826. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1827. if (ig_order.getIgo_status() >= 20) {
  1828. submit = false;
  1829. } else {
  1830. body = ig_order.getIgo_order_sn();
  1831. attach = ig_order.getId() + "_" + ig_order.getIgo_order_sn() + "_" + ig_order.getIgo_user().getId()
  1832. + "_" + order_type+"_"+pay_type;
  1833. out_trade_no = ig_order.getIgo_order_sn();
  1834. total_fee = Double.valueOf(ig_order.getIgo_trans_fee().toString()).doubleValue() * 100.0D;
  1835. resultMap.put("obj", ig_order);
  1836. }
  1837. }
  1838. if (order_type.equals("cloudpurchase")) {
  1839. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1840. if (cp_order.getStatus() == 5) {
  1841. submit = false;
  1842. } else {
  1843. body = cp_order.getIgo_order_sn();
  1844. attach = cp_order.getId() + "_" + cp_order.getIgo_order_sn() + "_" + cp_order.getUser_id() + "_"
  1845. + order_type+"_"+pay_type;
  1846. out_trade_no = cp_order.getIgo_order_sn();
  1847. total_fee = Double.valueOf(cp_order.getPrice()).doubleValue() * 100.0D;
  1848. resultMap.put("obj", cp_order);
  1849. }
  1850. }
  1851. if ((submit) && (payment != null)) {
  1852. if (payment != null) {
  1853. String app_id = payment.getWx_appid();
  1854. String app_key = payment.getWx_paySignKey();
  1855. String partner = payment.getTenpay_partner();
  1856. String notify_url = payment.getTenpay_partner();
  1857. String noncestr = Sha1Util.getNonceStr();
  1858. String timestamp = Sha1Util.getTimeStamp();
  1859. String path = request.getContextPath();
  1860. String basePath = notify_url + "/";
  1861. reqHandler.setParameter("appid", app_id);
  1862. reqHandler.setParameter("mch_id", partner);
  1863. reqHandler.setParameter("nonce_str", noncestr);
  1864. reqHandler.setParameter("device_info", "wechat_mini_program");
  1865. reqHandler.setParameter("body", body);
  1866. reqHandler.setParameter("attach", attach);
  1867. reqHandler.setParameter("out_trade_no", out_trade_no);
  1868. BigDecimal total_feeBig = new BigDecimal(total_fee);
  1869. reqHandler.setParameter("total_fee", total_feeBig.setScale(0, BigDecimal.ROUND_UP)+"");
  1870. reqHandler.setParameter("spbill_create_ip", CommUtil.getIpAddr(request));
  1871. reqHandler.setParameter("notify_url", basePath + "weixin_return");
  1872. reqHandler.setParameter("trade_type", "JSAPI");
  1873. // trade_type=JSAPI时,必须传入openid
  1874. UserDto user = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(of.getUser_id()));
  1875. reqHandler.setParameter("openid", user.getOpenId());
  1876. String requestUrl = reqHandler.reqToXml(app_key);
  1877. HttpURLConnection conn = creatConnection(requestUrl);
  1878. String result = getInput(conn);
  1879. Map<String, String> map = doXMLParse(result);
  1880. String return_code = ((String) map.get("return_code")).toString();
  1881. String prepay_id = "";
  1882. String code_url = "";
  1883. if ("SUCCESS".equals(return_code)) {
  1884. String result_code = ((String) map.get("result_code")).toString();
  1885. if ("SUCCESS".equals(result_code)) {
  1886. prepay_id = (String) map.get("prepay_id");
  1887. code_url = (String) map.get("code_url");
  1888. } else {
  1889. // 预下单异常信息显示
  1890. log.error(map.toString());
  1891. }
  1892. } else {
  1893. // 预下单异常信息显示
  1894. log.error(map.toString());
  1895. }
  1896. reqHandler.getAllParameters().clear();
  1897. String newPackage = "prepay_id=" + prepay_id;
  1898. reqHandler.setParameter("appId", app_id);
  1899. reqHandler.setParameter("nonceStr", noncestr);
  1900. reqHandler.setParameter("package", newPackage);
  1901. reqHandler.setParameter("signType", "MD5");
  1902. reqHandler.setParameter("timeStamp", timestamp+"");
  1903. reqHandler.genSign(app_key);
  1904. String order_sign = reqHandler.getParameter("sign");
  1905. resultMap.put("app_id", app_id);
  1906. resultMap.put("timestamp", timestamp+"");
  1907. resultMap.put("noncestr", noncestr);
  1908. resultMap.put("packageValue", newPackage);
  1909. resultMap.put("sign", order_sign);
  1910. resultMap.put("code_url", code_url);
  1911. resultMap.put("signType", "MD5");
  1912. System.out.print("返回给前端---------------------------");
  1913. System.out.print(resultMap.toString());
  1914. System.out.print("返回给前端---------------------------");
  1915. reqHandler.getAllParameters().clear();
  1916. reqHandler.setParameter("appId", app_id);
  1917. reqHandler.setParameter("nonceStr", noncestr);
  1918. reqHandler.genSign(app_key);
  1919. order_sign=reqHandler.getParameter("sign");
  1920. if ((order_type.equals("goods")) || (order_type.equals("group"))) {
  1921. of.setOrder_sign(order_sign);
  1922. this.orderFormFeignClient.updateById(of);
  1923. }
  1924. if (order_type.equals("cash")) {
  1925. pd.setOrder_sign(order_sign);
  1926. this.predepositFeignClient.updateById(pd);
  1927. }
  1928. if (order_type.equals("gold")) {
  1929. gold.setOrder_sign(order_sign);
  1930. this.goldRecordService.updateById(gold);
  1931. }
  1932. if (order_type.equals("integral")) {
  1933. ig_order.setOrder_sign(order_sign);
  1934. this.integralGoodsOrderFeignClient.updateById(ig_order);
  1935. }
  1936. if (order_type.equals("cloudpurchase")) {
  1937. cp_order.setOrder_sign(order_sign);
  1938. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  1939. }
  1940. } else {
  1941. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  1942. }
  1943. } else {
  1944. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  1945. }
  1946. return ResponseCode.buildSuccessMap(resultMap) ;
  1947. }
  1948. /**
  1949. * 微信支付
  1950. *
  1951. * @param request
  1952. * @param response
  1953. * @param id 订单id
  1954. * @param pay_type 支付方式 小程序端写死为wx_pay
  1955. * @param order_type 订单类型
  1956. * @return
  1957. * @throws Exception
  1958. */
  1959. @RequestMapping({ "/pay/wx_pay" })
  1960. public Map<String, Object> wx_pay(HttpServletRequest request, HttpServletResponse response,
  1961. @RequestBody JSONObject json) throws Exception {
  1962. Long id = json.optLong("id");
  1963. String pay_type = json.optString("pay_type");
  1964. String order_type = json.optString("order_type");
  1965. Map<String, Object> resultMap = new HashMap<String, Object>();
  1966. RequestHandler reqHandler = new RequestHandler(request, response);
  1967. List<Payment> payments = Lists.newArrayList();
  1968. Map<String, Object> params = Maps.newHashMap();
  1969. if (StringUtils.isEmpty(pay_type)) {
  1970. pay_type = "wx_miniprogram";
  1971. }
  1972. params.put("mark", pay_type);
  1973. payments = this.paymentService.queryPageList(params);
  1974. Payment payment = null;
  1975. if (payments.size() > 0) {
  1976. payment = (Payment) payments.get(0);
  1977. }
  1978. String body = "";
  1979. String attach = "";
  1980. String out_trade_no = "";
  1981. String order_sign = "";
  1982. double total_fee = 0.0D;
  1983. boolean submit = true;
  1984. OrderFormDto of = null;
  1985. PredepositDto pd = null;
  1986. GoldRecord gold = null;
  1987. PlatformPay platformpay = null;
  1988. RushOrderformDto rushOrderformDto =null;
  1989. Date time = new Date();
  1990. IntegralGoodsOrderDto ig_order = null;
  1991. CloudPurchaseOrderDto cp_order = null;
  1992. UserDto user = null;
  1993. if ((order_type.equals("goods")) || (order_type.equals("group"))) {
  1994. of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  1995. if (of.getOrder_status() >= 20) {
  1996. submit = false;
  1997. } else {
  1998. body = of.getOrder_id();
  1999. attach = of.getId() + "_" + of.getOrder_id() + "_" + of.getUser_id() + "_" + order_type + "_"
  2000. + pay_type;
  2001. // out_trade_no = of.getOrder_id();
  2002. out_trade_no = of.getId() + "" + time.getTime();
  2003. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  2004. resultMap.put("obj", of);
  2005. }
  2006. } // 第一次付款, 带上子订单信息
  2007. if ((order_type.equals("goodsfirst")) || (order_type.equals("groupfirst"))) {
  2008. of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  2009. if (of.getOrder_status() >= 20) {
  2010. submit = false;
  2011. } else {
  2012. body = of.getOrder_id();
  2013. attach = of.getId() + "_" + of.getOrder_id() + "_" + of.getUser_id() + "_" + order_type + "_"
  2014. + pay_type;
  2015. // out_trade_no = of.getOrder_id();
  2016. out_trade_no = of.getId() + "" + time.getTime();
  2017. // 第一次付款取子订单总价格
  2018. total_fee = Double.valueOf(
  2019. orderFormToolsFeignClient.query_order_pay_price(CommUtil.null2String(of.getId()))) * 100.0D;
  2020. resultMap.put("obj", of);
  2021. }
  2022. }
  2023. if (order_type.equals("cash")) {
  2024. pd = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  2025. if (pd.getPd_pay_status() >= 2) {
  2026. submit = false;
  2027. } else {
  2028. body = pd.getPd_sn();
  2029. attach = pd.getId() + "_" + pd.getPd_sn() + "_" + pd.getPd_user().getId() + "_" + order_type + "_"
  2030. + pay_type;
  2031. out_trade_no = pd.getPd_sn();
  2032. total_fee = Double.valueOf(pd.getPd_amount().toString()).doubleValue() * 100.0D;
  2033. resultMap.put("obj", pd);
  2034. }
  2035. }
  2036. if (order_type.equals("gold")) {
  2037. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(id));
  2038. if (gold.getGold_pay_status() >= 2) {
  2039. submit = false;
  2040. } else {
  2041. body = gold.getGold_sn();
  2042. attach = gold.getId() + "_" + gold.getGold_sn() + "_" + gold.getGold_user().getId() + "_" + order_type
  2043. + "_" + pay_type;
  2044. out_trade_no = gold.getGold_sn();
  2045. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  2046. resultMap.put("obj", gold);
  2047. }
  2048. }
  2049. if (order_type.equals("integral")) {
  2050. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  2051. if (ig_order.getIgo_status() >= 20) {
  2052. submit = false;
  2053. } else {
  2054. body = ig_order.getIgo_order_sn();
  2055. attach = ig_order.getId() + "_" + ig_order.getIgo_order_sn() + "_" + ig_order.getIgo_user().getId()
  2056. + "_" + order_type + "_" + pay_type;
  2057. out_trade_no = ig_order.getIgo_order_sn();
  2058. //积分订单 支付金额 = 运费 加 付款金额
  2059. total_fee = Double.valueOf(ig_order.getIgo_pay_amount().toString()).doubleValue() * 100.0D;
  2060. resultMap.put("obj", ig_order);
  2061. }
  2062. }
  2063. if (order_type.equals("cloudpurchase")) {
  2064. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  2065. if (cp_order.getStatus() == 5) {
  2066. submit = false;
  2067. } else {
  2068. body = cp_order.getIgo_order_sn();
  2069. attach = cp_order.getId() + "_" + cp_order.getIgo_order_sn() + "_" + cp_order.getUser_id() + "_"
  2070. + order_type + "_" + pay_type;
  2071. out_trade_no = cp_order.getIgo_order_sn();
  2072. total_fee = Double.valueOf(cp_order.getPrice()).doubleValue() * 100.0D;
  2073. resultMap.put("obj", cp_order);
  2074. }
  2075. }
  2076. if (order_type.equals("platformpay")) { // 保证金
  2077. platformpay = this.platformPayService.selectByPrimaryKey(CommUtil.null2Long(id));
  2078. if (platformpay.getPay_status() == 1) { // 已支付
  2079. submit = false;
  2080. } else {
  2081. body = platformpay.getPay_no();
  2082. attach = platformpay.getId() + "_" + platformpay.getPay_no() + "_" + platformpay.getUser_id() + "_"
  2083. + order_type + "_" + pay_type;
  2084. out_trade_no = platformpay.getPay_no();
  2085. total_fee = platformpay.getAmount().doubleValue() * 100.0D;
  2086. resultMap.put("obj", platformpay);
  2087. user = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(platformpay.getUser_id()));
  2088. }
  2089. }
  2090. if (order_type.equals("rushorder")) { // 抢购单
  2091. rushOrderformDto = rushOrderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  2092. if (rushOrderformDto.getPay_time()!=null) { // 已支付
  2093. submit = false;
  2094. } else {
  2095. body = rushOrderformDto.getOrder_no(); //订单号id
  2096. attach = rushOrderformDto.getId() + "_" + rushOrderformDto.getOrder_no() + "_" + rushOrderformDto.getRush_id() + "_"
  2097. + order_type + "_" + pay_type;
  2098. out_trade_no = rushOrderformDto.getId() + "" + time.getTime(); //流水号
  2099. total_fee = rushOrderformDto.getBond_money().doubleValue() * 100.0D; //上架费
  2100. resultMap.put("obj", rushOrderformDto);
  2101. user = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(rushOrderformDto.getRush_id()));
  2102. }
  2103. }
  2104. if ((submit) && (payment != null)) {
  2105. if (payment != null) {
  2106. String app_id = payment.getWx_appid();
  2107. String app_key = payment.getWx_paySignKey();
  2108. String partner = payment.getTenpay_partner();
  2109. String notify_url = payment.getNotify_url();
  2110. String noncestr = Sha1Util.getNonceStr();
  2111. String timestamp = Sha1Util.getTimeStamp();
  2112. String path = request.getContextPath();
  2113. String basePath = notify_url + "/";
  2114. if (pay_type.equals("wx_pay")) {
  2115. reqHandler.setParameter("appid", app_id);
  2116. reqHandler.setParameter("mch_id", partner);
  2117. reqHandler.setParameter("nonce_str", noncestr);
  2118. reqHandler.setParameter("device_info", "WEB");
  2119. reqHandler.setParameter("body", body);
  2120. reqHandler.setParameter("attach", attach);
  2121. reqHandler.setParameter("out_trade_no", out_trade_no);
  2122. BigDecimal total_feeBig = new BigDecimal(total_fee);
  2123. reqHandler.setParameter("total_fee", total_feeBig.setScale(0, BigDecimal.ROUND_UP)+"");
  2124. reqHandler.setParameter("spbill_create_ip", CommUtil.getIpAddr(request));
  2125. reqHandler.setParameter("notify_url", basePath + "weixin_return");
  2126. reqHandler.setParameter("scene_info", "'h5_info':{'type':'Wap','wap_url':'http://haiwah5.minglisoft.cn/','wap_name': '海哇'}");
  2127. reqHandler.setParameter("trade_type", "MWEB");
  2128. if (of != null) {
  2129. // trade_type=JSAPI时,必须传入openid
  2130. // user = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(of.getUser_id()));
  2131. }
  2132. /*reqHandler.setParameter("openid", user.getOpenId());*/
  2133. String requestUrl = reqHandler.reqToXml(app_key);
  2134. HttpURLConnection conn = creatConnection(requestUrl);
  2135. String result = getInput(conn);
  2136. Map<String, String> map = doXMLParse(result);
  2137. String return_code = ((String) map.get("return_code")).toString();
  2138. String prepay_id = "";
  2139. String code_url = "";
  2140. if ("SUCCESS".equals(return_code)) {
  2141. System.out.println("mapppp==="+map);
  2142. String result_code = ((String) map.get("result_code")).toString();
  2143. if ("SUCCESS".equals(result_code)) {
  2144. prepay_id = (String) map.get("prepay_id");
  2145. code_url = (String) map.get("mweb_url");
  2146. } else {
  2147. // 预下单异常信息显示
  2148. log.error(map.toString());
  2149. }
  2150. } else {
  2151. // 预下单异常信息显示
  2152. log.error(map.toString());
  2153. }
  2154. reqHandler.getAllParameters().clear();
  2155. String newPackage = "prepay_id=" + prepay_id;
  2156. reqHandler.setParameter("appId", app_id);
  2157. reqHandler.setParameter("nonceStr", noncestr);
  2158. reqHandler.setParameter("package", newPackage);
  2159. reqHandler.setParameter("signType", "MD5");
  2160. reqHandler.setParameter("timeStamp", timestamp + "");
  2161. reqHandler.genSign(app_key);
  2162. order_sign = reqHandler.getParameter("sign");
  2163. resultMap.put("app_id", app_id);
  2164. resultMap.put("timestamp", timestamp + "");
  2165. resultMap.put("noncestr", noncestr);
  2166. resultMap.put("packageValue", newPackage);
  2167. resultMap.put("sign", order_sign); // http://haiwah5.minglisoft.cn/#/pagesA/order/index/index?type=order_nopay
  2168. resultMap.put("code_url", code_url+"&redirect_url="+"http://haiwah5.minglisoft.cn/%23/pagesA/order/index/index?type=order_nopay");
  2169. resultMap.put("signType", "MD5");
  2170. System.out.print("返回给前端-new1--------------------------");
  2171. System.out.print(resultMap.toString());
  2172. System.out.print("返回给前端---------------------------");
  2173. reqHandler.getAllParameters().clear();
  2174. reqHandler.setParameter("appId", app_id);
  2175. reqHandler.setParameter("nonceStr", noncestr);
  2176. reqHandler.genSign(app_key);
  2177. order_sign = reqHandler.getParameter("sign");
  2178. } else {
  2179. reqHandler.setParameter("appid", app_id);
  2180. reqHandler.setParameter("mch_id", partner);
  2181. reqHandler.setParameter("nonce_str", noncestr);
  2182. reqHandler.setParameter("device_info", "wechat_mini_program");
  2183. reqHandler.setParameter("body", body);
  2184. reqHandler.setParameter("attach", attach);
  2185. reqHandler.setParameter("out_trade_no", out_trade_no);
  2186. BigDecimal total_feeBig = new BigDecimal(total_fee);
  2187. reqHandler.setParameter("total_fee", total_feeBig.setScale(0, BigDecimal.ROUND_UP) + "");
  2188. reqHandler.setParameter("spbill_create_ip", CommUtil.getIpAddr(request));
  2189. reqHandler.setParameter("notify_url", basePath + "weixin_return");
  2190. reqHandler.setParameter("trade_type", "JSAPI");
  2191. if (of != null) {
  2192. // trade_type=JSAPI时,必须传入openid
  2193. user = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(of.getUser_id()));
  2194. }
  2195. reqHandler.setParameter("openid", user.getOpenId());
  2196. String requestUrl = reqHandler.reqToXml(app_key);
  2197. HttpURLConnection conn = creatConnection(requestUrl);
  2198. String result = getInput(conn);
  2199. Map<String, String> map = doXMLParse(result);
  2200. String return_code = ((String) map.get("return_code")).toString();
  2201. String prepay_id = "";
  2202. String code_url = "";
  2203. if ("SUCCESS".equals(return_code)) {
  2204. String result_code = ((String) map.get("result_code")).toString();
  2205. if ("SUCCESS".equals(result_code)) {
  2206. prepay_id = (String) map.get("prepay_id");
  2207. code_url = (String) map.get("code_url");
  2208. } else {
  2209. // 预下单异常信息显示
  2210. log.error(map.toString());
  2211. }
  2212. } else {
  2213. // 预下单异常信息显示
  2214. log.error(map.toString());
  2215. }
  2216. reqHandler.getAllParameters().clear();
  2217. String newPackage = "prepay_id=" + prepay_id;
  2218. reqHandler.setParameter("appId", app_id);
  2219. reqHandler.setParameter("nonceStr", noncestr);
  2220. reqHandler.setParameter("package", newPackage);
  2221. reqHandler.setParameter("signType", "MD5");
  2222. reqHandler.setParameter("timeStamp", timestamp + "");
  2223. reqHandler.genSign(app_key);
  2224. order_sign = reqHandler.getParameter("sign");
  2225. resultMap.put("app_id", app_id);
  2226. resultMap.put("timestamp", timestamp + "");
  2227. resultMap.put("noncestr", noncestr);
  2228. resultMap.put("packageValue", newPackage);
  2229. resultMap.put("sign", order_sign);
  2230. resultMap.put("code_url", code_url);
  2231. resultMap.put("signType", "MD5");
  2232. System.out.print("返回给前端---------------------------");
  2233. System.out.print(resultMap.toString());
  2234. System.out.print("返回给前端---------------------------");
  2235. reqHandler.getAllParameters().clear();
  2236. reqHandler.setParameter("appId", app_id);
  2237. reqHandler.setParameter("nonceStr", noncestr);
  2238. reqHandler.genSign(app_key);
  2239. order_sign = reqHandler.getParameter("sign");
  2240. }
  2241. if ((order_type.equals("goods")) || (order_type.equals("group")) || (order_type.equals("goodsfirst"))
  2242. || (order_type.equals("goodsfirst"))) {
  2243. of.setOrder_sign(order_sign);
  2244. of.setTrade_no(out_trade_no);
  2245. this.orderFormFeignClient.updateById(of);
  2246. }
  2247. if (order_type.equals("cash")) {
  2248. pd.setOrder_sign(order_sign);
  2249. this.predepositFeignClient.updateById(pd);
  2250. }
  2251. if (order_type.equals("gold")) {
  2252. gold.setOrder_sign(order_sign);
  2253. this.goldRecordService.updateById(gold);
  2254. }
  2255. if (order_type.equals("integral")) {
  2256. ig_order.setOrder_sign(order_sign);
  2257. this.integralGoodsOrderFeignClient.updateById(ig_order);
  2258. }
  2259. if (order_type.equals("cloudpurchase")) {
  2260. cp_order.setOrder_sign(order_sign);
  2261. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  2262. }
  2263. if (order_type.equals("platformpay")) {
  2264. platformpay.setTrade_no(order_sign);
  2265. platformpay.setSign(order_sign);
  2266. this.platformPayService.updateById(platformpay);
  2267. }
  2268. if (order_type.equals("rushorder")) {
  2269. rushOrderformDto.setSign(order_sign);
  2270. rushOrderformDto.setTrade_no(out_trade_no);
  2271. this.rushOrderFormFeignClient.updateById(rushOrderformDto);
  2272. }
  2273. } else {
  2274. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  2275. }
  2276. } else {
  2277. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  2278. }
  2279. return ResponseCode.buildSuccessMap(resultMap);
  2280. }
  2281. public void disAgentProfit(OrderFormDto orderformDto){
  2282. //分销收益
  2283. try{
  2284. // 拓展配置信息
  2285. DistributionSettingDto distributionSetting = distributionSettingFeignClient.getDistributionSetting();
  2286. // 下单成功后调用分销的处理逻辑
  2287. if (null != distributionSetting && "1".equals(distributionSetting.getIsOpen()) && 4 != orderformDto.getOrder_cat()) {
  2288. distributionProfitFeignClient.profitInsert(orderformDto);
  2289. agentProfitFeignClient.profitInsert(orderformDto);
  2290. // 计算分销的佣金
  2291. //BigDecimal disProfit = distributionProfitFeignClient.totalProfitByOrderId(orderformDto.getId());
  2292. //BigDecimal agentProfit = agentProfitFeignClient.totalProfitByOrderId(orderformDto.getId());
  2293. List<Map> goods_list = JSON.parseArray(orderformDto.getGoods_info(), Map.class);
  2294. BigDecimal goods_distribution_price = BigDecimal.ZERO;
  2295. for (Map<String, Object> map : goods_list) {
  2296. goods_distribution_price = goods_distribution_price.add(CommUtil.toBigDecimal(map.get("goods_distribution_price")));
  2297. }
  2298. // 平台的分佣+分销的佣金
  2299. BigDecimal commission_amount = goods_distribution_price.add(orderformDto.getCommission_amount());
  2300. orderformDto.setCommission_amount(commission_amount);
  2301. orderFormFeignClient.updateById(orderformDto);
  2302. }
  2303. }catch (Exception e) {
  2304. logger.error("PayController >> disAgentProfit(distribution&agentProfit) >> Exception:"+ e.getMessage());
  2305. }
  2306. }
  2307. public void sendOrderMessage(OrderFormDto orderformDto){
  2308. //分销收益
  2309. try{
  2310. MessageDto msg = new MessageDto();
  2311. msg.setAddTime(new Date());
  2312. msg.setDeleteStatus(0);
  2313. msg.setContent("订单编号:"+orderformDto.getOrder_id()+"已付款。下单人:"+orderformDto.getUser_name()+",订单金额:"+orderformDto.getTotalPrice()+"。");
  2314. msg.setMsg_cat(0);
  2315. msg.setReply_status(0);
  2316. msg.setStatus(0);
  2317. msg.setTitle("用户付款");
  2318. msg.setType(2);
  2319. msg.setFromUser_id(1L);
  2320. UserDto seller = userFeignClient.getUserByStoreId(Long.parseLong(orderformDto.getStore_id()));
  2321. msg.setToUser_id(seller.getId());
  2322. messageFeignClient.saveEntity(msg);
  2323. }catch (Exception e) {
  2324. logger.error("PayController >> sendOrderMessage >> Exception:"+ e.getMessage());
  2325. }
  2326. }
  2327. public void sendTxMessage(OrderFormDto orderformDto){
  2328. UserDto saler = userFeignClient.getUserByStoreId(Long.parseLong(orderformDto.getStore_id()));
  2329. try{
  2330. Map<String, Object> params2 = new HashMap<String, Object>();
  2331. params2.put("order_id", orderformDto.getOrder_id());
  2332. params2.put("orderMoney", orderformDto.getTotalPrice()+"");
  2333. params2.put("nickname", orderformDto.getUser_name());
  2334. params2.put("user_id", saler.getId().toString());
  2335. logger.info("params2[{}]",params2);
  2336. tXTemplateFeignClient.delivereMsg(params2);
  2337. tXTemplateFeignClient.paySuccessMsg(orderformDto);
  2338. }catch (Exception e) {
  2339. logger.error("PayController >> sendTxMessage >> Exception:"+ e.getMessage());
  2340. }
  2341. try{
  2342. jiguangPushFeignClient.deliveryReminder(saler.getId());
  2343. }catch (Exception e) {
  2344. logger.error("PayController >> jiGuangMessage >> Exception:"+ e.getMessage());
  2345. }
  2346. }
  2347. //发送酒店消息
  2348. public void sendHotelMessage(OrderFormDto orderformDto){
  2349. UserDto saler = userFeignClient.getUserByStoreId(Long.parseLong(orderformDto.getStore_id()));
  2350. UserDto buyer = userFeignClient.selectByPrimaryKey(Long.parseLong(orderformDto.getUser_id()));
  2351. try{
  2352. Map<String, Object> params2 = new HashMap<String, Object>();
  2353. params2.put("user_id", saler.getId().toString());
  2354. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
  2355. params2.put("check_in_time", sdf.format(orderformDto.getCheck_in_time()));
  2356. params2.put("departure_time", sdf.format(orderformDto.getDeparture_time()));
  2357. List<Map> goods_list = JSON.parseArray(orderformDto.getGoods_info(), Map.class);
  2358. for (Map<String, Object> map : goods_list) {
  2359. params2.put("days", map.get("days").toString());
  2360. params2.put("goods_name", map.get("goods_name").toString());
  2361. params2.put("count", map.get("goods_count").toString());
  2362. }
  2363. params2.put("goods_price", orderformDto.getTotalPrice().toString());
  2364. params2.put("receiver_name", orderformDto.getReceiver_Name());
  2365. params2.put("receiver_mobile", orderformDto.getReceiver_mobile());
  2366. logger.info("params2[{}]",params2);
  2367. tXTemplateFeignClient.shotelOrderMsg(params2);
  2368. params2.put("store_name", orderformDto.getStore_name());
  2369. params2.put("wx_open_id", buyer.getWx_open_id());
  2370. logger.info("params2[{}]",params2);
  2371. tXTemplateFeignClient.uhotelOrderMsg(params2);
  2372. }catch (Exception e) {
  2373. logger.error("PayController >> sendHotelMessage >> Exception:"+ e.getMessage());
  2374. }
  2375. }
  2376. /**
  2377. * 微信回调
  2378. *
  2379. * @param request
  2380. * @param response
  2381. * @throws Exception
  2382. */
  2383. @RequestMapping({ "/weixin_return" })
  2384. public void weixin_return(HttpServletRequest request, HttpServletResponse response) throws Exception {
  2385. response.setContentType("text/plain");
  2386. response.setHeader("Cache-Control", "no-cache");
  2387. response.setCharacterEncoding("UTF-8");
  2388. BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
  2389. String line = "";
  2390. StringBuffer strBuf = new StringBuffer();
  2391. while ((line = in.readLine()) != null) {
  2392. strBuf.append(line).append("\n");
  2393. }
  2394. in.close();
  2395. Map<String, String> xml = doXMLParse(strBuf.toString().trim());
  2396. //扩展信息表
  2397. SysConfigExtendDto sysConfigExtendDto=sysconrigExtendFeignClient.getSysConfigExtend();
  2398. String appid = ((String) xml.get("appid")).toString();
  2399. if ("SUCCESS".equals(((String) xml.get("return_code")).toString())) {
  2400. if ("SUCCESS".equals(((String) xml.get("result_code")).toString())) {
  2401. String total_fee = (String) xml.get("total_fee");
  2402. String out_trade_no = (String) xml.get("out_trade_no");
  2403. String[] attachs = ((String) xml.get("attach")).split("_");
  2404. String type = attachs[3];
  2405. //支付方式 因为微信支付方式是"wx_miniprogram" 形式故pay_type为attachs[4]+"_"+attachs[5]
  2406. String pay_type = attachs[4]+"_"+attachs[5];
  2407. System.out.println("返回的pay_type:"+pay_type);
  2408. OrderFormDto main_order = null;
  2409. PredepositDto obj = null;
  2410. GoldRecord gold = null;
  2411. IntegralGoodsOrderDto ig_order = null;
  2412. CloudPurchaseOrderDto cp_order = null;
  2413. List<Payment> payments = Lists.newArrayList();
  2414. Map<String, Object> params = Maps.newHashMap();
  2415. params.put("mark",pay_type);
  2416. payments = this.paymentService.queryPageList(params);
  2417. Payment payment = null;
  2418. if (payments.size() > 0) {
  2419. payment = (Payment) payments.get(0);
  2420. }
  2421. RequestHandler reqHandler = new RequestHandler(request, response);
  2422. reqHandler.setParameter("appId", payment.getWx_appid());
  2423. reqHandler.setParameter("nonceStr", ((String) xml.get("nonce_str")).toString());
  2424. reqHandler.genSign(payment.getWx_paySignKey());
  2425. String sign = reqHandler.getParameter("sign");
  2426. if (("goodsfirst".equals(type)) || ("groupfirst".equals(type))) {
  2427. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2428. if (sign.equals(main_order.getOrder_sign())) {
  2429. main_order.setPayTime(new Date());
  2430. main_order.setPayment_mark(payment.getMark());
  2431. main_order.setPayment_name(payment.getName());
  2432. main_order.setOut_order_id(out_trade_no);
  2433. boolean flag = false;
  2434. //查询修改相关子订单
  2435. main_order.setOrder_first(0);
  2436. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  2437. if (flag) {
  2438. main_order.setOrder_status(20);
  2439. //分销收益
  2440. try{
  2441. disAgentProfit(main_order);
  2442. sendOrderMessage(main_order);
  2443. if(main_order.getChild_order_detail() != null){
  2444. List<Map> datalist = com.alibaba.fastjson.JSONObject.parseArray(main_order.getChild_order_detail(), Map.class);
  2445. for (Map map : datalist) {
  2446. Integer order_id = (Integer) map.get("order_id");
  2447. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(order_id.longValue());
  2448. if(order != null){
  2449. disAgentProfit(order);
  2450. sendOrderMessage(order);
  2451. }
  2452. }
  2453. }
  2454. }catch (Exception e) {
  2455. logger.error("PayController >> weixin_return(distribution&agentProfit【goods_first】) >> Exception:"+ e.getMessage());
  2456. }
  2457. //更新库存
  2458. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  2459. //该订单存在直播商品
  2460. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  2461. liveOrderFeignClient.updateLiveOrder(main_order);
  2462. }
  2463. //如果订单是增值服务,修改用户 审核状态
  2464. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  2465. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  2466. }
  2467. //如果订单是拉新用户订单 , 添加
  2468. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==5) {
  2469. main_order.setOrder_status(14);
  2470. orderFormFeignClient.updateById(main_order);
  2471. }else{
  2472. if(main_order.getCheck_in_time() != null){
  2473. sendHotelMessage(main_order);
  2474. }else if(main_order.getOrder_offline()==1){
  2475. //TODO 待修改 , 验证码消息
  2476. }else{
  2477. try{
  2478. sendTxMessage(main_order);
  2479. if(main_order.getChild_order_detail() != null){
  2480. List<Map> datalist = com.alibaba.fastjson.JSONObject.parseArray(main_order.getChild_order_detail(), Map.class);
  2481. for (Map map : datalist) {
  2482. Integer order_id = (Integer) map.get("order_id");
  2483. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(order_id.longValue());
  2484. if(order != null){
  2485. sendTxMessage(main_order);
  2486. }
  2487. }
  2488. }
  2489. }catch (Exception e) {
  2490. logger.error("PayController >> weixin_return(sendTxMessage【goods_first】) >> Exception:"+ e.getMessage());
  2491. }
  2492. }
  2493. }
  2494. //发站内消息
  2495. /*//拓展配置中分销为开启
  2496. if(null !=sysConfigExtendDto && sysConfigExtendDto.isDistribution_open() && main_order.getOrder_cat()==0){
  2497. OrderFormDto updateorder=main_order;
  2498. //更新分销订单状态
  2499. updateorder.setOrder_status(20);
  2500. distributionOrderFeignClient.updateOrderStatus(updateorder);
  2501. }*/
  2502. }
  2503. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  2504. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  2505. }
  2506. }
  2507. if (("goods".equals(type)) || ("group".equals(type))) {
  2508. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2509. if (sign.equals(main_order.getOrder_sign())) {
  2510. main_order.setPayTime(new Date());
  2511. main_order.setPayment_mark(payment.getMark());
  2512. main_order.setPayment_name(payment.getName());
  2513. main_order.setOut_order_id(out_trade_no);
  2514. boolean flag = false;
  2515. //不查询相关子订单
  2516. main_order.setOrder_first(1);
  2517. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  2518. if (flag) {
  2519. main_order.setOrder_status(20);
  2520. try{
  2521. disAgentProfit(main_order);
  2522. sendOrderMessage(main_order);
  2523. }catch (Exception e) {
  2524. logger.error("PayController >> weixin_return(distribution&agentProfit【goods】) >> Exception:"+ e.getMessage());
  2525. }
  2526. if (main_order.getOrder_cat() != null && main_order.getOrder_cat() != 5) {
  2527. if (main_order.getCheck_in_time() != null) {
  2528. sendHotelMessage(main_order);
  2529. } else if(main_order.getOrder_offline()==1){
  2530. //TODO 待修改 , 验证码消息
  2531. }else {
  2532. try {
  2533. sendTxMessage(main_order);
  2534. } catch (Exception e) {
  2535. logger.error(
  2536. "PayController >> weixin_return(sendTxMessage【goods】) >> Exception:"
  2537. + e.getMessage());
  2538. }
  2539. }
  2540. }
  2541. //更新库存
  2542. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  2543. //该订单存在直播商品
  2544. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  2545. liveOrderFeignClient.updateLiveOrder(main_order);
  2546. }
  2547. //如果订单是增值服务,修改用户 审核状态
  2548. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  2549. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  2550. }
  2551. //如果订单是拉新用户订单 , 添加
  2552. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==5) {
  2553. main_order.setOrder_status(14);
  2554. orderFormFeignClient.updateById(main_order);
  2555. }
  2556. }
  2557. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  2558. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  2559. }
  2560. }
  2561. if ("integral".equals(type)) {
  2562. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2563. if ((ig_order != null) && (ig_order.getIgo_status() < 20)
  2564. && (sign.equals(ig_order.getOrder_sign()))) {
  2565. ig_order.setIgo_status(20);
  2566. ig_order.setIgo_order_sn(out_trade_no);
  2567. ig_order.setIgo_pay_time(new Date());
  2568. ig_order.setIgo_payment(payment.getMark());
  2569. this.integralGoodsOrderFeignClient.updateById(ig_order);
  2570. List<Map> ig_maps = this.orderFormToolsFeignClient
  2571. .query_integral_goodsinfo(ig_order.getGoods_info());
  2572. for (Map map : ig_maps) {
  2573. IntegralGoodsDto goods = this.integralGoodsFeignClient
  2574. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  2575. goods.setIg_goods_count(
  2576. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  2577. goods.setIg_exchange_count(
  2578. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  2579. this.integralGoodsFeignClient.updateById(goods);
  2580. }
  2581. }
  2582. }
  2583. if ("cash".equals(type)) {
  2584. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2585. if ((obj != null) && (obj.getPd_pay_status() != 2) && (sign.equals(obj.getOrder_sign()))) {
  2586. obj.setPd_payment(payment.getMark());
  2587. obj.setPd_status(1);
  2588. obj.setPd_pay_status(2);
  2589. this.predepositFeignClient.updateById(obj);
  2590. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  2591. user.setAvailableBalance(
  2592. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  2593. this.userFeignClient.updateById(user);
  2594. PredepositLogDto log = new PredepositLogDto();
  2595. log.setAddTime(new Date());
  2596. log.setPd_log_amount(obj.getPd_amount());
  2597. log.setPd_log_user(obj.getPd_user());
  2598. log.setPd_op_type("充值");
  2599. log.setPd_type("可用预存款");
  2600. log.setPd_log_info(payment.getName());
  2601. this.predepositLogFeignClient.saveEntity(log);
  2602. }
  2603. }
  2604. if ("gold".equals(type)) {
  2605. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2606. if ((gold != null) && (gold.getGold_pay_status() != 2) && (sign.equals(gold.getOrder_sign()))) {
  2607. gold.setGold_status(1);
  2608. gold.setGold_pay_status(2);
  2609. gold.setGold_payment(payment.getMark());
  2610. this.goldRecordService.updateById(gold);
  2611. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  2612. user.setGold(user.getGold() + gold.getGold_count());
  2613. this.userFeignClient.updateById(user);
  2614. GoldLog log = new GoldLog();
  2615. log.setAddTime(new Date());
  2616. log.setGl_payment(gold.getGold_payment());
  2617. log.setGl_content(payment.getName());
  2618. log.setGl_money(gold.getGold_money());
  2619. log.setGl_count(gold.getGold_count());
  2620. log.setGl_type(0);
  2621. log.setGl_user(gold.getGold_user());
  2622. log.setGr(gold);
  2623. this.goldLogService.saveEntity(log);
  2624. }
  2625. }
  2626. if (type.equals("cloudpurchase")) {
  2627. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2628. if (cp_order.getStatus() < 5) {
  2629. cp_order.setStatus(5);
  2630. cp_order.setPayTime(new Date());
  2631. cp_order.setPayment(payment.getMark());
  2632. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  2633. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  2634. }
  2635. }
  2636. if (type.equals("platformpay")) {
  2637. PlatformPay pf = this.platformPayService.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2638. if (pf.getPay_status() == 0 && StringUtils.equals(sign, pf.getSign())) {
  2639. pf.setPay_status(1);
  2640. pf.setUpdate_date(new Date());
  2641. pf.setPay_type(payment.getMark());
  2642. this.platformPayService.updateById(pf);
  2643. PlatformPayFlow platformpayflow = new PlatformPayFlow();
  2644. platformpayflow.setPlatform_pay_id(pf.getId());
  2645. platformpayflow.setInfo("编号["+pf.getPay_no()+"]店铺保证金,支付成功");
  2646. platformpayflow.setCreate_date(new Date());
  2647. this.platformPayFlowService.saveEntity(platformpayflow);
  2648. UserDto user = userFeignClient.selectByPrimaryKey(pf.getUser_id());
  2649. StoreDto store = this.storeFeignClient.selectByPrimaryKey(user.getStore_id());
  2650. store.setDeposit(pf.getAmount());
  2651. this.storeFeignClient.updateById(store);
  2652. }
  2653. }
  2654. //支付抢购订单上架费
  2655. if (type.equals("rushorder")) {
  2656. RushOrderformDto rushorderformdto = rushOrderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  2657. if (rushorderformdto.getOrder_status()==5 && StringUtils.equals(sign, rushorderformdto.getSign())) {
  2658. rushorderformdto.setPay_mark(payment.getMark());
  2659. rushorderformdto.setPayment_id(payment.getId());
  2660. rushorderformdto.setPayment_name(payment.getName());
  2661. rushorderformdto.setOut_order_id(out_trade_no);
  2662. rushorderformdto.setPay_time(new Date());
  2663. rushOrderFormFeignClient.completePayment(rushorderformdto);
  2664. //2022 支付流水待写入
  2665. /*PlatformPayFlow platformpayflow = new PlatformPayFlow();
  2666. platformpayflow.setPlatform_pay_id(pf.getId());
  2667. platformpayflow.setInfo("编号["+pf.getPay_no()+"]店铺保证金,支付成功");
  2668. platformpayflow.setCreate_date(new Date());
  2669. this.platformPayFlowService.saveEntity(platformpayflow);
  2670. UserDto user = userFeignClient.selectByPrimaryKey(pf.getUser_id());*/
  2671. }
  2672. }
  2673. PrintWriter write = response.getWriter();
  2674. write.print(
  2675. "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>");
  2676. } else {
  2677. PrintWriter write = response.getWriter();
  2678. write.print(
  2679. "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>");
  2680. }
  2681. } else {
  2682. PrintWriter write = response.getWriter();
  2683. write.print(
  2684. "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>");
  2685. }
  2686. }
  2687. /**
  2688. *
  2689. * @param request
  2690. * @param response
  2691. * @return
  2692. * @throws Exception
  2693. */
  2694. @RequestMapping({ "/unionpay_return" })
  2695. public Map<String, Object> unionpay_return(HttpServletRequest request, HttpServletResponse response)
  2696. throws Exception {
  2697. Map<String, Object> resultMap = new HashMap<String, Object>();
  2698. request.setCharacterEncoding("ISO-8859-1");
  2699. String encoding = request.getParameter("encoding");
  2700. Map<String, String> reqParam = getAllRequestParam(request);
  2701. Map<String, String> valideData = null;
  2702. if ((reqParam != null) && (!reqParam.isEmpty())) {
  2703. Iterator<Map.Entry<String, String>> it = reqParam.entrySet().iterator();
  2704. valideData = new HashMap(reqParam.size());
  2705. while (it.hasNext()) {
  2706. Map.Entry<String, String> e = (Map.Entry) it.next();
  2707. String key = (String) e.getKey();
  2708. String value = (String) e.getValue();
  2709. value = new String(value.getBytes("ISO-8859-1"), encoding);
  2710. valideData.put(key, value);
  2711. }
  2712. }
  2713. if (!SDKUtil.validate(valideData, encoding)) {
  2714. resultMap.put("op_title", "支付回调失败");
  2715. resultMap.put("url", CommUtil.getURL(request) + "/index");
  2716. } else {
  2717. String orderId = (String) valideData.get("orderId");
  2718. String respCode = (String) valideData.get("respCode");
  2719. String txtAmt = (String) valideData.get("txtAmt");
  2720. String reqReserved = (String) valideData.get("reqReserved");
  2721. String[] infos = reqReserved.split("_");
  2722. String type = infos[0];
  2723. String order_no = infos[1];
  2724. OrderFormDto main_order = null;
  2725. PredepositDto obj = null;
  2726. GoldRecord gold = null;
  2727. IntegralGoodsOrderDto ig_order = null;
  2728. CloudPurchaseOrderDto cp_order = null;
  2729. if (type.equals("goods")) {
  2730. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2731. }
  2732. if (type.equals("cash")) {
  2733. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2734. }
  2735. if (type.equals("gold")) {
  2736. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2737. }
  2738. if (type.equals("integral")) {
  2739. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2740. }
  2741. if (type.equals("group")) {
  2742. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2743. }
  2744. if (type.equals("cloudpurchase")) {
  2745. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2746. }
  2747. Payment payment = null;
  2748. if ((type.equals("goods")) || (type.equals("group"))) {
  2749. payment = this.paymentService.selectByPrimaryKey(main_order.getPayment_id());
  2750. }
  2751. if ((type.equals("goods")) || (type.equals("group"))) {
  2752. boolean flag = this.handleOrderFormFeignClient.payByOnline(main_order, main_order.getTrade_no(),
  2753. CommUtil.getURL(request));
  2754. if (flag) {
  2755. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  2756. }
  2757. resultMap.put("all_price", Double.valueOf(this.orderFormToolsFeignClient
  2758. .query_order_pay_price(CommUtil.null2String(main_order.getId()))));
  2759. resultMap.put("obj", main_order);
  2760. }
  2761. if (type.equals("cash")) {
  2762. if (obj.getPd_pay_status() != 2) {
  2763. obj.setPd_status(1);
  2764. obj.setPd_pay_status(2);
  2765. this.predepositFeignClient.updateById(obj);
  2766. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  2767. user.setAvailableBalance(
  2768. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  2769. this.userFeignClient.updateById(user);
  2770. PredepositLogDto log = new PredepositLogDto();
  2771. log.setAddTime(new Date());
  2772. log.setPd_log_amount(obj.getPd_amount());
  2773. log.setPd_log_user(obj.getPd_user());
  2774. log.setPd_op_type("充值");
  2775. log.setPd_type("可用预存款");
  2776. log.setPd_log_info("银联在线支付");
  2777. this.predepositLogFeignClient.saveEntity(log);
  2778. }
  2779. resultMap.put("op_title", "恭喜您,成功充值" + obj.getPd_amount() + "元");
  2780. resultMap.put("url", CommUtil.getURL(request) + "/buyer/predeposit_list");
  2781. }
  2782. if (type.equals("gold")) {
  2783. if (gold.getGold_pay_status() != 2) {
  2784. gold.setGold_status(1);
  2785. gold.setGold_pay_status(2);
  2786. this.goldRecordService.updateById(gold);
  2787. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  2788. user.setGold(user.getGold() + gold.getGold_count());
  2789. this.userFeignClient.updateById(user);
  2790. GoldLog log = new GoldLog();
  2791. log.setAddTime(new Date());
  2792. log.setGl_payment(gold.getGold_payment());
  2793. log.setGl_content("银联支付");
  2794. log.setGl_money(gold.getGold_money());
  2795. log.setGl_count(gold.getGold_count());
  2796. log.setGl_type(0);
  2797. log.setGl_user(gold.getGold_user());
  2798. log.setGr(gold);
  2799. this.goldLogService.saveEntity(log);
  2800. }
  2801. resultMap.put("op_title", "兑换" + gold.getGold_count() + "金币成功");
  2802. resultMap.put("url", CommUtil.getURL(request) + "/seller/gold_record_list");
  2803. }
  2804. if (type.equals("integral")) {
  2805. if (ig_order.getIgo_status() < 20) {
  2806. ig_order.setIgo_status(20);
  2807. ig_order.setIgo_pay_time(new Date());
  2808. ig_order.setIgo_payment("unionpay");
  2809. this.integralGoodsOrderFeignClient.updateById(ig_order);
  2810. List<Map> ig_maps = this.orderFormToolsFeignClient
  2811. .query_integral_goodsinfo(ig_order.getGoods_info());
  2812. for (Map map : ig_maps) {
  2813. IntegralGoodsDto goods = this.integralGoodsFeignClient
  2814. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  2815. goods.setIg_goods_count(
  2816. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  2817. goods.setIg_exchange_count(
  2818. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  2819. this.integralGoodsFeignClient.updateById(goods);
  2820. }
  2821. }
  2822. resultMap.put("obj", ig_order);
  2823. }
  2824. if (type.equals("cloudpurchase")) {
  2825. if (cp_order.getStatus() < 5) {
  2826. cp_order.setStatus(5);
  2827. cp_order.setPayTime(new Date());
  2828. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  2829. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  2830. }
  2831. resultMap.put("op_title", "预付款支付成功!");
  2832. resultMap.put("url", CommUtil.getURL(request) + "/buyer/cloudbuy_order");
  2833. }
  2834. }
  2835. return resultMap;
  2836. }
  2837. @RequestMapping({ "/unionpay_notify" })
  2838. public void unionpay_notify(HttpServletRequest request, HttpServletResponse response) throws Exception {
  2839. String result = "ok";
  2840. request.setCharacterEncoding("ISO-8859-1");
  2841. String encoding = request.getParameter("encoding");
  2842. Map<String, String> reqParam = getAllRequestParam(request);
  2843. Map<String, String> valideData = null;
  2844. if ((reqParam != null) && (!reqParam.isEmpty())) {
  2845. Iterator<Map.Entry<String, String>> it = reqParam.entrySet().iterator();
  2846. valideData = new HashMap(reqParam.size());
  2847. while (it.hasNext()) {
  2848. Map.Entry<String, String> e = (Map.Entry) it.next();
  2849. String key = (String) e.getKey();
  2850. String value = (String) e.getValue();
  2851. value = new String(value.getBytes("ISO-8859-1"), encoding);
  2852. valideData.put(key, value);
  2853. }
  2854. }
  2855. if (!SDKUtil.validate(valideData, encoding)) {
  2856. result = "no";
  2857. } else {
  2858. String orderId = (String) valideData.get("orderId");
  2859. String respCode = (String) valideData.get("respCode");
  2860. String txtAmt = (String) valideData.get("txtAmt");
  2861. String reqReserved = (String) valideData.get("reqReserved");
  2862. String[] infos = reqReserved.split("_");
  2863. String type = infos[0];
  2864. String order_no = infos[1];
  2865. OrderFormDto main_order = null;
  2866. PredepositDto obj = null;
  2867. GoldRecord gold = null;
  2868. IntegralGoodsOrderDto ig_order = null;
  2869. CloudPurchaseOrderDto cp_order = null;
  2870. if (type.equals("goods")) {
  2871. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2872. }
  2873. if (type.equals("cash")) {
  2874. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2875. }
  2876. if (type.equals("gold")) {
  2877. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2878. }
  2879. if (type.equals("integral")) {
  2880. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2881. }
  2882. if (type.equals("group")) {
  2883. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2884. }
  2885. if (type.equals("cloudpurchase")) {
  2886. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_no));
  2887. }
  2888. Payment payment = null;
  2889. if ((type.equals("goods")) || (type.equals("group"))) {
  2890. payment = this.paymentService.selectByPrimaryKey(main_order.getPayment_id());
  2891. }
  2892. if ((type.equals("goods")) || (type.equals("group"))) {
  2893. boolean flag = this.handleOrderFormFeignClient.payByOnline(main_order, main_order.getTrade_no(),
  2894. CommUtil.getURL(request));
  2895. if (flag) {
  2896. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  2897. }
  2898. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  2899. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  2900. }
  2901. if ((type.equals("cash")) && (obj.getPd_pay_status() != 2)) {
  2902. obj.setPd_status(1);
  2903. obj.setPd_pay_status(2);
  2904. this.predepositFeignClient.updateById(obj);
  2905. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  2906. user.setAvailableBalance(
  2907. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  2908. this.userFeignClient.updateById(user);
  2909. PredepositLogDto log = new PredepositLogDto();
  2910. log.setAddTime(new Date());
  2911. log.setPd_log_amount(obj.getPd_amount());
  2912. log.setPd_log_user(obj.getPd_user());
  2913. log.setPd_op_type("充值");
  2914. log.setPd_type("可用预存款");
  2915. log.setPd_log_info("银联在线支付");
  2916. this.predepositLogFeignClient.saveEntity(log);
  2917. }
  2918. if ((type.equals("gold")) && (gold.getGold_pay_status() != 2)) {
  2919. gold.setGold_status(1);
  2920. gold.setGold_pay_status(2);
  2921. this.goldRecordService.updateById(gold);
  2922. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  2923. user.setGold(user.getGold() + gold.getGold_count());
  2924. this.userFeignClient.updateById(user);
  2925. GoldLog log = new GoldLog();
  2926. log.setAddTime(new Date());
  2927. log.setGl_payment(gold.getGold_payment());
  2928. log.setGl_content("银联支付");
  2929. log.setGl_money(gold.getGold_money());
  2930. log.setGl_count(gold.getGold_count());
  2931. log.setGl_type(0);
  2932. log.setGl_user(gold.getGold_user());
  2933. log.setGr(gold);
  2934. this.goldLogService.saveEntity(log);
  2935. }
  2936. if ((type.equals("integral")) && (ig_order.getIgo_status() < 20)) {
  2937. ig_order.setIgo_status(20);
  2938. ig_order.setIgo_pay_time(new Date());
  2939. ig_order.setIgo_payment("unionpay");
  2940. this.integralGoodsOrderFeignClient.updateById(ig_order);
  2941. List<Map> ig_maps = this.orderFormToolsFeignClient.query_integral_goodsinfo(ig_order.getGoods_info());
  2942. for (Map map : ig_maps) {
  2943. IntegralGoodsDto goods = this.integralGoodsFeignClient
  2944. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  2945. goods.setIg_goods_count(goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  2946. goods.setIg_exchange_count(
  2947. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  2948. this.integralGoodsFeignClient.updateById(goods);
  2949. }
  2950. }
  2951. if ((type.equals("cloudpurchase")) && (cp_order.getStatus() < 5)) {
  2952. cp_order.setStatus(5);
  2953. cp_order.setPayTime(new Date());
  2954. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  2955. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  2956. }
  2957. }
  2958. response.setContentType("text/plain");
  2959. response.setHeader("Cache-Control", "no-cache");
  2960. response.setCharacterEncoding("UTF-8");
  2961. try {
  2962. PrintWriter writer = response.getWriter();
  2963. writer.print(result);
  2964. } catch (IOException e) {
  2965. log.error(e.toString());
  2966. }
  2967. }
  2968. public static Map<String, String> getAllRequestParam(HttpServletRequest request) {
  2969. Map<String, String> res = Maps.newHashMap();
  2970. Enumeration<?> temp = request.getParameterNames();
  2971. if (temp != null) {
  2972. while (temp.hasMoreElements()) {
  2973. String en = (String) temp.nextElement();
  2974. String value = request.getParameter(en);
  2975. res.put(en, value);
  2976. if ((res.get(en) == null) || ("".equals(res.get(en)))) {
  2977. res.remove(en);
  2978. }
  2979. }
  2980. }
  2981. return res;
  2982. }
  2983. /**
  2984. * 移动端订单预付款支付
  2985. * @param request
  2986. * @param response
  2987. * @param order_id
  2988. * @param pay_msg
  2989. * @param type
  2990. * @return
  2991. * @throws Exception
  2992. */
  2993. @RequestMapping({ "/order_pay_balance" })
  2994. public Map<String,Object> order_pay_balance(HttpServletRequest request,
  2995. HttpServletResponse response, @RequestBody JSONObject json) throws Exception {
  2996. String order_id = json.optString("order_id");
  2997. String pay_msg = json.optString("pay_msg");
  2998. String type = json.optString("type");
  2999. Map<String,Object> result=Maps.newHashMap();
  3000. OrderFormDto order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3001. //余额支付信息
  3002. Payment balance_payment=paymentService.selectByPrimaryKey(1L);
  3003. order.setPayment_id(balance_payment.getId());
  3004. order.setPayment_mark(balance_payment.getMark());
  3005. order.setPayment_name(balance_payment.getName());
  3006. //扩展信息表
  3007. SysConfigExtendDto sysConfigExtendDto=sysconrigExtendFeignClient.getSysConfigExtend();
  3008. UserDto user = SecurityUserHolder.getCurrentUser(request);
  3009. user=userFeignClient.selectByPrimaryKey(user.getId());
  3010. Map<Boolean, Object> map_verify = this.orderFormToolsFeignClient.orderForm_verify( order, user.getId());
  3011. Iterator iterator = map_verify.keySet().iterator();
  3012. while (iterator.hasNext()) {
  3013. Boolean verify_result = (Boolean) iterator.next();
  3014. if (!verify_result.booleanValue()) {
  3015. return ResponseCode.buildFailMap("", map_verify.get(verify_result));
  3016. }
  3017. }
  3018. double order_total_price = this.orderFormToolsFeignClient.query_order_pay_price(order_id);
  3019. if (CommUtil.null2Double(user.getAvailableBalance()) >= order_total_price) {
  3020. boolean ret = this.handleOrderFormFeignClient.payByBalance(order,CommUtil.getURL(request), pay_msg);
  3021. if(ret){
  3022. //调用拼一拼更新拼团状态服务
  3023. if(null !=sysConfigExtendDto && sysConfigExtendDto.isPin_open() && order.getOrder_cat()==3){
  3024. //调用拼一拼更新拼团状态服务
  3025. pinPayRecordFeignClient.updateStatusByOrderId(order.getId(),0);
  3026. }
  3027. if(null !=sysConfigExtendDto && sysConfigExtendDto.isDistribution_open() && order.getOrder_cat()==0){
  3028. //更新分销订单状态
  3029. order.setOrder_status(20);
  3030. distributionOrderFeignClient.updateOrderStatus(order);
  3031. }
  3032. result.put("op_title", "预付款支付成功");
  3033. }else{
  3034. result.put("op_title", "预付款支付成功");
  3035. }
  3036. } else {
  3037. result.put("op_title", "可用余额不足,支付失败");
  3038. }
  3039. return result;
  3040. }
  3041. /**
  3042. * 移动端订单预付款支付
  3043. * @param request
  3044. * @param response
  3045. * @param order_id
  3046. * @param pay_msg
  3047. * @param type
  3048. * @return
  3049. * @throws Exception
  3050. */
  3051. @RequestMapping({ "/rushorder_pay_balance" })
  3052. public Map<String,Object> rushorder_pay_balance(HttpServletRequest request,
  3053. HttpServletResponse response, @RequestBody JSONObject json) {
  3054. String id = json.optString("id");
  3055. String pay_password = json.optString("pay_password");
  3056. UserDto user = SecurityUserHolder.getCurrentUser(request);
  3057. // 用户密码是否匹配
  3058. if (!StringUtils.equals(Md5Encrypt.md5(pay_password), user.getPassword())) {
  3059. return ResponseCode.buildFailMap("支付密码错误", null);
  3060. }
  3061. Map<String, Object> result = Maps.newHashMap();
  3062. RushOrderformDto rushorder = rushOrderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3063. if(rushorder==null||rushorder.getOrder_status()!=5){
  3064. return ResponseCode.buildFailMap("订单数据错误", null);
  3065. }
  3066. user = userFeignClient.selectByPrimaryKey(user.getId());
  3067. if (CommUtil.null2Double(user.getAvailableBalance()) >= CommUtil.null2Double(rushorder.getBond_money())) {
  3068. // 余额
  3069. // 买家减去余额
  3070. user.setAvailableBalance(
  3071. BigDecimal.valueOf(CommUtil.subtract(user.getAvailableBalance(), rushorder.getBond_money())));
  3072. userFeignClient.updateById(user);
  3073. PredepositLogDto log = new PredepositLogDto();
  3074. log.setAddTime(new Date());
  3075. //log.setPd_log_user(buyer);
  3076. log.setPd_log_user_id(user.getId());
  3077. log.setPd_op_type("消费");
  3078. log.setPd_log_amount(BigDecimal.valueOf(-CommUtil.null2Double(rushorder.getBond_money())));
  3079. log.setPd_log_info(rushorder.getOrder_no() + "抢购订单支付上架费减少可用预存款");
  3080. log.setPd_type("可用预存款");
  3081. predepositLogFeignClient.saveEntity(log);
  3082. rushorder.setPay_mark("balance");
  3083. rushorder.setPayment_id(1L);
  3084. rushorder.setPayment_name("余额支付");
  3085. rushorder.setPay_time(new Date());
  3086. rushOrderFormFeignClient.completePayment(rushorder);
  3087. return ResponseCode.buildSuccessMap(result);//支付成功
  3088. } else {
  3089. return ResponseCode.buildFailMap("可用余额不足,支付失败", null);
  3090. }
  3091. }
  3092. @RequestMapping({ "/pay_code/generate" })
  3093. public void pay_code_generate(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject json)
  3094. throws IOException {
  3095. String url = json.optString("url");
  3096. String logoPath = "";
  3097. SysConfigDto sysconfig = sysConfigFeignClient.getSysConfig();
  3098. if (sysconfig.getQr_logo() != null) {
  3099. logoPath =
  3100. request.getSession().getServletContext().getRealPath("/") + sysconfig.getQr_logo().getPath()
  3101. + File.separator + sysconfig.getQr_logo().getName();
  3102. }
  3103. QRCodeUtil.encode(url, logoPath, response, true);
  3104. }
  3105. private HttpURLConnection creatConnection(String requestUrl) throws IOException {
  3106. URL url = new URL("https://api.mch.weixin.qq.com/pay/unifiedorder");
  3107. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  3108. conn.setConnectTimeout(30000);
  3109. conn.setReadTimeout(30000);
  3110. conn.setDoOutput(true);
  3111. conn.setDoInput(true);
  3112. conn.setUseCaches(false);
  3113. conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  3114. conn.setRequestMethod("POST");
  3115. conn.setRequestProperty("Content-Length", requestUrl.length() + "");
  3116. String encode = "utf-8";
  3117. OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), encode);
  3118. out.write(requestUrl.toString());
  3119. out.flush();
  3120. out.close();
  3121. return conn;
  3122. }
  3123. private String getInput(HttpURLConnection conn) throws IOException {
  3124. if (conn.getResponseCode() != 200) {
  3125. return null;
  3126. }
  3127. BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
  3128. String line = "";
  3129. StringBuffer strBuf = new StringBuffer();
  3130. while ((line = in.readLine()) != null) {
  3131. strBuf.append(line).append("\n");
  3132. }
  3133. in.close();
  3134. return strBuf.toString().trim();
  3135. }
  3136. public Map doXMLParse(String strxml) throws JDOMException, IOException {
  3137. strxml = strxml.replaceFirst("encoding=\".*\"", "encoding=\"UTF-8\"");
  3138. if ((strxml == null) || ("".equals(strxml))) {
  3139. return null;
  3140. }
  3141. Map m = Maps.newHashMap();
  3142. InputStream in = new ByteArrayInputStream(strxml.getBytes("UTF-8"));
  3143. SAXBuilder builder = new SAXBuilder();
  3144. Document doc = builder.build(in);
  3145. Element root = doc.getRootElement();
  3146. List list = root.getChildren();
  3147. Iterator it = list.iterator();
  3148. while (it.hasNext()) {
  3149. Element e = (Element) it.next();
  3150. String k = e.getName();
  3151. String v = "";
  3152. List children = e.getChildren();
  3153. if (children.isEmpty()) {
  3154. v = e.getTextNormalize();
  3155. } else {
  3156. v = getChildrenText(children);
  3157. }
  3158. m.put(k, v);
  3159. }
  3160. in.close();
  3161. return m;
  3162. }
  3163. public String getChildrenText(List children) {
  3164. StringBuffer sb = new StringBuffer();
  3165. if (!children.isEmpty()) {
  3166. Iterator it = children.iterator();
  3167. while (it.hasNext()) {
  3168. Element e = (Element) it.next();
  3169. String name = e.getName();
  3170. String value = e.getTextNormalize();
  3171. List list = e.getChildren();
  3172. sb.append("<" + name + ">");
  3173. if (!list.isEmpty()) {
  3174. sb.append(getChildrenText(list));
  3175. }
  3176. sb.append(value);
  3177. sb.append("</" + name + ">");
  3178. }
  3179. }
  3180. return sb.toString();
  3181. }
  3182. /**
  3183. * 微信回调
  3184. *
  3185. * @param request
  3186. * @param response
  3187. * @throws Exception
  3188. */
  3189. @RequestMapping(value = "/weixin_returntest2636dd", method = RequestMethod.POST)
  3190. public void weixin_returntest2636dd(HttpServletRequest request, HttpServletResponse response,@RequestBody JSONObject json) throws Exception {
  3191. String type = json.optString("type");
  3192. String pay_type = json.optString("pay_type");
  3193. String order_id = json.optString("order_id");
  3194. //扩展信息表
  3195. if (true) {
  3196. if (true) {
  3197. //支付方式 因为微信支付方式是"wx_miniprogram" 形式故pay_type为attachs[4]+"_"+attachs[5]
  3198. OrderFormDto main_order = null;
  3199. PredepositDto obj = null;
  3200. GoldRecord gold = null;
  3201. IntegralGoodsOrderDto ig_order = null;
  3202. CloudPurchaseOrderDto cp_order = null;
  3203. List<Payment> payments = Lists.newArrayList();
  3204. Map<String, Object> params = Maps.newHashMap();
  3205. params.put("mark",pay_type);
  3206. payments = this.paymentService.queryPageList(params);
  3207. Payment payment = null;
  3208. if (payments.size() > 0) {
  3209. payment = (Payment) payments.get(0);
  3210. }
  3211. if (("goods_first".equals(type)) || ("group_first".equals(type))) {
  3212. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3213. if (true) {
  3214. main_order.setPayment_mark(payment.getMark());
  3215. main_order.setPayment_name(payment.getName());
  3216. boolean flag = false;
  3217. //查询修改相关子订单
  3218. main_order.setOrder_first(0);
  3219. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  3220. if (flag) {
  3221. main_order.setOrder_status(20);
  3222. //分销收益
  3223. try{
  3224. disAgentProfit(main_order);
  3225. sendOrderMessage(main_order);
  3226. if(main_order.getChild_order_detail() != null){
  3227. List<Map> datalist = com.alibaba.fastjson.JSONObject.parseArray(main_order.getChild_order_detail(), Map.class);
  3228. for (Map map : datalist) {
  3229. Integer order_id1 = (Integer) map.get("order_id");
  3230. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(order_id1.longValue());
  3231. if(order != null){
  3232. disAgentProfit(order);
  3233. sendOrderMessage(order);
  3234. }
  3235. }
  3236. }
  3237. }catch (Exception e) {
  3238. logger.error("PayController >> weixin_returntest2636dd(distribution) >> Exception:"+ e.getMessage());
  3239. }
  3240. //更新库存
  3241. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  3242. //该订单存在直播商品
  3243. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  3244. liveOrderFeignClient.updateLiveOrder(main_order);
  3245. }
  3246. //如果订单是增值服务,修改用户 审核状态
  3247. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  3248. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  3249. }
  3250. //调用拼一拼更新拼团状态服务
  3251. if(true && main_order.getOrder_cat()==3){
  3252. //调用拼一拼更新拼团状态服务
  3253. orderFormToolsFeignClient.updateStatusByOrderId(main_order.getId(),0);
  3254. }
  3255. //拓展配置中分销为开启
  3256. if(true && main_order.getOrder_cat()==0){
  3257. OrderFormDto updateorder=main_order;
  3258. //更新分销订单状态
  3259. updateorder.setOrder_status(20);
  3260. distributionOrderFeignClient.updateOrderStatus(updateorder);
  3261. }
  3262. }
  3263. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  3264. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  3265. }
  3266. }
  3267. if (("goods".equals(type)) || ("group".equals(type))) {
  3268. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3269. if (true) {
  3270. main_order.setPayment_mark(payment.getMark());
  3271. main_order.setPayment_name(payment.getName());
  3272. boolean flag = false;
  3273. //不查询相关子订单
  3274. main_order.setOrder_first(1);
  3275. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  3276. if (flag) {
  3277. main_order.setOrder_status(20);
  3278. //分销收益
  3279. try{
  3280. disAgentProfit(main_order);
  3281. sendOrderMessage(main_order);
  3282. }catch (Exception e) {
  3283. logger.error("PayController >> weixin_returntest2636dd(distribution) >> Exception:"+ e.getMessage());
  3284. }
  3285. //更新库存
  3286. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  3287. //该订单存在直播商品
  3288. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  3289. liveOrderFeignClient.updateLiveOrder(main_order);
  3290. }
  3291. //如果订单是增值服务,修改用户 审核状态
  3292. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  3293. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  3294. }
  3295. }
  3296. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  3297. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  3298. }
  3299. }
  3300. if ("integral".equals(type)) {
  3301. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3302. if ((ig_order != null) && (ig_order.getIgo_status() < 20)
  3303. && (true)) {
  3304. ig_order.setIgo_status(20);
  3305. ig_order.setIgo_pay_time(new Date());
  3306. ig_order.setIgo_payment(payment.getMark());
  3307. this.integralGoodsOrderFeignClient.updateById(ig_order);
  3308. List<Map> ig_maps = this.orderFormToolsFeignClient
  3309. .query_integral_goodsinfo(ig_order.getGoods_info());
  3310. for (Map map : ig_maps) {
  3311. IntegralGoodsDto goods = this.integralGoodsFeignClient
  3312. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  3313. goods.setIg_goods_count(
  3314. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  3315. goods.setIg_exchange_count(
  3316. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  3317. this.integralGoodsFeignClient.updateById(goods);
  3318. }
  3319. }
  3320. }
  3321. if ("cash".equals(type)) {
  3322. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3323. if ((obj != null) && (obj.getPd_pay_status() != 2) && (true)) {
  3324. obj.setPd_payment(payment.getMark());
  3325. obj.setPd_status(1);
  3326. obj.setPd_pay_status(2);
  3327. this.predepositFeignClient.updateById(obj);
  3328. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  3329. user.setAvailableBalance(
  3330. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  3331. this.userFeignClient.updateById(user);
  3332. PredepositLogDto log = new PredepositLogDto();
  3333. log.setAddTime(new Date());
  3334. log.setPd_log_amount(obj.getPd_amount());
  3335. log.setPd_log_user(obj.getPd_user());
  3336. log.setPd_op_type("充值");
  3337. log.setPd_type("可用预存款");
  3338. log.setPd_log_info(payment.getName());
  3339. this.predepositLogFeignClient.saveEntity(log);
  3340. }
  3341. }
  3342. if ("gold".equals(type)) {
  3343. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3344. if ((gold != null) && (gold.getGold_pay_status() != 2) && (true)) {
  3345. gold.setGold_status(1);
  3346. gold.setGold_pay_status(2);
  3347. gold.setGold_payment(payment.getMark());
  3348. this.goldRecordService.updateById(gold);
  3349. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  3350. user.setGold(user.getGold() + gold.getGold_count());
  3351. this.userFeignClient.updateById(user);
  3352. GoldLog log = new GoldLog();
  3353. log.setAddTime(new Date());
  3354. log.setGl_payment(gold.getGold_payment());
  3355. log.setGl_content(payment.getName());
  3356. log.setGl_money(gold.getGold_money());
  3357. log.setGl_count(gold.getGold_count());
  3358. log.setGl_type(0);
  3359. log.setGl_user(gold.getGold_user());
  3360. log.setGr(gold);
  3361. this.goldLogService.saveEntity(log);
  3362. }
  3363. }
  3364. if (type.equals("cloudpurchase")) {
  3365. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3366. if (cp_order.getStatus() < 5) {
  3367. cp_order.setStatus(5);
  3368. cp_order.setPayTime(new Date());
  3369. cp_order.setPayment(payment.getMark());
  3370. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  3371. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  3372. }
  3373. }
  3374. if (type.equals("platformpay")) {
  3375. PlatformPay pf = this.platformPayService.selectByPrimaryKey(CommUtil.null2Long(order_id));
  3376. if (pf.getPay_status() == 0 && true) {
  3377. pf.setPay_status(1);
  3378. pf.setUpdate_date(new Date());
  3379. pf.setPay_type(payment.getMark());
  3380. this.platformPayService.updateById(pf);
  3381. PlatformPayFlow platformpayflow = new PlatformPayFlow();
  3382. platformpayflow.setPlatform_pay_id(pf.getId());
  3383. platformpayflow.setInfo("编号["+pf.getPay_no()+"]店铺保证金,支付成功");
  3384. platformpayflow.setCreate_date(new Date());
  3385. this.platformPayFlowService.saveEntity(platformpayflow);
  3386. UserDto user = userFeignClient.selectByPrimaryKey(pf.getUser_id());
  3387. StoreDto store = this.storeFeignClient.selectByPrimaryKey(user.getStore_id());
  3388. store.setDeposit(pf.getAmount());
  3389. this.storeFeignClient.updateById(store);
  3390. }
  3391. }
  3392. PrintWriter write = response.getWriter();
  3393. write.print(
  3394. "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>");
  3395. } else {
  3396. PrintWriter write = response.getWriter();
  3397. write.print(
  3398. "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>");
  3399. }
  3400. } else {
  3401. PrintWriter write = response.getWriter();
  3402. write.print(
  3403. "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>");
  3404. }
  3405. }
  3406. /**
  3407. * 移动端订单支付
  3408. * @param request
  3409. * @param response
  3410. * @param payType
  3411. * @param order_id
  3412. * @param order_type
  3413. * @param pay_password
  3414. * @return
  3415. * @throws Exception
  3416. */
  3417. @RequestMapping({ "/order_unifiedorder" })
  3418. public Object order_unifiedorder(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject json) throws Exception {
  3419. Long id = json.optLong("id");
  3420. String pay_type =json.optString("pay_type");
  3421. String order_type =json.optString("order_type");
  3422. Map<String,Object> resultMap=new HashMap<String,Object>();
  3423. //TODO
  3424. try{
  3425. //检查支付方式
  3426. if(pay_type.equals("wx_app")){
  3427. return this.weixin_unifiedorder(request, response,pay_type, id,
  3428. order_type);
  3429. }else if(pay_type.equals("alipay_app")){
  3430. return alipayService.app_alipay_unifiedorder(request, response,pay_type, id,
  3431. order_type);
  3432. }else{
  3433. resultMap.put("60001", "支付方式错误");
  3434. }
  3435. }catch(Exception e){
  3436. logger.error(e.toString());
  3437. }
  3438. return resultMap;
  3439. }
  3440. /**
  3441. * 移动端移动端预下单
  3442. * @param request
  3443. * @param response
  3444. * @param payType
  3445. * @param order_id 订单id
  3446. * @param type 订单类型
  3447. * @return
  3448. * @throws Exception
  3449. */
  3450. private Map<String,Object> weixin_unifiedorder(HttpServletRequest request,
  3451. HttpServletResponse response,String pay_type,Long id,
  3452. String order_type) throws Exception {
  3453. Map<String, Object> resultMap = new HashMap<String, Object>();
  3454. RequestHandler reqHandler = new RequestHandler(request, response);
  3455. List<Payment> payments = Lists.newArrayList();
  3456. Map<String, Object> params = Maps.newHashMap();
  3457. // TODO
  3458. //pay_type = "wx_app";
  3459. params.put("mark", pay_type);
  3460. payments = this.paymentService.queryPageList(params);
  3461. Payment payment = null;
  3462. if (payments.size() > 0) {
  3463. payment = (Payment) payments.get(0);
  3464. }
  3465. String body = "";
  3466. String attach = "";
  3467. String out_trade_no = "";
  3468. double total_fee = 0.0D;
  3469. boolean submit = true;
  3470. OrderFormDto of = null;
  3471. PredepositDto pd = null;
  3472. GoldRecord gold = null;
  3473. PlatformPay platformpay=null;
  3474. IntegralGoodsOrderDto ig_order = null;
  3475. CloudPurchaseOrderDto cp_order = null;
  3476. UserDto user=null;
  3477. if ((order_type.equals("goods")) || (order_type.equals("group"))) {
  3478. of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3479. if (of.getOrder_status() >= 20) {
  3480. submit = false;
  3481. } else {
  3482. body = of.getOrder_id();
  3483. attach = of.getId() + "_" + of.getOrder_id() + "_" + of.getUser_id() + "_" + order_type + "_"
  3484. + pay_type;
  3485. out_trade_no = of.getOrder_id();
  3486. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  3487. resultMap.put("obj", of);
  3488. }
  3489. }//第一次付款, 带上子订单信息
  3490. if ((order_type.equals("goodsfirst")) || (order_type.equals("groupfirst"))) {
  3491. of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3492. if (of.getOrder_status() >= 20) {
  3493. submit = false;
  3494. } else {
  3495. body = of.getOrder_id();
  3496. attach = of.getId() + "_" + of.getOrder_id() + "_" + of.getUser_id() + "_" + order_type + "_"
  3497. + pay_type;
  3498. out_trade_no = of.getOrder_id();
  3499. //第一次付款取子订单总价格
  3500. total_fee = Double
  3501. .valueOf(orderFormToolsFeignClient.query_order_pay_price(CommUtil.null2String(of.getId())))* 100.0D;
  3502. resultMap.put("obj", of);
  3503. }
  3504. }
  3505. if (order_type.equals("cash")) {
  3506. pd = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3507. if (pd.getPd_pay_status() >= 2) {
  3508. submit = false;
  3509. } else {
  3510. body = pd.getPd_sn();
  3511. attach = pd.getId() + "_" + pd.getPd_sn() + "_" + pd.getPd_user().getId() + "_" + order_type + "_"
  3512. + pay_type;
  3513. out_trade_no = pd.getPd_sn();
  3514. total_fee = Double.valueOf(pd.getPd_amount().toString()).doubleValue() * 100.0D;
  3515. resultMap.put("obj", pd);
  3516. }
  3517. }
  3518. if (order_type.equals("gold")) {
  3519. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(id));
  3520. if (gold.getGold_pay_status() >= 2) {
  3521. submit = false;
  3522. } else {
  3523. body = gold.getGold_sn();
  3524. attach = gold.getId() + "_" + gold.getGold_sn() + "_" + gold.getGold_user().getId() + "_" + order_type
  3525. + "_" + pay_type;
  3526. out_trade_no = gold.getGold_sn();
  3527. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  3528. resultMap.put("obj", gold);
  3529. }
  3530. }
  3531. if (order_type.equals("integral")) {
  3532. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3533. if (ig_order.getIgo_status() >= 20) {
  3534. submit = false;
  3535. } else {
  3536. body = ig_order.getIgo_order_sn();
  3537. attach = ig_order.getId() + "_" + ig_order.getIgo_order_sn() + "_" + ig_order.getIgo_user().getId()
  3538. + "_" + order_type + "_" + pay_type;
  3539. out_trade_no = ig_order.getIgo_order_sn();
  3540. total_fee = Double.valueOf(ig_order.getIgo_trans_fee().toString()).doubleValue() * 100.0D;
  3541. resultMap.put("obj", ig_order);
  3542. }
  3543. }
  3544. if (order_type.equals("cloudpurchase")) {
  3545. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3546. if (cp_order.getStatus() == 5) {
  3547. submit = false;
  3548. } else {
  3549. body = cp_order.getIgo_order_sn();
  3550. attach = cp_order.getId() + "_" + cp_order.getIgo_order_sn() + "_" + cp_order.getUser_id() + "_"
  3551. + order_type + "_" + pay_type;
  3552. out_trade_no = cp_order.getIgo_order_sn();
  3553. total_fee = Double.valueOf(cp_order.getPrice()).doubleValue() * 100.0D;
  3554. resultMap.put("obj", cp_order);
  3555. }
  3556. }
  3557. if (order_type.equals("platformpay")) { //保证金
  3558. platformpay = this.platformPayService.selectByPrimaryKey(CommUtil.null2Long(id));
  3559. if (platformpay.getPay_status() == 1) { //已支付
  3560. submit = false;
  3561. } else {
  3562. body = platformpay.getPay_no();
  3563. attach = platformpay.getId() + "_" + platformpay.getPay_no() + "_" + platformpay.getUser_id() + "_"
  3564. + order_type + "_" + pay_type;
  3565. out_trade_no = platformpay.getPay_no();
  3566. total_fee = platformpay.getAmount().doubleValue() * 100.0D;
  3567. resultMap.put("obj", platformpay);
  3568. user = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(platformpay.getUser_id()));
  3569. }
  3570. }
  3571. if ((submit) && (payment != null)) {
  3572. if (payment != null) {
  3573. String app_id = payment.getWx_appid();
  3574. String app_key = payment.getWx_paySignKey();
  3575. String partner = payment.getTenpay_partner();
  3576. String notify_url = payment.getNotify_url();
  3577. String noncestr = Sha1Util.getNonceStr();
  3578. String timestamp = Sha1Util.getTimeStamp();
  3579. String path = request.getContextPath();
  3580. String basePath = notify_url+ "/";
  3581. reqHandler.setParameter("appid", app_id);
  3582. reqHandler.setParameter("mch_id", partner);
  3583. reqHandler.setParameter("nonce_str", noncestr);
  3584. reqHandler.setParameter("body", body);
  3585. reqHandler.setParameter("attach", attach);
  3586. reqHandler.setParameter("out_trade_no", out_trade_no);
  3587. BigDecimal total_feeBig = new BigDecimal(total_fee);
  3588. reqHandler.setParameter("total_fee", total_feeBig.setScale(0, BigDecimal.ROUND_UP) + "");
  3589. reqHandler.setParameter("notify_url", basePath + "weixin_return");
  3590. reqHandler.setParameter("trade_type", "APP");
  3591. String requestUrl = reqHandler.reqToXml(app_key);
  3592. HttpURLConnection conn = creatConnection(requestUrl);
  3593. String result = getInput(conn);
  3594. Map<String, String> map = doXMLParse(result);
  3595. String return_code = ((String) map.get("return_code")).toString();
  3596. String prepay_id = "";
  3597. String code_url = "";
  3598. if ("SUCCESS".equals(return_code)) {
  3599. String result_code = ((String) map.get("result_code")).toString();
  3600. if ("SUCCESS".equals(result_code)) {
  3601. prepay_id = (String) map.get("prepay_id");
  3602. code_url = (String) map.get("code_url");
  3603. } else {
  3604. // 预下单异常信息显示
  3605. log.error(map.toString());
  3606. }
  3607. } else {
  3608. // 预下单异常信息显示
  3609. log.error(map.toString());
  3610. }
  3611. reqHandler.getAllParameters().clear();
  3612. reqHandler.setParameter("appid", app_id);
  3613. reqHandler.setParameter("partnerid", payment.getTenpay_partner());
  3614. reqHandler.setParameter("prepayid", prepay_id);
  3615. reqHandler.setParameter("package", "Sign=WXPay");
  3616. reqHandler.setParameter("noncestr", noncestr);
  3617. reqHandler.setParameter("timestamp", timestamp);
  3618. reqHandler.genSign(app_key);
  3619. resultMap.put("appid", app_id);
  3620. resultMap.put("partnerid", payment.getTenpay_partner());
  3621. resultMap.put("prepayid", prepay_id);
  3622. resultMap.put("package", "Sign=WXPay");
  3623. resultMap.put("noncestr", noncestr);
  3624. resultMap.put("timestamp", timestamp);
  3625. resultMap.put("sign", reqHandler.getParameter("sign"));
  3626. System.out.print("返回给前端---------------------------");
  3627. System.out.print(resultMap.toString());
  3628. System.out.print("返回给前端---------------------------");
  3629. reqHandler.getAllParameters().clear();
  3630. reqHandler.setParameter("appId", app_id);
  3631. reqHandler.setParameter("nonceStr", noncestr);
  3632. reqHandler.genSign(app_key);
  3633. String order_sign = reqHandler.getParameter("sign");
  3634. if ((order_type.equals("goods")) || (order_type.equals("group"))
  3635. ||(order_type.equals("goodsfirst")) || (order_type.equals("goodsfirst"))) {
  3636. of.setOrder_sign(order_sign);
  3637. this.orderFormFeignClient.updateById(of);
  3638. }
  3639. if (order_type.equals("cash")) {
  3640. pd.setOrder_sign(order_sign);
  3641. this.predepositFeignClient.updateById(pd);
  3642. }
  3643. if (order_type.equals("gold")) {
  3644. gold.setOrder_sign(order_sign);
  3645. this.goldRecordService.updateById(gold);
  3646. }
  3647. if (order_type.equals("integral")) {
  3648. ig_order.setOrder_sign(order_sign);
  3649. this.integralGoodsOrderFeignClient.updateById(ig_order);
  3650. }
  3651. if (order_type.equals("cloudpurchase")) {
  3652. cp_order.setOrder_sign(order_sign);
  3653. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  3654. }
  3655. if (order_type.equals("platformpay")) {
  3656. platformpay.setTrade_no(order_sign);
  3657. platformpay.setSign(order_sign);
  3658. this.platformPayService.updateById(platformpay);
  3659. }
  3660. } else {
  3661. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  3662. }
  3663. } else {
  3664. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  3665. }
  3666. return ResponseCode.buildSuccessMap(resultMap);
  3667. }
  3668. /**
  3669. * 微信app支付回调
  3670. * @param request
  3671. * @param response
  3672. * @throws Exception
  3673. */
  3674. @RequestMapping({ "/weixin_return_app" })
  3675. public void weixin_return_app(HttpServletRequest request,
  3676. HttpServletResponse response) throws Exception {
  3677. response.setContentType("text/plain");
  3678. response.setHeader("Cache-Control", "no-cache");
  3679. response.setCharacterEncoding("UTF-8");
  3680. BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
  3681. String line = "";
  3682. StringBuffer strBuf = new StringBuffer();
  3683. while ((line = in.readLine()) != null) {
  3684. strBuf.append(line).append("\n");
  3685. }
  3686. in.close();
  3687. Map<String, String> xml = doXMLParse(strBuf.toString().trim());
  3688. //扩展信息表
  3689. SysConfigExtendDto sysConfigExtendDto=sysconrigExtendFeignClient.getSysConfigExtend();
  3690. String appid = ((String) xml.get("appid")).toString();
  3691. if ("SUCCESS".equals(((String) xml.get("return_code")).toString())) {
  3692. if ("SUCCESS".equals(((String) xml.get("result_code")).toString())) {
  3693. String total_fee = (String) xml.get("total_fee");
  3694. String[] attachs = ((String) xml.get("attach")).split("_");
  3695. String type = attachs[3];
  3696. //支付方式 因为微信支付方式是"wx_miniprogram" 形式故pay_type为attachs[4]+"_"+attachs[5]
  3697. String pay_type = attachs[4]+"_"+attachs[5];
  3698. System.out.println("返回的pay_type:"+pay_type);
  3699. OrderFormDto main_order = null;
  3700. PredepositDto obj = null;
  3701. GoldRecord gold = null;
  3702. IntegralGoodsOrderDto ig_order = null;
  3703. CloudPurchaseOrderDto cp_order = null;
  3704. List<Payment> payments = Lists.newArrayList();
  3705. Map<String, Object> params = Maps.newHashMap();
  3706. params.put("mark",pay_type);
  3707. payments = this.paymentService.queryPageList(params);
  3708. Payment payment = null;
  3709. if (payments.size() > 0) {
  3710. payment = (Payment) payments.get(0);
  3711. }
  3712. RequestHandler reqHandler = new RequestHandler(request, response);
  3713. reqHandler.setParameter("appId", payment.getWx_appid());
  3714. reqHandler.setParameter("nonceStr", ((String) xml.get("nonce_str")).toString());
  3715. reqHandler.genSign(payment.getWx_paySignKey());
  3716. String sign = reqHandler.getParameter("sign");
  3717. if (("goodsfirst".equals(type)) || ("groupfirst".equals(type))) {
  3718. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  3719. if (sign.equals(main_order.getOrder_sign())) {
  3720. main_order.setPayTime(new Date());
  3721. main_order.setPayment_mark(payment.getMark());
  3722. main_order.setPayment_name(payment.getName());
  3723. boolean flag = false;
  3724. //查询修改相关子订单
  3725. main_order.setOrder_first(0);
  3726. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  3727. if (flag) {
  3728. main_order.setOrder_status(20);
  3729. //分销收益
  3730. try{
  3731. disAgentProfit(main_order);
  3732. sendOrderMessage(main_order);
  3733. if(main_order.getChild_order_detail() != null){
  3734. List<Map> datalist = com.alibaba.fastjson.JSONObject.parseArray(main_order.getChild_order_detail(), Map.class);
  3735. for (Map map : datalist) {
  3736. Integer order_id = (Integer) map.get("order_id");
  3737. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(order_id.longValue());
  3738. if(order != null){
  3739. disAgentProfit(order);
  3740. sendOrderMessage(order);
  3741. }
  3742. }
  3743. }
  3744. }catch (Exception e) {
  3745. logger.error("PayController >> weixin_return(distribution&agentProfit【goods_first】) >> Exception:"+ e.getMessage());
  3746. }
  3747. //更新库存
  3748. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  3749. //该订单存在直播商品
  3750. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  3751. liveOrderFeignClient.updateLiveOrder(main_order);
  3752. }
  3753. //如果订单是增值服务,修改用户 审核状态
  3754. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  3755. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  3756. }
  3757. try{
  3758. sendTxMessage(main_order);
  3759. if(main_order.getChild_order_detail() != null){
  3760. List<Map> datalist = com.alibaba.fastjson.JSONObject.parseArray(main_order.getChild_order_detail(), Map.class);
  3761. for (Map map : datalist) {
  3762. Integer order_id = (Integer) map.get("order_id");
  3763. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(order_id.longValue());
  3764. if(order != null){
  3765. sendTxMessage(main_order);
  3766. }
  3767. }
  3768. }
  3769. }catch (Exception e) {
  3770. logger.error("PayController >> weixin_return(sendTxMessage【goods_first】) >> Exception:"+ e.getMessage());
  3771. }
  3772. //发站内消息
  3773. /*//拓展配置中分销为开启
  3774. if(null !=sysConfigExtendDto && sysConfigExtendDto.isDistribution_open() && main_order.getOrder_cat()==0){
  3775. OrderFormDto updateorder=main_order;
  3776. //更新分销订单状态
  3777. updateorder.setOrder_status(20);
  3778. distributionOrderFeignClient.updateOrderStatus(updateorder);
  3779. }*/
  3780. }
  3781. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  3782. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  3783. }
  3784. }
  3785. if (("goods".equals(type)) || ("group".equals(type))) {
  3786. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  3787. if (sign.equals(main_order.getOrder_sign())) {
  3788. main_order.setPayment_mark(payment.getMark());
  3789. main_order.setPayment_name(payment.getName());
  3790. boolean flag = false;
  3791. //不查询相关子订单
  3792. main_order.setOrder_first(1);
  3793. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  3794. if (flag) {
  3795. main_order.setOrder_status(20);
  3796. try{
  3797. disAgentProfit(main_order);
  3798. sendOrderMessage(main_order);
  3799. }catch (Exception e) {
  3800. logger.error("PayController >> weixin_return(distribution&agentProfit【goods】) >> Exception:"+ e.getMessage());
  3801. }
  3802. try{
  3803. sendTxMessage(main_order);
  3804. }catch (Exception e) {
  3805. logger.error("PayController >> weixin_return(sendTxMessage【goods】) >> Exception:"+ e.getMessage());
  3806. }
  3807. //更新库存
  3808. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  3809. //该订单存在直播商品
  3810. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  3811. liveOrderFeignClient.updateLiveOrder(main_order);
  3812. }
  3813. //如果订单是增值服务,修改用户 审核状态
  3814. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  3815. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  3816. }
  3817. }
  3818. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  3819. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  3820. }
  3821. }
  3822. if ("integral".equals(type)) {
  3823. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  3824. if ((ig_order != null) && (ig_order.getIgo_status() < 20)
  3825. && (sign.equals(ig_order.getOrder_sign()))) {
  3826. ig_order.setIgo_status(20);
  3827. ig_order.setIgo_pay_time(new Date());
  3828. ig_order.setIgo_payment(payment.getMark());
  3829. this.integralGoodsOrderFeignClient.updateById(ig_order);
  3830. List<Map> ig_maps = this.orderFormToolsFeignClient
  3831. .query_integral_goodsinfo(ig_order.getGoods_info());
  3832. for (Map map : ig_maps) {
  3833. IntegralGoodsDto goods = this.integralGoodsFeignClient
  3834. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  3835. goods.setIg_goods_count(
  3836. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  3837. goods.setIg_exchange_count(
  3838. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  3839. this.integralGoodsFeignClient.updateById(goods);
  3840. }
  3841. }
  3842. }
  3843. if ("cash".equals(type)) {
  3844. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  3845. if ((obj != null) && (obj.getPd_pay_status() != 2) && (sign.equals(obj.getOrder_sign()))) {
  3846. obj.setPd_payment(payment.getMark());
  3847. obj.setPd_status(1);
  3848. obj.setPd_pay_status(2);
  3849. this.predepositFeignClient.updateById(obj);
  3850. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  3851. user.setAvailableBalance(
  3852. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  3853. this.userFeignClient.updateById(user);
  3854. PredepositLogDto log = new PredepositLogDto();
  3855. log.setAddTime(new Date());
  3856. log.setPd_log_amount(obj.getPd_amount());
  3857. log.setPd_log_user(obj.getPd_user());
  3858. log.setPd_op_type("充值");
  3859. log.setPd_type("可用预存款");
  3860. log.setPd_log_info(payment.getName());
  3861. this.predepositLogFeignClient.saveEntity(log);
  3862. }
  3863. }
  3864. if ("gold".equals(type)) {
  3865. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  3866. if ((gold != null) && (gold.getGold_pay_status() != 2) && (sign.equals(gold.getOrder_sign()))) {
  3867. gold.setGold_status(1);
  3868. gold.setGold_pay_status(2);
  3869. gold.setGold_payment(payment.getMark());
  3870. this.goldRecordService.updateById(gold);
  3871. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  3872. user.setGold(user.getGold() + gold.getGold_count());
  3873. this.userFeignClient.updateById(user);
  3874. GoldLog log = new GoldLog();
  3875. log.setAddTime(new Date());
  3876. log.setGl_payment(gold.getGold_payment());
  3877. log.setGl_content(payment.getName());
  3878. log.setGl_money(gold.getGold_money());
  3879. log.setGl_count(gold.getGold_count());
  3880. log.setGl_type(0);
  3881. log.setGl_user(gold.getGold_user());
  3882. log.setGr(gold);
  3883. this.goldLogService.saveEntity(log);
  3884. }
  3885. }
  3886. if (type.equals("cloudpurchase")) {
  3887. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  3888. if (cp_order.getStatus() < 5) {
  3889. cp_order.setStatus(5);
  3890. cp_order.setPayTime(new Date());
  3891. cp_order.setPayment(payment.getMark());
  3892. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  3893. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  3894. }
  3895. }
  3896. if (type.equals("platformpay")) {
  3897. PlatformPay pf = this.platformPayService.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  3898. if (pf.getPay_status() == 0 && StringUtils.equals(sign, pf.getSign())) {
  3899. pf.setPay_status(1);
  3900. pf.setUpdate_date(new Date());
  3901. pf.setPay_type(payment.getMark());
  3902. this.platformPayService.updateById(pf);
  3903. PlatformPayFlow platformpayflow = new PlatformPayFlow();
  3904. platformpayflow.setPlatform_pay_id(pf.getId());
  3905. platformpayflow.setInfo("编号["+pf.getPay_no()+"]店铺保证金,支付成功");
  3906. platformpayflow.setCreate_date(new Date());
  3907. this.platformPayFlowService.saveEntity(platformpayflow);
  3908. UserDto user = userFeignClient.selectByPrimaryKey(pf.getUser_id());
  3909. StoreDto store = this.storeFeignClient.selectByPrimaryKey(user.getStore_id());
  3910. store.setDeposit(pf.getAmount());
  3911. this.storeFeignClient.updateById(store);
  3912. }
  3913. }
  3914. PrintWriter write = response.getWriter();
  3915. write.print(
  3916. "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>");
  3917. } else {
  3918. PrintWriter write = response.getWriter();
  3919. write.print(
  3920. "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>");
  3921. }
  3922. } else {
  3923. PrintWriter write = response.getWriter();
  3924. write.print(
  3925. "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>");
  3926. }
  3927. }
  3928. public Map<String, Object> wxh5_pay(HttpServletRequest request, HttpServletResponse response, Long id,
  3929. String pay_type, String order_type) throws Exception {
  3930. Map<String, Object> resultMap = new HashMap<String, Object>();
  3931. RequestHandler reqHandler = new RequestHandler(request, response);
  3932. List<Payment> payments = Lists.newArrayList();
  3933. Map<String, Object> params = Maps.newHashMap();
  3934. //TODO
  3935. pay_type="wx_pay";
  3936. params.put("mark", pay_type);
  3937. payments = this.paymentService.queryPageList(params);
  3938. Payment payment = null;
  3939. if (payments.size() > 0) {
  3940. payment = (Payment) payments.get(0);
  3941. }
  3942. String body = "";
  3943. String attach = "";
  3944. String out_trade_no = "";
  3945. double total_fee = 0.0D;
  3946. boolean submit = true;
  3947. OrderFormDto of = null;
  3948. PredepositDto pd = null;
  3949. GoldRecord gold = null;
  3950. IntegralGoodsOrderDto ig_order = null;
  3951. CloudPurchaseOrderDto cp_order = null;
  3952. if ((order_type.equals("goods")) || (order_type.equals("group"))) {
  3953. of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3954. if (of.getOrder_status() >= 20) {
  3955. submit = false;
  3956. } else {
  3957. body = of.getOrder_id();
  3958. attach = of.getId() + "_" + of.getOrder_id() + "_" + of.getUser_id() + "_" + order_type +"_"+pay_type;
  3959. out_trade_no = of.getOrder_id();
  3960. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  3961. resultMap.put("obj", of);
  3962. }
  3963. }
  3964. if (order_type.equals("cash")) {
  3965. pd = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3966. if (pd.getPd_pay_status() >= 2) {
  3967. submit = false;
  3968. } else {
  3969. body = pd.getPd_sn();
  3970. attach = pd.getId() + "_" + pd.getPd_sn() + "_" + pd.getPd_user().getId() + "_" + order_type+"_"+pay_type;
  3971. out_trade_no = pd.getPd_sn();
  3972. total_fee = Double.valueOf(pd.getPd_amount().toString()).doubleValue() * 100.0D;
  3973. resultMap.put("obj", pd);
  3974. }
  3975. }
  3976. if (order_type.equals("gold")) {
  3977. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(id));
  3978. if (gold.getGold_pay_status() >= 2) {
  3979. submit = false;
  3980. } else {
  3981. body = gold.getGold_sn();
  3982. attach = gold.getId() + "_" + gold.getGold_sn() + "_" + gold.getGold_user().getId() + "_" + order_type+"_"+pay_type;
  3983. out_trade_no = gold.getGold_sn();
  3984. total_fee = Double.valueOf(of.getTotalPrice().toString()).doubleValue() * 100.0D;
  3985. resultMap.put("obj", gold);
  3986. }
  3987. }
  3988. if (order_type.equals("integral")) {
  3989. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  3990. if (ig_order.getIgo_status() >= 20) {
  3991. submit = false;
  3992. } else {
  3993. body = ig_order.getIgo_order_sn();
  3994. attach = ig_order.getId() + "_" + ig_order.getIgo_order_sn() + "_" + ig_order.getIgo_user().getId()
  3995. + "_" + order_type+"_"+pay_type;
  3996. out_trade_no = ig_order.getIgo_order_sn();
  3997. total_fee = Double.valueOf(ig_order.getIgo_trans_fee().toString()).doubleValue() * 100.0D;
  3998. resultMap.put("obj", ig_order);
  3999. }
  4000. }
  4001. if (order_type.equals("cloudpurchase")) {
  4002. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
  4003. if (cp_order.getStatus() == 5) {
  4004. submit = false;
  4005. } else {
  4006. body = cp_order.getIgo_order_sn();
  4007. attach = cp_order.getId() + "_" + cp_order.getIgo_order_sn() + "_" + cp_order.getUser_id() + "_"
  4008. + order_type+"_"+pay_type;
  4009. out_trade_no = cp_order.getIgo_order_sn();
  4010. total_fee = Double.valueOf(cp_order.getPrice()).doubleValue() * 100.0D;
  4011. resultMap.put("obj", cp_order);
  4012. }
  4013. }
  4014. if ((submit) && (payment != null)) {
  4015. if (payment != null) {
  4016. String app_id = payment.getWx_appid();
  4017. String app_key = payment.getWx_paySignKey();
  4018. String partner = payment.getTenpay_partner();
  4019. String notify_url = payment.getNotify_url();
  4020. String noncestr = Sha1Util.getNonceStr();
  4021. String timestamp = Sha1Util.getTimeStamp();
  4022. String path = request.getContextPath();
  4023. String basePath = notify_url + "/";
  4024. reqHandler.setParameter("appid", app_id);
  4025. reqHandler.setParameter("mch_id", partner);
  4026. reqHandler.setParameter("nonce_str", noncestr);
  4027. /*reqHandler.setParameter("device_info", "wechat_mini_program");*/
  4028. reqHandler.setParameter("body", body);
  4029. reqHandler.setParameter("attach", attach);
  4030. reqHandler.setParameter("out_trade_no", out_trade_no);
  4031. BigDecimal total_feeBig = new BigDecimal(total_fee);
  4032. reqHandler.setParameter("total_fee", total_feeBig.setScale(0, BigDecimal.ROUND_UP)+"");
  4033. reqHandler.setParameter("spbill_create_ip", CommUtil.getIpAddr(request));
  4034. reqHandler.setParameter("notify_url", basePath + "weixin_return");
  4035. reqHandler.setParameter("scene_info", "'h5_info':{'type':'Wap','wap_url':'http://haiwah5.minglisoft.cn/','wap_name': '海哇'}");
  4036. reqHandler.setParameter("trade_type", "MWEB");
  4037. // trade_type=JSAPI时,必须传入openid
  4038. UserDto user = userFeignClient.selectByPrimaryKey(CommUtil.null2Long(of.getUser_id()));
  4039. reqHandler.setParameter("openid", user.getOpenId());
  4040. String requestUrl = reqHandler.reqToXml(app_key);
  4041. HttpURLConnection conn = creatConnection(requestUrl);
  4042. String result = getInput(conn);
  4043. Map<String, String> map = doXMLParse(result);
  4044. String return_code = ((String) map.get("return_code")).toString();
  4045. String prepay_id = "";
  4046. String code_url = "";
  4047. if ("SUCCESS".equals(return_code)) {
  4048. String result_code = ((String) map.get("result_code")).toString();
  4049. if ("SUCCESS".equals(result_code)) {
  4050. prepay_id = (String) map.get("prepay_id");
  4051. code_url = (String) map.get("code_url");
  4052. } else {
  4053. // 预下单异常信息显示
  4054. log.error(map.toString());
  4055. }
  4056. } else {
  4057. // 预下单异常信息显示
  4058. log.error(map.toString());
  4059. }
  4060. reqHandler.getAllParameters().clear();
  4061. String newPackage = "prepay_id=" + prepay_id;
  4062. reqHandler.setParameter("appId", app_id);
  4063. reqHandler.setParameter("nonceStr", noncestr);
  4064. reqHandler.setParameter("package", newPackage);
  4065. reqHandler.setParameter("signType", "MD5");
  4066. reqHandler.setParameter("timeStamp", timestamp+"");
  4067. reqHandler.genSign(app_key);
  4068. String order_sign = reqHandler.getParameter("sign");
  4069. resultMap.put("app_id", app_id);
  4070. resultMap.put("timestamp", timestamp+"");
  4071. resultMap.put("noncestr", noncestr);
  4072. resultMap.put("packageValue", newPackage);
  4073. resultMap.put("sign", order_sign);
  4074. resultMap.put("code_url", code_url);
  4075. resultMap.put("signType", "MD5");
  4076. System.out.print("返回给前端---------------------------");
  4077. System.out.print(resultMap.toString());
  4078. System.out.print("返回给前端---------------------------");
  4079. reqHandler.getAllParameters().clear();
  4080. reqHandler.setParameter("appId", app_id);
  4081. reqHandler.setParameter("nonceStr", noncestr);
  4082. reqHandler.genSign(app_key);
  4083. order_sign=reqHandler.getParameter("sign");
  4084. if ((order_type.equals("goods")) || (order_type.equals("group"))) {
  4085. of.setOrder_sign(order_sign);
  4086. this.orderFormFeignClient.updateById(of);
  4087. }
  4088. if (order_type.equals("cash")) {
  4089. pd.setOrder_sign(order_sign);
  4090. this.predepositFeignClient.updateById(pd);
  4091. }
  4092. if (order_type.equals("gold")) {
  4093. gold.setOrder_sign(order_sign);
  4094. this.goldRecordService.updateById(gold);
  4095. }
  4096. if (order_type.equals("integral")) {
  4097. ig_order.setOrder_sign(order_sign);
  4098. this.integralGoodsOrderFeignClient.updateById(ig_order);
  4099. }
  4100. if (order_type.equals("cloudpurchase")) {
  4101. cp_order.setOrder_sign(order_sign);
  4102. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  4103. }
  4104. } else {
  4105. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  4106. }
  4107. } else {
  4108. return ResponseCode.buildCodeMap("20001", "支付方式错误!", null);
  4109. }
  4110. return ResponseCode.buildSuccessMap(resultMap) ;
  4111. }
  4112. @RequestMapping({ "/pay/ditu" })
  4113. public Map<String, Object> ditu(HttpServletRequest request, HttpServletResponse response,
  4114. @RequestBody JSONObject json) throws Exception {
  4115. List<Payment> payments = Lists.newArrayList();
  4116. Map<String, Object> params = Maps.newHashMap();
  4117. params.put("mark", "wx_pay");
  4118. payments = this.paymentService.queryPageList(params);
  4119. Payment payment = null;
  4120. if (payments.size() > 0) {
  4121. payment = (Payment) payments.get(0);
  4122. }
  4123. String app_id = payment.getWx_appid();
  4124. String app_key = payment.getWx_paySignKey();
  4125. String noncestr = Sha1Util.getNonceStr();
  4126. String timestamp = Sha1Util.getTimeStamp();
  4127. //String accessToken = accessTokenTools.getAccessTokenOld(app_id, payment.getWx_appSecret());
  4128. String accessToken = accessTokenTools.getAccessToken(app_id, payment.getWx_appSecret());
  4129. System.out.println("accessToken===="+accessToken);
  4130. Map<String, String> jsapiTicket = accessTokenTools.JsapiTicket(accessToken);
  4131. String str = "jsapi_ticket="+jsapiTicket.get("ticket")+"&noncestr="+noncestr+"&timestamp="+timestamp+"&url="+"http://haiwah5.minglisoft.cn/";
  4132. String signature = Sha1Util.getSha1(str);
  4133. //String signature = SHA1.SHA1(str);
  4134. Map<String, Object> resultMap = new HashMap<String, Object>();
  4135. resultMap.put("app_id", payment.getWx_appid());
  4136. resultMap.put("timestamp", timestamp + "");
  4137. resultMap.put("nonceStr", noncestr);
  4138. resultMap.put("jsapiTicket", jsapiTicket.get("ticket"));
  4139. resultMap.put("sign", signature);
  4140. return ResponseCode.buildSuccessMap(resultMap);
  4141. }
  4142. /**
  4143. * 支付宝app 支付成功 处理订单
  4144. * @param request
  4145. * @param payment 支付方式
  4146. * @param type 类型
  4147. * @param attachs 附加参数
  4148. */
  4149. private void afterNotifyOrderHandling_alipay(HttpServletRequest request,Payment payment,String type,String[] attachs ){
  4150. OrderFormDto main_order = null;
  4151. PredepositDto obj = null;
  4152. GoldRecord gold = null;
  4153. IntegralGoodsOrderDto ig_order = null;
  4154. CloudPurchaseOrderDto cp_order = null;
  4155. if (("goodsfirst".equals(type)) || ("groupfirst".equals(type))) {
  4156. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  4157. if(main_order==null||main_order.getOrder_status()!=10){
  4158. return;
  4159. }
  4160. main_order.setPayTime(new Date());
  4161. main_order.setPayment_mark(payment.getMark());
  4162. main_order.setPayment_name(payment.getName());
  4163. boolean flag = false;
  4164. //查询修改相关子订单
  4165. main_order.setOrder_first(0);
  4166. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  4167. if (flag) {
  4168. main_order.setOrder_status(20);
  4169. //分销收益
  4170. try{
  4171. disAgentProfit(main_order);
  4172. sendOrderMessage(main_order);
  4173. if(main_order.getChild_order_detail() != null){
  4174. List<Map> datalist = com.alibaba.fastjson.JSONObject.parseArray(main_order.getChild_order_detail(), Map.class);
  4175. for (Map map : datalist) {
  4176. Integer order_id = (Integer) map.get("order_id");
  4177. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(order_id.longValue());
  4178. if(order != null){
  4179. disAgentProfit(order);
  4180. sendOrderMessage(order);
  4181. }
  4182. }
  4183. }
  4184. }catch (Exception e) {
  4185. logger.error("PayController >> weixin_return(distribution&agentProfit【goods_first】) >> Exception:"+ e.getMessage());
  4186. }
  4187. //更新库存
  4188. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  4189. //该订单存在直播商品
  4190. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  4191. liveOrderFeignClient.updateLiveOrder(main_order);
  4192. }
  4193. //如果订单是增值服务,修改用户 审核状态
  4194. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  4195. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  4196. }
  4197. //如果订单是拉新用户订单 , 添加
  4198. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==5) {
  4199. main_order.setOrder_status(14);
  4200. orderFormFeignClient.updateById(main_order);
  4201. }else{
  4202. if(main_order.getCheck_in_time() != null){
  4203. sendHotelMessage(main_order);
  4204. }else if(main_order.getOrder_offline()==1){
  4205. //TODO 待修改 , 验证码消息
  4206. }else{
  4207. try{
  4208. sendTxMessage(main_order);
  4209. if(main_order.getChild_order_detail() != null){
  4210. List<Map> datalist = com.alibaba.fastjson.JSONObject.parseArray(main_order.getChild_order_detail(), Map.class);
  4211. for (Map map : datalist) {
  4212. Integer order_id = (Integer) map.get("order_id");
  4213. OrderFormDto order = orderFormFeignClient.selectByPrimaryKey(order_id.longValue());
  4214. if(order != null){
  4215. sendTxMessage(main_order);
  4216. }
  4217. }
  4218. }
  4219. }catch (Exception e) {
  4220. logger.error("PayController >> weixin_return(sendTxMessage【goods_first】) >> Exception:"+ e.getMessage());
  4221. }
  4222. }
  4223. }
  4224. //发站内消息
  4225. /*//拓展配置中分销为开启
  4226. if(null !=sysConfigExtendDto && sysConfigExtendDto.isDistribution_open() && main_order.getOrder_cat()==0){
  4227. OrderFormDto updateorder=main_order;
  4228. //更新分销订单状态
  4229. updateorder.setOrder_status(20);
  4230. distributionOrderFeignClient.updateOrderStatus(updateorder);
  4231. }*/
  4232. }
  4233. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  4234. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  4235. }
  4236. if (("goods".equals(type)) || ("group".equals(type))) {
  4237. main_order = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  4238. if(main_order==null||main_order.getOrder_status()!=10){
  4239. return;
  4240. }
  4241. main_order.setPayTime(new Date());
  4242. main_order.setPayment_mark(payment.getMark());
  4243. main_order.setPayment_name(payment.getName());
  4244. boolean flag = false;
  4245. //不查询相关子订单
  4246. main_order.setOrder_first(1);
  4247. flag = this.handleOrderFormFeignClient.payByOnline(main_order, "", CommUtil.getURL(request));
  4248. if (flag) {
  4249. main_order.setOrder_status(20);
  4250. try{
  4251. disAgentProfit(main_order);
  4252. sendOrderMessage(main_order);
  4253. }catch (Exception e) {
  4254. logger.error("PayController >> weixin_return(distribution&agentProfit【goods】) >> Exception:"+ e.getMessage());
  4255. }
  4256. if (main_order.getOrder_cat() != null && main_order.getOrder_cat() != 5) {
  4257. if (main_order.getCheck_in_time() != null) {
  4258. sendHotelMessage(main_order);
  4259. } else if(main_order.getOrder_offline()==1){
  4260. //TODO 待修改 , 验证码消息
  4261. }else {
  4262. try {
  4263. sendTxMessage(main_order);
  4264. } catch (Exception e) {
  4265. logger.error(
  4266. "PayController >> weixin_return(sendTxMessage【goods】) >> Exception:"
  4267. + e.getMessage());
  4268. }
  4269. }
  4270. }
  4271. //更新库存
  4272. this.orderFormToolsFeignClient.updateGoodsInventory(main_order);
  4273. //该订单存在直播商品
  4274. if (main_order.getLiveorder_type() != null && main_order.getLiveorder_type()==1) {
  4275. liveOrderFeignClient.updateLiveOrder(main_order);
  4276. }
  4277. //如果订单是增值服务,修改用户 审核状态
  4278. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==4) {
  4279. userFeignClient.updateLiveById(CommUtil.null2Long(main_order.getUser_id()));
  4280. }
  4281. //如果订单是拉新用户订单 , 添加
  4282. if (main_order.getOrder_cat() != null && main_order.getOrder_cat()==5) {
  4283. main_order.setOrder_status(14);
  4284. orderFormFeignClient.updateById(main_order);
  4285. }
  4286. }
  4287. this.orderFormToolsFeignClient.sendMsgWhenHandleOrder(CommUtil.getURL(request), main_order,
  4288. "tobuyer_online_pay_ok_notify", "toseller_online_pay_ok_notify");
  4289. }
  4290. if ("integral".equals(type)) {
  4291. ig_order = this.integralGoodsOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  4292. if (ig_order != null && ig_order.getIgo_status() < 20) {
  4293. ig_order.setIgo_status(20);
  4294. ig_order.setIgo_pay_time(new Date());
  4295. ig_order.setIgo_payment(payment.getMark());
  4296. this.integralGoodsOrderFeignClient.updateById(ig_order);
  4297. List<Map> ig_maps = this.orderFormToolsFeignClient
  4298. .query_integral_goodsinfo(ig_order.getGoods_info());
  4299. for (Map map : ig_maps) {
  4300. IntegralGoodsDto goods = this.integralGoodsFeignClient
  4301. .selectByPrimaryKey(CommUtil.null2Long(map.get("id")));
  4302. goods.setIg_goods_count(
  4303. goods.getIg_goods_count() - CommUtil.null2Int(map.get("ig_goods_count")));
  4304. goods.setIg_exchange_count(
  4305. goods.getIg_exchange_count() + CommUtil.null2Int(map.get("ig_goods_count")));
  4306. this.integralGoodsFeignClient.updateById(goods);
  4307. }
  4308. }
  4309. }
  4310. if ("cash".equals(type)) {
  4311. obj = this.predepositFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  4312. if (obj != null && obj.getPd_pay_status() != 2) {
  4313. obj.setPd_payment(payment.getMark());
  4314. obj.setPd_status(1);
  4315. obj.setPd_pay_status(2);
  4316. this.predepositFeignClient.updateById(obj);
  4317. UserDto user = this.userFeignClient.selectByPrimaryKey(obj.getPd_user().getId());
  4318. user.setAvailableBalance(
  4319. BigDecimal.valueOf(CommUtil.add(user.getAvailableBalance(), obj.getPd_amount())));
  4320. this.userFeignClient.updateById(user);
  4321. PredepositLogDto log = new PredepositLogDto();
  4322. log.setAddTime(new Date());
  4323. log.setPd_log_amount(obj.getPd_amount());
  4324. log.setPd_log_user(obj.getPd_user());
  4325. log.setPd_op_type("充值");
  4326. log.setPd_type("可用预存款");
  4327. log.setPd_log_info(payment.getName());
  4328. this.predepositLogFeignClient.saveEntity(log);
  4329. }
  4330. }
  4331. if ("gold".equals(type)) {
  4332. gold = this.goldRecordService.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  4333. if (gold != null && gold.getGold_pay_status() != 2) {
  4334. gold.setGold_status(1);
  4335. gold.setGold_pay_status(2);
  4336. gold.setGold_payment(payment.getMark());
  4337. this.goldRecordService.updateById(gold);
  4338. UserDto user = this.userFeignClient.selectByPrimaryKey(gold.getGold_user().getId());
  4339. user.setGold(user.getGold() + gold.getGold_count());
  4340. this.userFeignClient.updateById(user);
  4341. GoldLog log = new GoldLog();
  4342. log.setAddTime(new Date());
  4343. log.setGl_payment(gold.getGold_payment());
  4344. log.setGl_content(payment.getName());
  4345. log.setGl_money(gold.getGold_money());
  4346. log.setGl_count(gold.getGold_count());
  4347. log.setGl_type(0);
  4348. log.setGl_user(gold.getGold_user());
  4349. log.setGr(gold);
  4350. this.goldLogService.saveEntity(log);
  4351. }
  4352. }
  4353. if (type.equals("cloudpurchase")) {
  4354. cp_order = this.cloudPurchaseOrderFeignClient.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  4355. if (cp_order.getStatus() < 5) {
  4356. cp_order.setStatus(5);
  4357. cp_order.setPayTime(new Date());
  4358. cp_order.setPayment(payment.getMark());
  4359. this.cloudPurchaseOrderFeignClient.updateById(cp_order);
  4360. this.cloudPurchaseOrderFeignClient.reduce_inventory(cp_order, request);
  4361. }
  4362. }
  4363. if (type.equals("platformpay")) {
  4364. PlatformPay pf = this.platformPayService.selectByPrimaryKey(CommUtil.null2Long(attachs[0]));
  4365. if (pf.getPay_status() == 0 ) {
  4366. pf.setPay_status(1);
  4367. pf.setUpdate_date(new Date());
  4368. pf.setPay_type(payment.getMark());
  4369. this.platformPayService.updateById(pf);
  4370. PlatformPayFlow platformpayflow = new PlatformPayFlow();
  4371. platformpayflow.setPlatform_pay_id(pf.getId());
  4372. platformpayflow.setInfo("编号["+pf.getPay_no()+"]店铺保证金,支付成功");
  4373. platformpayflow.setCreate_date(new Date());
  4374. this.platformPayFlowService.saveEntity(platformpayflow);
  4375. UserDto user = userFeignClient.selectByPrimaryKey(pf.getUser_id());
  4376. StoreDto store = this.storeFeignClient.selectByPrimaryKey(user.getStore_id());
  4377. store.setDeposit(pf.getAmount());
  4378. this.storeFeignClient.updateById(store);
  4379. }
  4380. }
  4381. }
  4382. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/122904
推荐阅读
相关标签
  

闽ICP备14008679号