public void EnumStringTest() { var obj = new Card_BaseInfoBase() { code_type = Card_CodeType.CODE_TYPE_BARCODE }; var str = obj.ToJson(); Console.WriteLine(str); Assert.IsTrue(str.Contains("CODE_TYPE_BARCODE")); }
/// <summary> /// 添加卡券 /// </summary> /// <param name="info"></param> public bool Add(WXCardLogInfo info) { bool issuccess = false; string acctoken = ""; string curHost = "http://" + Core.Helper.WebHelper.GetHost(); string imagefile = "/images/defaultwxlogo.png"; string wxlogo = Core.HimallIO.GetImagePath(imagefile); if (wxlogo.IndexOf("http") < 0) { wxlogo = curHost + imagefile; } var siteSetting = ServiceProvider.Instance <ISiteSettingService> .Create.GetSiteSettings(); var shopser = ServiceProvider.Instance <IShopService> .Create; var vshopser = ServiceProvider.Instance <IVShopService> .Create; CardCreateResultJson wxResultJson = new CardCreateResultJson(); #region 组织数据 //基础数据 Card_BaseInfoBase _BaseInfo = new Card_BaseInfoBase() { logo_url = wxlogo, brand_name = siteSetting.SiteName, code_type = Card_CodeType.CODE_TYPE_BARCODE, title = info.CardTitle, sub_title = info.CardSubTitle, color = info.CardColor, notice = "专供" + siteSetting.SiteName + "使用", description = @"" + (info.LeastCost > 0 ? "满¥" + (info.LeastCost / 100).ToString("F2") + "使用" : "无门槛使用") + ",有效期至" + info.BeginTime.ToString("yyyy年MM月dd日") + "-" + info.EndTime.ToString("yyyy年MM月dd日"), date_info = new Card_BaseInfo_DateInfo() { type = Card_DateInfo_Type.DATE_TYPE_FIX_TIME_RANGE.ToString(), begin_timestamp = DateTimeHelper.GetWeixinDateTime(info.BeginTime), end_timestamp = DateTimeHelper.GetWeixinDateTime(info.EndTime), }, sku = new Card_BaseInfo_Sku() { quantity = info.Quantity == 0 ? MaxStock : info.Quantity }, get_limit = info.GetLimit == 0 ? MaxStock : info.GetLimit, use_custom_code = false, bind_openid = false, can_share = false, can_give_friend = false, custom_url_name = "立即使用", }; //代金券数据 var cardData = new Card_GeneralCouponData() { base_info = _BaseInfo, default_detail = info.DefaultDetail }; #endregion #region 诊所发布 if (info.ShopId > 0) { _BaseInfo.custom_url = curHost + "/Shop/Home/" + info.ShopId.ToString(); } var vshopSetting = vshopser.GetVShopSetting(info.ShopId); var vshopinfo = vshopser.GetVShopByShopId(info.ShopId); var shopinfo = shopser.GetShop(info.ShopId); if (vshopSetting != null && shopinfo != null && vshopinfo != null) { if (!string.IsNullOrWhiteSpace(vshopSetting.AppId) && !string.IsNullOrWhiteSpace(vshopSetting.AppSecret)) { acctoken = GetAccessToken(vshopSetting.AppId, vshopSetting.AppSecret); if (!string.IsNullOrWhiteSpace(acctoken)) { _BaseInfo.brand_name = shopinfo.ShopName; if (!string.IsNullOrWhiteSpace(vshopinfo.WXLogo)) { wxlogo = curHost + vshopinfo.WXLogo; _BaseInfo.logo_url = wxlogo; } wxResultJson = CardApi.CreateCard(acctoken, cardData); if (wxResultJson.errcode == Senparc.Weixin.ReturnCode.请求成功) { info.AppId = vshopSetting.AppId; info.AppSecret = vshopSetting.AppSecret; info.CardId = wxResultJson.card_id; issuccess = true; } } } } #endregion if (!issuccess) { #region 平台发布 if (!string.IsNullOrWhiteSpace(siteSetting.WeixinAppId) && !string.IsNullOrWhiteSpace(siteSetting.WeixinAppSecret)) { acctoken = GetAccessToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret); if (!string.IsNullOrWhiteSpace(acctoken)) { _BaseInfo.brand_name = shopinfo.ShopName; if (!string.IsNullOrWhiteSpace(siteSetting.WXLogo)) { wxlogo = curHost + siteSetting.WXLogo; _BaseInfo.logo_url = wxlogo; } wxResultJson = CardApi.CreateCard(acctoken, cardData); if (wxResultJson.errcode == Senparc.Weixin.ReturnCode.请求成功) { info.AppId = siteSetting.WeixinAppId; info.AppSecret = siteSetting.WeixinAppSecret; info.CardId = wxResultJson.card_id; issuccess = true; } } } if (info.ShopId < 1) { _BaseInfo.custom_url = curHost + "/"; } #endregion } if (issuccess) { info.AuditStatus = (int)WXCardLogInfo.AuditStatusEnum.Auditin; //初始审核状态 //数据入库 Context.WXCardLogInfo.Add(info); Context.SaveChanges(); } return(issuccess); }
public bool Add(WXCardLogInfo info) { string str; bool flag = false; string accessToken = ""; string str1 = string.Concat("http://", WebHelper.GetHost()); string str2 = string.Concat(str1, "/images/defaultwxlogo.png"); SiteSettingsInfo siteSettings = Instance <ISiteSettingService> .Create.GetSiteSettings(); IShopService create = Instance <IShopService> .Create; IVShopService vShopService = Instance <IVShopService> .Create; CardCreateResultJson cardCreateResultJson = new CardCreateResultJson(); Card_BaseInfoBase cardBaseInfoBase = new Card_BaseInfoBase() { logo_url = str2, brand_name = siteSettings.SiteName, code_type = Card_CodeType.CODE_TYPE_BARCODE, title = info.CardTitle, sub_title = info.CardSubTitle, color = info.CardColor, notice = string.Concat("专供", siteSettings.SiteName, "使用") }; Card_BaseInfoBase cardBaseInfoBase1 = cardBaseInfoBase; string[] strArrays = new string[5]; string[] strArrays1 = strArrays; if (info.LeastCost > 0) { int leastCost = info.LeastCost / 100; str = string.Concat("满¥", leastCost.ToString("F2"), "使用"); } else { str = "无门槛使用"; } strArrays1[0] = str; strArrays[1] = ",有效期至"; strArrays[2] = info.BeginTime.ToString("yyyy年MM月dd日"); strArrays[3] = "-"; strArrays[4] = info.EndTime.ToString("yyyy年MM月dd日"); cardBaseInfoBase1.description = string.Concat(strArrays); Card_BaseInfo_DateInfo cardBaseInfoDateInfo = new Card_BaseInfo_DateInfo() { type = Card_DateInfo_Type.DATE_TYPE_FIX_TIME_RANGE.ToString(), begin_timestamp = Senparc.Weixin.Helpers.DateTimeHelper.GetWeixinDateTime(info.BeginTime), end_timestamp = Senparc.Weixin.Helpers.DateTimeHelper.GetWeixinDateTime(info.EndTime) }; cardBaseInfoBase.date_info = cardBaseInfoDateInfo; Card_BaseInfoBase cardBaseInfoBase2 = cardBaseInfoBase; Card_BaseInfo_Sku cardBaseInfoSku = new Card_BaseInfo_Sku() { quantity = (info.Quantity == 0 ? MaxStock : info.Quantity) }; cardBaseInfoBase2.sku = cardBaseInfoSku; cardBaseInfoBase.get_limit = (info.GetLimit == 0 ? MaxStock : info.GetLimit); cardBaseInfoBase.use_custom_code = false; cardBaseInfoBase.bind_openid = false; cardBaseInfoBase.can_share = false; cardBaseInfoBase.can_give_friend = false; cardBaseInfoBase.custom_url_name = "立即使用"; Card_BaseInfoBase shopName = cardBaseInfoBase; Card_GeneralCouponData cardGeneralCouponDatum = new Card_GeneralCouponData() { base_info = shopName, default_detail = info.DefaultDetail }; Card_GeneralCouponData cardGeneralCouponDatum1 = cardGeneralCouponDatum; if (info.ShopId > 0) { long shopId = info.ShopId; shopName.custom_url = string.Concat(str1, "/Shop/Home/", shopId.ToString()); } WXShopInfo vShopSetting = vShopService.GetVShopSetting(info.ShopId); VShopInfo vShopByShopId = vShopService.GetVShopByShopId(info.ShopId); ShopInfo shop = create.GetShop(info.ShopId, false); if (vShopSetting != null && shop != null && vShopByShopId != null && !string.IsNullOrWhiteSpace(vShopSetting.AppId) && !string.IsNullOrWhiteSpace(vShopSetting.AppSecret)) { accessToken = GetAccessToken(vShopSetting.AppId, vShopSetting.AppSecret); if (!string.IsNullOrWhiteSpace(accessToken)) { shopName.brand_name = shop.ShopName; if (!string.IsNullOrWhiteSpace(vShopByShopId.WXLogo)) { shopName.logo_url = string.Concat(str1, vShopByShopId.WXLogo); } cardCreateResultJson = CardApi.CreateCard(accessToken, cardGeneralCouponDatum1, 10000); if (cardCreateResultJson.errcode == ReturnCode.请求成功) { info.AppId = vShopSetting.AppId; info.AppSecret = vShopSetting.AppSecret; info.CardId = cardCreateResultJson.card_id; flag = true; } } } if (!flag) { if (!string.IsNullOrWhiteSpace(siteSettings.WeixinAppId) && !string.IsNullOrWhiteSpace(siteSettings.WeixinAppSecret)) { accessToken = GetAccessToken(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret); if (!string.IsNullOrWhiteSpace(accessToken)) { shopName.brand_name = shop.ShopName; if (!string.IsNullOrWhiteSpace(siteSettings.WXLogo)) { shopName.logo_url = string.Concat(str1, siteSettings.WXLogo); } cardCreateResultJson = CardApi.CreateCard(accessToken, cardGeneralCouponDatum1, 10000); if (cardCreateResultJson.errcode == ReturnCode.请求成功) { info.AppId = siteSettings.WeixinAppId; info.AppSecret = siteSettings.WeixinAppSecret; info.CardId = cardCreateResultJson.card_id; flag = true; } } } if (info.ShopId < 1) { shopName.custom_url = string.Concat(str1, "/"); } } if (flag) { info.AuditStatus = new int?(0); context.WXCardLogInfo.Add(info); context.SaveChanges(); } return(flag); }
/// <summary> /// 创建微信卡券 /// </summary> /// <param name="gift"></param> /// <returns></returns> public async Task <string> CreateWeChatCardAsync(GiftInputModel gift) { if (gift.Type == 0) { return(null); //实物不创建卡券 } var infoBase = new Card_BaseInfoBase { brand_name = "天使健康积分平台", can_give_friend = false, can_share = false, color = "Color010", code_type = Card_CodeType.CODE_TYPE_QRCODE, description = gift.Description, logo_url = "http://www.lgstatic.com/thumbnail_300x300/image1/M00/44/07/Cgo8PFXT8p2AIiAvAAAnzQSZgWQ814.png", notice = "请出示二维码核销卡券", sku = new Card_BaseInfo_Sku { quantity = 1000000, total_quantity = 1000000 } }; var timeStampBegin = new DateTime(1970, 1, 1); if (gift.ExpiryDate.HasValue) { var beginTimestamp = (DateTime.Now.Ticks - timeStampBegin.Ticks) / 10000000; var endTimestamp = (DateTime.MaxValue.Ticks - timeStampBegin.Ticks) / 10000000; infoBase.date_info = new Card_BaseInfo_DateInfo { begin_timestamp = beginTimestamp, end_timestamp = endTimestamp, type = "1" }; } if (gift.AvailableDays.HasValue) { infoBase.date_info = new Card_BaseInfo_DateInfo { fixed_begin_term = 0, fixed_term = gift.AvailableDays.Value, type = "2" }; } if (gift.Type == 1)//满减类 { infoBase.title = $"¥{gift.DiscountPrice} 代金券"; var cardInfo = new Card_CashData { least_cost = (int)(gift.OrderLimit.Value * 100), reduce_cost = (int)(gift.DiscountPrice.Value * 100), base_info = infoBase }; var result = await CardApi.CreateCardAsync(_wxParams.AppId, cardInfo); return(result.card_id); } if (gift.Type == 2)//打折类 { infoBase.title = $"{(long)gift.DiscountPrice.Value * 100}折 折扣券"; if (gift.OrderLimit.HasValue) { infoBase.title = $"满¥{(long)gift.OrderLimit}打{(long)gift.DiscountPrice.Value * 100}折"; } else { infoBase.title = $"{(long)gift.DiscountPrice.Value * 100}折优惠券"; } var discount = 100L - (long)gift.DiscountRate.Value * 100; var cardInfo = new Card_DisCountData { discount = discount }; var result = await CardApi.CreateCardAsync(_wxParams.AppId, cardInfo); return(result.card_id); } return(null); }