public async Task <IActionResult> CreateMemberCard([FromServices] IUtilRepository util) { var ret = new JsonData(); using (StreamReader d = new StreamReader(Request.Body)) { var str = await d.ReadToEndAsync(); var json = JObject.Parse(str); json["card"]["member_card"]["base_info"]["logo_url"] = $"{AppData.FileUri}/File/Logo/{Business.ID}/{Business.LogoSrc}"; LoadRule((JObject)json["card"], out List <CardChargeRule> charges, out CardBonusRule bonusSale, out CardBonusRule bonusCharge, out CardBonusRule bonusOpen); var token = await util.GetTokenAsync(Business.WeChatAppId, Business.WeChatSecret); var msg = await WxHelper.CreateCardAsync(token, json); var result = JObject.Parse(msg); if (result["errcode"].ToString() != "0") { ret.Msg = result["errmsg"].ToString(); return(Json(ret)); } var data = new WxCard { BusinessId = Business.ID, CardId = result["card_id"].ToString(), Category = CardCategory.MemberCard, Name = json["card"]["member_card"]["base_info"]["brand_name"].ToString(), Status = EntityStatus.Normal, Color = json["card"]["member_card"]["base_info"]["color"].ToString() }; var card = await Service.AddAsync(data); charges.ForEach(a => a.WxCardId = card.ID); bonusSale.WxCardId = card.ID; bonusCharge.WxCardId = card.ID; bonusOpen.WxCardId = card.ID; await Service.SaveCardChargesAsync(charges); await Service.SaveCardBonusAsync(new[] { bonusSale, bonusCharge, bonusOpen }); SetMemberCardActiveOptionAsync(card); ret.Success = true; ret.Msg = "εε»Ίζε"; ret.Data = data.CardId; return(Json(ret)); } }