View Javadoc
1   package com.foxinmy.weixin4j.model.card;
2   
3   import com.alibaba.fastjson.annotation.JSONField;
4   import com.foxinmy.weixin4j.type.card.CardType;
5   import com.foxinmy.weixin4j.type.card.SubCardType;
6   
7   /**
8    * 储值类礼品卡
9    *
10   * @author kit(kit.li@qq.com)
11   * @date 2018年10月26日
12   */
13  public class GiftCard extends CardCoupon {
14  
15      /**
16       * 子卡券类型
17       */
18      @JSONField(name = "sub_card_type")
19      private final String subCardType;
20      /**
21       * 礼品卡背景图片,非必需
22       */
23      @JSONField(name = "background_pic_url")
24      private String backgroundPicUrl;
25      /**
26       * 是否支持积分,填写true或者false。默认为false
27       */
28      @JSONField(name = "supply_bonus")
29      private boolean supplyBonus;
30      /**
31       * 是否支持余额,填写true或者false。默认为false
32       */
33      @JSONField(name = "supply_balance")
34      private boolean supplyBalance;
35      /**
36       * 自定义会员信息类目,会员卡激活后显示,包含name和url字段
37       */
38      @JSONField(name = "custom_field1")
39      private MemCardCustomField customField1;
40      /**
41       * 自定义会员信息类目,会员卡激活后显示,包含name和url字段
42       */
43      @JSONField(name = "custom_field2")
44      private MemCardCustomField customField2;
45      /**
46       * 自定义会员信息类目,会员卡激活后显示,包含name和url字段
47       */
48      @JSONField(name = "custom_field3")
49      private MemCardCustomField customField3;
50      /**
51       * 是否自动激活,若开发者不需要额外激活流程则填写true。
52       */
53      @JSONField(name = "auto_activate")
54      private boolean autoActivate;
55      /**
56       * 初始余额,用户购买礼品卡后卡面上显示的初始余额
57       */
58      @JSONField(name = "init_balance")
59      private Integer initBalance;
60  
61      public GiftCard(CouponBaseInfo baseInfo, GiftCard.Builder builder){
62          super(baseInfo);
63          this.subCardType = SubCardType.VOUCHER.name();
64          this.autoActivate = builder.isAutoActivate();
65          this.backgroundPicUrl = builder.getBackgroundPicUrl();
66          this.customField1 = builder.getCustomField1();
67          this.customField2 = builder.getCustomField2();
68          this.customField3 = builder.getCustomField3();
69          this.supplyBalance = builder.isSupplyBalance();
70          this.supplyBonus = builder.isSupplyBonus();
71          this.initBalance = builder.getInitBalance();
72      }
73  
74      @JSONField(serialize = false)
75      @Override
76      public CardType getCardType() {
77          return CardType.GENERAL_COUPON;
78      }
79  
80      public static final class Builder {
81          private String backgroundPicUrl;
82          private boolean supplyBonus;
83          private boolean supplyBalance;
84          private boolean autoActivate;
85          private Integer initBalance;
86          private MemCardCustomField customField1;
87          private MemCardCustomField customField2;
88          private MemCardCustomField customField3;
89  
90          public Builder(){
91              this.autoActivate = true;
92              this.supplyBalance = false;
93              this.supplyBonus = false;
94          }
95  
96          public String getBackgroundPicUrl() {
97              return backgroundPicUrl;
98          }
99  
100         public boolean isSupplyBonus() {
101             return supplyBonus;
102         }
103 
104         public boolean isSupplyBalance() {
105             return supplyBalance;
106         }
107 
108         public boolean isAutoActivate() {
109             return autoActivate;
110         }
111 
112         public Integer getInitBalance() {
113             return initBalance;
114         }
115 
116         public MemCardCustomField getCustomField1() {
117             return customField1;
118         }
119 
120         public MemCardCustomField getCustomField2() {
121             return customField2;
122         }
123 
124         public MemCardCustomField getCustomField3() {
125             return customField3;
126         }
127 
128         /**
129          * 设置礼品卡背景图片
130          * @param url
131          * @return
132          */
133         public Builder backgroundPicUrl(String url){
134             this.backgroundPicUrl = url;
135             return this;
136         }
137 
138         /**
139          * 设置是否支持积分(目前未清楚单品类礼品卡是否支持积分)
140          * @param supplyBonus
141          * @return
142          */
143         public Builder supplyBonus(boolean supplyBonus){
144             this.supplyBonus = supplyBonus;
145             return this;
146         }
147 
148         /**
149          * 设置是否支持余额(需礼品卡类型为GIFT_CARD,单品类礼品卡VOUCHER并非用于储值)
150          * 注意事项:开发者仅能在supply_balance和custom_field1、custom_field2、custom_field3中选择最多3个填写,否则报错。
151          * @param supplyBalance
152          * @return
153          */
154         public Builder supplyBalance(boolean supplyBalance){
155             this.supplyBalance = supplyBalance;
156             return this;
157         }
158 
159         /**
160          * 设置礼品卡是否自动激活,若开发者不需要额外激活流程则填写true。
161          * @param autoActivate
162          * @return
163          */
164         public Builder autoActivate(boolean autoActivate){
165             this.autoActivate = autoActivate;
166             return this;
167         }
168 
169         /**
170          * 设置初始化的余额(需礼品卡类型为GIFT_CARD,单品类礼品卡VOUCHER并非用于储值)
171          * @param initBalance
172          * @return
173          */
174         public Builder initBalance(Integer initBalance){
175             this.initBalance = initBalance;
176             return this;
177         }
178 
179         /**
180          * 设置自定义会员信息类目
181          * 注意事项:开发者仅能在supply_balance和custom_field1、custom_field2、custom_field3中选择最多3个填写,否则报错。
182          * @param name 自定义信息类目名称
183          * @param url 自定义信息类目跳转url
184          * @return
185          */
186         public Builder customField1(String name, String url){
187             MemCardCustomField field = new MemCardCustomField(name, url, null);
188             this.customField1 = field;
189             return this;
190         }
191 
192         /**
193          * 设置自定义会员信息类目
194          * 注意事项:开发者仅能在supply_balance和custom_field1、custom_field2、custom_field3中选择最多3个填写,否则报错。
195          * @param name 自定义信息类目名称
196          * @param url 自定义信息类目跳转url
197          * @return
198          */
199         public Builder customField2(String name, String url){
200             MemCardCustomField field = new MemCardCustomField(name, url, null);
201             this.customField2 = field;
202             return this;
203         }
204 
205         /**
206          * 设置自定义会员信息类目
207          * 注意事项:开发者仅能在supply_balance和custom_field1、custom_field2、custom_field3中选择最多3个填写,否则报错。
208          * @param name 自定义信息类目名称
209          * @param url 自定义信息类目跳转url
210          * @return
211          */
212         public Builder customField3(String name, String url){
213             MemCardCustomField field = new MemCardCustomField(name, url, null);
214             this.customField3 = field;
215             return this;
216         }
217     }
218 
219 }