1 package com.foxinmy.weixin4j.model.card;
2
3 import java.io.Serializable;
4 import java.util.Arrays;
5 import java.util.Date;
6 import java.util.List;
7
8 import com.alibaba.fastjson.JSONObject;
9 import com.alibaba.fastjson.annotation.JSONField;
10 import com.foxinmy.weixin4j.type.card.CardCodeType;
11 import com.foxinmy.weixin4j.type.card.CardColor;
12
13
14
15
16
17
18
19
20
21
22 public class CouponBaseInfo implements Serializable {
23
24 private static final long serialVersionUID = -5725424121330101717L;
25
26
27
28
29 @JSONField(name = "giftcard_info")
30 private JSONObject giftcardInfo;
31
32
33
34 @JSONField(name = "max_give_friend_times")
35 private int maxGiveFriendTimes;
36
37
38
39 @JSONField(name = "logo_url")
40 private String logoUrl;
41
42
43
44 @JSONField(name = "brand_name")
45 private String brandName;
46
47
48
49 private String title;
50
51
52
53 @JSONField(name = "code_type")
54 private CardCodeType codeType;
55
56
57
58 @JSONField(name = "color")
59 private CardColor cardColor;
60
61
62
63 private String notice;
64
65
66
67 private String description;
68
69
70
71 private JSONObject sku;
72
73
74
75 @JSONField(name = "date_info")
76 private JSONObject date;
77
78
79
80
81
82 @JSONField(name = "use_custom_code")
83 private Boolean useCustomCode;
84
85
86
87 @JSONField(name = "bind_openid")
88 private Boolean bindOpenId;
89
90
91
92 @JSONField(name = "service_phone")
93 private String servicePhone;
94
95
96
97 @JSONField(name = "location_id_list")
98 private List<String> locationIds;
99
100
101
102 @JSONField(name = "use_all_locations")
103 private boolean useAllLocation;
104
105
106
107 @JSONField(name = "center_title")
108 private String centerTitle;
109
110
111
112 @JSONField(name = "center_url")
113 private String centerUrl;
114
115
116
117 @JSONField(name = "center_sub_title")
118 private String centerSubTitle;
119
120
121
122 @JSONField(name = "custom_url_name")
123 private String customTitle;
124
125
126
127 @JSONField(name = "custom_url")
128 private String customUrl;
129
130
131
132 @JSONField(name = "custom_url_sub_title")
133 private String customSubTitle;
134
135
136
137 @JSONField(name = "promotion_url_name")
138 private String promotionTitle;
139
140
141
142 @JSONField(name = "promotion_url")
143 private String promotionUrl;
144
145
146
147 @JSONField(name = "promotion_url_sub_title")
148 private String promotionSubTitle;
149
150
151
152 private String source;
153
154
155
156 @JSONField(name = "get_limit")
157 private int limitNum;
158
159
160
161 @JSONField(name = "can_share")
162 private boolean canShare;
163
164
165
166 @JSONField(name = "can_give_friend")
167 private boolean canGiveFriend;
168
169 @JSONField(name = "need_push_on_view")
170 private Boolean needPushOnView;
171
172
173
174 @JSONField(name = "center_app_brand_user_name")
175 private String centerAppBrandUserName;
176
177
178
179 @JSONField(name = "center_app_brand_pass")
180 private String centerAppBrandPass;
181
182
183
184 @JSONField(name = "custom_app_brand_user_name")
185 private String customAppBrandUserName;
186
187
188
189 @JSONField(name = "custom_app_brand_pass")
190 private String customAppBrandPass;
191
192
193
194 @JSONField(name = "promotion_app_brand_user_name")
195 private String promotionAppBrandUserName;
196
197
198
199 @JSONField(name = "promotion_app_brand_pass")
200 private String promotionAppBrandPass;
201
202 private CouponBaseInfo(Builder builder) {
203 this.giftcardInfo = builder.giftcardInfo;
204 this.logoUrl = builder.logoUrl;
205 this.maxGiveFriendTimes = builder.maxGiveFriendTimes;
206 this.brandName = builder.brandName;
207 this.title = builder.title;
208 this.codeType = builder.codeType;
209 this.cardColor = builder.cardColor;
210 this.notice = builder.notice;
211 this.description = builder.description;
212 this.sku = builder.sku;
213 this.date = builder.date;
214 this.useCustomCode = builder.useCustomCode;
215 this.bindOpenId = builder.bindOpenId;
216 this.servicePhone = builder.servicePhone;
217 this.locationIds = builder.locationIds;
218 this.useAllLocation = builder.useAllLocation;
219 this.centerTitle = builder.centerTitle;
220 this.centerUrl = builder.centerUrl;
221 this.centerSubTitle = builder.centerSubTitle;
222 this.centerAppBrandUserName = builder.centerAppBrandUserName;
223 this.centerAppBrandPass = builder.centerAppBrandPass;
224 this.customTitle = builder.customTitle;
225 this.customUrl = builder.customUrl;
226 this.customSubTitle = builder.customSubTitle;
227 this.customAppBrandUserName = builder.customAppBrandUserName;
228 this.customAppBrandPass = builder.customAppBrandPass;
229 this.promotionTitle = builder.promotionTitle;
230 this.promotionUrl = builder.promotionUrl;
231 this.promotionSubTitle = builder.promotionSubTitle;
232 this.promotionAppBrandUserName = builder.promotionAppBrandUserName;
233 this.promotionAppBrandPass = builder.promotionAppBrandPass;
234 this.source = builder.source;
235 this.limitNum = builder.limitNum;
236 this.canShare = builder.canShare;
237 this.canGiveFriend = builder.canGiveFriend;
238 this.needPushOnView = builder.needPushOnView;
239 };
240
241 public String getLogoUrl() {
242 return logoUrl;
243 }
244
245 public String getBrandName() {
246 return brandName;
247 }
248
249 public String getTitle() {
250 return title;
251 }
252
253 public CardCodeType getCodeType() {
254 return codeType;
255 }
256
257 public CardColor getCardColor() {
258 return cardColor;
259 }
260
261 public String getNotice() {
262 return notice;
263 }
264
265 public String getDescription() {
266 return description;
267 }
268
269 public JSONObject getSku() {
270 return sku;
271 }
272
273 public JSONObject getDate() {
274 return date;
275 }
276
277 public Boolean isUseCustomCode() {
278 return useCustomCode;
279 }
280
281 public Boolean isBindOpenId() {
282 return bindOpenId;
283 }
284
285 public String getServicePhone() {
286 return servicePhone;
287 }
288
289 public List<String> getLocationIds() {
290 return locationIds;
291 }
292
293 public boolean isUseAllLocation() {
294 return useAllLocation;
295 }
296
297 public String getCenterTitle() {
298 return centerTitle;
299 }
300
301 public String getCenterUrl() {
302 return centerUrl;
303 }
304
305 public String getCenterSubTitle() {
306 return centerSubTitle;
307 }
308
309 public String getCustomTitle() {
310 return customTitle;
311 }
312
313 public String getCustomUrl() {
314 return customUrl;
315 }
316
317 public String getCustomSubTitle() {
318 return customSubTitle;
319 }
320
321 public String getPromotionTitle() {
322 return promotionTitle;
323 }
324
325 public String getPromotionUrl() {
326 return promotionUrl;
327 }
328
329 public String getPromotionSubTitle() {
330 return promotionSubTitle;
331 }
332
333 public String getSource() {
334 return source;
335 }
336
337 public int getLimitNum() {
338 return limitNum;
339 }
340
341 public boolean isCanShare() {
342 return canShare;
343 }
344
345 public boolean isCanGiveFriend() {
346 return canGiveFriend;
347 }
348
349 public Boolean getNeedPushOnView() {
350 return needPushOnView;
351 }
352
353 public JSONObject getGiftcardInfo() {
354 return giftcardInfo;
355 }
356
357 public int getMaxGiveFriendTimes() {
358 return maxGiveFriendTimes;
359 }
360
361 public Boolean getUseCustomCode() {
362 return useCustomCode;
363 }
364
365 public Boolean getBindOpenId() {
366 return bindOpenId;
367 }
368
369 public String getCenterAppBrandUserName() {
370 return centerAppBrandUserName;
371 }
372
373 public String getCenterAppBrandPass() {
374 return centerAppBrandPass;
375 }
376
377 public String getCustomAppBrandUserName() {
378 return customAppBrandUserName;
379 }
380
381 public String getCustomAppBrandPass() {
382 return customAppBrandPass;
383 }
384
385 public String getPromotionAppBrandUserName() {
386 return promotionAppBrandUserName;
387 }
388
389 public String getPromotionAppBrandPass() {
390 return promotionAppBrandPass;
391 }
392
393 @Override
394 public String toString() {
395 return "CouponBaseInfo{" +
396 "giftcardInfo=" + giftcardInfo +
397 ", maxGiveFriendTimes=" + maxGiveFriendTimes +
398 ", logoUrl='" + logoUrl + '\'' +
399 ", brandName='" + brandName + '\'' +
400 ", title='" + title + '\'' +
401 ", codeType=" + codeType +
402 ", cardColor=" + cardColor +
403 ", notice='" + notice + '\'' +
404 ", description='" + description + '\'' +
405 ", sku=" + sku +
406 ", date=" + date +
407 ", useCustomCode=" + useCustomCode +
408 ", bindOpenId=" + bindOpenId +
409 ", servicePhone='" + servicePhone + '\'' +
410 ", locationIds=" + locationIds +
411 ", useAllLocation=" + useAllLocation +
412 ", centerTitle='" + centerTitle + '\'' +
413 ", centerUrl='" + centerUrl + '\'' +
414 ", centerSubTitle='" + centerSubTitle + '\'' +
415 ", customTitle='" + customTitle + '\'' +
416 ", customUrl='" + customUrl + '\'' +
417 ", customSubTitle='" + customSubTitle + '\'' +
418 ", promotionTitle='" + promotionTitle + '\'' +
419 ", promotionUrl='" + promotionUrl + '\'' +
420 ", promotionSubTitle='" + promotionSubTitle + '\'' +
421 ", source='" + source + '\'' +
422 ", limitNum=" + limitNum +
423 ", canShare=" + canShare +
424 ", canGiveFriend=" + canGiveFriend +
425 ", needPushOnView=" + needPushOnView +
426 ", centerAppBrandUserName='" + centerAppBrandUserName + '\'' +
427 ", centerAppBrandPass='" + centerAppBrandPass + '\'' +
428 ", customAppBrandUserName='" + customAppBrandUserName + '\'' +
429 ", customAppBrandPass='" + customAppBrandPass + '\'' +
430 ", promotionAppBrandUserName='" + promotionAppBrandUserName + '\'' +
431 ", promotionAppBrandPass='" + promotionAppBrandPass + '\'' +
432 '}';
433 }
434
435 public void cleanCantUpdateField() {
436 this.brandName = null;
437
438 this.sku = null;
439 this.bindOpenId = null;
440 this.useCustomCode = null;
441 }
442
443
444
445
446
447
448
449
450
451 public static final class Builder {
452
453
454
455 private JSONObject giftcardInfo;
456
457
458
459 private String logoUrl;
460
461
462
463 private int maxGiveFriendTimes;
464
465
466
467 private String brandName;
468
469
470
471 private String title;
472
473
474
475 private CardCodeType codeType;
476
477
478
479 private CardColor cardColor;
480
481
482
483 private String notice;
484
485
486
487 private String description;
488
489
490
491 private JSONObject sku;
492
493
494
495 private JSONObject date;
496
497
498
499
500
501 private boolean useCustomCode;
502
503
504
505 private boolean bindOpenId;
506
507
508
509 private String servicePhone;
510
511
512
513 private List<String> locationIds;
514
515
516
517 private boolean useAllLocation;
518
519
520
521 private String centerTitle;
522
523
524
525 private String centerUrl;
526
527
528
529 private String centerSubTitle;
530
531
532
533 private String customTitle;
534
535
536
537 private String customUrl;
538
539
540
541 private String customSubTitle;
542
543
544
545 private String promotionTitle;
546
547
548
549 private String promotionUrl;
550
551
552
553 private String promotionSubTitle;
554
555
556
557 private String source;
558
559
560
561 private int limitNum;
562
563
564
565 private boolean canShare;
566
567
568
569 private boolean canGiveFriend;
570
571
572
573
574 private boolean needPushOnView;
575
576
577
578 private String centerAppBrandUserName;
579
580
581
582 private String centerAppBrandPass;
583
584
585
586 private String customAppBrandUserName;
587
588
589
590 private String customAppBrandPass;
591
592
593
594 private String promotionAppBrandUserName;
595
596
597
598 private String promotionAppBrandPass;
599
600
601
602
603 public Builder() {
604 this.giftcardInfo = new JSONObject();
605 this.maxGiveFriendTimes = 1;
606 this.sku = new JSONObject();
607 this.date = new JSONObject();
608 this.date.put("type",CardActiveType.DATE_TYPE_PERMANENT);
609 this.useAllLocation = true;
610 this.canShare = true;
611 this.canGiveFriend = true;
612 this.limitNum = 50;
613 }
614
615 public Builder customAppBrandPass(String pass){
616 this.customAppBrandPass = pass;
617 return this;
618 }
619
620 public Builder centerAppBrandUserName(String name){
621 this.centerAppBrandUserName = name;
622 return this;
623 }
624
625 public Builder centerAppBrandPass(String pass){
626 this.centerAppBrandPass = pass;
627 return this;
628 }
629
630 public Builder customAppBrandUserName(String name){
631 this.customAppBrandUserName = name;
632 return this;
633 }
634
635 public Builder promotionAppBrandUserName(String userName){
636 this.promotionAppBrandUserName = userName;
637 return this;
638 }
639
640 public Builder promotionAppBrandPass(String pass){
641 this.promotionAppBrandPass = pass;
642 return this;
643 }
644
645 public Builder maxGiveFriendTimes(int times){
646 this.maxGiveFriendTimes = times;
647 return this;
648 }
649
650 public Builder price(int price){
651 this.giftcardInfo.put("price", price);
652 return this;
653 }
654
655
656
657
658
659
660
661
662 public Builder logoUrl(String logoUrl) {
663 this.logoUrl = logoUrl;
664 return this;
665 }
666
667
668
669
670
671
672
673
674 public Builder brandName(String brandName) {
675 this.brandName = brandName;
676 return this;
677 }
678
679
680
681
682
683
684
685
686 public Builder title(String title) {
687 this.title = title;
688 return this;
689 }
690
691
692
693
694
695
696
697
698 public Builder codeType(CardCodeType codeType) {
699 this.codeType = codeType;
700 return this;
701 }
702
703
704
705
706
707
708
709
710 public Builder cardColor(CardColor cardColor) {
711 this.cardColor = cardColor;
712 return this;
713 }
714
715
716
717
718
719
720
721
722 public Builder notice(String notice) {
723 this.notice = notice;
724 return this;
725 }
726
727
728
729
730
731
732
733
734 public Builder description(String description) {
735 this.description = description;
736 return this;
737 }
738
739
740
741
742
743
744
745
746
747 public Builder quantity(int quantity) {
748 quantity = quantity > 100000000 ? 100000000 : quantity;
749 this.sku.put("quantity", quantity);
750 return this;
751 }
752
753
754
755
756
757
758
759
760
761
762 public Builder activeAt(Date beginTime, Date endTime) {
763 this.date.clear();
764 this.date.put("type", CardActiveType.DATE_TYPE_FIX_TIME_RANGE);
765 this.date.put("begin_timestamp", beginTime.getTime() / 1000l);
766 this.date.put("end_timestamp", endTime.getTime() / 1000l);
767 return this;
768 }
769
770
771
772
773
774
775
776
777
778
779
780
781
782 public Builder activeAt(int days, int beginDays, Date endTime) {
783 this.date.clear();
784 this.date.put("type", CardActiveType.DATE_TYPE_FIX_TERM);
785 this.date.put("fixed_term", days);
786 this.date.put("fixed_begin_term", beginDays);
787 this.date.put("end_timestamp", endTime.getTime() / 1000l);
788 return this;
789 }
790
791
792
793
794
795
796
797
798
799
800 public Builder activeAt(int days, int beginDays) {
801 this.date.clear();
802 this.date.put("type", CardActiveType.DATE_TYPE_FIX_TERM);
803 this.date.put("fixed_term", days);
804 this.date.put("fixed_begin_term", beginDays);
805 return this;
806 }
807
808
809
810
811
812
813
814
815 public Builder useCustomCode(boolean useCustomCode) {
816 this.useCustomCode = useCustomCode;
817 return this;
818 }
819
820
821
822
823
824
825
826
827 public Builder bindOpenId(boolean bindOpenId) {
828 this.bindOpenId = bindOpenId;
829 return this;
830 }
831
832
833
834
835
836
837
838
839 public Builder servicePhone(String servicePhone) {
840 this.servicePhone = servicePhone;
841 return this;
842 }
843
844
845
846
847
848
849
850
851 public Builder locationIds(String... locationIds) {
852 this.locationIds.addAll(Arrays.asList(locationIds));
853 this.useAllLocation = false;
854 return this;
855 }
856
857
858
859
860
861
862
863
864 public Builder centerTitle(String centerTitle) {
865 this.centerTitle = centerTitle;
866 return this;
867 }
868
869
870
871
872
873
874
875
876 public Builder centerUrl(String centerUrl) {
877 this.centerUrl = centerUrl;
878 return this;
879 }
880
881
882
883
884
885
886
887
888 public Builder centerSubTitle(String centerSubTitle) {
889 this.centerSubTitle = centerSubTitle;
890 return this;
891 }
892
893
894
895
896
897
898
899
900 public Builder customTitle(String customTitle) {
901 this.customTitle = customTitle;
902 return this;
903 }
904
905
906
907
908
909
910
911
912 public Builder customUrl(String customUrl) {
913 this.customUrl = customUrl;
914 return this;
915 }
916
917
918
919
920
921
922
923
924 public Builder customSubTitle(String customSubTitle) {
925 this.customSubTitle = customSubTitle;
926 return this;
927 }
928
929
930
931
932
933
934
935
936 public Builder promotionTitle(String promotionTitle) {
937 this.promotionTitle = promotionTitle;
938 return this;
939 }
940
941
942
943
944
945
946
947
948 public Builder promotionUrl(String promotionUrl) {
949 this.promotionUrl = promotionUrl;
950 return this;
951 }
952
953
954
955
956
957
958
959
960 public Builder promotionSubTitle(String promotionSubTitle) {
961 this.promotionSubTitle = promotionSubTitle;
962 return this;
963 }
964
965
966
967
968
969
970
971
972 public Builder source(String source) {
973 this.source = source;
974 return this;
975 }
976
977
978
979
980
981
982
983
984 public Builder limitNum(int limitNum) {
985 this.limitNum = limitNum;
986 return this;
987 }
988
989
990
991
992
993
994
995
996 public Builder canShare(boolean canShare) {
997 this.canShare = canShare;
998 return this;
999 }
1000
1001
1002
1003
1004
1005
1006
1007
1008 public Builder canGiveFriend(boolean canGiveFriend) {
1009 this.canGiveFriend = canGiveFriend;
1010 return this;
1011 }
1012
1013 public Builder needPushOnView(boolean needPushOnView){
1014 this.needPushOnView = needPushOnView;
1015 return this;
1016 }
1017
1018
1019
1020
1021
1022
1023 public CouponBaseInfo build() {
1024 return new CouponBaseInfo(this);
1025 }
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036 public enum CardActiveType {
1037
1038
1039
1040 DATE_TYPE_FIX_TIME_RANGE,
1041
1042
1043
1044 DATE_TYPE_FIX_TERM,
1045
1046
1047 DATE_TYPE_PERMANENT;
1048 }
1049 }
1050 }