/// <summary> /// 领取卡券 /// </summary> /// <param name="context"></param> /// <returns></returns> private string ReciveCardCoupon(HttpContext context) { string cardCouponId = context.Request["cardcoupon_id"]; CardCoupons cardCoupon = bllCardCoupon.GetCardCoupon(int.Parse(cardCouponId)); if (cardCoupon == null) { resp.errcode = 1; resp.errmsg = "cardcoupon_id 不存在"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } cardCoupon = bllCardCoupon.ConvertExpireTime(cardCoupon); var myCardCoupon = bllCardCoupon.GetMyCardCouponMainId(int.Parse(cardCouponId), currentUserInfo.UserID); if (myCardCoupon != null) { resp.errcode = 1; resp.errmsg = "已经领取过了"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (DateTime.Now > (DateTime)(cardCoupon.ValidTo)) { resp.errcode = 2; resp.errmsg = "卡券已过期"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (cardCoupon.MaxCount > 0) { if (bllCardCoupon.GetCardCouponSendCount(cardCoupon.CardId) >= cardCoupon.MaxCount) { resp.errcode = 2; resp.errmsg = "卡券已经领完"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } if (cardCoupon.GetLimitType != null) { if (cardCoupon.GetLimitType == "1" && !bllUser.IsDistributionMember(currentUserInfo, true)) { resp.errcode = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyDistMember; resp.errmsg = "只有分销员才能领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (cardCoupon.GetLimitType == "2" && bllUser.IsDistributionMember(currentUserInfo)) { resp.errcode = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyNotDistMember; resp.errmsg = "该券仅新用户(无购买历史)可以领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } if (!string.IsNullOrEmpty(cardCoupon.BindChannelUserId)) { if (string.IsNullOrEmpty(currentUserInfo.DistributionOwner)) { resp.errcode = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyChannel; resp.errmsg = "只有指定渠道才能领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } BLLJIMP.BLLDistribution bllDis = new BLLJIMP.BLLDistribution(); string channelUserId = bllDis.GetUserChannel(currentUserInfo); if (cardCoupon.BindChannelUserId != channelUserId) { resp.errcode = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyChannel; resp.errmsg = "只有指定渠道才能领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } MyCardCoupons model = new MyCardCoupons(); model.CardCouponNumber = string.Format("No.{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), bllMall.GetGUID(BLLJIMP.TransacType.CommAdd)); model.CardCouponType = cardCoupon.CardCouponType; model.CardId = cardCoupon.CardId; model.InsertDate = DateTime.Now; model.UserId = currentUserInfo.UserID; model.WebSiteOwner = bllCardCoupon.WebsiteOwner; if (bllCardCoupon.Add(model)) { resp.errmsg = "ok"; string title = "您收到了一张优惠券"; string content = string.Format("{0}", cardCoupon.Name); if (cardCoupon.ValidTo.HasValue) { content += string.Format("\\n{0}", ((DateTime)cardCoupon.ValidTo).ToString("yyyy-MM-dd")); } string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/mycoupons#/mycoupons", context.Request.Url.Host); if (bllUser.WebsiteOwner == "jikuwifi") { url = string.Format("http://{0}/customize/jikuwifi/?v=1.0&ngroute=/mycoupons#/mycoupons", context.Request.Url.Host); } bllWeixin.SendTemplateMessageNotifyComm(currentUserInfo, title, content, url); //#region 同时发放到微信卡包 //if (!string.IsNullOrEmpty(cardCoupon.WeixinCardId) && (!string.IsNullOrEmpty(CurrentUserInfo.WXOpenId))) //{ // bllWeixinCard.SendByMass(cardCoupon.WeixinCardId, CurrentUserInfo.WXOpenId); //} //#endregion } else { resp.errcode = 1; resp.errmsg = "领取优惠券失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }