一、java实现订单支付status逻辑,主要是通过位运算实现的,例:
二、可设置常量来进行状态判断:
public static final Long ORDER2_DELETED = (1L); //已删除
public static final Long ORDER2_CANCELLED = (1L << 1); //已取消
public static final Long ORDER2_ALLPAID = (1L << 6); //完成支付
public static final Long ORDER2_REFUNDED = (1L << 7); //已退款
public static final Long ORDER2_CANCEL_BYCUSTOMER = (1L << 8); //商家发起取消订单
public static final Long ORDER2_CANCEL_BYMERCHANT = (1L << 9); //消费者发起取消订单
public static final Long ORDER2_EXPRESS_FILLED = (1L << 10); //发货信息已填写
public static final Long ORDER2_GOODS_SENT = (1L << 11); //已完成发货
public static final Long ORDER2_GOODS_RECEIVED = (1L << 12); //消费者确认收货
public static final Long ORDER2_ORDER_COMPLETED = (1L << 13); //订单已完成
public static final Long ORDER2_PAIED_BYWECHAT = (1L << 16); //通过微信支付
public static final Long ORDER2_PAIED_BYALI = (1L << 17); //通过支付宝支付
三、通过从数据库中查询status值,与常量进行位运算,获取订单状态,如:
(1)订单已删除:if ( status & ORDER2_DELETED == ORDER2_DELETED) { return "已删除"; }
(2)订单已取消:if ( status & ORDER2_CANCELLED == ORDER2_CANCELLED) { return "已取消"; }
(3)订单待收货:if ( (status & ORDER2_ALLPAID) == ORDER2_ALLPAID && (status & ORDER2_GOODS_RECEIVED) != ORDER2_GOODS_RECEIVED) { return "待收货" ;}
(4)订单待付款:if ( (status & ORDER2_DELETED) != ORDER2_DELETED && (status & ORDER2_CANCELLED) != ORDER2_CANCELLED &&( status & ORDER2_ALLPAID) != ORDER2_ALLPAID ) { return "待付款" ;}
(5) 订单已完成:if ((status & ORDER2_ORDER_COMPLETED ) == ORDER2_ORDER_COMPLETED ) { return "订单已完成";}
四、订单状态对应的操作,可设常量辅助,如:
public static final Integer ORDERVO2_IMMEDIATE_PAY = 1;// 立即支付
public static final Integer ORDERVO2_GOODS_ORDER_CANCEL = (1 << 1); // 取消订单
public static final Integer ORDERVO2_BUY_AGAIN = (1 << 2); // 再次购买
public static final Integer ORDERVO2_ENSURE_TAKE_GODDS = (1 << 3); // 确认收货
(1)订单已删除:
(2)订单已取消:再次购买 { return buttonController = ORDERVO2_BUY_AGAIN }
(3) 订单待收货:确认收货,再次购买 { return buttonController = ORDERVO2_BUY_AGAIN | ORDERVO2_ENSURE_TAKE_GODDS }
(4) 订单待付款:取消订单、立即支付 { return buttonController = ORDERVO2_IMMEDIATE_PAY | ORDERVO2_GOODS_ORDER_CANCEL }
(5) 订单已完成:再次购买 { return buttonController = ORDERVO2_BUY_AGAIN }
五、前台根据获取的 订单状态,buttonController 进行位运算,进行后续逻辑。