예제 #1
0
        /// <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()));
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        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 ModifyStock()
        {
            var ModifyInfo = new ModifyStockRequest()
            {
                CardId           = "pl0uwwXdAIetRFMDxLlsoqRlBJac",
                ReduceStockValue = 100
            };
            var result = _weChatApi.ModifyStock(ModifyInfo);

            if (!result.IsSuccess())
            {
                Assert.Fail("修改库存失败,错误信息:" + result.DetailResult + ";Msg:" + result.GetFriendlyMessage());
            }
        }