/// <summary>
        /// 使用卡券
        /// </summary>
        /// <param name="code"></param>
        /// <param name="cardid"></param>
        /// <returns></returns>
        public void Consume(string cardid, string code)
        {
            WXCardCodeLogInfo wxcdata = Context.WXCardCodeLogInfo.FirstOrDefault(d => d.CardId == cardid && d.Code == code);

            if (wxcdata != null)
            {
                var carddata = Context.WXCardLogInfo.FirstOrDefault(d => d.Id == wxcdata.CardLogId.Value);
                if (carddata != null)
                {
#if DEBUG
                    Core.Log.Info("开始核销卡券:" + wxcdata.Code);
#endif
                    var acctoken = GetAccessToken(carddata.AppId, carddata.AppSecret);
                    if (!string.IsNullOrWhiteSpace(acctoken) && !string.IsNullOrWhiteSpace(wxcdata.Code))
                    {
                        var wxResultJson = CardApi.CardUnavailable(acctoken, wxcdata.Code, wxcdata.CardId);
                        if (wxResultJson.errcode != Senparc.Weixin.ReturnCode.请求成功)
                        {
                            Core.Log.Error("微信同步使用卡券失败", new Exception(((int)wxResultJson.errcode).ToString() + ":" + wxResultJson.errmsg));
                        }
                    }
                }
                wxcdata.CodeStatus = (int)WXCardCodeLogInfo.CodeStatusEnum.HasConsume;
                wxcdata.UsedTime   = DateTime.Now;
                Context.SaveChanges();
            }
        }
Exemple #2
0
        public void Unavailable(string cardid, string code)
        {
            WXCardCodeLogInfo nullable = context.WXCardCodeLogInfo.FirstOrDefault((WXCardCodeLogInfo d) => (d.CardId == cardid) && (d.Code == code));

            if (nullable != null)
            {
                WXCardLogInfo wXCardLogInfo = context.WXCardLogInfo.FirstOrDefault((WXCardLogInfo d) => d.Id == nullable.CardLogId.Value);
                if (wXCardLogInfo != null)
                {
                    string accessToken = GetAccessToken(wXCardLogInfo.AppId, wXCardLogInfo.AppSecret);
                    if (!string.IsNullOrWhiteSpace(accessToken))
                    {
                        WxJsonResult wxJsonResult = CardApi.CardUnavailable(accessToken, nullable.Code, nullable.CardId, 10000);
                        if (wxJsonResult.errcode != ReturnCode.请求成功)
                        {
                            int num = (int)wxJsonResult.errcode;
                            Log.Error("微信同步修改卡券库存失败", new Exception(string.Concat(num.ToString(), ":", wxJsonResult.errmsg)));
                        }
                    }
                }
                nullable.CodeStatus = -1;
                nullable.UsedTime   = new DateTime?(DateTime.Now);
                context.SaveChanges();
            }
        }
Exemple #3
0
        /// <summary>
        /// 设置卡券失效接口
        /// </summary>
        /// <param name="code">需要设置为失效的code</param>
        /// <param name="cardId">自定义code 的卡券必填。非自定义code 的卡券不填。</param>
        /// <returns></returns>
        public ActionResult CardUnavailable(string code, string cardId)
        {
            if (!VerifyParam("code"))
            {
                return(ErrMsg());
            }

            var weChatConfig = GetWechatConfig();

            var ret = CardApi.CardUnavailable(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, code, cardId);


            if (ret.errcode == Weixin.ReturnCode.请求成功)
            {
                return(Json(new
                {
                    message = "",
                    success = true
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new
                {
                    message = ret.errmsg,
                    success = false
                }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #4
0
 /// <summary>
 /// 卡券Code失效
 /// </summary>
 /// <param name="code"></param>
 /// <param name="cardid"></param>
 public void Unavailable(string cardid, string code)
 {
     Entities.WXCardCodeLogInfo wxcdata = DbFactory.Default.Get <Entities.WXCardCodeLogInfo>().Where(d => d.CardId == cardid && d.Code == code).FirstOrDefault();
     if (wxcdata != null)
     {
         var carddata = DbFactory.Default.Get <Entities.WXCardLogInfo>().Where(d => d.Id == wxcdata.CardLogId).FirstOrDefault();
         if (carddata != null)
         {
             var acctoken = GetAccessToken(carddata.AppId, carddata.AppSecret);
             if (!string.IsNullOrWhiteSpace(acctoken))
             {
                 var wxResultJson = CardApi.CardUnavailable(acctoken, wxcdata.Code, wxcdata.CardId);
                 if (wxResultJson.errcode != Senparc.Weixin.ReturnCode.请求成功)
                 {
                     Core.Log.Error("微信同步修改卡券库存失败", new Exception(((int)wxResultJson.errcode).ToString() + ":" + wxResultJson.errmsg));
                 }
             }
         }
         wxcdata.CodeStatus = (int)Entities.WXCardCodeLogInfo.CodeStatusEnum.HasFailed;
         wxcdata.UsedTime   = DateTime.Now;
         DbFactory.Default.Update(wxcdata);
     }
 }