/// <summary> /// 卡券转赠 /// </summary> /// <param name="context"></param> /// <returns></returns> private string Give(HttpContext context) { string cardcouponId = context.Request["cardcoupon_id"];//我的卡券ID if (string.IsNullOrEmpty(cardcouponId)) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.PrimaryKeyIncomplete; apiResp.msg = "cardcoupon_id 参数必传"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } MyCardCoupons fromMyCardCoupon = bllCardCoupon.GetMyCardCoupon(int.Parse(cardcouponId));//要赠送的卡券信息 CardCoupons cardCoupon = bllCardCoupon.GetCardCoupon(fromMyCardCoupon.CardId); if (fromMyCardCoupon == null) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.PrimaryKeyIncomplete; apiResp.msg = "卡券不存在"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (fromMyCardCoupon.UserId == currentUserInfo.UserID) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.NoFollow; apiResp.msg = "不能接收自己的卡券"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (!string.IsNullOrEmpty(fromMyCardCoupon.FromUserId)) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.NoFollow; apiResp.msg = "优惠券不能多次转赠"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (cardCoupon.GetLimitType != null) { if (cardCoupon.GetLimitType == "1" && !bllUser.IsDistributionMember(currentUserInfo, true)) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyDistMember; apiResp.msg = "只有分销员才能领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } if (cardCoupon.GetLimitType == "2" && bllUser.IsDistributionMember(currentUserInfo)) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyNotDistMember; apiResp.msg = "该券仅新用户(无购买历史)可以领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } } if (!string.IsNullOrEmpty(cardCoupon.BindChannelUserId)) { if (string.IsNullOrEmpty(currentUserInfo.DistributionOwner)) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyChannel; apiResp.msg = "只有指定渠道才能领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } BLLJIMP.BLLDistribution bllDis = new BLLJIMP.BLLDistribution(); string channelUserId = bllDis.GetUserChannel(currentUserInfo); if (cardCoupon.BindChannelUserId != channelUserId) { apiResp.code = (int)BLLJIMP.Enums.APIErrCode.MallGetCardOnlyChannel; apiResp.msg = "只有指定渠道才能领取"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } } string msg = ""; if (!bllCardCoupon.IsCanGiveCoupon(fromMyCardCoupon, out msg))//无法转赠给他人 { apiResp.msg = msg; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { MyCardCoupons model = new MyCardCoupons(); model.CardCouponNumber = string.Format("No.{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), bllMall.GetGUID(BLLJIMP.TransacType.CommAdd)); model.CardCouponType = fromMyCardCoupon.CardCouponType; model.CardId = fromMyCardCoupon.CardId; model.InsertDate = DateTime.Now; model.UserId = currentUserInfo.UserID; model.WebSiteOwner = currentUserInfo.WebsiteOwner; model.FromUserId = fromMyCardCoupon.UserId; if (!bllCardCoupon.Add(model)) { tran.Rollback(); apiResp.msg = "接收失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } fromMyCardCoupon.Status = 2; fromMyCardCoupon.ToUserId = currentUserInfo.UserID; if (!bllCardCoupon.Update(fromMyCardCoupon)) { tran.Rollback(); apiResp.msg = "接收失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } // CardCoupons cardCoupon = bllCardCoupon.GetCardCoupon(fromMyCardCoupon.CardId); //if (cardCoupon == null) //{ // tran.Rollback(); // apiResp.msg = "卡券不存在"; // return ZentCloud.Common.JSONHelper.ObjectToJson(apiResp); //} UserInfo fromUserInfo = bllUser.GetUserInfo(fromMyCardCoupon.UserId); if (fromUserInfo == null) { tran.Rollback(); apiResp.msg = "赠送用户不存在"; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } bllWeixin.SendTemplateMessageNotifyComm(fromUserInfo, "优惠券转赠通知", string.Format(" {0}已领取你转赠的优惠券{1}", bllUser.GetUserDispalyName(currentUserInfo), cardCoupon.Name)); bllWeixin.SendTemplateMessageNotifyComm(currentUserInfo, "优惠券领取通知", string.Format(" 您已经领取来自{0}转赠的优惠券{1}", bllUser.GetUserDispalyName(fromUserInfo), cardCoupon.Name)); tran.Commit(); #region 分销关系建立 BLLPermission.BLLMenuPermission bllMenuPermission = new BLLPermission.BLLMenuPermission(""); if (bllMenuPermission.CheckUserAndPmsKey(currentUserInfo.WebsiteOwner, BLLPermission.Enums.PermissionSysKey.OnlineDistribution)) { if (string.IsNullOrWhiteSpace(currentUserInfo.DistributionOwner)) { WebsiteInfo websiteInfo = bllMall.GetWebsiteInfoModelFromDataBase(); if (websiteInfo.DistributionRelationBuildMallOrder == 1) { if (bllUser.IsDistributionMember(fromUserInfo) || (fromUserInfo.UserID == websiteInfo.WebsiteOwner))//上级符合分销员标准 { BLLJIMP.BLLDistribution bllDis = new BLLJIMP.BLLDistribution(); var setUserDistributionOwnerResult = bllDis.SetUserDistributionOwner(currentUserInfo.UserID, fromUserInfo.UserID, currentUserInfo.WebsiteOwner); } } } } #endregion apiResp.status = true; apiResp.msg = "ok"; } catch (Exception ex) { apiResp.msg = ex.Message; return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); } return(ZentCloud.Common.JSONHelper.ObjectToJson(apiResp)); }