OrderServiceImpl.java 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. package com.goafanti.order.service.impl;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.math.BigDecimal;
  4. import java.text.ParseException;
  5. import java.util.ArrayList;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.UUID;
  11. import org.apache.commons.beanutils.BeanUtils;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import com.goafanti.common.bo.Error;
  17. import com.goafanti.common.constant.AFTConstants;
  18. import com.goafanti.common.constant.ErrorConstants;
  19. import com.goafanti.common.dao.ContractMapper;
  20. import com.goafanti.common.dao.OrganizationManagementMapper;
  21. import com.goafanti.common.dao.TOrderBillMapper;
  22. import com.goafanti.common.dao.TOrderDetailMapper;
  23. import com.goafanti.common.dao.TOrderMapper;
  24. import com.goafanti.common.error.BusinessException;
  25. import com.goafanti.common.model.Admin;
  26. import com.goafanti.common.model.Contract;
  27. import com.goafanti.common.model.ContractDetail;
  28. import com.goafanti.common.model.OrganizationManagement;
  29. import com.goafanti.common.model.TOrder;
  30. import com.goafanti.common.model.TOrderBill;
  31. import com.goafanti.common.model.TOrderDetail;
  32. import com.goafanti.common.model.User;
  33. import com.goafanti.common.utils.DateUtils;
  34. import com.goafanti.core.mybatis.BaseMybatisDao;
  35. import com.goafanti.core.mybatis.JDBCIdGenerator;
  36. import com.goafanti.core.mybatis.page.Pagination;
  37. import com.goafanti.core.shiro.token.TokenManager;
  38. import com.goafanti.order.bo.BillDetailBo;
  39. import com.goafanti.order.bo.BillListBo;
  40. import com.goafanti.order.bo.CommodityDetailBo;
  41. import com.goafanti.order.bo.OperatorActive;
  42. import com.goafanti.order.bo.OrderListBo;
  43. import com.goafanti.order.bo.ServiceOrderDetailBo;
  44. import com.goafanti.order.bo.C2BOrderDetailBo;
  45. import com.goafanti.order.bo.C2COrderDetailBo;
  46. import com.goafanti.order.enums.ActiveState;
  47. import com.goafanti.order.enums.ApprovalState;
  48. import com.goafanti.order.enums.AuditState;
  49. import com.goafanti.order.enums.CommodityType;
  50. import com.goafanti.order.enums.LiquidationState;
  51. import com.goafanti.order.enums.OrderAction;
  52. import com.goafanti.order.enums.OrderChannel;
  53. import com.goafanti.order.enums.OrderStage;
  54. import com.goafanti.order.enums.OrderState;
  55. import com.goafanti.order.enums.PayChannel;
  56. import com.goafanti.order.enums.ProjectStage;
  57. import com.goafanti.order.enums.TransactionMode;
  58. import com.goafanti.order.enums.TransactionSubject;
  59. import com.goafanti.order.service.OrderService;
  60. @Service
  61. public class OrderServiceImpl extends BaseMybatisDao<TOrderMapper> implements OrderService {
  62. @Autowired
  63. private TOrderMapper tOrderMapper;
  64. @Autowired
  65. private TOrderDetailMapper tOrderDetailMapper;
  66. @Autowired
  67. private JDBCIdGenerator idGenerator;
  68. @Autowired
  69. private TOrderBillMapper tOrderBillMapper;
  70. @Autowired
  71. private OrganizationManagementMapper organizationManagementMapper;
  72. @Autowired
  73. private ContractMapper contractMapper;
  74. private final BigDecimal DEFAULT_FIRST_PAYMENT = new BigDecimal(0);// 默认首付价格
  75. private final BigDecimal DEFAULT_COMMODITY_PRICE = new BigDecimal(0);// 默认单价
  76. private final String DEFAULT_PLATFORM_ID = "0";// 平台默认id
  77. private final double DEFAULT_BROKERAGE_PROPORTION = 0; //佣金比例
  78. private final double DEFAULT_COMMODITY_DISCOUNT = 1; //折扣比例
  79. private final String DEFAULT_COMMODITY_MODE = "NO_MODE"; //暂无规格
  80. private final String DEFAULT_CREATER = "PLATFORM";//平台方
  81. /*
  82. * -------------------------------------------------- APP管理端 --------------------------------------------------------
  83. */
  84. @Override
  85. public C2COrderDetailBo selectCommodityDetail(String commodityId, Integer commodityType) {
  86. C2COrderDetailBo bo = new C2COrderDetailBo();
  87. CommodityDetailBo cdb = tOrderMapper.selectCommodityDetail(commodityId,commodityType);
  88. try {
  89. BeanUtils.copyProperties(bo, cdb);
  90. bo.setOrderNo(String.valueOf(idGenerator.generateId()));
  91. bo.setCreateTime(DateUtils.formatDate(new Date(),AFTConstants.YYYYMMDDHHMMSS));
  92. bo.setCommodityType(commodityType);
  93. if(bo.getCommodityPrice().equals("0"))
  94. bo.setCommodityPrice("面议");
  95. else
  96. bo.setCommodityPrice(bo.getCommodityPrice()+" 万");
  97. if(StringUtils.isBlank(bo.getFirstPayment()))
  98. bo.setFirstPayment("面议");
  99. else
  100. bo.setFirstPayment(bo.getFirstPayment()+" 万");
  101. } catch (IllegalAccessException | InvocationTargetException e) {
  102. e.printStackTrace();
  103. }
  104. return bo;
  105. }
  106. /**
  107. * to update 18
  108. * 后期规则:自营服务订单 、需求订单、其他订单不能同时加入购物车
  109. */
  110. @Override
  111. public int addIntention(String orderNo, String commodityId, String commodityMode, Integer commodityQuantity,Integer commodityType,
  112. String createTime,String remarks) throws ParseException {
  113. CommodityDetailBo bo = tOrderMapper.selectCommodityDetail(commodityId,commodityType);
  114. BigDecimal commodityPrice = StringUtils.isBlank(bo.getCommodityPrice()) ? DEFAULT_COMMODITY_PRICE
  115. : new BigDecimal(Double.valueOf(bo.getCommodityPrice()));
  116. BigDecimal commodityFirstPayment = StringUtils.isBlank(bo.getCommodityFirstPayment()) ? DEFAULT_FIRST_PAYMENT
  117. : new BigDecimal(Double.valueOf(bo.getCommodityFirstPayment()));
  118. BigDecimal discountPrice = commodityPrice.multiply(new BigDecimal(DEFAULT_COMMODITY_DISCOUNT));
  119. BigDecimal discountFirstPayment = commodityFirstPayment.multiply(new BigDecimal(DEFAULT_COMMODITY_DISCOUNT));
  120. BigDecimal orderAmount = discountPrice.multiply(new BigDecimal(commodityQuantity));
  121. TOrder tOrder = new TOrder();
  122. tOrder.setOrderNo(orderNo);
  123. tOrder.setCreater(DEFAULT_CREATER);
  124. tOrder.setCreateTime(DateUtils.parseDate(createTime, AFTConstants.YYYYMMDDHHMMSS));
  125. if(commodityType == CommodityType.DEMAND.getTypeCode()){
  126. tOrder.setBuyerId(StringUtils.isBlank(bo.getSellerId()) ? DEFAULT_PLATFORM_ID : bo.getSellerId());
  127. tOrder.setSellerId(TokenManager.getUserId());
  128. }else{
  129. tOrder.setBuyerId(TokenManager.getUserId());
  130. tOrder.setSellerId(StringUtils.isBlank(bo.getSellerId()) ? DEFAULT_PLATFORM_ID : bo.getSellerId());
  131. }
  132. tOrder.setBrokerageAmount(discountPrice.multiply(new BigDecimal(DEFAULT_BROKERAGE_PROPORTION)));
  133. tOrder.setFirstPayment(DEFAULT_FIRST_PAYMENT);
  134. tOrder.setOrderAmount(orderAmount);
  135. tOrder.setOrderRemarks(remarks);
  136. tOrder.setDeleteSign(ActiveState.NORMAL.getCode());
  137. tOrder.setOrderChannel(OrderChannel.APP.getCode());
  138. setOrderState(OrderAction.ADD_INTENTION, new BigDecimal(0), tOrder, false);
  139. TOrderDetail tOrderDetail = new TOrderDetail();
  140. tOrderDetail.setId(UUID.randomUUID().toString());
  141. tOrderDetail.setOrderNo(orderNo);
  142. tOrderDetail.setCommodityId(commodityId);
  143. tOrderDetail.setCommodityName(bo.getCommodityName());
  144. tOrderDetail.setCommodityMode(StringUtils.isBlank(commodityMode)?DEFAULT_COMMODITY_MODE: commodityMode);
  145. tOrderDetail.setCommodityType(commodityType);
  146. tOrderDetail.setCommodityQuantity(commodityQuantity);
  147. tOrderDetail.setCommodityPrice(commodityPrice);
  148. tOrderDetail.setCommodityFirstPayment(commodityFirstPayment);
  149. tOrderDetail.setDiscountPrice(discountPrice);
  150. tOrderDetail.setDiscountFirstPayment(discountFirstPayment);
  151. tOrderDetailMapper.insert(tOrderDetail);
  152. tOrderMapper.insert(tOrder);
  153. return 1;
  154. }
  155. /**
  156. *
  157. * 订单状态流转
  158. * @param orderStatus
  159. * @param intentionStatus
  160. * @param tradingStatus
  161. * @param paymentStatus
  162. * @param liquidationStatus
  163. * @param actionType
  164. */
  165. public void setOrderState(OrderAction orderAction,BigDecimal changeAmount,TOrder tOrder,boolean confrim){
  166. checkOrder(tOrder);
  167. if(orderAction == OrderAction.ADD_INTENTION){ //添加意向订单
  168. tOrder.setOrderStatus(OrderState.INVALID.getCode());
  169. tOrder.setLiquidationStatus(LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode());
  170. tOrder.setOrderStage(OrderStage.INTENTION.getCode());
  171. tOrder.setProjectStage(ProjectStage.NOT_SATISFY_CONDITION.getCode());
  172. tOrder.setActuallyFirstPayment(new BigDecimal(0));
  173. tOrder.setActuallyTotalAmount(new BigDecimal(0));
  174. tOrder.setActuallyBrokerageAmount(new BigDecimal(0));
  175. tOrder.setActuallyWithdrawAmount(new BigDecimal(0));
  176. }else if(orderAction == OrderAction.CONFIRM_INTENTION){ //确认意向订单 (用户确认)
  177. if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
  178. && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()){
  179. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"确认意向订单"));
  180. }
  181. if (confrim) {
  182. tOrder.setOrderStatus(OrderState.WAIT_FOR_SIGN.getCode()); // 卖家同意
  183. tOrder.setOrderStage(OrderStage.FOLLOWING.getCode());
  184. } else {
  185. tOrder.setOrderStatus(OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()); // 买家拒绝
  186. }
  187. }else if(orderAction == OrderAction.CONFIRM_PAY_FOR_FIRST){ // 支付首付(审核流水)
  188. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()
  189. || tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
  190. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
  191. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,""));
  192. }
  193. int boundary = tOrder.getActuallyFirstPayment().add(changeAmount).compareTo(tOrder.getFirstPayment());
  194. if(boundary == 1){
  195. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"支付首付款"));
  196. }else if(boundary == -1){ //首付待付清
  197. tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
  198. tOrder.setActuallyFirstPayment(tOrder.getActuallyFirstPayment().add(changeAmount));
  199. }else if(boundary == 0){ //首付已结清
  200. tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
  201. tOrder.setActuallyFirstPayment(tOrder.getActuallyFirstPayment().add(changeAmount));
  202. tOrder.setLiquidationStatus(LiquidationState.WAIT_PAY_LAST_BALANCE.getCode());
  203. }
  204. }else if(orderAction == OrderAction.CONFIRM_PAY_FOR_LAST){ //支付尾款 (审核流水)
  205. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()
  206. || tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
  207. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
  208. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"支付尾款"));
  209. }
  210. int boundary = tOrder.getActuallyTotalAmount().add(changeAmount).compareTo(tOrder.getOrderAmount());
  211. if(boundary == 1){
  212. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"支付尾款"));
  213. }else if(boundary == -1){
  214. tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
  215. }else if(boundary == 0){
  216. tOrder.setOrderStatus(OrderState.ALREADY_SIGN.getCode());
  217. tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
  218. tOrder.setLiquidationStatus(LiquidationState.ALREADY_PAY.getCode());
  219. }
  220. }else if(orderAction == OrderAction.APPLY_FOR_WITHDRAW){ //提现申请
  221. if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
  222. && tOrder.getLiquidationStatus() == LiquidationState.ALREADY_PAY.getCode()
  223. && tOrder.getActuallyTotalAmount().doubleValue() > 0){
  224. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"等待提现"));
  225. }
  226. tOrder.setLiquidationStatus(LiquidationState.WAIT_FOR_WITHDRAW.getCode());
  227. }else if(orderAction == OrderAction.CONFIRM_WITHDRAW){ //提现确认 (审核员先审核流水)
  228. if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
  229. && tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_WITHDRAW.getCode()
  230. && tOrder.getActuallyTotalAmount().doubleValue() > 0){
  231. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"确认提现"));
  232. }
  233. tOrder.setLiquidationStatus(LiquidationState.ALREADY_WITHDRAW.getCode());
  234. tOrder.setActuallyWithdrawAmount(tOrder.getActuallyWithdrawAmount().add(changeAmount));
  235. }else if(orderAction == OrderAction.APPLY_FOR_CANCEL){ //取消订单
  236. boolean flag = true;
  237. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
  238. || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
  239. flag = false;
  240. }
  241. if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
  242. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
  243. flag = false;
  244. }
  245. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
  246. && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
  247. && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
  248. flag = false;
  249. }
  250. if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"取消订单"));
  251. if(TokenManager.getToken() instanceof Admin){
  252. if(!tOrder.getSellerId().equals(DEFAULT_PLATFORM_ID))
  253. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"取消订单"));
  254. if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode())
  255. tOrder.setOrderStatus(OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode());
  256. if( tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode())
  257. tOrder.setOrderStatus(OrderState.SELLER_CANCEL_AFTER_SIGN.getCode());
  258. }else if(TokenManager.getToken() instanceof User){
  259. if(TokenManager.getUserId().equals(tOrder.getSellerId())){
  260. if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode())
  261. tOrder.setOrderStatus(OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode());
  262. if( tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode())
  263. tOrder.setOrderStatus(OrderState.SELLER_CANCEL_AFTER_SIGN.getCode());
  264. }else if(TokenManager.getUserId().equals(tOrder.getBuyerId())){
  265. if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode())
  266. tOrder.setOrderStatus(OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode());
  267. if( tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode())
  268. tOrder.setOrderStatus(OrderState.BUYER_CANCEL_AFTER_SIGN.getCode());
  269. }
  270. }
  271. }else if(orderAction == OrderAction.APPLY_FOR_REFUND){ //退款申请
  272. boolean flag = true;
  273. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  274. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  275. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  276. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  277. flag = false;
  278. }
  279. if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
  280. flag = false;
  281. if(tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode()
  282. || tOrder.getLiquidationStatus() == LiquidationState.REFUSE_REFUND.getCode()
  283. || tOrder.getLiquidationStatus() == LiquidationState.AGREE_REFUND.getCode()
  284. || tOrder.getLiquidationStatus() == LiquidationState.COMPLETE_REFUND.getCode()){
  285. flag = false;
  286. }
  287. if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
  288. flag = false;
  289. if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"申请退款"));
  290. tOrder.setLiquidationStatus(LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode());
  291. }else if(orderAction == OrderAction.CONFIRM_REFUND){ //退款确认
  292. boolean flag = true;
  293. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  294. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  295. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  296. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  297. flag = false;
  298. }
  299. if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
  300. flag = false;
  301. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode())
  302. flag = false;
  303. if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
  304. flag = false;
  305. if(confrim) {
  306. if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"同意退款"));
  307. tOrder.setLiquidationStatus(LiquidationState.AGREE_REFUND.getCode());
  308. }else{
  309. if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"拒绝退款"));
  310. tOrder.setLiquidationStatus(LiquidationState.REFUSE_REFUND.getCode());
  311. }
  312. }else if(orderAction == OrderAction.COMPLETE_REFUND){ //完成退款
  313. boolean flag = true;
  314. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  315. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  316. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  317. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  318. flag = false;
  319. }
  320. if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
  321. flag = false;
  322. if(tOrder.getLiquidationStatus() != LiquidationState.AGREE_REFUND.getCode())
  323. flag = false;
  324. if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
  325. flag = false;
  326. if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"申请退款"));
  327. tOrder.setLiquidationStatus(LiquidationState.COMPLETE_REFUND.getCode());
  328. }
  329. }
  330. /**
  331. * 设置按钮状态
  332. * @param tOrder
  333. * @return
  334. */
  335. private OperatorActive setOperatorActive(TOrder tOrder){
  336. OperatorActive active = new OperatorActive();
  337. if(tOrder.getDeleteSign() == ActiveState.ABOLISH.getCode())
  338. return active;
  339. if(tOrder.getDeleteSign() == ActiveState.LOCKING.getCode()) {
  340. active.setApplyUnLock(true);
  341. return active;
  342. }
  343. if (TokenManager.getToken() instanceof User) {
  344. active.setConfirmPayForFirst(false);
  345. active.setConfirmPayForLast(false);
  346. active.setConfirmWithdraw(false);
  347. active.setCompleteRefund(false);
  348. active.setApplyLock(false);
  349. active.setApplyUnLock(false);
  350. active.setApplyRevoke(false);
  351. active.setApplySign(false);
  352. if (TokenManager.getUserId().equals(tOrder.getBuyerId())) { // 买方
  353. active.setApplyForWithdraw(false);
  354. if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
  355. && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()) {
  356. /** 需求订单 开始 **/
  357. if (tOrder.getOrderType() == CommodityType.DEMAND.getTypeCode()) {
  358. active.setConfirmIntention(true);
  359. active.setRefuseIntention(true);
  360. } else {
  361. active.setConfirmIntention(false);
  362. active.setRefuseIntention(false);
  363. }
  364. /** 需求订单 结束 **/
  365. } else {
  366. active.setConfirmIntention(false);
  367. active.setRefuseIntention(false);
  368. }
  369. if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
  370. && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
  371. && tOrder.getOrderStage() == OrderStage.FOLLOWING.getCode()) {
  372. active.setPayForFirst(true); //支付首付
  373. } else {
  374. active.setPayForFirst(false); //支付首付
  375. }
  376. if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
  377. && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
  378. && tOrder.getOrderStage() == OrderStage.FOLLOWING.getCode()) {
  379. active.setPayForLast(true); //支付尾款
  380. } else {
  381. active.setPayForLast(false); //支付尾款
  382. }
  383. boolean flag = true;
  384. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
  385. || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
  386. flag = false;
  387. }
  388. if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
  389. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
  390. flag = false;
  391. }
  392. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
  393. && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
  394. && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
  395. flag = false;
  396. }
  397. active.setApplyForCancel(flag); //申请取消
  398. flag = true;
  399. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  400. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  401. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  402. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  403. flag = false;
  404. }
  405. if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
  406. flag = false;
  407. if(tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode()
  408. || tOrder.getLiquidationStatus() == LiquidationState.REFUSE_REFUND.getCode()
  409. || tOrder.getLiquidationStatus() == LiquidationState.AGREE_REFUND.getCode()
  410. || tOrder.getLiquidationStatus() == LiquidationState.COMPLETE_REFUND.getCode()){
  411. flag = false;
  412. }
  413. if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
  414. flag = false;
  415. active.setApplyForRefund(flag); //申请退款
  416. }else if(TokenManager.getUserId().equals(tOrder.getSellerId())){ //卖方
  417. active.setPayForFirst(false);
  418. active.setPayForLast(false);
  419. active.setApplyForRefund(false);
  420. if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
  421. && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()) {
  422. /** 需求订单 开始 **/
  423. if (tOrder.getOrderType() == CommodityType.DEMAND.getTypeCode()) {
  424. active.setConfirmIntention(false);
  425. active.setRefuseIntention(false);
  426. } else {
  427. active.setConfirmIntention(true);
  428. active.setRefuseIntention(true);
  429. }
  430. /** 需求订单 结束 **/
  431. } else {
  432. active.setConfirmIntention(false);
  433. active.setRefuseIntention(false);
  434. }
  435. boolean flag = true;
  436. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
  437. || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
  438. flag = false;
  439. }
  440. if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
  441. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
  442. flag = false;
  443. }
  444. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
  445. && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
  446. && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
  447. flag = false;
  448. }
  449. active.setApplyForCancel(flag); //申请取消
  450. flag = true;
  451. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  452. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  453. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  454. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  455. flag = false;
  456. }
  457. if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
  458. flag = false;
  459. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode())
  460. flag = false;
  461. if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
  462. flag = false;
  463. active.setAgreeRefund(flag); //同意退款
  464. active.setRefuseRefund(flag); //拒绝退款
  465. if (tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
  466. && tOrder.getLiquidationStatus() == LiquidationState.ALREADY_PAY.getCode()
  467. && tOrder.getActuallyTotalAmount().doubleValue() > 0) {
  468. active.setApplyForWithdraw(true); //申请提现
  469. } else {
  470. active.setApplyForWithdraw(false); //申请提现
  471. }
  472. }else{
  473. active.setPayForFirst(false);
  474. active.setPayForLast(false);
  475. active.setConfirmIntention(false);
  476. active.setRefuseIntention(false);
  477. active.setApplyForCancel(false);
  478. active.setApplyForRefund(false);
  479. active.setAgreeRefund(false);
  480. active.setRefuseRefund(false);
  481. active.setApplyForWithdraw(false);
  482. }
  483. }
  484. if (TokenManager.getToken() instanceof Admin) {
  485. active.setPayForFirst(false);
  486. active.setPayForLast(false);
  487. active.setApplyForWithdraw(false);
  488. active.setApplyForRefund(false);
  489. if (tOrder.getSellerId().equals(DEFAULT_PLATFORM_ID)) { // 平台作为卖方
  490. if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
  491. && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()) {
  492. active.setConfirmIntention(true);
  493. active.setRefuseIntention(true);
  494. } else {
  495. active.setConfirmIntention(false);
  496. active.setRefuseIntention(false);
  497. }
  498. // 平台方作为中间方 确认首付 - 尾款 - 退款
  499. boolean flag = true;
  500. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
  501. || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
  502. flag = false;
  503. }
  504. if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
  505. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
  506. flag = false;
  507. }
  508. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
  509. && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
  510. && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
  511. flag = false;
  512. }
  513. active.setApplyForCancel(flag); //申请取消
  514. flag = true;
  515. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  516. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  517. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  518. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  519. flag = false;
  520. }
  521. if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
  522. flag = false;
  523. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode())
  524. flag = false;
  525. if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
  526. flag = false;
  527. active.setAgreeRefund(flag); //同意退款
  528. active.setRefuseRefund(flag); //拒绝退款
  529. } else {
  530. active.setConfirmIntention(false); //确认意向
  531. active.setRefuseIntention(false); //拒绝意向
  532. active.setApplyForCancel(false); //申请取消
  533. active.setAgreeRefund(false); //同意退款
  534. active.setRefuseRefund(false); //拒绝退款
  535. }
  536. }
  537. //平台方作为中间方 确认首付 - 尾款 - 提现 - 退款
  538. if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
  539. && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()){
  540. active.setConfirmPayForFirst(true);
  541. }else{
  542. active.setConfirmPayForFirst(false);
  543. }
  544. if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
  545. && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()){
  546. active.setConfirmPayForLast(true);
  547. }else{
  548. active.setConfirmPayForLast(false);
  549. }
  550. if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
  551. && tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_WITHDRAW.getCode()){
  552. active.setConfirmWithdraw(true);
  553. }else{
  554. active.setConfirmWithdraw(false);
  555. }
  556. boolean flag = true;
  557. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  558. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  559. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  560. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  561. flag = false;
  562. }
  563. if(flag && tOrder.getActuallyTotalAmount().doubleValue() == 0){
  564. active.setApplyRevoke(true); //作废
  565. }else{
  566. active.setApplyRevoke(false); //作废
  567. }
  568. if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
  569. flag = false;
  570. if(tOrder.getLiquidationStatus() != LiquidationState.AGREE_REFUND.getCode())
  571. flag = false;
  572. if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
  573. flag = false;
  574. active.setCompleteRefund(flag); //完成退款
  575. flag = true;
  576. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()
  577. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode())
  578. flag = false;
  579. if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
  580. && tOrder.getApproval() != ApprovalState.AUDIT_PASS.getCode())
  581. flag = false;
  582. active.setApplySign(flag);
  583. return active;
  584. }
  585. /**
  586. * 添加流水记录
  587. * @param orderNo 订单编号
  588. * @param creater 创建人
  589. * @param payeeId 收款人
  590. * @param payerId 付款人
  591. * @param remarks 附言
  592. * @param transactionSubject 交易科目
  593. * @param payChannel 支付渠道
  594. * @param transactionMode 支付方式
  595. * @param FundAudit 流水审核
  596. * @return
  597. */
  598. public int addFundRecord(String orderNo,String creater,String payeeId,String payerId,String remarks,TransactionSubject transactionSubject,PayChannel payChannel,
  599. BigDecimal transactionAmount,TransactionMode transactionMode,AuditState auditState){
  600. TOrderBill bill = new TOrderBill();
  601. bill.setBillNo(UUID.randomUUID().toString().replace("-", ""));
  602. bill.setConfirmSign(auditState.getCode());
  603. bill.setCreater(creater);
  604. bill.setDeleteSign(Boolean.FALSE);
  605. bill.setOrderNo(orderNo);
  606. bill.setTransactionAmount(transactionAmount);
  607. bill.setPayeeId(payeeId);
  608. bill.setPayerId(payerId);
  609. bill.setRemarks(remarks);
  610. bill.setTransactionAmount(transactionAmount);
  611. bill.setTransactionMode(transactionMode.getCode());
  612. bill.setTransactionSubject(transactionSubject.getCode());
  613. bill.setTransactionChannel(payChannel.getCode());
  614. bill.setCreateTime(new Date());
  615. tOrderBillMapper.insert(bill);
  616. return 1;
  617. }
  618. @Override
  619. public int updatePayForFirst(String orderNo, BigDecimal fundAmount,String remarks) {
  620. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  621. addFundRecord(orderNo, TokenManager.getUserToken().getNickname(), DEFAULT_PLATFORM_ID, TokenManager.getUserId(), remarks,
  622. TransactionSubject.SUPPLY_PAY,PayChannel.UNIONPAY, fundAmount, TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
  623. tOrder.setUpdateTime(new Date());
  624. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  625. return 1;
  626. }
  627. @Override
  628. public int updatePayForLast(String orderNo, BigDecimal fundAmount, String remarks) {
  629. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  630. addFundRecord(orderNo, TokenManager.getUserToken().getNickname(), DEFAULT_PLATFORM_ID, TokenManager.getUserId(), remarks,
  631. TransactionSubject.SUPPLY_PAY,PayChannel.UNIONPAY, fundAmount, TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
  632. tOrder.setUpdateTime(new Date());
  633. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  634. return 1;
  635. }
  636. @SuppressWarnings("unchecked")
  637. @Override
  638. //to update 18
  639. public Pagination<C2BOrderDetailBo> selectOrderList(boolean confirm,Integer pageNo,Integer pageSize) {
  640. Map<String, Object> params = new HashMap<String, Object>();
  641. Pagination<C2BOrderDetailBo> result = new Pagination<C2BOrderDetailBo>();
  642. //if(!confirm) params.put("intentionStatus", IntentionSate.WAIT_SELLER_CONFIRM.getCode()); //购买意向
  643. params.put("uid", TokenManager.getUserId());
  644. Pagination<TOrder> data = (Pagination<TOrder>)findPage("selectOrderListByPage", "selectOrderListCount", params, pageNo, pageSize);
  645. List<TOrder> list = (List<TOrder>)data.getList();
  646. C2BOrderDetailBo bo = null;
  647. List<C2BOrderDetailBo> boList = new ArrayList<C2BOrderDetailBo>();
  648. List<CommodityDetailBo> commoditys = null;
  649. CommodityDetailBo cdb = null;
  650. if(list.size()>0){
  651. for(TOrder t:list){
  652. bo = new C2BOrderDetailBo();
  653. commoditys = new ArrayList<CommodityDetailBo>();
  654. bo.setOrderNo(String.valueOf(t.getOrderNo()));
  655. bo.setOrderRemarks(t.getOrderRemarks());
  656. bo.setOrderStatus(OrderState.getStatus(t.getOrderStatus()).getDesc());
  657. bo.setCreateTime(DateUtils.formatDate(t.getCreateTime(),AFTConstants.YYYYMMDDHHMMSS));
  658. bo.setOrderAmount(String.valueOf(t.getOrderAmount()).equals("0")?"面议":String.valueOf(t.getOrderAmount())+" 万");
  659. bo.setFirstPayment(String.valueOf(t.getFirstPayment()).equals("0")?"面议":String.valueOf(t.getFirstPayment())+" 万");
  660. bo.setOperatorActive(setOperatorActive(t));
  661. List<TOrderDetail> tdList = tOrderMapper.selectOrderCommodity(String.valueOf(t.getOrderNo()));
  662. for(TOrderDetail tod : tdList ){
  663. cdb = new CommodityDetailBo();
  664. cdb.setCommodityPrice(String.valueOf(tod.getCommodityPrice()).equals("0")?"面议":String.valueOf(tod.getCommodityPrice())+" 万");
  665. cdb.setDiscountPrice(String.valueOf(tod.getDiscountPrice()).equals("0")?"面议":String.valueOf(tod.getDiscountPrice())+" 万");
  666. cdb.setCommodityId(tod.getCommodityId());
  667. cdb.setCommodityName(tod.getCommodityName());
  668. cdb.setCommodityMode(tod.getCommodityMode());
  669. cdb.setCommodityType(tod.getCommodityType());
  670. cdb.setCommodityQuantity(tod.getCommodityQuantity());
  671. commoditys.add(cdb);
  672. }
  673. bo.setCommoditys(commoditys);
  674. boList.add(bo);
  675. }
  676. }
  677. result.setList(boList);
  678. result.setPageNo(data.getPageNo());
  679. result.setPageSize(data.getPageSize());
  680. result.setTotalCount(data.getTotalCount());
  681. result.setFilterNo(data.getFilterNo());
  682. return result;
  683. }
  684. @Override
  685. public C2BOrderDetailBo selectOrderDetail(String orderNo) {
  686. TOrder t = tOrderMapper.selectByPrimaryKey(orderNo);
  687. C2BOrderDetailBo bo = new C2BOrderDetailBo();
  688. bo.setOrderNo(String.valueOf(t.getOrderNo()));
  689. bo.setOrderRemarks(t.getOrderRemarks());
  690. bo.setOrderStatus(OrderState.getStatus(t.getOrderStatus()).getDesc());
  691. bo.setCreateTime(DateUtils.formatDate(t.getCreateTime(),AFTConstants.YYYYMMDDHHMMSS));
  692. bo.setOrderAmount(String.valueOf(t.getOrderAmount()).equals("0")?"面议":String.valueOf(t.getOrderAmount())+" 万");
  693. bo.setFirstPayment(String.valueOf(t.getFirstPayment()).equals("0")?"面议":String.valueOf(t.getFirstPayment())+" 万");
  694. bo.setOperatorActive(setOperatorActive(t));
  695. List<CommodityDetailBo> commoditys = new ArrayList<CommodityDetailBo>();
  696. CommodityDetailBo cdb = null;
  697. List<TOrderDetail> tdList = tOrderMapper.selectOrderCommodity(String.valueOf(t.getOrderNo()));
  698. for(TOrderDetail tod : tdList ){
  699. cdb = new CommodityDetailBo();
  700. cdb.setCommodityPrice(String.valueOf(tod.getCommodityPrice()).equals("0")?"面议":String.valueOf(tod.getCommodityPrice())+" 万");
  701. cdb.setDiscountPrice(String.valueOf(tod.getDiscountPrice()).equals("0")?"面议":String.valueOf(tod.getDiscountPrice())+" 万");
  702. cdb.setCommodityId(tod.getCommodityId());
  703. cdb.setCommodityName(tod.getCommodityName());
  704. cdb.setCommodityMode(tod.getCommodityMode());
  705. cdb.setCommodityType(tod.getCommodityType());
  706. cdb.setCommodityQuantity(tod.getCommodityQuantity());
  707. commoditys.add(cdb);
  708. }
  709. bo.setCommoditys(commoditys);
  710. return bo;
  711. }
  712. @SuppressWarnings("unchecked")
  713. @Override
  714. public Pagination<BillListBo> selectOrderBillList(String orderNo,Integer pageNo,Integer pageSize) {
  715. Map<String, Object> params = new HashMap<String, Object>();
  716. if(orderNo != null) params.put("orderNo", orderNo);
  717. params.put("uid", TokenManager.getUserId());
  718. Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectOrderBillByPage","selectOrderBillCount", params, pageNo, pageSize);
  719. List<BillListBo> list = (List<BillListBo>)data.getList();
  720. if(list.size()>0){
  721. for(BillListBo bo:list){
  722. bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
  723. }
  724. }
  725. data.setList(list);
  726. return data;
  727. }
  728. @Override
  729. @Transactional
  730. public int updateApplyForWithdraw(String orderNo,String remarks) {
  731. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  732. BigDecimal transactionAmount = tOrder.getActuallyTotalAmount().subtract(tOrder.getActuallyBrokerageAmount());
  733. addFundRecord(orderNo, TokenManager.getUserToken().getNickname(), TokenManager.getUserId(), DEFAULT_PLATFORM_ID, remarks,
  734. TransactionSubject.SUPPLY_COLLECT, PayChannel.UNIONPAY,transactionAmount,TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
  735. setOrderState(OrderAction.APPLY_FOR_WITHDRAW, new BigDecimal(0), tOrder, false);
  736. tOrder.setUpdateTime(new Date());
  737. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  738. return 1;
  739. }
  740. @Override
  741. @Transactional
  742. //to update 18
  743. public int updateApplyForCancel(String orderNo) {
  744. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  745. setOrderState(OrderAction.APPLY_FOR_CANCEL, new BigDecimal(0), tOrder, false);
  746. if(true){ //退款
  747. BigDecimal transactionAmount = tOrder.getActuallyTotalAmount().subtract(tOrder.getActuallyBrokerageAmount());
  748. addFundRecord(orderNo, "平台方", DEFAULT_PLATFORM_ID,TokenManager.getUserId(), "买家取消订单",
  749. TransactionSubject.REFUND, PayChannel.UNIONPAY,transactionAmount,TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
  750. }
  751. tOrder.setUpdateTime(new Date());
  752. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  753. return 1;
  754. }
  755. /**
  756. *
  757. * @param transactionSubject 交易科目
  758. * @param transactionAmount 交易金额
  759. * @param payeeId 收款人
  760. * @param payerId 付款人
  761. * @return
  762. */
  763. private String setBusinessDesc(Integer transactionSubject,BigDecimal transactionAmount){
  764. String result = "";
  765. if(transactionSubject == TransactionSubject.SUPPLY_COLLECT.getCode() || transactionSubject == TransactionSubject.REFUND.getCode()){
  766. result = "收入-"+transactionAmount;
  767. }else if(transactionSubject == TransactionSubject.SUPPLY_PAY.getCode()){
  768. result = "支出-"+transactionAmount;
  769. }
  770. return result;
  771. }
  772. @Override
  773. public int updateConfirmIntention(String orderNo, boolean confirm) {
  774. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  775. setOrderState(OrderAction.CONFIRM_INTENTION, new BigDecimal(0), tOrder, confirm);
  776. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  777. return 1;
  778. }
  779. /*
  780. * -------------------------------------------------- 后台管理端 --------------------------------------------------------
  781. */
  782. @SuppressWarnings("unchecked")
  783. @Override
  784. public Pagination<OrderListBo> selectServiceOrder(OrderListBo bo,String startDate,String endDate,Integer intention,Integer formal,
  785. Integer pageNo, Integer pageSize) {
  786. Map<String,Object> params = disposeParams(bo,startDate,endDate);
  787. params.put("salesmanId", TokenManager.getAdminId());
  788. if((1 == intention && 0 == formal) || ( 0 == intention && 1 == formal)){
  789. params.put("intention", intention);
  790. params.put("formal", formal);
  791. }else if(0 == intention && 0 == formal){
  792. return new Pagination<OrderListBo>();
  793. }
  794. Pagination<OrderListBo> data = (Pagination<OrderListBo>)findPage("selectServiceOrderByPage","selectServiceOrderCount",
  795. params, pageNo, pageSize);
  796. return data;
  797. }
  798. private Map<String,Object> disposeParams(OrderListBo bo,String startDate,String endDate){
  799. Map<String,Object> params = new HashMap<>();
  800. if(StringUtils.isNotBlank(bo.getBuyerName())) params.put("buyerName", bo.getBuyerName());
  801. if(StringUtils.isNotBlank(startDate)) params.put("startDate", startDate +" 00:00:00");
  802. if(StringUtils.isNotBlank(endDate)) params.put("endDate", endDate + "23:59:59");
  803. if(bo.getOrderStatus() != null) params.put("orderStatus", bo.getOrderStatus());
  804. if(bo.getLiquidationStatus() != null) params.put("liquidationStatus", bo.getLiquidationStatus());
  805. if(bo.getProjectStage() != null) params.put("projectStage", bo.getProjectStage());
  806. if(bo.getOrderChannel() != null) params.put("orderChannel", bo.getOrderChannel());
  807. return params;
  808. }
  809. @Override
  810. public ServiceOrderDetailBo selectServiceOrderDetail(String orderNo) {
  811. return tOrderMapper.selectServiceOrderDetail(orderNo);
  812. }
  813. @Override
  814. public int updateServiceOrder(String orderNo, String firstPayment, String orderAmount, String signFirstPayment,
  815. String signTotalAmount, String orderRemarks) {
  816. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  817. checkOrder(tOrder);
  818. boolean flag = false;
  819. if (new BigDecimal(firstPayment).compareTo(tOrder.getFirstPayment()) != 0)
  820. flag = true;
  821. if (new BigDecimal(orderAmount).compareTo(tOrder.getOrderAmount()) != 0)
  822. flag = true;
  823. if (new BigDecimal(signFirstPayment).compareTo(tOrder.getSignFirstPayment()) != 0)
  824. flag = true;
  825. if (new BigDecimal(signTotalAmount).compareTo(tOrder.getSignTotalAmount()) != 0)
  826. flag = true;
  827. if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() || flag) {
  828. throw new BusinessException(new Error(ErrorConstants.ORDER_CAN_NOT_MODIFY, orderNo, ""));
  829. }
  830. tOrder.setFirstPayment(new BigDecimal(firstPayment));
  831. tOrder.setOrderAmount(new BigDecimal(orderAmount));
  832. tOrder.setSignFirstPayment(new BigDecimal(signFirstPayment));
  833. tOrder.setSignTotalAmount(new BigDecimal(signTotalAmount));
  834. tOrder.setOrderRemarks(orderRemarks);
  835. tOrder.setUpdateTime(new Date());
  836. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  837. return 1;
  838. }
  839. @Override
  840. public int updateSignServiceOrder(String orderNo, String signFirstPayment, String signTotalAmount,String approval,
  841. String orderRemarks) {
  842. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  843. checkOrder(tOrder);
  844. if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() // 等待签单- 跟单中
  845. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()) {
  846. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo, ""));
  847. } else {
  848. if (tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode() // 已经付款 or 特批
  849. && Integer.valueOf(approval) != ApprovalState.WAIT_AUDIT.getCode())
  850. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo, ""));
  851. tOrder.setSignFirstPayment(new BigDecimal(signFirstPayment));
  852. tOrder.setSignTotalAmount(new BigDecimal(signTotalAmount));
  853. tOrder.setOrderStage(OrderStage.SIGNED.getCode());
  854. tOrder.setOrderStatus(OrderState.ALREADY_SIGN.getCode());
  855. tOrder.setProjectStage(ProjectStage.WAIT_SET_UP.getCode());
  856. tOrder.setApproval(Integer.valueOf(approval));
  857. tOrder.setUpdateTime(new Date());
  858. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  859. }
  860. return 1;
  861. }
  862. @Override
  863. public int updateRevokeOrder(String orderNo) {
  864. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  865. boolean flag = true;
  866. if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
  867. && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
  868. && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
  869. && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
  870. flag = false;
  871. }
  872. if(flag && tOrder.getActuallyTotalAmount().doubleValue() == 0){
  873. tOrder.setDeleteSign(ActiveState.ABOLISH.getCode());
  874. }else{
  875. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"作废"));
  876. }
  877. tOrder.setUpdateTime(new Date());
  878. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  879. return 1;
  880. }
  881. public void checkOrder(TOrder tOrder){
  882. if(tOrder == null)
  883. throw new BusinessException(new Error(ErrorConstants.ORDER_NOT_EXIST, tOrder.getOrderNo(),""));
  884. if(tOrder.getDeleteSign() == ActiveState.ABOLISH.getCode())
  885. throw new BusinessException(new Error(ErrorConstants.ORDER_ALREADY_FREEZE, tOrder.getOrderNo(),""));
  886. if(tOrder.getDeleteSign() == ActiveState.LOCKING.getCode())
  887. throw new BusinessException(new Error(ErrorConstants.ORDER_ALREADY_REVOKE, tOrder.getOrderNo(),""));
  888. }
  889. @Override
  890. @Transactional
  891. public int addOrderCommodity(String orderNo, String commodityId,String commodityName, String commodityMode, Integer commodityQuantity,Integer commodityType,
  892. String commodityPrice, String discountPrice,String commodityFirstPayment,String discountFirstPayment, String remarks) {
  893. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  894. checkOrder(tOrder);
  895. if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() //等待签单 + 跟单中
  896. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
  897. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo,""));
  898. }else{
  899. TOrderDetail detail = new TOrderDetail();
  900. detail.setId(UUID.randomUUID().toString());
  901. detail.setOrderNo(orderNo);
  902. detail.setCommodityId(commodityId);
  903. detail.setCommodityQuantity(commodityQuantity);
  904. detail.setCommodityType(commodityType);
  905. detail.setCommodityMode(StringUtils.isBlank(commodityMode)?DEFAULT_COMMODITY_MODE:commodityMode);
  906. detail.setCommodityPrice(new BigDecimal(commodityPrice));
  907. detail.setDiscountPrice(new BigDecimal(discountPrice));
  908. detail.setCommodityFirstPayment(new BigDecimal(commodityFirstPayment));
  909. detail.setDiscountFirstPayment(new BigDecimal(discountFirstPayment));
  910. detail.setRemarks(remarks);
  911. tOrderDetailMapper.insert(detail);
  912. //订单市场价总额
  913. BigDecimal totalAmountChange = new BigDecimal(commodityPrice).multiply(new BigDecimal(commodityQuantity));
  914. //订单市场价首付金额
  915. BigDecimal firstPaymentChange = new BigDecimal(commodityFirstPayment).multiply(new BigDecimal(commodityQuantity));
  916. //订单签单总额
  917. BigDecimal signTotalAmountChange = new BigDecimal(discountPrice).multiply(new BigDecimal(commodityQuantity));
  918. //订单签单首付金额
  919. BigDecimal signFirstPaymentChange = new BigDecimal(discountFirstPayment).multiply(new BigDecimal(commodityQuantity));
  920. tOrder.setOrderAmount(tOrder.getOrderAmount().add(totalAmountChange));
  921. tOrder.setFirstPayment(tOrder.getFirstPayment().add(firstPaymentChange));
  922. tOrder.setSignTotalAmount(tOrder.getSignTotalAmount().add(signTotalAmountChange));
  923. tOrder.setSignFirstPayment(tOrder.getSignFirstPayment().add(signFirstPaymentChange));
  924. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  925. }
  926. return 1;
  927. }
  928. @Override
  929. @Transactional
  930. public int updateOrderCommodity(String detailId,String commodityId, String commodityName,String commodityMode, Integer commodityQuantity,Integer commodityType,
  931. String commodityPrice, String discountPrice,String commodityFirstPayment,String discountFirstPayment,String remarks) {
  932. TOrderDetail oldDetail = tOrderDetailMapper.selectByPrimaryKey(detailId);
  933. TOrder tOrder = tOrderMapper.selectByPrimaryKey(oldDetail.getOrderNo());
  934. checkOrder(tOrder);
  935. if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() // 等待签单 - 跟单中
  936. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()) {
  937. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, oldDetail.getOrderNo(), ""));
  938. } else {
  939. TOrderDetail detail = new TOrderDetail();
  940. detail.setId(detailId);
  941. detail.setOrderNo(oldDetail.getOrderNo());
  942. detail.setCommodityId(commodityId);
  943. detail.setCommodityQuantity(commodityQuantity);
  944. detail.setCommodityType(commodityType);
  945. detail.setCommodityMode(StringUtils.isBlank(commodityMode) ? DEFAULT_COMMODITY_MODE : commodityMode);
  946. detail.setCommodityPrice(new BigDecimal(commodityPrice));
  947. detail.setDiscountPrice(new BigDecimal(discountPrice));
  948. detail.setCommodityFirstPayment(new BigDecimal(commodityFirstPayment));
  949. detail.setDiscountFirstPayment(new BigDecimal(discountFirstPayment));
  950. detail.setRemarks(remarks);
  951. tOrderDetailMapper.insert(detail);
  952. new BigDecimal(discountFirstPayment).multiply(new BigDecimal(commodityQuantity)).subtract(
  953. oldDetail.getDiscountFirstPayment().multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
  954. // 订单市场价总额
  955. BigDecimal totalAmountChange = new BigDecimal(commodityPrice).multiply(new BigDecimal(commodityQuantity))
  956. .subtract(oldDetail.getCommodityPrice().multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
  957. // 订单市场价首付金额
  958. BigDecimal firstPaymentChange = new BigDecimal(commodityFirstPayment)
  959. .multiply(new BigDecimal(commodityQuantity)).subtract(oldDetail.getCommodityFirstPayment()
  960. .multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
  961. // 订单签单总额
  962. BigDecimal signTotalAmountChange = new BigDecimal(discountPrice).multiply(new BigDecimal(commodityQuantity))
  963. .subtract(oldDetail.getDiscountPrice().multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
  964. // 订单签单首付金额
  965. BigDecimal signFirstPaymentChange = new BigDecimal(discountFirstPayment)
  966. .multiply(new BigDecimal(commodityQuantity)).subtract(oldDetail.getDiscountFirstPayment()
  967. .multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
  968. tOrder.setOrderAmount(tOrder.getOrderAmount().add(totalAmountChange));
  969. tOrder.setFirstPayment(tOrder.getFirstPayment().add(firstPaymentChange));
  970. tOrder.setSignTotalAmount(tOrder.getSignTotalAmount().add(signTotalAmountChange));
  971. tOrder.setSignFirstPayment(tOrder.getSignFirstPayment().add(signFirstPaymentChange));
  972. tOrder.setUpdateTime(new Date());
  973. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  974. }
  975. return 1;
  976. }
  977. @Override
  978. public int deleteOrderCommodity(String detailId) {
  979. TOrderDetail detail = tOrderDetailMapper.selectByPrimaryKey(detailId);
  980. TOrder tOrder = tOrderMapper.selectByPrimaryKey(detail.getOrderNo());
  981. checkOrder(tOrder);
  982. if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() // 等待签单 - 跟单中
  983. || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()) {
  984. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, detail.getOrderNo(), ""));
  985. } else {
  986. BigDecimal totalAmountChange = detail.getCommodityPrice()
  987. .multiply(new BigDecimal(detail.getCommodityQuantity()));
  988. BigDecimal firstPaymentChange = detail.getCommodityFirstPayment()
  989. .multiply(new BigDecimal(detail.getCommodityQuantity()));
  990. BigDecimal signTotalAmountChange = detail.getDiscountPrice()
  991. .multiply(new BigDecimal(detail.getCommodityQuantity()));
  992. BigDecimal signFirstPaymentChange = detail.getCommodityFirstPayment()
  993. .multiply(new BigDecimal(detail.getCommodityQuantity()));
  994. tOrder.setOrderAmount(tOrder.getOrderAmount().subtract(totalAmountChange));
  995. tOrder.setFirstPayment(tOrder.getFirstPayment().subtract(firstPaymentChange));
  996. tOrder.setSignTotalAmount(tOrder.getSignTotalAmount().subtract(signTotalAmountChange));
  997. tOrder.setSignFirstPayment(tOrder.getSignFirstPayment().subtract(signFirstPaymentChange));
  998. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  999. tOrderDetailMapper.deleteByPrimaryKey(detailId);
  1000. }
  1001. return 1;
  1002. }
  1003. @Override
  1004. public List<OrganizationManagement> selectMyDaeps(){
  1005. if(TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.APPROVAL_DECISION))
  1006. return organizationManagementMapper.selectAllDeps();
  1007. else
  1008. return selectCurrentDep(TokenManager.getAdminId());
  1009. }
  1010. private List<OrganizationManagement> selectSubDeps(List<OrganizationManagement> allData,List<OrganizationManagement> superData){
  1011. List<OrganizationManagement> subData = new ArrayList<>();
  1012. String superIds = "";
  1013. for(OrganizationManagement om : superData){
  1014. if(!om.getId().equals(om.getSuperId())){
  1015. superIds += om.getSuperId() + ",";
  1016. }
  1017. }
  1018. if(StringUtils.isNotBlank(superIds)) subData = organizationManagementMapper.selectSubDeps(superIds.substring(0, superIds.length()-1));
  1019. if(subData != null && subData.size()>0) {
  1020. allData.addAll(subData);
  1021. selectSubDeps(allData,subData);
  1022. }
  1023. return allData;
  1024. }
  1025. private List<OrganizationManagement> selectCurrentDep(String managerId){
  1026. List<OrganizationManagement> allData = new ArrayList<OrganizationManagement>();
  1027. List<OrganizationManagement> superData = organizationManagementMapper.selectCurrentDeps(managerId);
  1028. if(superData != null && superData.size()>0){
  1029. allData.addAll(superData);
  1030. }
  1031. selectSubDeps(allData,superData);
  1032. return allData;
  1033. }
  1034. @SuppressWarnings("unchecked")
  1035. @Override
  1036. public Pagination<OrderListBo> selectDepServiceOrder(OrderListBo bo, String startDate, String endDate,
  1037. Integer intention, Integer formal, String depIds,Integer pageNo, Integer pageSize) {
  1038. Map<String,Object> params = disposeParams(bo,startDate,endDate);
  1039. if(StringUtils.isNotBlank(depIds)) {
  1040. params.put("depIds", depIds);
  1041. }else{
  1042. if(!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.APPROVAL_DECISION))
  1043. return new Pagination<OrderListBo>();
  1044. }
  1045. if((1 == intention && 0 == formal) || ( 0 == intention && 1 == formal)){
  1046. params.put("intention", intention);
  1047. params.put("formal", formal);
  1048. }else if(0 == intention && 0 == formal){
  1049. return new Pagination<OrderListBo>();
  1050. }
  1051. return (Pagination<OrderListBo>)findPage("selectServiceOrderByPage","selectServiceOrderCount",
  1052. params, pageNo, pageSize);
  1053. }
  1054. @SuppressWarnings("unchecked")
  1055. @Override
  1056. public Pagination<OrderListBo> selectApprovalServiceOrder(OrderListBo bo, String startDate, String endDate,
  1057. String depIds,Integer approvalHistory, Integer pageNo, Integer pageSize) {
  1058. Map<String,Object> params = disposeParams(bo,startDate,endDate);
  1059. if(StringUtils.isNotBlank(depIds)) {
  1060. params.put("depIds", depIds);
  1061. }else{
  1062. if(!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.APPROVAL_DECISION))
  1063. return new Pagination<OrderListBo>();
  1064. }
  1065. if(approvalHistory != null){
  1066. params.put("approvalHistory", approvalHistory);
  1067. }
  1068. return (Pagination<OrderListBo>)findPage("selectServiceOrderByPage","selectServiceOrderCount",
  1069. params, pageNo, pageSize);
  1070. }
  1071. @Override
  1072. public int createServiceOrder(String uid, Integer orderType) {
  1073. TOrder tOrder = new TOrder();
  1074. tOrder.setOrderNo(idGenerator.generateId().toString());
  1075. tOrder.setCreater(TokenManager.getAdminId());
  1076. tOrder.setCreateTime(new Date());
  1077. tOrder.setBuyerId(uid);
  1078. tOrder.setSellerId(DEFAULT_PLATFORM_ID);
  1079. tOrder.setBrokerageAmount(new BigDecimal(0));
  1080. tOrder.setFirstPayment(new BigDecimal(0));
  1081. tOrder.setOrderAmount(new BigDecimal(0));
  1082. tOrder.setOrderRemarks("");
  1083. tOrder.setDeleteSign(ActiveState.NORMAL.getCode());
  1084. tOrder.setOrderChannel(OrderChannel.PORTAL.getCode());
  1085. setOrderState(OrderAction.ADD_INTENTION, new BigDecimal(0), tOrder, false);
  1086. return tOrderMapper.insert(tOrder);
  1087. }
  1088. @SuppressWarnings("unchecked")
  1089. @Override
  1090. public Pagination<OrderListBo> listPublicOrder(Integer pageNo, Integer pageSize) {
  1091. return (Pagination<OrderListBo>)findPage("selectPublicOrderByPage","selectPublicOrderCount",
  1092. null, pageNo, pageSize);
  1093. }
  1094. @Override
  1095. public int updateAppointSalesman(String orderNo, String salesmanId) {
  1096. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  1097. checkOrder(tOrder);
  1098. tOrder.setSalesmanId(salesmanId);
  1099. tOrder.setUpdateTime(new Date());
  1100. return tOrderMapper.updateByPrimaryKeySelective(tOrder);
  1101. }
  1102. @SuppressWarnings("unchecked")
  1103. @Override
  1104. public Pagination<BillListBo> selectMySettlementList(String payeeName, String payerName, String depId,
  1105. String salesmanName, String orderNo, Integer pageNo, Integer pageSize) {
  1106. Map<String, Object> params = new HashMap<String, Object>();
  1107. if(StringUtils.isNotBlank(payerName)) params.put("payeeName", payeeName);
  1108. if(StringUtils.isNotBlank(payerName)) params.put("payerName", payerName);
  1109. if(StringUtils.isNotBlank(depId)) params.put("depId", depId);
  1110. if(StringUtils.isNotBlank(salesmanName)) params.put("salesmanName", salesmanName);
  1111. if(orderNo != null) params.put("orderNo", orderNo);
  1112. /** 特殊处理字段开始 **/
  1113. if(!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  1114. params.put("isFinance", 1);
  1115. }
  1116. params.put("aid", TokenManager.getAdminId());
  1117. /** 特殊处理字段结束 **/
  1118. Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectBillByPage","selectBillCount", params, pageNo, pageSize);
  1119. List<BillListBo> list = (List<BillListBo>)data.getList();
  1120. if(list.size()>0){
  1121. for(BillListBo bo:list){
  1122. bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
  1123. }
  1124. }
  1125. data.setList(list);
  1126. return data;
  1127. }
  1128. @SuppressWarnings("unchecked")
  1129. @Override
  1130. public Pagination<BillListBo> selectMyBillList(String payeeName, String payerName, String depId,
  1131. String salesmanName,String orderNo, Integer pageNo, Integer pageSize) {
  1132. Map<String, Object> params = new HashMap<String, Object>();
  1133. if(StringUtils.isNotBlank(payerName)) params.put("payeeName", payeeName);
  1134. if(StringUtils.isNotBlank(payerName)) params.put("payerName", payerName);
  1135. if(StringUtils.isNotBlank(depId)) params.put("depId", depId);
  1136. if(StringUtils.isNotBlank(salesmanName)) params.put("salesmanName", salesmanName);
  1137. if(orderNo != null) params.put("orderNo", orderNo);
  1138. /** 特殊处理字段开始 **/
  1139. if(!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  1140. params.put("isFinance", 0);
  1141. }
  1142. params.put("aid", TokenManager.getAdminId());
  1143. /** 特殊处理字段结束 **/
  1144. Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectBillByPage","selectBillCount", params, pageNo, pageSize);
  1145. List<BillListBo> list = (List<BillListBo>)data.getList();
  1146. if(list.size()>0){
  1147. for(BillListBo bo:list){
  1148. bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
  1149. }
  1150. }
  1151. data.setList(list);
  1152. return data;
  1153. }
  1154. @SuppressWarnings("unchecked")
  1155. @Override
  1156. public Pagination<BillListBo> selectAllBillList(String payeeName, String payerName, String depId,
  1157. String salesmanName ,String financeName, String orderNo, Integer pageNo, Integer pageSize) {
  1158. Map<String, Object> params = new HashMap<String, Object>();
  1159. if(StringUtils.isNotBlank(payerName)) params.put("payeeName", payeeName);
  1160. if(StringUtils.isNotBlank(payerName)) params.put("payerName", payerName);
  1161. if(StringUtils.isNotBlank(depId)) params.put("depId", depId);
  1162. if(StringUtils.isNotBlank(salesmanName)) params.put("salesmanName", salesmanName);
  1163. if(StringUtils.isNotBlank(financeName)) params.put("financeName", financeName);
  1164. if(orderNo != null) params.put("orderNo", orderNo);
  1165. Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectBillByPage","selectBillCount", params, pageNo, pageSize);
  1166. List<BillListBo> list = (List<BillListBo>)data.getList();
  1167. if(list.size()>0){
  1168. for(BillListBo bo:list){
  1169. bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
  1170. }
  1171. }
  1172. data.setList(list);
  1173. return data;
  1174. }
  1175. @Override
  1176. public BillDetailBo selectBillDetail(String billNo) {
  1177. return tOrderMapper.selectBillDetail(billNo);
  1178. }
  1179. @Override
  1180. @Transactional
  1181. public int updateBill(String billNo, String orderNo, Integer confrim,String financialPayNo,String financialPayTime,String remarks) {
  1182. TOrderBill bill = tOrderBillMapper.selectByPrimaryKey(billNo);
  1183. TOrder order = tOrderMapper.selectByPrimaryKey(orderNo);
  1184. if(bill != null && order != null){
  1185. bill.setBillNo(billNo);
  1186. bill.setFinancialPayNo(financialPayNo);
  1187. try {
  1188. bill.setFinancialPayTime(DateUtils.parseDate(financialPayTime, AFTConstants.YYYYMMDDHHMMSS));
  1189. } catch (ParseException e) {
  1190. e.printStackTrace();
  1191. }
  1192. bill.setRemarks(remarks);
  1193. if(confrim == AFTConstants.YES){
  1194. bill.setConfirmSign(AuditState.AUDIT_SUCCESS.getCode());
  1195. checkOrder(order);
  1196. if(order.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode())
  1197. setOrderState(OrderAction.CONFIRM_PAY_FOR_FIRST, bill.getTransactionAmount(), order, false);
  1198. if(order.getLiquidationStatus() == LiquidationState.WAIT_PAY_LAST_BALANCE.getCode())
  1199. setOrderState(OrderAction.CONFIRM_PAY_FOR_LAST, bill.getTransactionAmount(), order, false);
  1200. order.setUpdateTime(new Date());
  1201. tOrderMapper.updateByPrimaryKeySelective(order);
  1202. }else if(confrim == AFTConstants.NO){
  1203. bill.setConfirmSign(AuditState.AUDIT_FAIL.getCode());
  1204. bill.setDeleteSign(Boolean.TRUE);
  1205. }
  1206. tOrderBillMapper.updateByPrimaryKey(bill);
  1207. }
  1208. return 1;
  1209. }
  1210. @Override
  1211. public int updateBill(String billNo, String financialPayNo, String financialPayTime, String remarks) {
  1212. TOrderBill bill = new TOrderBill();
  1213. bill.setBillNo(billNo);
  1214. bill.setFinancialPayNo(financialPayNo);
  1215. try {
  1216. bill.setFinancialPayTime(DateUtils.parseDate(financialPayTime, AFTConstants.YYYYMMDDHHMMSS));
  1217. } catch (ParseException e) {
  1218. e.printStackTrace();
  1219. }
  1220. bill.setRemarks(remarks);
  1221. tOrderBillMapper.updateByPrimaryKey(bill);
  1222. return 1;
  1223. }
  1224. @Override
  1225. public int approvalServiceOrder(String orderNo, Integer confirm) {
  1226. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  1227. checkOrder(tOrder);
  1228. if(tOrder.getProjectStage() != ProjectStage.NOT_SATISFY_CONDITION.getCode()
  1229. || tOrder.getOrderStatus() != OrderState.ALREADY_SIGN.getCode()
  1230. || tOrder.getOrderStage() != OrderStage.SIGNED.getCode()
  1231. || tOrder.getApproval() != ApprovalState.WAIT_AUDIT.getCode()){
  1232. throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo , ""));
  1233. }
  1234. tOrder.setUpdateTime(new Date());
  1235. if(confirm == AFTConstants.YES){
  1236. tOrder.setApproval(ApprovalState.AUDIT_PASS.getCode());
  1237. tOrder.setProjectStage(ProjectStage.WAIT_SET_UP.getCode());
  1238. }else if(confirm == AFTConstants.NO){
  1239. tOrder.setApproval(ApprovalState.AUDIT_REFUSE.getCode());
  1240. }
  1241. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  1242. return 1;
  1243. }
  1244. @SuppressWarnings("unchecked")
  1245. @Override
  1246. public Pagination<OrderListBo> listSetUpServiceOrder(String buyerName,String salesmanName, String financeName,
  1247. String depId,Integer approval, Integer pageNo, Integer pageSize) {
  1248. Map<String,Object> params = new HashMap<String,Object>();
  1249. if(StringUtils.isNotBlank(buyerName))
  1250. params.put("buyerName", buyerName);
  1251. if(StringUtils.isNotBlank(salesmanName))
  1252. params.put("salesmanName", salesmanName);
  1253. if(StringUtils.isNotBlank(financeName))
  1254. params.put("financeName",financeName);
  1255. if(StringUtils.isNotBlank(depId))
  1256. params.put("depId", depId);
  1257. if(approval != null)
  1258. params.put("approval", approval);
  1259. return (Pagination<OrderListBo>)findPage("selectSetUpServiceOrderByPage","selectSetUpServiceOrderCount",
  1260. params, pageNo, pageSize);
  1261. }
  1262. @Override
  1263. @Transactional
  1264. public int setUpProject(String orderNo, String signDate, String signComment) {
  1265. TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
  1266. checkOrder(tOrder);
  1267. boolean flag = false;
  1268. if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()){
  1269. if(tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_LAST_BALANCE.getCode())
  1270. flag = true;
  1271. if(tOrder.getLiquidationStatus() == LiquidationState.ALREADY_PAY.getCode())
  1272. flag = true;
  1273. if(tOrder.getApproval() == ApprovalState.AUDIT_PASS.getCode())
  1274. flag = true;
  1275. }
  1276. if(!flag)
  1277. throw new BusinessException(new Error(ErrorConstants.ORDER_CAN_NOT_MODIFY, orderNo, ""));
  1278. tOrder.setProjectStage(ProjectStage.ALREADY_SET_UP.getCode());
  1279. tOrder.setUpdateTime(new Date());
  1280. tOrderMapper.updateByPrimaryKeySelective(tOrder);
  1281. //-------------- 查询订单详情 --------------------------
  1282. List<TOrderDetail> orderDetailList = tOrderMapper.selectOrderCommodity(orderNo);
  1283. List<ContractDetail> contractDetailList = new ArrayList<>();
  1284. ContractDetail contractDetail = null;
  1285. Date createTime = new Date();
  1286. String contractId = UUID.randomUUID().toString(); //合同ID
  1287. Contract contract = new Contract();
  1288. contract.setId(contractId);
  1289. contract.setCreateTime(createTime);
  1290. contract.setType(tOrder.getOrderType());
  1291. contract.setSignDate(createTime);
  1292. contract.setOrderNo(orderNo);
  1293. contract.setStatus(ProjectStage.ALREADY_SET_UP.getCode());
  1294. contract.setUid(tOrder.getBuyerId());
  1295. contractMapper.insert(contract);
  1296. for(TOrderDetail orderDetail: orderDetailList){
  1297. for(int i=0; i<orderDetail.getCommodityQuantity();i++){
  1298. contractDetail = new ContractDetail();
  1299. contractDetail.setId(UUID.randomUUID().toString());
  1300. contractDetail.setCommodityId(orderDetail.getCommodityId());
  1301. contractDetail.setCommodityMode(orderDetail.getCommodityMode());
  1302. contractDetail.setCommodityName(orderDetail.getCommodityName());
  1303. contractDetail.setCommodityType(orderDetail.getCommodityType());
  1304. contractDetail.setCommodityQuantity(1);
  1305. contractDetail.setCreateTime(createTime);
  1306. contractDetail.setContractId(contractId);
  1307. contractDetailList.add(contractDetail);
  1308. }
  1309. }
  1310. contractMapper.batchInsertContractDetail(contractDetailList);
  1311. return 1;
  1312. }
  1313. }