View Javadoc
1   package com.foxinmy.weixin4j.pay.payment.mch;
2   
3   import com.alibaba.fastjson.annotation.JSONField;
4   import com.foxinmy.weixin4j.pay.payment.coupon.OrderCouponInfo;
5   import com.foxinmy.weixin4j.pay.type.BankType;
6   import com.foxinmy.weixin4j.pay.type.CurrencyType;
7   import com.foxinmy.weixin4j.pay.type.TradeState;
8   import com.foxinmy.weixin4j.pay.type.TradeType;
9   import com.foxinmy.weixin4j.util.DateUtil;
10  import com.foxinmy.weixin4j.xml.ListsuffixResult;
11  
12  import javax.xml.bind.annotation.XmlAccessType;
13  import javax.xml.bind.annotation.XmlAccessorType;
14  import javax.xml.bind.annotation.XmlElement;
15  import javax.xml.bind.annotation.XmlRootElement;
16  import java.util.Date;
17  import java.util.List;
18  
19  /**
20   * 订单信息
21   * 
22   * @className Order
23   * @author jinyu(foxinmy@gmail.com)
24   * @date 2014年11月2日
25   * @since JDK 1.6
26   * @see
27   */
28  @XmlRootElement
29  @XmlAccessorType(XmlAccessType.FIELD)
30  public class Order extends MerchantTradeResult {
31  
32  	private static final long serialVersionUID = 5636828325595317079L;
33  	/**
34  	 * 交易状态
35  	 * 
36  	 * @see TradeState
37  	 */
38  	@XmlElement(name = "trade_state")
39  	@JSONField(name = "trade_state")
40  	private String tradeState;
41  	/**
42  	 * 用户的openid
43  	 */
44  	@XmlElement(name = "openid")
45  	@JSONField(name = "openid")
46  	private String openId;
47  	/**
48  	 * 用户是否关注公众账号,Y- 关注,N-未关注,仅在公众 账号类型支付有效
49  	 */
50  	@XmlElement(name = "is_subscribe")
51  	@JSONField(name = "is_subscribe")
52  	private String isSubscribe;
53  	/**
54  	 * 交易类型
55  	 *
56  	 * @see TradeType
57  	 */
58  	@XmlElement(name = "trade_type")
59  	@JSONField(name = "trade_type")
60  	private String tradeType;
61  	/**
62  	 * 银行类型
63  	 */
64  	@XmlElement(name = "bank_type")
65  	@JSONField(name = "bank_type")
66  	private String bankType;
67  
68  	/**
69  	 * 现金支付货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
70  	 * 
71  	 * @see com.foxinmy.weixin4j.pay.type.CurrencyType
72  	 */
73  	@XmlElement(name = "cash_fee_type")
74  	@JSONField(name = "cash_fee_type")
75  	private String cashFeeType;
76  	/**
77  	 * 代金券金额:“代金券”金额<=订单金额,订单金额-“代金券”金额=现金支付金额
78  	 */
79  	@XmlElement(name = "coupon_fee")
80  	@JSONField(name = "coupon_fee")
81  	private Integer couponFee;
82  	/**
83  	 * 代金券或立减优惠使用数量
84  	 */
85  	@XmlElement(name = "coupon_count")
86  	@JSONField(name = "coupon_count")
87  	private Integer couponCount;
88  	/**
89  	 * 代金券信息 验证签名有点麻烦
90  	 */
91  	@ListsuffixResult
92  	private List<OrderCouponInfo> couponList;
93  	/**
94  	 * 商家数据包
95  	 */
96  	private String attach;
97  	/**
98  	 * 支付完成时间,格式为 yyyyMMddhhmmss
99  	 */
100 	@XmlElement(name = "time_end")
101 	@JSONField(name = "time_end")
102 	private String timeEnd;
103 	/**
104 	 * 交易状态描述
105 	 */
106 	@XmlElement(name = "trade_state_desc")
107 	@JSONField(name = "trade_state_desc")
108 	private String tradeStateDesc;
109 
110 	/**
111 	 * 用户在子商户下的openid
112 	 */
113 	@XmlElement(name = "sub_openid")
114 	@JSONField(name = "sub_openid")
115 	private String subOpenId;
116 	/**
117 	 * 是否关注子公众账号,Y- 关注,N-未关注,仅在公众 账号类型支付有效
118 	 */
119 	@XmlElement(name = "sub_is_subscribe")
120 	@JSONField(name = "sub_is_subscribe")
121 	private String subIsSubscribe;
122 
123 	protected Order() {
124 		// jaxb required
125 	}
126 
127 	@JSONField(serialize = false)
128 	public TradeState getFormatTradeState() {
129 		return tradeState != null ? TradeState
130 				.valueOf(tradeState.toUpperCase()) : null;
131 	}
132 
133 	public String getOpenId() {
134 		return openId;
135 	}
136 
137 	public void setOpenId(String openId) {
138 		this.openId = openId;
139 	}
140 
141 	public String getIsSubscribe() {
142 		return isSubscribe;
143 	}
144 
145 	public void setIsSubscribe(String isSubscribe) {
146 		this.isSubscribe = isSubscribe;
147 	}
148 
149 	@JSONField(serialize = false)
150 	public boolean getFormatIsSubscribe() {
151 		return isSubscribe != null && isSubscribe.equalsIgnoreCase("y");
152 	}
153 
154 	@JSONField(serialize = false)
155 	public TradeType getFormatTradeType() {
156 		return tradeType != null ? TradeType.valueOf(tradeType.toUpperCase())
157 				: null;
158 	}
159 
160 	public String getBankType() {
161 		return bankType;
162 	}
163 
164 	public void setBankType(String bankType) {
165 		this.bankType = bankType;
166 	}
167 
168 	@JSONField(serialize = false)
169 	public BankType getFormatBankType() {
170 		return bankType != null ? BankType.valueOf(bankType.toUpperCase())
171 				: null;
172 	}
173 
174 	public Integer getCouponFee() {
175 		return couponFee;
176 	}
177 
178 	public void setCouponFee(Integer couponFee) {
179 		this.couponFee = couponFee;
180 	}
181 
182 	/**
183 	 * <font color="red">调用接口获取单位为分,get方法转换为元方便使用</font>
184 	 * 
185 	 * @return 元单位
186 	 */
187 	@JSONField(serialize = false)
188 	public double getFormatCouponFee() {
189 		return couponFee != null ? couponFee / 100d : 0d;
190 	}
191 
192 	public Integer getCouponCount() {
193 		return couponCount;
194 	}
195 
196 	public void setCouponCount(Integer couponCount) {
197 		this.couponCount = couponCount;
198 	}
199 
200 	public String getTradeState() {
201 		return tradeState;
202 	}
203 
204 	public void setTradeState(String tradeState) {
205 		this.tradeState = tradeState;
206 	}
207 
208 	public String getTradeType() {
209 		return tradeType;
210 	}
211 
212 	public void setTradeType(String tradeType) {
213 		this.tradeType = tradeType;
214 	}
215 
216 	public String getAttach() {
217 		return attach;
218 	}
219 
220 	public void setAttach(String attach) {
221 		this.attach = attach;
222 	}
223 
224 	public String getTimeEnd() {
225 		return timeEnd;
226 	}
227 
228 	public void setTimeEnd(String timeEnd) {
229 		this.timeEnd = timeEnd;
230 	}
231 
232 	@JSONField(serialize = false)
233 	public Date getFormatTimeEnd() {
234 		return timeEnd != null ? DateUtil.parse2yyyyMMddHHmmss(timeEnd) : null;
235 	}
236 
237 	public String getTradeStateDesc() {
238 		return tradeStateDesc;
239 	}
240 
241 	public void setTradeStateDesc(String tradeStateDesc) {
242 		this.tradeStateDesc = tradeStateDesc;
243 	}
244 
245 	public List<OrderCouponInfo> getCouponList() {
246 		return couponList;
247 	}
248 
249 	public void setCouponList(List<OrderCouponInfo> couponList) {
250 		this.couponList = couponList;
251 	}
252 
253 	public String getSubOpenId() {
254 		return subOpenId;
255 	}
256 
257 	public void setSubOpenId(String subOpenId) {
258 		this.subOpenId = subOpenId;
259 	}
260 
261 	public String getSubIsSubscribe() {
262 		return subIsSubscribe;
263 	}
264 
265 	public void setSubIsSubscribe(String subIsSubscribe) {
266 		this.subIsSubscribe = subIsSubscribe;
267 	}
268 
269 	@JSONField(serialize = false)
270 	public boolean getFormatSubIsSubscribe() {
271 		return subIsSubscribe != null && subIsSubscribe.equalsIgnoreCase("y");
272 	}
273 
274 	public String getCashFeeType() {
275 		return cashFeeType;
276 	}
277 
278 	public void setCashFeeType(String cashFeeType) {
279 		this.cashFeeType = cashFeeType;
280 	}
281 
282 	@JSONField(serialize = false)
283 	public CurrencyType getFormatCashFeeType() {
284 		return cashFeeType != null ? CurrencyType.valueOf(cashFeeType
285 				.toUpperCase()) : null;
286 	}
287 
288 	@Override
289 	public String toString() {
290 		return "Order [tradeState=" + tradeState + ", openId=" + openId
291 				+ ", isSubscribe=" + isSubscribe + ", tradeType=" + tradeType
292 				+ ", bankType=" + bankType + ", cashFeeType=" + cashFeeType
293 				+ ", couponFee=" + couponFee + ", couponCount=" + couponCount
294 				+ ", couponList=" + couponList + ", attach=" + attach
295 				+ ", timeEnd=" + timeEnd + ", tradeStateDesc=" + tradeStateDesc
296 				+ ", subOpenId=" + subOpenId + ", subIsSubscribe="
297 				+ subIsSubscribe + ", " + super.toString() + "]";
298 	}
299 }