/// <summary> /// 修改卡券库存 /// </summary> /// <param name="num"></param> /// <param name="cardid"></param> public void EditStock(int num, string cardid) { var carddata = Context.WXCardLogInfo.FirstOrDefault(d => d.CardId == cardid); if (carddata != null) { var acctoken = GetAccessToken(carddata.AppId, carddata.AppSecret); if (!string.IsNullOrWhiteSpace(acctoken)) { //获取现在库存 var wxcarddata = CardApi.CardDetailGet(acctoken, carddata.CardId); if (wxcarddata != null) { //计算差值 var diffnum = num - wxcarddata.card.general_coupon.base_info.sku.quantity; if (diffnum != 0) { //提交修改 var wxResultJson = CardApi.ModifyStock(acctoken, carddata.CardId, (diffnum > 0 ? diffnum : 0), (diffnum < 0 ? Math.Abs(diffnum) : 0)); if (wxResultJson.errcode != Senparc.Weixin.ReturnCode.请求成功) { Core.Log.Error("微信同步修改卡券库存失败", new Exception(((int)wxResultJson.errcode).ToString())); } } } } } }
//// 取得token //private string getWxToken(int agentid = 0) //{ // var config = WeChatCommonService.GetWeChatConfigByID(agentid); // var strToken = AccessTokenContainer.GetToken(config.WeixinCorpId, config.WeixinCorpSecret); // if (!string.IsNullOrEmpty(strToken)) // { // return strToken; // } // return null; //} #region 查看卡券详情接口 /// <summary> /// 查看卡券详情接口 /// </summary> /// <param name="cardId">卡券ID</param> /// <returns></returns> public ActionResult GetCardDetail(string cardId) { if (!VerifyParam("cardId")) { return(ErrMsg()); } var weChatConfig = GetWechatConfig(); var ret = CardApi.CardDetailGet(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, cardId); if (ret.errcode == Weixin.ReturnCode.请求成功) { return(Json(new { message = "", success = true, card = ret.card }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { message = ret.errmsg, success = false }, JsonRequestBehavior.AllowGet)); } }
public void EditStock(int num, string cardid) { WXCardLogInfo wXCardLogInfo = context.WXCardLogInfo.FirstOrDefault((WXCardLogInfo d) => d.CardId == cardid); if (wXCardLogInfo != null) { string accessToken = GetAccessToken(wXCardLogInfo.AppId, wXCardLogInfo.AppSecret); if (!string.IsNullOrWhiteSpace(accessToken)) { CardDetailGetResultJson cardDetailGetResultJson = CardApi.CardDetailGet(accessToken, wXCardLogInfo.CardId, 10000); if (cardDetailGetResultJson != null) { int num1 = num - cardDetailGetResultJson.card.general_coupon.base_info.sku.quantity; if (num1 != 0) { WxJsonResult wxJsonResult = CardApi.ModifyStock(accessToken, wXCardLogInfo.CardId, (num1 > 0 ? num1 : 0), (num1 < 0 ? Math.Abs(num1) : 0), 10000); if (wxJsonResult.errcode != ReturnCode.请求成功) { int num2 = (int)wxJsonResult.errcode; Log.Error("微信同步修改卡券库存失败", new Exception(num2.ToString())); } } } } } }
public void CardDetailGet() { string cardId = "p3IHxjt-CLCTd_r3eZ9cQqM7jrZE"; //换成你的卡券Id var accessToken = AccessTokenContainer.GetToken(_appId); var result = CardApi.CardDetailGet(accessToken, cardId); Console.Write(result); Assert.IsNotNull(result); }
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "toufang") { // int dd = int.Parse(lbtn_Update.CommandArgument.ToString()); int dd = int.Parse(e.Item.ItemIndex.ToString()); string Cardid = ((HiddenField)rptList.Items[dd].FindControl("HiddenField1")).Value; var cardId = Cardid; string accessToken = Token(); var result = CardApi.CreateQR(accessToken, cardId); string ticket = result.ticket; string url_image = GetShowQrCodeUrl(ticket); int ss = int.Parse(e.Item.ItemIndex.ToString()); Image sss = (Image)rptList.Items[ss].FindControl("Image2"); sss.ImageUrl = url_image; } else if (e.CommandName == "deletecard") { DropDownList dr = new DropDownList(); dr = (DropDownList)rptList.Controls[0].FindControl("DropDownList2"); string dd = dr.SelectedValue; int cardid = int.Parse(e.Item.ItemIndex.ToString()); string card_wx_id = ((HiddenField)rptList.Items[cardid].FindControl("HiddenField1")).Value; var result = CardApi.CardDelete(Token(), card_wx_id); if (result.errmsg == "ok") { bll.delete(card_wx_id); } else { string ss = result.errmsg; } string where = "wid=" + wid() + " and Card_type=团购券"; Rqlistb(where); } else if (e.CommandName == "update_q") { int dd = int.Parse(e.Item.ItemIndex.ToString()); string Cardid = ((HiddenField)rptList.Items[dd].FindControl("HiddenField1")).Value; var cardId = Cardid; string Cardtype = ((HiddenField)rptList.Items[dd].FindControl("hd2")).Value; string accessToken = Token(); int ss = int.Parse(e.Item.ItemIndex.ToString()); TextBox sss = (TextBox)rptList.Items[ss].FindControl("quantity"); var result = CardApi.CardDetailGet(accessToken, cardId); if (Cardtype == "团购券") { sss.Text = result.card.groupon.base_info.sku.quantity.ToString(); } else if (Cardtype == "代金券") { sss.Text = result.card.cash.base_info.sku.quantity.ToString(); } else if (Cardtype == "折扣券") { sss.Text = result.card.discount.base_info.sku.quantity.ToString(); } else if (Cardtype == "优惠券") { sss.Text = result.card.general_coupon.base_info.sku.quantity.ToString(); } Model.Card_wx.Card_BaseInfo Base = new Model.Card_wx.Card_BaseInfo(); Base.quantity = int.Parse(sss.Text); Base.Wx_Card_id = cardId; Base.wid = wid(); bll.Upadata_kucun(Base); // var result= CardApi.ModifyStock(Token(), Cardid, int.Parse(sss.Text)); // try // { // if (result.errmsg == "ok") // { // } // } // catch (Exception ex) // { // } } else if (e.CommandName == "exit") { int dd = int.Parse(e.Item.ItemIndex.ToString()); string Cardid = ((HiddenField)rptList.Items[dd].FindControl("HiddenField1")).Value; var cardId = Cardid; string Cardtype = ((HiddenField)rptList.Items[dd].FindControl("hd2")).Value; Response.Redirect("Card_wx_exid.aspx?cardtype=" + Cardtype + "&cardid=" + cardId + "&type=exit"); } }