卡券类字段

卡券字段极其复杂繁多,为了好管理和分类,基于5个基础卡券种类:通用,折扣,团购,代金,礼品券。

定义了3张表和N个枚举类,若要方便调用枚举字段,.net枚举已有举例可以查阅。

先贴3张基础字段

 1     [TableDisplay("卡券")]
 2     public class wxCard:Base
 3     {
 4         [Display(Name = "卡券唯一编号")]
 5         public String CardId { get; set; }
 6         [Display(Name = "卡券种类")]
 7         public CardType cardType { get; set; }
 8         [Display(Name = "卡券特殊字段")]
 9         public String CardField { get; set; }
10     }
View Code
 1     [TableDisplay("卡券基本信息")]
 2     public class wxCardBaseInfo : Base
 3     {
 4         [Display(Name = "卡券编号")]
 5         public Int32 WxCardId { get; set; }
 6         [Display(Name = "卡券")]
 7         [ForeignKey("WxCardId")]
 8         public virtual wxCard WxCard { get; set; }
 9         [Display(Name = "卡券的商户logoId")]
10         public String logo_url { get; set; }
11         [Display(Name = "CodeType展示类型")]
12         public String code_type { get; set; }
13         [Display(Name = "商户名字")]
14         public String brand_name { get; set; }
15         [Display(Name = "券名")]
16         public String title { get; set; }
17         [Display(Name = "券名的副标题")]
18         public String sub_title { get; set; }
19         [Display(Name = "券颜色")]
20         public String color { get; set; }
21         [Display(Name = "使用提醒")]
22         public String notice { get; set; }
23         [Display(Name = "客服电话")]
24         public String service_phone { get; set; }
25         [Display(Name = "第三方来源名")]
26         public String source { get; set; }
27         [Display(Name = "使用说明")]
28         public String description { get; set; }
29         [Display(Name = "每人最大领取次数")]
30         public int get_limit { get; set; }
31         [Display(Name = "自定义code码")]
32         public bool use_custom_code { get; set; }
33         [Display(Name = "指定用户领取")]
34         public bool bind_openid { get; set; }
35         [Display(Name = "是否可分享")]
36         public bool can_share { get; set; }
37         [Display(Name = "是否可转赠")]
38         public bool can_give_friend { get; set; }
39         [Display(Name = "门店位置ID")]
40         public List<String> location_id_list { get; set; }
41         [Display(Name = "使用日期,有效期的信息")]
42         public Card_BaseInfo_DateInfo date_info { get; set; }
43         [Display(Name = "商品信息")]
44         public Card_BaseInfo_Sku sku { get; set; }
45         [Display(Name = "商户自定义cell名称")]
46         public String url_name_type { get; set; }
47         [Display(Name = "商户自定义url 地址")]
48         public String custom_url { get; set; }
49         [Display(Name = "自定义跳转外链的入口名字")]
50         public String custom_url_name { get; set; }
51         [Display(Name = "显示在入口右侧的提示语")]
52         public String custom_url_sub_title { get; set; }
53         [Display(Name = "营销场景的自定义入口名称")]
54         public String promotion_url_name { get; set; }
55         [Display(Name = "入口跳转外链的地址链接")]
56         public String promotion_url { get; set; }
57         [Display(Name = "显示在营销入口右侧的提示语")]
58         public String promotion_url_sub_title { get; set; }
View Code
基本字段扩展
 1     /// <summary>
 2     /// 使用日期,有效期的信息
 3     /// </summary>
 4     public class Card_BaseInfo_DateInfo
 5     {
 6         /// <summary>
 7         /// 使用时间的类型 1:固定日期区间,2:固定时长(自领取后按天算)
 8         /// 必填
 9         /// </summary>
10         public string type { get; set; }
11         /// <summary>
12         /// 固定日期区间专用,表示起用时间。从1970 年1 月1 日00:00:00 至起用时间的秒数,最终需转换为字符串形态传入,下同。(单位为秒)
13         /// 必填
14         /// </summary>
15         public string begin_timestamp { get; set; }
16         /// <summary>
17         /// 固定日期区间专用,表示结束时间。(单位为秒)
18         /// 必填
19         /// </summary>
20         public string end_timestamp { get; set; }
21         /// <summary>
22         /// 固定时长专用,表示自领取后多少天内有效。(单位为天)
23         /// 必填
24         /// </summary>
25         public int? fixed_term { get; set; }
26         /// <summary>
27         /// 固定时长专用,表示自领取后多少天开始生效。(单位为天)
28         /// 必填
29         /// </summary>
30         public int? fixed_begin_term { get; set; }
31     }
32 
33     /// <summary>
34     /// 商品信息
35     /// </summary>
36     public class Card_BaseInfo_Sku
37     {
38         /// <summary>
39         /// 上架的数量。(不支持填写0或无限大)
40         /// 必填
41         /// </summary>
42         public int quantity { get; set; }
43     }
44 
45     public class Card_CodeBaseInfoBase : Card_BaseInfoBase
46     {
47         public string get_custom_code_mode
48         {
49             get { return "GET_CUSTOM_CODE_MODE_DEPOSIT"; }
50         }
51     }
View Code
    [TableDisplay("卡券code编号")]
    public class wxCardCodeList:Base
    {
        [Display(Name = "卡券编号")]
        public Int32 WxCardId { get; set; }
        [Display(Name = "卡券")]
        [ForeignKey("WxCardId")]
        public virtual wxCard WxCard { get; set; }
        [Display(Name = "卡券编号")]
        public String CodeNum { get; set; }
        [Display(Name = "单张描述")]
        public String Description { get; set; }
        [Display(Name = "微信导入")]
        public Boolean WxPlay { get; set; }
        [Display(Name = "本地导入")]
        public Boolean DisPlay { get; set; }
        [Display(Name = "是否已核销")]
        public Boolean Vilid { get; set; }
    }
View Code

一下列举卡券所用的枚举

  1     /// <summary>
  2     /// 卡券使用时间的类型
  3     /// </summary>
  4     public enum Card_DateInfo_Type
  5     {
  6         [Description("固定日期区间")]
  7         DATE_TYPE_FIX_TIME_RANGE = 0,
  8         [Description("固定时长(自领取后按天算)")]
  9         DATE_TYPE_FIX_TERM = 1,
 10         [Description("永久有效")]
 11         DATE_TYPE_PERMANENT = 2
 12     }
 13     /// <summary>
 14     /// 卡券种类
 15     /// </summary>
 16     public enum CardType
 17     {
 18         [Description("通用券")]
 19         GENERAL_COUPON = 0,
 20         [Description("团购券")]
 21         GROUPON = 1,
 22         [Description("折扣券")]
 23         DISCOUNT = 2,
 24         [Description("礼品券")]
 25         GIFT = 3,
 26         [Description("代金券")]
 27         CASH = 4,
 28         [Description("会员卡")]
 29         MEMBER_CARD = 5,
 30         [Description("门票")]
 31         SCENIC_TICKET = 6,
 32         [Description("电影票")]
 33         MOVIE_TICKET = 7,
 34         [Description("飞机票")]
 35         BOARDING_PASS = 8,
 36         [Description("红包")]
 37         LUCKY_MONEY = 9,
 38         [Description("会议门票")]
 39         MEETING_TICKET = 10,
 40     }
 41     /// <summary>
 42     /// 卡券code码展示类型
 43     /// </summary>
 44     public enum Card_CodeType
 45     {
 46         [Description("文本")]
 47         CODE_TYPE_TEXT = 0,
 48         [Description("一维码")]
 49         CODE_TYPE_BARCODE = 1,
 50         [Description("二维码")]
 51         CODE_TYPE_QRCODE = 2,
 52         [Description("二维码不显示code")]
 53         CODE_TYPE_ONLY_QRCODE = 3,
 54         [Description("无code类型")]
 55         CODE_TYPE_NONE =4
 56     }
 57     /// <summary>
 58     /// 卡券 商户自定义cell 名称
 59     /// </summary>
 60     public enum Card_UrlNameType
 61     {
 62         [Description("外卖")]
 63         URL_NAME_TYPE_TAKE_AWAY = 0,
 64         [Description("在线预订")]
 65         URL_NAME_TYPE_RESERVATION = 1,
 66         [Description("立即使用")]
 67         URL_NAME_TYPE_USE_IMMEDIATELY = 2,
 68         [Description("在线预约")]
 69         URL_NAME_TYPE_APPOINTMENT = 3,
 70         [Description("在线兑换")]
 71         URL_NAME_TYPE_EXCHANGE = 4,
 72         [Description("车辆信息")]
 73         URL_NAME_TYPE_VEHICLE_INFORMATION = 5,
 74     }
 75 
 76     public enum MemberCard_CustomField_NameType
 77     {
 78         /// <summary>
 79         /// 等级
 80         /// </summary>
 81         FIELD_NAME_TYPE_LEVEL = 0,
 82         /// <summary>
 83         /// 优惠券
 84         /// </summary>
 85         FIELD_NAME_TYPE_COUPON = 1,
 86         /// <summary>
 87         /// 印花
 88         /// </summary>
 89         FIELD_NAME_TYPE_STAMP = 2,
 90         /// <summary>
 91         /// 折扣
 92         /// </summary>
 93         FIELD_NAME_TYPE_DISCOUNT = 3,
 94         /// <summary>
 95         /// 成就
 96         /// </summary>
 97         FIELD_NAME_TYPE_ACHIEVEMEN = 4,
 98         /// <summary>
 99         /// 里程
100         /// </summary>
101         FIELD_NAME_TYPE_MILEAGE = 5,
102     }
103 
104     public enum CardColor
105     {
106         [Description("淡绿色")]
107         Color010 = 0,
108         [Description("绿色")]
109         Color020 = 1,
110         [Description("淡蓝色")]
111         Color030 = 2,
112         [Description("蓝色")]
113         Color040 = 3,
114         [Description("紫色")]
115         Color050 = 4,
116         [Description("土黄色")]
117         Color060 = 5,
118         [Description("黄色")]
119         Color070 = 6,
120         [Description("橘黄色")]
121         Color080 = 7,
122         [Description("橙色")]
123         Color081 = 8,
124         [Description("银光绿")]
125         Color082 = 9,
126         [Description("淡红色")]
127         Color090 = 10,
128         [Description("深红")]
129         Color100 = 11,
130         [Description("红色")]
131         Color101 = 12,
132         [Description("灰色")]
133         Color102 = 13,
134     }
135 
136     /// <summary>
137     /// 卡券code查询状态
138     /// </summary>
139     public enum UserCardStatus
140     {
141         [Description("正常")]
142         NORMAL = 0,
143         [Description("已核销")]
144         CONSUMED = 1,
145         [Description("已过期")]
146         EXPIRE = 2,
147         [Description("转赠中")]
148         GIFTING = 3,
149         [Description("转赠超时")]
150         GIFT_TIMEOUT = 4,
151         [Description("已删除")]
152         DELETE = 5,
153         [Description("已失效")]
154         UNAVAILABLE = 6
155     }
View Code

 而微信又提供了自定义code模式

所以多出一个继承类

1     public class Card_CodeBaseInfoBase : Card_BaseInfoBase
2     {
3         public string get_custom_code_mode
4         {
5             get { return "GET_CUSTOM_CODE_MODE_DEPOSIT"; }
6         }
7     }

关系类构造post需要的Json请看如下code,若不需要的看官请勿打开,比较长

  1     /// <summary>
  2     /// 卡券信息数据中的card字段
  3     /// </summary>
  4     public class CardCreateInfo_Card
  5     {
  6         
  7     }
  8 
  9 
 10     #region 不同卡券类型对应的信息
 11 
 12     /// <summary>
 13     /// 通用券
 14     /// </summary>
 15     public class Card_GeneralCoupon : CardCreateInfo_Card
 16     {
 17         public string card_type { get; set; }
 18         public Card_GeneralCouponData general_coupon { get; set; }
 19     }
 20 
 21     /// <summary>
 22     /// 团购券
 23     /// </summary>
 24     public class Card_Groupon : CardCreateInfo_Card
 25     {
 26         public string card_type { get; set; }
 27         public Card_GrouponData groupon { get; set; }
 28     }
 29 
 30     /// <summary>
 31     /// 礼品券
 32     /// </summary>
 33     public class Card_Gift : CardCreateInfo_Card
 34     {
 35         public string card_type { get; set; }
 36         public Card_GiftData gift { get; set; }
 37     }
 38 
 39     /// <summary>
 40     /// 代金券
 41     /// </summary>
 42     public class Card_Cash : CardCreateInfo_Card
 43     {
 44         public string card_type { get; set; }
 45         public Card_CashData cash { get; set; }
 46     }
 47 
 48     /// <summary>
 49     /// 折扣券
 50     /// </summary>
 51     public class Card_DisCount : CardCreateInfo_Card
 52     {
 53         public string card_type { get; set; }
 54         public Card_DisCountData discount { get; set; }
 55     }
 56 
 57     /// <summary>
 58     /// 会员卡
 59     /// </summary>
 60     public class Card_MemberCard : CardCreateInfo_Card
 61     {
 62         public string card_type { get; set; }
 63         public Card_MemberCardData member_card { get; set; }
 64     }
 65 
 66     /// <summary>
 67     /// 门票
 68     /// </summary>
 69     public class Card_ScenicTicket : CardCreateInfo_Card
 70     {
 71         public string card_type { get; set; }
 72         public Card_ScenicTicketData scenic_ticket { get; set; }
 73     }
 74 
 75     /// <summary>
 76     /// 电影票
 77     /// </summary>
 78     public class Card_MovieTicket : CardCreateInfo_Card
 79     {
 80         public string card_type { get; set; }
 81         public Card_MovieTicketData movie_ticket { get; set; }
 82     }
 83 
 84     /// <summary>
 85     /// 飞机票
 86     /// </summary>
 87     public class Card_BoardingPass : CardCreateInfo_Card
 88     {
 89         public string card_type { get; set; }
 90         public Card_BoardingPassData boarding_pass { get; set; }
 91     }
 92 
 93     /// <summary>
 94     /// 红包
 95     /// </summary>
 96     public class Card_LuckyMoney : CardCreateInfo_Card
 97     {
 98         public string card_type { get; set; }
 99         public Card_LuckyMoneyData lucky_money { get; set; }
100     }
101 
102     /// <summary>
103     /// 会议门票
104     /// </summary>
105     public class Card_MeetingTicket : CardCreateInfo_Card
106     {
107         public string card_type { get; set; }
108         public Card_MeetingTicketData meeting_ticket { get; set; }
109     }
110     #endregion
111 
112 
113     public abstract class BaseCardInfo
114     {
115         /// <summary>
116         /// 基本的卡券数据
117         /// </summary>
118         public Card_BaseInfoBase base_info { get; set; }
119         /// <summary>
120         /// 卡类型(不在Json数据中)
121         /// </summary>
122         protected CardType CardType { get; set; }
123 
124         public CardType GetCardType()
125         {
126             return CardType;
127         }
128 
129         public BaseCardInfo(CardType cardType)
130         {
131             CardType = cardType;
132         }
133     }
134 
135     /* 所有类型的卡券数据 */
136 
137 
138     /// <summary>
139     /// 通用券数据
140     /// </summary>
141     public class Card_GeneralCouponData : BaseCardInfo
142     {
143         [Display(Name = "描述文本")]
144         public string default_detail { get; set; }
145 
146         public Card_GeneralCouponData()
147             : base(CardType.GENERAL_COUPON)
148         {
149         }
150     }
151 
152     /// <summary>
153     /// 团购券数据
154     /// </summary>
155     public class Card_GrouponData : BaseCardInfo
156     {
157         [Display(Name = "团购详情")]
158         public string deal_detail { get; set; }
159 
160         public Card_GrouponData()
161             : base(CardType.GROUPON)
162         {
163         }
164     }
165 
166     /// <summary>
167     /// 礼品券数据
168     /// </summary>
169     public class Card_GiftData : BaseCardInfo
170     {
171         [Display(Name = "礼品名字")]
172         public string gift { get; set; }
173 
174         public Card_GiftData()
175             : base(CardType.GIFT)
176         {
177         }
178     }
179 
180     /// <summary>
181     /// 代金券数据
182     /// </summary>
183     public class Card_CashData : BaseCardInfo
184     {
185         [Display(Name = "起用金额")]
186         public int least_cost { get; set; }
187         [Display(Name = "减免金额")]
188         public int reduce_cost { get; set; }
189 
190         public Card_CashData()
191             : base(CardType.CASH)
192         {
193         }
194     }
195 
196     /// <summary>
197     /// 折扣券数据
198     /// </summary>
199     public class Card_DisCountData : BaseCardInfo
200     {
201         [Display(Name = "打折额度(百分比).填30 就是七折")]
202         public float discount { get; set; }
203 
204         public Card_DisCountData()
205             : base(CardType.DISCOUNT)
206         {
207         }
208     }
209 
210     /// <summary>
211     /// 会员卡数据
212     /// </summary>
213     public class Card_MemberCardData : BaseCardInfo
214     {
215         [Display(Name = "支持积分")]
216         /// <summary>
217         /// 是否支持积分,填写true 或false,如填写true,积分相关字段均为必填。填写false,积分字段无需填写。储值字段处理方式相同。
218         /// 必填
219         /// </summary>
220         public bool supply_bonus { get; set; }
221         [Display(Name = "支持储值")]
222         /// <summary>
223         /// 是否支持储值,填写true 或false。
224         /// 必填
225         /// </summary>
226         public bool supply_balance { get; set; }
227         /// <summary>
228         /// 设置为true时用户领取会员卡后系统自动将其激活,无需调用激活接口。
229         /// 非必填
230         /// </summary>
231         public bool auto_activate { get; set; }
232         /// <summary>
233         /// 设置为true时会员卡支持一键激活,不允许同时传入activate_url字段,否则设置wx_activate失效。
234         /// 非必填
235         /// </summary>
236         public bool wx_activate { get; set; }
237         /// <summary>
238         /// 积分清零规则
239         /// 非必填
240         /// </summary>
241         public string bonus_cleared { get; set; }
242         /// <summary>
243         /// 积分规则
244         /// 非必填
245         /// </summary>
246         public string bonus_rules { get; set; }
247         /// <summary>
248         /// 储值说明
249         /// 非必填
250         /// </summary>
251         public string balance_rules { get; set; }
252         /// <summary>
253         /// 特权说明
254         /// 必填
255         /// </summary>
256         public string prerogative { get; set; }
257         /// <summary>
258         /// 绑定旧卡的url,与“activate_url”字段二选一必填。
259         /// </summary>
260         public string bind_old_card_url { get; set; }
261         /// <summary>
262         /// 激活会员卡的url,与“bind_old_card_url”字段二选一必填。
263         /// </summary>
264         public string activate_url { get; set; }
265         /// <summary>
266         /// 设置跳转外链查看积分详情。仅适用于积分无法通过激活接口同步的情况下使用该字段。
267         /// 非必填
268         /// </summary>
269         public string bonus_url { get; set; }
270         /// <summary>
271         /// 设置跳转外链查看余额详情。仅适用于余额无法通过激活接口同步的情况下使用该字段。
272         /// 非必填
273         /// </summary>
274         public string balance_url { get; set; }
275         /// <summary>
276         /// 自定义会员信息类目,会员卡激活后显示。
277         /// 非必填
278         /// </summary>
279         public CustomField custom_field1 { get; set; }
280         /// <summary>
281         /// 自定义会员信息类目,会员卡激活后显示。
282         /// 非必填
283         /// </summary>
284         public CustomField custom_field2 { get; set; }
285         /// <summary>
286         /// 自定义会员信息类目,会员卡激活后显示。
287         /// 非必填
288         /// </summary>
289         public CustomField custom_field3 { get; set; }
290         /// <summary>
291         /// 自定义会员信息类目,会员卡激活后显示
292         /// 非必填
293         /// </summary>
294         public CustomCell custom_cell1 { get; set; }
295         /// <summary>
296         /// 会员卡背景图片,非必填
297         /// </summary>
298         public string background_pic_url { get; set; }
299 
300         public Card_MemberCardData()
301             : base(CardType.MEMBER_CARD)
302         {
303         }
304     }
305 
306     public class CustomField
307     {
308         /// <summary>
309         /// 会员信息类目名称。FIELD_NAME_TYPE_LEVEL等级;FIELD_NAME_TYPE_COUPON优惠券;FIELD_NAME_TYPE_STAMP印花;FIELD_NAME_TYPE_DISCOUNT折扣;FIELD_NAME_TYPE_ACHIEVEMEN成就;FIELD_NAME_TYPE_MILEAGE里程。
310         /// </summary>
311         public MemberCard_CustomField_NameType name_type { get; set; }
312         /// <summary>
313         /// 点击类目跳转外链url
314         /// </summary>
315         public string url { get; set; }
316     }
317 
318     public class CustomCell
319     {
320         /// <summary>
321         /// 入口名称
322         /// 必填
323         /// </summary>
324         public string name { get; set; }
325         /// <summary>
326         /// 入口右侧提示语,6个汉字内
327         /// 必填
328         /// </summary>
329         public string tips { get; set; }
330         /// <summary>
331         /// 入口跳转链接
332         /// 必填
333         /// </summary>
334         public string url { get; set; }
335     }
336 
337     /// <summary>
338     /// 门票数据
339     /// </summary>
340     public class Card_ScenicTicketData : BaseCardInfo
341     {
342         /// <summary>
343         /// 票类型,例如平日全票,套票等
344         /// 非必填
345         /// </summary>
346         public string ticket_class { get; set; }
347         /// <summary>
348         /// 导览图url
349         /// 非必填
350         /// </summary>
351         public string guide_url { get; set; }
352 
353         public Card_ScenicTicketData()
354             : base(CardType.SCENIC_TICKET)
355         {
356         }
357     }
358 
359     /// <summary>
360     /// 电影票数据
361     /// </summary>
362     public class Card_MovieTicketData : BaseCardInfo
363     {
364         /// <summary>
365         /// 电影票详请
366         /// 非必填
367         /// </summary>
368         public string detail { get; set; }
369 
370         public Card_MovieTicketData()
371             : base(CardType.MOVIE_TICKET)
372         {
373         }
374     }
375 
376     /// <summary>
377     /// 飞机票数据
378     /// </summary>
379     public class Card_BoardingPassData : BaseCardInfo
380     {
381         /// <summary>
382         /// 起点,上限为18 个汉字
383         /// 必填
384         /// </summary>
385         public string from { get; set; }
386         /// <summary>
387         /// 终点,上限为18 个汉字
388         /// 必填
389         /// </summary>
390         public string to { get; set; }
391         /// <summary>
392         /// 航班
393         /// 必填
394         /// </summary>
395         public string flight { get; set; }
396         /// <summary>
397         /// 起飞时间,上限为17 个汉字
398         /// 非必填
399         /// </summary>
400         public string departure_time { get; set; }
401         /// <summary>
402         /// 降落时间,上限为17 个汉字
403         /// 非必填
404         /// </summary>
405         public string landing_time { get; set; }
406         /// <summary>
407         /// 在线值机的链接
408         /// 非必填
409         /// </summary>
410         public string check_in_url { get; set; }
411         /// <summary>
412         /// 登机口。如发生登机口变更,建议商家实时调用该接口变更
413         /// </summary>
414         public string gate { get; set; }
415         /// <summary>
416         /// 登机时间,只显示“时分”不显示日期,按时间戳格式填写。如发生登机时间变更,建议商家实时调用该接口变更
417         /// </summary>
418         public string boarding_time { get; set; }
419         /// <summary>
420         /// 机型,上限为8 个汉字
421         /// 非必填
422         /// </summary>
423         public string air_model { get; set; }
424 
425         public Card_BoardingPassData()
426             : base(CardType.BOARDING_PASS)
427         {
428         }
429     }
430 
431     /// <summary>
432     /// 红包数据
433     /// </summary>
434     public class Card_LuckyMoneyData : BaseCardInfo
435     {
436         public Card_LuckyMoneyData()
437             : base(CardType.LUCKY_MONEY)
438         {
439         }
440     }
441 
442     /// <summary>
443     /// 会议门票数据
444     /// </summary>
445     public class Card_MeetingTicketData : BaseCardInfo
446     {
447         /// <summary>
448         /// 会议详情
449         /// </summary>
450         public string meeting_detail { get; set; }
451 
452         /// <summary>
453         /// 会场导览图
454         /// </summary>
455         public string map_url { get; set; }
456 
457         public Card_MeetingTicketData()
458             : base(CardType.MEETING_TICKET)
459         {
460         }
461     }
462 
463 
464     public class CardCreateInfo
465     {
466         /// <summary>
467         /// 卡券信息部分
468         /// </summary>
469         public CardCreateInfo_Card card { get; set; }
470     }
View Code

 

最后随便拿出个地方编译下构造函数,已基础字段数据为准创建个BaseCardInfo即可

  1         public CardCreateInfo CreateCard(BaseCardInfo cardInfo)
  2         {
  3             CardCreateInfo cardData = null;
  4             CardType cardType = cardInfo.GetCardType();
  5             switch (cardType)
  6             {
  7                 case CardType.GENERAL_COUPON:
  8                     cardData = new CardCreateInfo()
  9                     {
 10                         card = new Card_GeneralCoupon()
 11                         {
 12                             card_type = cardType.ToString(),
 13                             general_coupon = cardInfo as Card_GeneralCouponData
 14                         }
 15                     };
 16                     break;
 17                 case CardType.GROUPON:
 18                     cardData = new CardCreateInfo()
 19                     {
 20                         card = new Card_Groupon()
 21                         {
 22                             card_type = cardType.ToString(),
 23                             groupon = cardInfo as Card_GrouponData
 24                         }
 25                     };
 26                     break;
 27                 case CardType.GIFT:
 28                     cardData = new CardCreateInfo()
 29                     {
 30                         card = new Card_Gift()
 31                         {
 32                             card_type = cardType.ToString(),
 33                             gift = cardInfo as Card_GiftData
 34                         }
 35                     };
 36                     break;
 37                 case CardType.CASH:
 38                     cardData = new CardCreateInfo()
 39                     {
 40                         card = new Card_Cash()
 41                         {
 42                             card_type = cardType.ToString(),
 43                             cash = cardInfo as Card_CashData
 44                         }
 45                     };
 46                     break;
 47                 case CardType.DISCOUNT:
 48                     cardData = new CardCreateInfo()
 49                     {
 50                         card = new Card_DisCount()
 51                         {
 52                             card_type = cardType.ToString(),
 53                             discount = cardInfo as Card_DisCountData
 54                         }
 55                     };
 56                     break;
 57                 case CardType.MEMBER_CARD:
 58                     cardData = new CardCreateInfo()
 59                     {
 60                         card = new Card_MemberCard()
 61                         {
 62                             card_type = cardType.ToString(),
 63                             member_card = cardInfo as Card_MemberCardData
 64                         }
 65                     };
 66                     break;
 67                 case CardType.SCENIC_TICKET:
 68                     cardData = new CardCreateInfo()
 69                     {
 70                         card = new Card_ScenicTicket()
 71                         {
 72                             card_type = cardType.ToString(),
 73                             scenic_ticket = cardInfo as Card_ScenicTicketData
 74                         }
 75                     };
 76                     break;
 77                 case CardType.MOVIE_TICKET:
 78                     cardData = new CardCreateInfo()
 79                     {
 80                         card = new Card_MovieTicket()
 81                         {
 82                             card_type = cardType.ToString(),
 83 
 84                             movie_ticket = cardInfo as Card_MovieTicketData
 85                         }
 86                     };
 87                     break;
 88                 case CardType.BOARDING_PASS:
 89                     cardData = new CardCreateInfo()
 90                     {
 91                         card = new Card_BoardingPass()
 92                         {
 93                             card_type = cardType.ToString(),
 94                             boarding_pass = cardInfo as Card_BoardingPassData
 95                         }
 96                     };
 97                     break;
 98                 case CardType.LUCKY_MONEY:
 99                     cardData = new CardCreateInfo()
100                     {
101                         card = new Card_LuckyMoney()
102                         {
103                             card_type = cardType.ToString(),
104                             lucky_money = cardInfo as Card_LuckyMoneyData
105                         }
106                     };
107                     break;
108                 case CardType.MEETING_TICKET:
109                     cardData = new CardCreateInfo()
110                     {
111                         card = new Card_MeetingTicket()
112                         {
113                             card_type = cardType.ToString(),
114                             meeting_ticket = cardInfo as Card_MeetingTicketData
115                         }
116                     };
117                     break;
118                 default:
119                     break;
120             }
121             return cardData;
122         }
View Code

 

如下来个案例吧!

        /// <summary>
        /// Card_CodeBaseInfoBase 自定义code
        /// Card_BaseInfoBase 非自定义code
        /// </summary>
        protected Card_BaseInfoBase _BaseInfo = new Card_BaseInfoBase()
        {
            logo_url = "http://mmbiz.qpic.cn/mmbiz/miaI74XjeZqtQsnpfib61eTC0dx1cxar5KZ7pGYm6wNVkSX78WRBKYQFVDzDfwWNiaEAuDbAftBrMuvN6bFY5o2qw/0?wx_fmt=jpeg",
            brand_name = "海底捞",
            code_type = Card_CodeType.CODE_TYPE_BARCODE.ToString(),
            title = "132 元双人火锅套餐",
            sub_title = "周末狂欢必备",
            color = "Color010",
            notice = "使用时向服务员出示此券",
            service_phone = "020-88888888",
            description = @"不可与其他优惠同享\n 如需团购券发票,请在消费时向商户提出\n 店内均可
使用,仅限堂食\n 餐前不可打包,餐后未吃完,可打包\n 本团购券不限人数,建议2 人使用,超过建议人
数须另收酱料费5 元/位\n 本单谢绝自带酒水饮料",
            date_info = new Card_BaseInfo_DateInfo()
            {
                type = Card_DateInfo_Type.DATE_TYPE_FIX_TIME_RANGE.ToString(),
                begin_timestamp = DateTime.Now.ToUnixTimestamp().ToString(),
                end_timestamp = DateTime.Now.AddDays(10).ToUnixTimestamp().ToString(),
            },
            sku = new Card_BaseInfo_Sku()
            {
                quantity = 5
            },
            use_limit = 1,
            get_limit = 3,
            use_custom_code = false,
            bind_openid = false,
            can_share = true,
            can_give_friend = true,
            url_name_type = Card_UrlNameType.URL_NAME_TYPE_RESERVATION.ToString(),
            custom_url = "http://www.weiweihi.com",
            source = "大众点评",
            custom_url_name = "立即使用",
            custom_url_sub_title = "6个汉字tips",
            promotion_url_name = "更多优惠",
            promotion_url = "http://www.qq.com",
            //location_id_list = { "123","321"},
        };

 运用这个类变成所需的品种:

            var data = new Card_GrouponData
            {
                base_info = _BaseInfo as Card_BaseInfoBase,
                deal_detail = "测试"
            };
            var card = new CardHelper(“Accestoken”);
            var result = card.CreateCard(data);

            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
            var jsonString = jsSerializer.Serialize(result);

我定义了新的类
CardHelper 已添加对应的属性,并调用一下所写的类
CreateCard就是刚刚所用到的创建类

  

posted @ 2016-08-11 15:51  Paras  阅读(422)  评论(0编辑  收藏  举报