| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366 |
- package com.goafanti.order.service.impl;
- import java.lang.reflect.InvocationTargetException;
- import java.math.BigDecimal;
- import java.text.ParseException;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import org.apache.commons.beanutils.BeanUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.goafanti.common.bo.Error;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.dao.ContractMapper;
- import com.goafanti.common.dao.OrganizationManagementMapper;
- import com.goafanti.common.dao.TOrderBillMapper;
- import com.goafanti.common.dao.TOrderDetailMapper;
- import com.goafanti.common.dao.TOrderMapper;
- import com.goafanti.common.error.BusinessException;
- import com.goafanti.common.model.Admin;
- import com.goafanti.common.model.Contract;
- import com.goafanti.common.model.ContractDetail;
- import com.goafanti.common.model.OrganizationManagement;
- import com.goafanti.common.model.TOrder;
- import com.goafanti.common.model.TOrderBill;
- import com.goafanti.common.model.TOrderDetail;
- import com.goafanti.common.model.User;
- import com.goafanti.common.utils.DateUtils;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.JDBCIdGenerator;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.order.bo.BillDetailBo;
- import com.goafanti.order.bo.BillListBo;
- import com.goafanti.order.bo.CommodityDetailBo;
- import com.goafanti.order.bo.OperatorActive;
- import com.goafanti.order.bo.OrderListBo;
- import com.goafanti.order.bo.ServiceOrderDetailBo;
- import com.goafanti.order.bo.C2BOrderDetailBo;
- import com.goafanti.order.bo.C2COrderDetailBo;
- import com.goafanti.order.enums.ActiveState;
- import com.goafanti.order.enums.ApprovalState;
- import com.goafanti.order.enums.AuditState;
- import com.goafanti.order.enums.CommodityType;
- import com.goafanti.order.enums.LiquidationState;
- import com.goafanti.order.enums.OrderAction;
- import com.goafanti.order.enums.OrderChannel;
- import com.goafanti.order.enums.OrderStage;
- import com.goafanti.order.enums.OrderState;
- import com.goafanti.order.enums.PayChannel;
- import com.goafanti.order.enums.ProjectStage;
- import com.goafanti.order.enums.TransactionMode;
- import com.goafanti.order.enums.TransactionSubject;
- import com.goafanti.order.service.OrderService;
- @Service
- public class OrderServiceImpl extends BaseMybatisDao<TOrderMapper> implements OrderService {
-
- @Autowired
- private TOrderMapper tOrderMapper;
- @Autowired
- private TOrderDetailMapper tOrderDetailMapper;
- @Autowired
- private JDBCIdGenerator idGenerator;
- @Autowired
- private TOrderBillMapper tOrderBillMapper;
- @Autowired
- private OrganizationManagementMapper organizationManagementMapper;
- @Autowired
- private ContractMapper contractMapper;
-
- private final BigDecimal DEFAULT_FIRST_PAYMENT = new BigDecimal(0);// 默认首付价格
- private final BigDecimal DEFAULT_COMMODITY_PRICE = new BigDecimal(0);// 默认单价
- private final String DEFAULT_PLATFORM_ID = "0";// 平台默认id
- private final double DEFAULT_BROKERAGE_PROPORTION = 0; //佣金比例
- private final double DEFAULT_COMMODITY_DISCOUNT = 1; //折扣比例
- private final String DEFAULT_COMMODITY_MODE = "NO_MODE"; //暂无规格
- private final String DEFAULT_CREATER = "PLATFORM";//平台方
- /*
- * -------------------------------------------------- APP管理端 --------------------------------------------------------
- */
- @Override
- public C2COrderDetailBo selectCommodityDetail(String commodityId, Integer commodityType) {
- C2COrderDetailBo bo = new C2COrderDetailBo();
- CommodityDetailBo cdb = tOrderMapper.selectCommodityDetail(commodityId,commodityType);
- try {
- BeanUtils.copyProperties(bo, cdb);
- bo.setOrderNo(String.valueOf(idGenerator.generateId()));
- bo.setCreateTime(DateUtils.formatDate(new Date(),AFTConstants.YYYYMMDDHHMMSS));
- bo.setCommodityType(commodityType);
- if(bo.getCommodityPrice().equals("0"))
- bo.setCommodityPrice("面议");
- else
- bo.setCommodityPrice(bo.getCommodityPrice()+" 万");
- if(StringUtils.isBlank(bo.getFirstPayment()))
- bo.setFirstPayment("面议");
- else
- bo.setFirstPayment(bo.getFirstPayment()+" 万");
- } catch (IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
- return bo;
- }
- /**
- * to update 18
- * 后期规则:自营服务订单 、需求订单、其他订单不能同时加入购物车
- */
- @Override
- public int addIntention(String orderNo, String commodityId, String commodityMode, Integer commodityQuantity,Integer commodityType,
- String createTime,String remarks) throws ParseException {
- CommodityDetailBo bo = tOrderMapper.selectCommodityDetail(commodityId,commodityType);
- BigDecimal commodityPrice = StringUtils.isBlank(bo.getCommodityPrice()) ? DEFAULT_COMMODITY_PRICE
- : new BigDecimal(Double.valueOf(bo.getCommodityPrice()));
- BigDecimal commodityFirstPayment = StringUtils.isBlank(bo.getCommodityFirstPayment()) ? DEFAULT_FIRST_PAYMENT
- : new BigDecimal(Double.valueOf(bo.getCommodityFirstPayment()));
- BigDecimal discountPrice = commodityPrice.multiply(new BigDecimal(DEFAULT_COMMODITY_DISCOUNT));
- BigDecimal discountFirstPayment = commodityFirstPayment.multiply(new BigDecimal(DEFAULT_COMMODITY_DISCOUNT));
- BigDecimal orderAmount = discountPrice.multiply(new BigDecimal(commodityQuantity));
- TOrder tOrder = new TOrder();
- tOrder.setOrderNo(orderNo);
- tOrder.setCreater(DEFAULT_CREATER);
- tOrder.setCreateTime(DateUtils.parseDate(createTime, AFTConstants.YYYYMMDDHHMMSS));
- if(commodityType == CommodityType.DEMAND.getTypeCode()){
- tOrder.setBuyerId(StringUtils.isBlank(bo.getSellerId()) ? DEFAULT_PLATFORM_ID : bo.getSellerId());
- tOrder.setSellerId(TokenManager.getUserId());
- }else{
- tOrder.setBuyerId(TokenManager.getUserId());
- tOrder.setSellerId(StringUtils.isBlank(bo.getSellerId()) ? DEFAULT_PLATFORM_ID : bo.getSellerId());
- }
- tOrder.setBrokerageAmount(discountPrice.multiply(new BigDecimal(DEFAULT_BROKERAGE_PROPORTION)));
- tOrder.setFirstPayment(DEFAULT_FIRST_PAYMENT);
- tOrder.setOrderAmount(orderAmount);
- tOrder.setOrderRemarks(remarks);
- tOrder.setDeleteSign(ActiveState.NORMAL.getCode());
- tOrder.setOrderChannel(OrderChannel.APP.getCode());
- setOrderState(OrderAction.ADD_INTENTION, new BigDecimal(0), tOrder, false);
-
- TOrderDetail tOrderDetail = new TOrderDetail();
- tOrderDetail.setId(UUID.randomUUID().toString());
- tOrderDetail.setOrderNo(orderNo);
- tOrderDetail.setCommodityId(commodityId);
- tOrderDetail.setCommodityName(bo.getCommodityName());
- tOrderDetail.setCommodityMode(StringUtils.isBlank(commodityMode)?DEFAULT_COMMODITY_MODE: commodityMode);
- tOrderDetail.setCommodityType(commodityType);
- tOrderDetail.setCommodityQuantity(commodityQuantity);
- tOrderDetail.setCommodityPrice(commodityPrice);
- tOrderDetail.setCommodityFirstPayment(commodityFirstPayment);
- tOrderDetail.setDiscountPrice(discountPrice);
- tOrderDetail.setDiscountFirstPayment(discountFirstPayment);
- tOrderDetailMapper.insert(tOrderDetail);
- tOrderMapper.insert(tOrder);
- return 1;
- }
-
- /**
- *
- * 订单状态流转
- * @param orderStatus
- * @param intentionStatus
- * @param tradingStatus
- * @param paymentStatus
- * @param liquidationStatus
- * @param actionType
- */
- public void setOrderState(OrderAction orderAction,BigDecimal changeAmount,TOrder tOrder,boolean confrim){
- checkOrder(tOrder);
- if(orderAction == OrderAction.ADD_INTENTION){ //添加意向订单
- tOrder.setOrderStatus(OrderState.INVALID.getCode());
- tOrder.setLiquidationStatus(LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode());
- tOrder.setOrderStage(OrderStage.INTENTION.getCode());
- tOrder.setProjectStage(ProjectStage.NOT_SATISFY_CONDITION.getCode());
- tOrder.setActuallyFirstPayment(new BigDecimal(0));
- tOrder.setActuallyTotalAmount(new BigDecimal(0));
- tOrder.setActuallyBrokerageAmount(new BigDecimal(0));
- tOrder.setActuallyWithdrawAmount(new BigDecimal(0));
- }else if(orderAction == OrderAction.CONFIRM_INTENTION){ //确认意向订单 (用户确认)
- if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
- && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"确认意向订单"));
- }
- if (confrim) {
- tOrder.setOrderStatus(OrderState.WAIT_FOR_SIGN.getCode()); // 卖家同意
- tOrder.setOrderStage(OrderStage.FOLLOWING.getCode());
- } else {
- tOrder.setOrderStatus(OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()); // 买家拒绝
- }
- }else if(orderAction == OrderAction.CONFIRM_PAY_FOR_FIRST){ // 支付首付(审核流水)
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()
- || tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,""));
- }
- int boundary = tOrder.getActuallyFirstPayment().add(changeAmount).compareTo(tOrder.getFirstPayment());
- if(boundary == 1){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"支付首付款"));
- }else if(boundary == -1){ //首付待付清
- tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
- tOrder.setActuallyFirstPayment(tOrder.getActuallyFirstPayment().add(changeAmount));
- }else if(boundary == 0){ //首付已结清
- tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
- tOrder.setActuallyFirstPayment(tOrder.getActuallyFirstPayment().add(changeAmount));
- tOrder.setLiquidationStatus(LiquidationState.WAIT_PAY_LAST_BALANCE.getCode());
- }
- }else if(orderAction == OrderAction.CONFIRM_PAY_FOR_LAST){ //支付尾款 (审核流水)
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()
- || tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"支付尾款"));
- }
- int boundary = tOrder.getActuallyTotalAmount().add(changeAmount).compareTo(tOrder.getOrderAmount());
- if(boundary == 1){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"支付尾款"));
- }else if(boundary == -1){
- tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
- }else if(boundary == 0){
- tOrder.setOrderStatus(OrderState.ALREADY_SIGN.getCode());
- tOrder.setActuallyTotalAmount(tOrder.getActuallyTotalAmount().add(changeAmount));
- tOrder.setLiquidationStatus(LiquidationState.ALREADY_PAY.getCode());
- }
- }else if(orderAction == OrderAction.APPLY_FOR_WITHDRAW){ //提现申请
- if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.ALREADY_PAY.getCode()
- && tOrder.getActuallyTotalAmount().doubleValue() > 0){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"等待提现"));
- }
- tOrder.setLiquidationStatus(LiquidationState.WAIT_FOR_WITHDRAW.getCode());
- }else if(orderAction == OrderAction.CONFIRM_WITHDRAW){ //提现确认 (审核员先审核流水)
- if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_WITHDRAW.getCode()
- && tOrder.getActuallyTotalAmount().doubleValue() > 0){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"确认提现"));
- }
- tOrder.setLiquidationStatus(LiquidationState.ALREADY_WITHDRAW.getCode());
- tOrder.setActuallyWithdrawAmount(tOrder.getActuallyWithdrawAmount().add(changeAmount));
- }else if(orderAction == OrderAction.APPLY_FOR_CANCEL){ //取消订单
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
- || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
- flag = false;
- }
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
- flag = false;
- }
- if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"取消订单"));
- if(TokenManager.getToken() instanceof Admin){
- if(!tOrder.getSellerId().equals(DEFAULT_PLATFORM_ID))
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"取消订单"));
- if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode())
- tOrder.setOrderStatus(OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode());
- if( tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode())
- tOrder.setOrderStatus(OrderState.SELLER_CANCEL_AFTER_SIGN.getCode());
- }else if(TokenManager.getToken() instanceof User){
- if(TokenManager.getUserId().equals(tOrder.getSellerId())){
- if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode())
- tOrder.setOrderStatus(OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode());
- if( tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode())
- tOrder.setOrderStatus(OrderState.SELLER_CANCEL_AFTER_SIGN.getCode());
- }else if(TokenManager.getUserId().equals(tOrder.getBuyerId())){
- if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode())
- tOrder.setOrderStatus(OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode());
- if( tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode())
- tOrder.setOrderStatus(OrderState.BUYER_CANCEL_AFTER_SIGN.getCode());
- }
- }
- }else if(orderAction == OrderAction.APPLY_FOR_REFUND){ //退款申请
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode()
- || tOrder.getLiquidationStatus() == LiquidationState.REFUSE_REFUND.getCode()
- || tOrder.getLiquidationStatus() == LiquidationState.AGREE_REFUND.getCode()
- || tOrder.getLiquidationStatus() == LiquidationState.COMPLETE_REFUND.getCode()){
- flag = false;
- }
- if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
- flag = false;
- if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"申请退款"));
- tOrder.setLiquidationStatus(LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode());
- }else if(orderAction == OrderAction.CONFIRM_REFUND){ //退款确认
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode())
- flag = false;
- if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
- flag = false;
- if(confrim) {
- if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"同意退款"));
- tOrder.setLiquidationStatus(LiquidationState.AGREE_REFUND.getCode());
- }else{
- if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"拒绝退款"));
- tOrder.setLiquidationStatus(LiquidationState.REFUSE_REFUND.getCode());
- }
- }else if(orderAction == OrderAction.COMPLETE_REFUND){ //完成退款
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() != LiquidationState.AGREE_REFUND.getCode())
- flag = false;
- if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
- flag = false;
- if(!flag) throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"申请退款"));
- tOrder.setLiquidationStatus(LiquidationState.COMPLETE_REFUND.getCode());
- }
- }
-
-
- /**
- * 设置按钮状态
- * @param tOrder
- * @return
- */
- private OperatorActive setOperatorActive(TOrder tOrder){
- OperatorActive active = new OperatorActive();
- if(tOrder.getDeleteSign() == ActiveState.ABOLISH.getCode())
- return active;
- if(tOrder.getDeleteSign() == ActiveState.LOCKING.getCode()) {
- active.setApplyUnLock(true);
- return active;
- }
- if (TokenManager.getToken() instanceof User) {
- active.setConfirmPayForFirst(false);
- active.setConfirmPayForLast(false);
- active.setConfirmWithdraw(false);
- active.setCompleteRefund(false);
- active.setApplyLock(false);
- active.setApplyUnLock(false);
- active.setApplyRevoke(false);
- active.setApplySign(false);
- if (TokenManager.getUserId().equals(tOrder.getBuyerId())) { // 买方
- active.setApplyForWithdraw(false);
- if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
- && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()) {
- /** 需求订单 开始 **/
- if (tOrder.getOrderType() == CommodityType.DEMAND.getTypeCode()) {
- active.setConfirmIntention(true);
- active.setRefuseIntention(true);
- } else {
- active.setConfirmIntention(false);
- active.setRefuseIntention(false);
- }
- /** 需求订单 结束 **/
- } else {
- active.setConfirmIntention(false);
- active.setRefuseIntention(false);
- }
- if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
- && tOrder.getOrderStage() == OrderStage.FOLLOWING.getCode()) {
- active.setPayForFirst(true); //支付首付
- } else {
- active.setPayForFirst(false); //支付首付
- }
- if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
- && tOrder.getOrderStage() == OrderStage.FOLLOWING.getCode()) {
- active.setPayForLast(true); //支付尾款
- } else {
- active.setPayForLast(false); //支付尾款
- }
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
- || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
- flag = false;
- }
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
- flag = false;
- }
- active.setApplyForCancel(flag); //申请取消
- flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode()
- || tOrder.getLiquidationStatus() == LiquidationState.REFUSE_REFUND.getCode()
- || tOrder.getLiquidationStatus() == LiquidationState.AGREE_REFUND.getCode()
- || tOrder.getLiquidationStatus() == LiquidationState.COMPLETE_REFUND.getCode()){
- flag = false;
- }
- if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
- flag = false;
- active.setApplyForRefund(flag); //申请退款
- }else if(TokenManager.getUserId().equals(tOrder.getSellerId())){ //卖方
- active.setPayForFirst(false);
- active.setPayForLast(false);
- active.setApplyForRefund(false);
- if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
- && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()) {
- /** 需求订单 开始 **/
- if (tOrder.getOrderType() == CommodityType.DEMAND.getTypeCode()) {
- active.setConfirmIntention(false);
- active.setRefuseIntention(false);
- } else {
- active.setConfirmIntention(true);
- active.setRefuseIntention(true);
- }
- /** 需求订单 结束 **/
- } else {
- active.setConfirmIntention(false);
- active.setRefuseIntention(false);
- }
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
- || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
- flag = false;
- }
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
- flag = false;
- }
- active.setApplyForCancel(flag); //申请取消
- flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode())
- flag = false;
- if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
- flag = false;
- active.setAgreeRefund(flag); //同意退款
- active.setRefuseRefund(flag); //拒绝退款
- if (tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.ALREADY_PAY.getCode()
- && tOrder.getActuallyTotalAmount().doubleValue() > 0) {
- active.setApplyForWithdraw(true); //申请提现
- } else {
- active.setApplyForWithdraw(false); //申请提现
- }
- }else{
- active.setPayForFirst(false);
- active.setPayForLast(false);
- active.setConfirmIntention(false);
- active.setRefuseIntention(false);
- active.setApplyForCancel(false);
- active.setApplyForRefund(false);
- active.setAgreeRefund(false);
- active.setRefuseRefund(false);
- active.setApplyForWithdraw(false);
- }
- }
- if (TokenManager.getToken() instanceof Admin) {
- active.setPayForFirst(false);
- active.setPayForLast(false);
- active.setApplyForWithdraw(false);
- active.setApplyForRefund(false);
- if (tOrder.getSellerId().equals(DEFAULT_PLATFORM_ID)) { // 平台作为卖方
- if (tOrder.getOrderStatus() == OrderState.WAIT_FOR_CONFIRM.getCode()
- && tOrder.getOrderStage() == OrderStage.INTENTION.getCode()) {
- active.setConfirmIntention(true);
- active.setRefuseIntention(true);
- } else {
- active.setConfirmIntention(false);
- active.setRefuseIntention(false);
- }
- // 平台方作为中间方 确认首付 - 尾款 - 退款
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_CONFIRM.getCode()
- || tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() != OrderStage.INTENTION.getCode()
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
- flag = false;
- }
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
- && tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode()){
- flag = false;
- }
- active.setApplyForCancel(flag); //申请取消
- flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_FOR_REFUND_CONFIRM.getCode())
- flag = false;
- if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
- flag = false;
- active.setAgreeRefund(flag); //同意退款
- active.setRefuseRefund(flag); //拒绝退款
- } else {
- active.setConfirmIntention(false); //确认意向
- active.setRefuseIntention(false); //拒绝意向
- active.setApplyForCancel(false); //申请取消
- active.setAgreeRefund(false); //同意退款
- active.setRefuseRefund(false); //拒绝退款
- }
- }
- //平台方作为中间方 确认首付 - 尾款 - 提现 - 退款
- if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()){
- active.setConfirmPayForFirst(true);
- }else{
- active.setConfirmPayForFirst(false);
- }
- if(tOrder.getOrderStatus() == OrderState.WAIT_FOR_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode()){
- active.setConfirmPayForLast(true);
- }else{
- active.setConfirmPayForLast(false);
- }
- if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()
- && tOrder.getLiquidationStatus() == LiquidationState.WAIT_FOR_WITHDRAW.getCode()){
- active.setConfirmWithdraw(true);
- }else{
- active.setConfirmWithdraw(false);
- }
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(flag && tOrder.getActuallyTotalAmount().doubleValue() == 0){
- active.setApplyRevoke(true); //作废
- }else{
- active.setApplyRevoke(false); //作废
- }
- if(tOrder.getOrderStage() == OrderStage.INTENTION.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() != LiquidationState.AGREE_REFUND.getCode())
- flag = false;
- if(tOrder.getActuallyTotalAmount().doubleValue() <= 0)
- flag = false;
- active.setCompleteRefund(flag); //完成退款
- flag = true;
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode()
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode())
- flag = false;
- if(tOrder.getLiquidationStatus() != LiquidationState.WAIT_PAY_LAST_BALANCE.getCode()
- && tOrder.getApproval() != ApprovalState.AUDIT_PASS.getCode())
- flag = false;
- active.setApplySign(flag);
- return active;
- }
- /**
- * 添加流水记录
- * @param orderNo 订单编号
- * @param creater 创建人
- * @param payeeId 收款人
- * @param payerId 付款人
- * @param remarks 附言
- * @param transactionSubject 交易科目
- * @param payChannel 支付渠道
- * @param transactionMode 支付方式
- * @param FundAudit 流水审核
- * @return
- */
- public int addFundRecord(String orderNo,String creater,String payeeId,String payerId,String remarks,TransactionSubject transactionSubject,PayChannel payChannel,
- BigDecimal transactionAmount,TransactionMode transactionMode,AuditState auditState){
- TOrderBill bill = new TOrderBill();
- bill.setBillNo(UUID.randomUUID().toString().replace("-", ""));
- bill.setConfirmSign(auditState.getCode());
- bill.setCreater(creater);
- bill.setDeleteSign(Boolean.FALSE);
- bill.setOrderNo(orderNo);
- bill.setTransactionAmount(transactionAmount);
- bill.setPayeeId(payeeId);
- bill.setPayerId(payerId);
- bill.setRemarks(remarks);
- bill.setTransactionAmount(transactionAmount);
- bill.setTransactionMode(transactionMode.getCode());
- bill.setTransactionSubject(transactionSubject.getCode());
- bill.setTransactionChannel(payChannel.getCode());
- bill.setCreateTime(new Date());
- tOrderBillMapper.insert(bill);
- return 1;
- }
-
- @Override
- public int updatePayForFirst(String orderNo, BigDecimal fundAmount,String remarks) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- addFundRecord(orderNo, TokenManager.getUserToken().getNickname(), DEFAULT_PLATFORM_ID, TokenManager.getUserId(), remarks,
- TransactionSubject.SUPPLY_PAY,PayChannel.UNIONPAY, fundAmount, TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
- @Override
- public int updatePayForLast(String orderNo, BigDecimal fundAmount, String remarks) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- addFundRecord(orderNo, TokenManager.getUserToken().getNickname(), DEFAULT_PLATFORM_ID, TokenManager.getUserId(), remarks,
- TransactionSubject.SUPPLY_PAY,PayChannel.UNIONPAY, fundAmount, TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
- @SuppressWarnings("unchecked")
- @Override
- //to update 18
- public Pagination<C2BOrderDetailBo> selectOrderList(boolean confirm,Integer pageNo,Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- Pagination<C2BOrderDetailBo> result = new Pagination<C2BOrderDetailBo>();
- //if(!confirm) params.put("intentionStatus", IntentionSate.WAIT_SELLER_CONFIRM.getCode()); //购买意向
- params.put("uid", TokenManager.getUserId());
- Pagination<TOrder> data = (Pagination<TOrder>)findPage("selectOrderListByPage", "selectOrderListCount", params, pageNo, pageSize);
- List<TOrder> list = (List<TOrder>)data.getList();
- C2BOrderDetailBo bo = null;
- List<C2BOrderDetailBo> boList = new ArrayList<C2BOrderDetailBo>();
- List<CommodityDetailBo> commoditys = null;
- CommodityDetailBo cdb = null;
- if(list.size()>0){
- for(TOrder t:list){
- bo = new C2BOrderDetailBo();
- commoditys = new ArrayList<CommodityDetailBo>();
- bo.setOrderNo(String.valueOf(t.getOrderNo()));
- bo.setOrderRemarks(t.getOrderRemarks());
- bo.setOrderStatus(OrderState.getStatus(t.getOrderStatus()).getDesc());
- bo.setCreateTime(DateUtils.formatDate(t.getCreateTime(),AFTConstants.YYYYMMDDHHMMSS));
- bo.setOrderAmount(String.valueOf(t.getOrderAmount()).equals("0")?"面议":String.valueOf(t.getOrderAmount())+" 万");
- bo.setFirstPayment(String.valueOf(t.getFirstPayment()).equals("0")?"面议":String.valueOf(t.getFirstPayment())+" 万");
- bo.setOperatorActive(setOperatorActive(t));
- List<TOrderDetail> tdList = tOrderMapper.selectOrderCommodity(String.valueOf(t.getOrderNo()));
- for(TOrderDetail tod : tdList ){
- cdb = new CommodityDetailBo();
- cdb.setCommodityPrice(String.valueOf(tod.getCommodityPrice()).equals("0")?"面议":String.valueOf(tod.getCommodityPrice())+" 万");
- cdb.setDiscountPrice(String.valueOf(tod.getDiscountPrice()).equals("0")?"面议":String.valueOf(tod.getDiscountPrice())+" 万");
- cdb.setCommodityId(tod.getCommodityId());
- cdb.setCommodityName(tod.getCommodityName());
- cdb.setCommodityMode(tod.getCommodityMode());
- cdb.setCommodityType(tod.getCommodityType());
- cdb.setCommodityQuantity(tod.getCommodityQuantity());
- commoditys.add(cdb);
- }
- bo.setCommoditys(commoditys);
- boList.add(bo);
- }
- }
- result.setList(boList);
- result.setPageNo(data.getPageNo());
- result.setPageSize(data.getPageSize());
- result.setTotalCount(data.getTotalCount());
- result.setFilterNo(data.getFilterNo());
- return result;
- }
- @Override
- public C2BOrderDetailBo selectOrderDetail(String orderNo) {
- TOrder t = tOrderMapper.selectByPrimaryKey(orderNo);
- C2BOrderDetailBo bo = new C2BOrderDetailBo();
- bo.setOrderNo(String.valueOf(t.getOrderNo()));
- bo.setOrderRemarks(t.getOrderRemarks());
- bo.setOrderStatus(OrderState.getStatus(t.getOrderStatus()).getDesc());
- bo.setCreateTime(DateUtils.formatDate(t.getCreateTime(),AFTConstants.YYYYMMDDHHMMSS));
- bo.setOrderAmount(String.valueOf(t.getOrderAmount()).equals("0")?"面议":String.valueOf(t.getOrderAmount())+" 万");
- bo.setFirstPayment(String.valueOf(t.getFirstPayment()).equals("0")?"面议":String.valueOf(t.getFirstPayment())+" 万");
- bo.setOperatorActive(setOperatorActive(t));
- List<CommodityDetailBo> commoditys = new ArrayList<CommodityDetailBo>();
- CommodityDetailBo cdb = null;
- List<TOrderDetail> tdList = tOrderMapper.selectOrderCommodity(String.valueOf(t.getOrderNo()));
- for(TOrderDetail tod : tdList ){
- cdb = new CommodityDetailBo();
- cdb.setCommodityPrice(String.valueOf(tod.getCommodityPrice()).equals("0")?"面议":String.valueOf(tod.getCommodityPrice())+" 万");
- cdb.setDiscountPrice(String.valueOf(tod.getDiscountPrice()).equals("0")?"面议":String.valueOf(tod.getDiscountPrice())+" 万");
- cdb.setCommodityId(tod.getCommodityId());
- cdb.setCommodityName(tod.getCommodityName());
- cdb.setCommodityMode(tod.getCommodityMode());
- cdb.setCommodityType(tod.getCommodityType());
- cdb.setCommodityQuantity(tod.getCommodityQuantity());
- commoditys.add(cdb);
- }
- bo.setCommoditys(commoditys);
- return bo;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<BillListBo> selectOrderBillList(String orderNo,Integer pageNo,Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- if(orderNo != null) params.put("orderNo", orderNo);
- params.put("uid", TokenManager.getUserId());
- Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectOrderBillByPage","selectOrderBillCount", params, pageNo, pageSize);
- List<BillListBo> list = (List<BillListBo>)data.getList();
- if(list.size()>0){
- for(BillListBo bo:list){
- bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
- }
- }
- data.setList(list);
- return data;
- }
- @Override
- @Transactional
- public int updateApplyForWithdraw(String orderNo,String remarks) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- BigDecimal transactionAmount = tOrder.getActuallyTotalAmount().subtract(tOrder.getActuallyBrokerageAmount());
- addFundRecord(orderNo, TokenManager.getUserToken().getNickname(), TokenManager.getUserId(), DEFAULT_PLATFORM_ID, remarks,
- TransactionSubject.SUPPLY_COLLECT, PayChannel.UNIONPAY,transactionAmount,TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
- setOrderState(OrderAction.APPLY_FOR_WITHDRAW, new BigDecimal(0), tOrder, false);
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
- @Override
- @Transactional
- //to update 18
- public int updateApplyForCancel(String orderNo) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- setOrderState(OrderAction.APPLY_FOR_CANCEL, new BigDecimal(0), tOrder, false);
- if(true){ //退款
- BigDecimal transactionAmount = tOrder.getActuallyTotalAmount().subtract(tOrder.getActuallyBrokerageAmount());
- addFundRecord(orderNo, "平台方", DEFAULT_PLATFORM_ID,TokenManager.getUserId(), "买家取消订单",
- TransactionSubject.REFUND, PayChannel.UNIONPAY,transactionAmount,TransactionMode.OFFLINE, AuditState.WAIT_AUDIT);
- }
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
- /**
- *
- * @param transactionSubject 交易科目
- * @param transactionAmount 交易金额
- * @param payeeId 收款人
- * @param payerId 付款人
- * @return
- */
- private String setBusinessDesc(Integer transactionSubject,BigDecimal transactionAmount){
- String result = "";
- if(transactionSubject == TransactionSubject.SUPPLY_COLLECT.getCode() || transactionSubject == TransactionSubject.REFUND.getCode()){
- result = "收入-"+transactionAmount;
- }else if(transactionSubject == TransactionSubject.SUPPLY_PAY.getCode()){
- result = "支出-"+transactionAmount;
- }
- return result;
- }
- @Override
- public int updateConfirmIntention(String orderNo, boolean confirm) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- setOrderState(OrderAction.CONFIRM_INTENTION, new BigDecimal(0), tOrder, confirm);
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
- /*
- * -------------------------------------------------- 后台管理端 --------------------------------------------------------
- */
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<OrderListBo> selectServiceOrder(OrderListBo bo,String startDate,String endDate,Integer intention,Integer formal,
- Integer pageNo, Integer pageSize) {
- Map<String,Object> params = disposeParams(bo,startDate,endDate);
- params.put("salesmanId", TokenManager.getAdminId());
- if((1 == intention && 0 == formal) || ( 0 == intention && 1 == formal)){
- params.put("intention", intention);
- params.put("formal", formal);
- }else if(0 == intention && 0 == formal){
- return new Pagination<OrderListBo>();
- }
- Pagination<OrderListBo> data = (Pagination<OrderListBo>)findPage("selectServiceOrderByPage","selectServiceOrderCount",
- params, pageNo, pageSize);
- return data;
- }
-
- private Map<String,Object> disposeParams(OrderListBo bo,String startDate,String endDate){
- Map<String,Object> params = new HashMap<>();
- if(StringUtils.isNotBlank(bo.getBuyerName())) params.put("buyerName", bo.getBuyerName());
- if(StringUtils.isNotBlank(startDate)) params.put("startDate", startDate +" 00:00:00");
- if(StringUtils.isNotBlank(endDate)) params.put("endDate", endDate + "23:59:59");
- if(bo.getOrderStatus() != null) params.put("orderStatus", bo.getOrderStatus());
- if(bo.getLiquidationStatus() != null) params.put("liquidationStatus", bo.getLiquidationStatus());
- if(bo.getProjectStage() != null) params.put("projectStage", bo.getProjectStage());
- if(bo.getOrderChannel() != null) params.put("orderChannel", bo.getOrderChannel());
-
- return params;
- }
- @Override
- public ServiceOrderDetailBo selectServiceOrderDetail(String orderNo) {
- return tOrderMapper.selectServiceOrderDetail(orderNo);
- }
- @Override
- public int updateServiceOrder(String orderNo, String firstPayment, String orderAmount, String signFirstPayment,
- String signTotalAmount, String orderRemarks) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- checkOrder(tOrder);
- boolean flag = false;
- if (new BigDecimal(firstPayment).compareTo(tOrder.getFirstPayment()) != 0)
- flag = true;
- if (new BigDecimal(orderAmount).compareTo(tOrder.getOrderAmount()) != 0)
- flag = true;
- if (new BigDecimal(signFirstPayment).compareTo(tOrder.getSignFirstPayment()) != 0)
- flag = true;
- if (new BigDecimal(signTotalAmount).compareTo(tOrder.getSignTotalAmount()) != 0)
- flag = true;
- if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() || flag) {
- throw new BusinessException(new Error(ErrorConstants.ORDER_CAN_NOT_MODIFY, orderNo, ""));
- }
- tOrder.setFirstPayment(new BigDecimal(firstPayment));
- tOrder.setOrderAmount(new BigDecimal(orderAmount));
- tOrder.setSignFirstPayment(new BigDecimal(signFirstPayment));
- tOrder.setSignTotalAmount(new BigDecimal(signTotalAmount));
- tOrder.setOrderRemarks(orderRemarks);
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
- @Override
- public int updateSignServiceOrder(String orderNo, String signFirstPayment, String signTotalAmount,String approval,
- String orderRemarks) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- checkOrder(tOrder);
- if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() // 等待签单- 跟单中
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()) {
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo, ""));
- } else {
- if (tOrder.getLiquidationStatus() != LiquidationState.ALREADY_PAY.getCode() // 已经付款 or 特批
- && Integer.valueOf(approval) != ApprovalState.WAIT_AUDIT.getCode())
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo, ""));
- tOrder.setSignFirstPayment(new BigDecimal(signFirstPayment));
- tOrder.setSignTotalAmount(new BigDecimal(signTotalAmount));
- tOrder.setOrderStage(OrderStage.SIGNED.getCode());
- tOrder.setOrderStatus(OrderState.ALREADY_SIGN.getCode());
- tOrder.setProjectStage(ProjectStage.WAIT_SET_UP.getCode());
- tOrder.setApproval(Integer.valueOf(approval));
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- }
- return 1;
- }
- @Override
- public int updateRevokeOrder(String orderNo) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- boolean flag = true;
- if(tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_BEFORE_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.BUYER_CANCEL_AFTER_SIGN.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_REFUSE_BEFORE_SIGNL.getCode()
- && tOrder.getOrderStatus() != OrderState.SELLER_CANCEL_AFTER_SIGN.getCode()){
- flag = false;
- }
- if(flag && tOrder.getActuallyTotalAmount().doubleValue() == 0){
- tOrder.setDeleteSign(ActiveState.ABOLISH.getCode());
- }else{
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT,"作废"));
- }
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
-
- public void checkOrder(TOrder tOrder){
- if(tOrder == null)
- throw new BusinessException(new Error(ErrorConstants.ORDER_NOT_EXIST, tOrder.getOrderNo(),""));
- if(tOrder.getDeleteSign() == ActiveState.ABOLISH.getCode())
- throw new BusinessException(new Error(ErrorConstants.ORDER_ALREADY_FREEZE, tOrder.getOrderNo(),""));
- if(tOrder.getDeleteSign() == ActiveState.LOCKING.getCode())
- throw new BusinessException(new Error(ErrorConstants.ORDER_ALREADY_REVOKE, tOrder.getOrderNo(),""));
- }
- @Override
- @Transactional
- public int addOrderCommodity(String orderNo, String commodityId,String commodityName, String commodityMode, Integer commodityQuantity,Integer commodityType,
- String commodityPrice, String discountPrice,String commodityFirstPayment,String discountFirstPayment, String remarks) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- checkOrder(tOrder);
- if(tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() //等待签单 + 跟单中
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo,""));
- }else{
- TOrderDetail detail = new TOrderDetail();
- detail.setId(UUID.randomUUID().toString());
- detail.setOrderNo(orderNo);
- detail.setCommodityId(commodityId);
- detail.setCommodityQuantity(commodityQuantity);
- detail.setCommodityType(commodityType);
- detail.setCommodityMode(StringUtils.isBlank(commodityMode)?DEFAULT_COMMODITY_MODE:commodityMode);
- detail.setCommodityPrice(new BigDecimal(commodityPrice));
- detail.setDiscountPrice(new BigDecimal(discountPrice));
- detail.setCommodityFirstPayment(new BigDecimal(commodityFirstPayment));
- detail.setDiscountFirstPayment(new BigDecimal(discountFirstPayment));
- detail.setRemarks(remarks);
- tOrderDetailMapper.insert(detail);
- //订单市场价总额
- BigDecimal totalAmountChange = new BigDecimal(commodityPrice).multiply(new BigDecimal(commodityQuantity));
- //订单市场价首付金额
- BigDecimal firstPaymentChange = new BigDecimal(commodityFirstPayment).multiply(new BigDecimal(commodityQuantity));
- //订单签单总额
- BigDecimal signTotalAmountChange = new BigDecimal(discountPrice).multiply(new BigDecimal(commodityQuantity));
- //订单签单首付金额
- BigDecimal signFirstPaymentChange = new BigDecimal(discountFirstPayment).multiply(new BigDecimal(commodityQuantity));
- tOrder.setOrderAmount(tOrder.getOrderAmount().add(totalAmountChange));
- tOrder.setFirstPayment(tOrder.getFirstPayment().add(firstPaymentChange));
- tOrder.setSignTotalAmount(tOrder.getSignTotalAmount().add(signTotalAmountChange));
- tOrder.setSignFirstPayment(tOrder.getSignFirstPayment().add(signFirstPaymentChange));
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- }
- return 1;
- }
- @Override
- @Transactional
- public int updateOrderCommodity(String detailId,String commodityId, String commodityName,String commodityMode, Integer commodityQuantity,Integer commodityType,
- String commodityPrice, String discountPrice,String commodityFirstPayment,String discountFirstPayment,String remarks) {
- TOrderDetail oldDetail = tOrderDetailMapper.selectByPrimaryKey(detailId);
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(oldDetail.getOrderNo());
- checkOrder(tOrder);
- if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() // 等待签单 - 跟单中
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()) {
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, oldDetail.getOrderNo(), ""));
- } else {
- TOrderDetail detail = new TOrderDetail();
- detail.setId(detailId);
- detail.setOrderNo(oldDetail.getOrderNo());
- detail.setCommodityId(commodityId);
- detail.setCommodityQuantity(commodityQuantity);
- detail.setCommodityType(commodityType);
- detail.setCommodityMode(StringUtils.isBlank(commodityMode) ? DEFAULT_COMMODITY_MODE : commodityMode);
- detail.setCommodityPrice(new BigDecimal(commodityPrice));
- detail.setDiscountPrice(new BigDecimal(discountPrice));
- detail.setCommodityFirstPayment(new BigDecimal(commodityFirstPayment));
- detail.setDiscountFirstPayment(new BigDecimal(discountFirstPayment));
- detail.setRemarks(remarks);
- tOrderDetailMapper.insert(detail);
- new BigDecimal(discountFirstPayment).multiply(new BigDecimal(commodityQuantity)).subtract(
- oldDetail.getDiscountFirstPayment().multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
- // 订单市场价总额
- BigDecimal totalAmountChange = new BigDecimal(commodityPrice).multiply(new BigDecimal(commodityQuantity))
- .subtract(oldDetail.getCommodityPrice().multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
- // 订单市场价首付金额
- BigDecimal firstPaymentChange = new BigDecimal(commodityFirstPayment)
- .multiply(new BigDecimal(commodityQuantity)).subtract(oldDetail.getCommodityFirstPayment()
- .multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
- // 订单签单总额
- BigDecimal signTotalAmountChange = new BigDecimal(discountPrice).multiply(new BigDecimal(commodityQuantity))
- .subtract(oldDetail.getDiscountPrice().multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
- // 订单签单首付金额
- BigDecimal signFirstPaymentChange = new BigDecimal(discountFirstPayment)
- .multiply(new BigDecimal(commodityQuantity)).subtract(oldDetail.getDiscountFirstPayment()
- .multiply(new BigDecimal(oldDetail.getCommodityQuantity())));
- tOrder.setOrderAmount(tOrder.getOrderAmount().add(totalAmountChange));
- tOrder.setFirstPayment(tOrder.getFirstPayment().add(firstPaymentChange));
- tOrder.setSignTotalAmount(tOrder.getSignTotalAmount().add(signTotalAmountChange));
- tOrder.setSignFirstPayment(tOrder.getSignFirstPayment().add(signFirstPaymentChange));
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- }
- return 1;
- }
- @Override
- public int deleteOrderCommodity(String detailId) {
- TOrderDetail detail = tOrderDetailMapper.selectByPrimaryKey(detailId);
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(detail.getOrderNo());
- checkOrder(tOrder);
- if (tOrder.getOrderStatus() != OrderState.WAIT_FOR_SIGN.getCode() // 等待签单 - 跟单中
- || tOrder.getOrderStage() != OrderStage.FOLLOWING.getCode()) {
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, detail.getOrderNo(), ""));
- } else {
- BigDecimal totalAmountChange = detail.getCommodityPrice()
- .multiply(new BigDecimal(detail.getCommodityQuantity()));
- BigDecimal firstPaymentChange = detail.getCommodityFirstPayment()
- .multiply(new BigDecimal(detail.getCommodityQuantity()));
- BigDecimal signTotalAmountChange = detail.getDiscountPrice()
- .multiply(new BigDecimal(detail.getCommodityQuantity()));
- BigDecimal signFirstPaymentChange = detail.getCommodityFirstPayment()
- .multiply(new BigDecimal(detail.getCommodityQuantity()));
- tOrder.setOrderAmount(tOrder.getOrderAmount().subtract(totalAmountChange));
- tOrder.setFirstPayment(tOrder.getFirstPayment().subtract(firstPaymentChange));
- tOrder.setSignTotalAmount(tOrder.getSignTotalAmount().subtract(signTotalAmountChange));
- tOrder.setSignFirstPayment(tOrder.getSignFirstPayment().subtract(signFirstPaymentChange));
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- tOrderDetailMapper.deleteByPrimaryKey(detailId);
- }
- return 1;
- }
-
- @Override
- public List<OrganizationManagement> selectMyDaeps(){
- if(TokenManager.hasRole(AFTConstants.SUPERADMIN) || TokenManager.hasRole(AFTConstants.APPROVAL_DECISION))
- return organizationManagementMapper.selectAllDeps();
- else
- return selectCurrentDep(TokenManager.getAdminId());
- }
-
- private List<OrganizationManagement> selectSubDeps(List<OrganizationManagement> allData,List<OrganizationManagement> superData){
- List<OrganizationManagement> subData = new ArrayList<>();
- String superIds = "";
- for(OrganizationManagement om : superData){
- if(!om.getId().equals(om.getSuperId())){
- superIds += om.getSuperId() + ",";
- }
- }
- if(StringUtils.isNotBlank(superIds)) subData = organizationManagementMapper.selectSubDeps(superIds.substring(0, superIds.length()-1));
- if(subData != null && subData.size()>0) {
- allData.addAll(subData);
- selectSubDeps(allData,subData);
- }
- return allData;
- }
-
- private List<OrganizationManagement> selectCurrentDep(String managerId){
- List<OrganizationManagement> allData = new ArrayList<OrganizationManagement>();
- List<OrganizationManagement> superData = organizationManagementMapper.selectCurrentDeps(managerId);
- if(superData != null && superData.size()>0){
- allData.addAll(superData);
- }
- selectSubDeps(allData,superData);
- return allData;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<OrderListBo> selectDepServiceOrder(OrderListBo bo, String startDate, String endDate,
- Integer intention, Integer formal, String depIds,Integer pageNo, Integer pageSize) {
- Map<String,Object> params = disposeParams(bo,startDate,endDate);
- if(StringUtils.isNotBlank(depIds)) {
- params.put("depIds", depIds);
- }else{
- if(!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.APPROVAL_DECISION))
- return new Pagination<OrderListBo>();
- }
- if((1 == intention && 0 == formal) || ( 0 == intention && 1 == formal)){
- params.put("intention", intention);
- params.put("formal", formal);
- }else if(0 == intention && 0 == formal){
- return new Pagination<OrderListBo>();
- }
- return (Pagination<OrderListBo>)findPage("selectServiceOrderByPage","selectServiceOrderCount",
- params, pageNo, pageSize);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<OrderListBo> selectApprovalServiceOrder(OrderListBo bo, String startDate, String endDate,
- String depIds,Integer approvalHistory, Integer pageNo, Integer pageSize) {
- Map<String,Object> params = disposeParams(bo,startDate,endDate);
- if(StringUtils.isNotBlank(depIds)) {
- params.put("depIds", depIds);
- }else{
- if(!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.APPROVAL_DECISION))
- return new Pagination<OrderListBo>();
- }
- if(approvalHistory != null){
- params.put("approvalHistory", approvalHistory);
- }
- return (Pagination<OrderListBo>)findPage("selectServiceOrderByPage","selectServiceOrderCount",
- params, pageNo, pageSize);
- }
- @Override
- public int createServiceOrder(String uid, Integer orderType) {
- TOrder tOrder = new TOrder();
- tOrder.setOrderNo(idGenerator.generateId().toString());
- tOrder.setCreater(TokenManager.getAdminId());
- tOrder.setCreateTime(new Date());
- tOrder.setBuyerId(uid);
- tOrder.setSellerId(DEFAULT_PLATFORM_ID);
- tOrder.setBrokerageAmount(new BigDecimal(0));
- tOrder.setFirstPayment(new BigDecimal(0));
- tOrder.setOrderAmount(new BigDecimal(0));
- tOrder.setOrderRemarks("");
- tOrder.setDeleteSign(ActiveState.NORMAL.getCode());
- tOrder.setOrderChannel(OrderChannel.PORTAL.getCode());
- setOrderState(OrderAction.ADD_INTENTION, new BigDecimal(0), tOrder, false);
- return tOrderMapper.insert(tOrder);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<OrderListBo> listPublicOrder(Integer pageNo, Integer pageSize) {
- return (Pagination<OrderListBo>)findPage("selectPublicOrderByPage","selectPublicOrderCount",
- null, pageNo, pageSize);
- }
- @Override
- public int updateAppointSalesman(String orderNo, String salesmanId) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- checkOrder(tOrder);
- tOrder.setSalesmanId(salesmanId);
- tOrder.setUpdateTime(new Date());
- return tOrderMapper.updateByPrimaryKeySelective(tOrder);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<BillListBo> selectMySettlementList(String payeeName, String payerName, String depId,
- String salesmanName, String orderNo, Integer pageNo, Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- if(StringUtils.isNotBlank(payerName)) params.put("payeeName", payeeName);
- if(StringUtils.isNotBlank(payerName)) params.put("payerName", payerName);
- if(StringUtils.isNotBlank(depId)) params.put("depId", depId);
- if(StringUtils.isNotBlank(salesmanName)) params.put("salesmanName", salesmanName);
- if(orderNo != null) params.put("orderNo", orderNo);
- /** 特殊处理字段开始 **/
- if(!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
- params.put("isFinance", 1);
- }
- params.put("aid", TokenManager.getAdminId());
- /** 特殊处理字段结束 **/
- Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectBillByPage","selectBillCount", params, pageNo, pageSize);
- List<BillListBo> list = (List<BillListBo>)data.getList();
- if(list.size()>0){
- for(BillListBo bo:list){
- bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
- }
- }
- data.setList(list);
- return data;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<BillListBo> selectMyBillList(String payeeName, String payerName, String depId,
- String salesmanName,String orderNo, Integer pageNo, Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- if(StringUtils.isNotBlank(payerName)) params.put("payeeName", payeeName);
- if(StringUtils.isNotBlank(payerName)) params.put("payerName", payerName);
- if(StringUtils.isNotBlank(depId)) params.put("depId", depId);
- if(StringUtils.isNotBlank(salesmanName)) params.put("salesmanName", salesmanName);
- if(orderNo != null) params.put("orderNo", orderNo);
- /** 特殊处理字段开始 **/
- if(!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
- params.put("isFinance", 0);
- }
- params.put("aid", TokenManager.getAdminId());
- /** 特殊处理字段结束 **/
- Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectBillByPage","selectBillCount", params, pageNo, pageSize);
- List<BillListBo> list = (List<BillListBo>)data.getList();
- if(list.size()>0){
- for(BillListBo bo:list){
- bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
- }
- }
- data.setList(list);
- return data;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<BillListBo> selectAllBillList(String payeeName, String payerName, String depId,
- String salesmanName ,String financeName, String orderNo, Integer pageNo, Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- if(StringUtils.isNotBlank(payerName)) params.put("payeeName", payeeName);
- if(StringUtils.isNotBlank(payerName)) params.put("payerName", payerName);
- if(StringUtils.isNotBlank(depId)) params.put("depId", depId);
- if(StringUtils.isNotBlank(salesmanName)) params.put("salesmanName", salesmanName);
- if(StringUtils.isNotBlank(financeName)) params.put("financeName", financeName);
- if(orderNo != null) params.put("orderNo", orderNo);
- Pagination<BillListBo> data = (Pagination<BillListBo>)findPage("selectBillByPage","selectBillCount", params, pageNo, pageSize);
- List<BillListBo> list = (List<BillListBo>)data.getList();
- if(list.size()>0){
- for(BillListBo bo:list){
- bo.setBusinessDesc(setBusinessDesc(bo.getTransactionSubject(),bo.getTransactionAmount()));
- }
- }
- data.setList(list);
- return data;
- }
- @Override
- public BillDetailBo selectBillDetail(String billNo) {
- return tOrderMapper.selectBillDetail(billNo);
- }
- @Override
- @Transactional
- public int updateBill(String billNo, String orderNo, Integer confrim,String financialPayNo,String financialPayTime,String remarks) {
- TOrderBill bill = tOrderBillMapper.selectByPrimaryKey(billNo);
- TOrder order = tOrderMapper.selectByPrimaryKey(orderNo);
- if(bill != null && order != null){
- bill.setBillNo(billNo);
- bill.setFinancialPayNo(financialPayNo);
- try {
- bill.setFinancialPayTime(DateUtils.parseDate(financialPayTime, AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- bill.setRemarks(remarks);
- if(confrim == AFTConstants.YES){
- bill.setConfirmSign(AuditState.AUDIT_SUCCESS.getCode());
- checkOrder(order);
- if(order.getLiquidationStatus() == LiquidationState.WAIT_PAY_FIRST_BALANCE.getCode())
- setOrderState(OrderAction.CONFIRM_PAY_FOR_FIRST, bill.getTransactionAmount(), order, false);
- if(order.getLiquidationStatus() == LiquidationState.WAIT_PAY_LAST_BALANCE.getCode())
- setOrderState(OrderAction.CONFIRM_PAY_FOR_LAST, bill.getTransactionAmount(), order, false);
- order.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(order);
- }else if(confrim == AFTConstants.NO){
- bill.setConfirmSign(AuditState.AUDIT_FAIL.getCode());
- bill.setDeleteSign(Boolean.TRUE);
- }
- tOrderBillMapper.updateByPrimaryKey(bill);
- }
- return 1;
- }
- @Override
- public int updateBill(String billNo, String financialPayNo, String financialPayTime, String remarks) {
- TOrderBill bill = new TOrderBill();
- bill.setBillNo(billNo);
- bill.setFinancialPayNo(financialPayNo);
- try {
- bill.setFinancialPayTime(DateUtils.parseDate(financialPayTime, AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- bill.setRemarks(remarks);
- tOrderBillMapper.updateByPrimaryKey(bill);
- return 1;
- }
- @Override
- public int approvalServiceOrder(String orderNo, Integer confirm) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- checkOrder(tOrder);
- if(tOrder.getProjectStage() != ProjectStage.NOT_SATISFY_CONDITION.getCode()
- || tOrder.getOrderStatus() != OrderState.ALREADY_SIGN.getCode()
- || tOrder.getOrderStage() != OrderStage.SIGNED.getCode()
- || tOrder.getApproval() != ApprovalState.WAIT_AUDIT.getCode()){
- throw new BusinessException(new Error(ErrorConstants.NOT_ACCORD_WITH_NEXT, orderNo , ""));
- }
- tOrder.setUpdateTime(new Date());
- if(confirm == AFTConstants.YES){
- tOrder.setApproval(ApprovalState.AUDIT_PASS.getCode());
- tOrder.setProjectStage(ProjectStage.WAIT_SET_UP.getCode());
- }else if(confirm == AFTConstants.NO){
- tOrder.setApproval(ApprovalState.AUDIT_REFUSE.getCode());
- }
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- return 1;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<OrderListBo> listSetUpServiceOrder(String buyerName,String salesmanName, String financeName,
- String depId,Integer approval, Integer pageNo, Integer pageSize) {
- Map<String,Object> params = new HashMap<String,Object>();
- if(StringUtils.isNotBlank(buyerName))
- params.put("buyerName", buyerName);
- if(StringUtils.isNotBlank(salesmanName))
- params.put("salesmanName", salesmanName);
- if(StringUtils.isNotBlank(financeName))
- params.put("financeName",financeName);
- if(StringUtils.isNotBlank(depId))
- params.put("depId", depId);
- if(approval != null)
- params.put("approval", approval);
- return (Pagination<OrderListBo>)findPage("selectSetUpServiceOrderByPage","selectSetUpServiceOrderCount",
- params, pageNo, pageSize);
- }
- @Override
- @Transactional
- public int setUpProject(String orderNo, String signDate, String signComment) {
- TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderNo);
- checkOrder(tOrder);
- boolean flag = false;
- if(tOrder.getOrderStatus() == OrderState.ALREADY_SIGN.getCode()){
- if(tOrder.getLiquidationStatus() == LiquidationState.WAIT_PAY_LAST_BALANCE.getCode())
- flag = true;
- if(tOrder.getLiquidationStatus() == LiquidationState.ALREADY_PAY.getCode())
- flag = true;
- if(tOrder.getApproval() == ApprovalState.AUDIT_PASS.getCode())
- flag = true;
- }
- if(!flag)
- throw new BusinessException(new Error(ErrorConstants.ORDER_CAN_NOT_MODIFY, orderNo, ""));
- tOrder.setProjectStage(ProjectStage.ALREADY_SET_UP.getCode());
- tOrder.setUpdateTime(new Date());
- tOrderMapper.updateByPrimaryKeySelective(tOrder);
- //-------------- 查询订单详情 --------------------------
- List<TOrderDetail> orderDetailList = tOrderMapper.selectOrderCommodity(orderNo);
- List<ContractDetail> contractDetailList = new ArrayList<>();
- ContractDetail contractDetail = null;
- Date createTime = new Date();
- String contractId = UUID.randomUUID().toString(); //合同ID
- Contract contract = new Contract();
- contract.setId(contractId);
- contract.setCreateTime(createTime);
- contract.setType(tOrder.getOrderType());
- contract.setSignDate(createTime);
- contract.setOrderNo(orderNo);
- contract.setStatus(ProjectStage.ALREADY_SET_UP.getCode());
- contract.setUid(tOrder.getBuyerId());
- contractMapper.insert(contract);
- for(TOrderDetail orderDetail: orderDetailList){
- for(int i=0; i<orderDetail.getCommodityQuantity();i++){
- contractDetail = new ContractDetail();
- contractDetail.setId(UUID.randomUUID().toString());
- contractDetail.setCommodityId(orderDetail.getCommodityId());
- contractDetail.setCommodityMode(orderDetail.getCommodityMode());
- contractDetail.setCommodityName(orderDetail.getCommodityName());
- contractDetail.setCommodityType(orderDetail.getCommodityType());
- contractDetail.setCommodityQuantity(1);
- contractDetail.setCreateTime(createTime);
- contractDetail.setContractId(contractId);
- contractDetailList.add(contractDetail);
- }
- }
- contractMapper.batchInsertContractDetail(contractDetailList);
- return 1;
- }
- }
|