//取未过期的券 public ResultObj <List <PrivilegeMemberRelationModel> > GetNoneExpirePrivilegeByMemberId(string memberId = "") { PrivilegeMemberRelationModel privilegeMemberInfo = new PrivilegeMemberRelationModel(); privilegeMemberInfo.MemberId = memberId; IWechat iwechat = new WechatService(); return(Content(iwechat.GetNoneExpirePrivilegeByMemberId(privilegeMemberInfo))); }
/// <summary> /// 取得会员可领优惠券的次数 /// </summary> /// <param name="memberId"></param> /// <param name="clientId"></param> /// <returns></returns> public ResultObj <int> GetCanTakeTicketCount(string memberId = "", string clientId = "", string principleType = "") { PrivilegeMemberRelationModel privilegeMemberInfo = new PrivilegeMemberRelationModel(); privilegeMemberInfo.MemberId = memberId; privilegeMemberInfo.ClientId = clientId; privilegeMemberInfo.PrincipleType = principleType; IWechat iwechat = new WechatService(); return(Content(iwechat.GetCanTakeTicketCount(privilegeMemberInfo))); }
public ResultObj <List <PrivilegeMemberRelationModel> > GetPrivilegeByMemberId(string memberId = "", int pageIndex = 1, int pageSize = 10) { PrivilegeMemberRelationModel privilegeMemberInfo = new PrivilegeMemberRelationModel(); privilegeMemberInfo.MemberId = memberId; privilegeMemberInfo.PageIndex = pageIndex; privilegeMemberInfo.PageSize = pageSize; IWechat iwechat = new WechatService(); return(Content(iwechat.GetPrivilegeByMemberId(privilegeMemberInfo))); }
public ResultObj <int> GivePrivilegeTicket([FromBody] PrivilegeMemberRelationModel privilegeMemberInfo) { if (!string.IsNullOrEmpty(privilegeMemberInfo.TimeRule)) { if (privilegeMemberInfo.TimeRule == "1") { privilegeMemberInfo.ExpireTime = Convert.ToDateTime(DateTime.Now.ToString("yyyyy-MM-dd") + " 23:59:59"); } } privilegeMemberInfo.PrivilegeStatus = 1; IMember _imember = new MemberService(); return(Content(_imember.GivePrivilegeTicket(privilegeMemberInfo))); }
public ResultObj <List <PrivilegeMemberRelationModel> > GetPrivilegeByMemberId(string memberId = "", int pageIndex = 1, int pageSize = 10) { PrivilegeMemberRelationModel privilegeMemberInfo = new PrivilegeMemberRelationModel(); privilegeMemberInfo.MemberId = memberId; privilegeMemberInfo.PageIndex = pageIndex; privilegeMemberInfo.PageSize = pageSize; IWechat iwechat = new WechatService(); int totalcount = iwechat.GetPrivilegeCountByMemberId(privilegeMemberInfo); var pagination = new Pagination { PageSize = pageSize, PageIndex = pageIndex, StartIndex = 0, TotalRows = totalcount, TotalPage = 0 }; return(Content(iwechat.GetPrivilegeByMemberId(privilegeMemberInfo), pagination)); }
public ResultObj <int> GetTicket([FromBody] PrivilegeMemberRelationModel privilegeMemberInfo) { IWechat iwechat = new WechatService(); int count = iwechat.IsExistTicket(privilegeMemberInfo); if (count > 0) { return(Content(0)); } if (!string.IsNullOrEmpty(privilegeMemberInfo.TimeRule)) { if (privilegeMemberInfo.TimeRule == "1") { privilegeMemberInfo.ExpireTime = Convert.ToDateTime(DateTime.Now.ToString("yyyyy-MM-dd") + " 23:59:59"); } } privilegeMemberInfo.PrivilegeStatus = 1; return(Content(iwechat.PostTicket(privilegeMemberInfo))); }
public int GivePrivilegeTicket(PrivilegeMemberRelationModel privilegeMemberInfo) { privilegeMemberInfo.Id = Guid.NewGuid().ToString(); privilegeMemberInfo.GetDate = DateTime.Now; return(GenerateDal.Create(privilegeMemberInfo)); }
//微信支付 public ResultObj <PayStateModel> PostDataW(string clientId, string openId, string privilegeIds, string selfChosen, [FromBody] List <ProductPayModel> lstProductPay) { var log = LogManager.GetLogger("FycnApi", "wechat"); try { IPay _ipay = new PayService(); //移动支付赋值 WxPayConfig payConfig = _ipay.GenerateConfigModelWByClientId(clientId); payConfig.NOTIFY_URL = PathConfig.NotidyAddr + "/Wechat/PostPayResultW"; //结果通知方法 JsApi jsApi = new JsApi(); PayModel payInfo = new PayModel(); payInfo.openid = openId; //JsApi.payInfo = new PayModel(); //生成code 根据code取微信支付的openid和access_token //jsApi.GetOpenidAndAccessToken(code, payConfig, payInfo, "/wechat.html#/pay?clientId=" + clientId, ""); PayStateModel payState = new PayStateModel(); //JSAPI支付预处理 //string result = HttpService.Get(payInfo.redirect_url); //生成交易号 payInfo.trade_no = new PayHelper().GeneraterTradeNo(); payInfo.jsonProduct = clientId; //取商品信息 decimal totalFee = 0; string productNames = string.Empty; List <ProductListModel> lstProduct = new List <ProductListModel>(); IWechat _iwechat = new WechatService(); string waresId = string.Empty; string waresGroupId = string.Empty; foreach (ProductPayModel productInfo in lstProductPay) { waresId = waresId + productInfo.WaresId + ","; } lstProduct = _iwechat.GetProdcutAndGroupList(waresId.TrimEnd(','), waresGroupId.TrimEnd(',')); //遍历商品 foreach (ProductListModel productInfo in lstProduct) { var productPay = (from m in lstProductPay where m.WaresId == productInfo.WaresId select m).ToList <ProductPayModel>(); if (productPay.Count > 0) { totalFee = totalFee + Convert.ToInt32(productPay[0].Number) * Convert.ToDecimal(productInfo.WaresDiscountUnitPrice == 0 ? productInfo.WaresUnitPrice: productInfo.WaresDiscountUnitPrice); productNames = productNames + productInfo.WaresName + ","; productPay[0].TradeNo = payInfo.trade_no; } } payInfo.product_name = productNames.Length > 25 ? productNames.Substring(0, 25) : productNames; payState.ProductJson = JsonHandler.GetJsonStrFromObject(lstProductPay, false); /*******************优惠券信息**********************/ PrivilegeMemberRelationModel privilegeInfo = new PrivilegeMemberRelationModel(); privilegeInfo.ClientId = clientId; privilegeInfo.MemberId = openId; if (totalFee > 0.01M) { List <PrivilegeMemberRelationModel> lstPrivilege = new List <PrivilegeMemberRelationModel>(); if (string.IsNullOrEmpty(privilegeIds) && string.IsNullOrEmpty(selfChosen)) { lstPrivilege = _iwechat.GetCanUsePrivilege(privilegeInfo, privilegeIds, ref totalFee, lstProductPay); } else if (!string.IsNullOrEmpty(privilegeIds)) { lstPrivilege = _iwechat.GetChosenPrivilege(privilegeInfo, privilegeIds, ref totalFee, lstProductPay); } log.Info("ddddd" + lstPrivilege.Count); if (lstPrivilege.Count > 0) { string[] lstStr = lstPrivilege.Select(m => m.Id).ToArray(); if (string.IsNullOrEmpty(privilegeIds)) { payInfo.jsonProduct = payInfo.jsonProduct + "~" + string.Join(",", lstStr); } else { payInfo.jsonProduct = payInfo.jsonProduct + "~" + privilegeIds; } payState.PrivilegeJson = JsonHandler.GetJsonStrFromObject(lstPrivilege, false); } } //string total_fee = "1"; //检测是否给当前页面传递了相关参数 // 1.先取购买商品的详情返回给用户 并缓存到页面 2.支付成功后跳转到支付结果页并把缓存数据插入到销售记录表 //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 // jsApiPay.openid = openid; /* * decimal privilegeMoney = 0; * int weixinMoney = 0; * if (lstPrivilege.Count > 0) * { * if (lstPrivilege[0].Money>0) * { * privilegeMoney = lstPrivilege[0].Money; * weixinMoney = Convert.ToInt32(((totalFee - privilegeMoney) * 100)); * } * else * { * privilegeMoney = lstPrivilege[0].Discount; * weixinMoney = Convert.ToInt32(((totalFee) * 100)* (privilegeMoney/10)); * } * * } * else * { */ int weixinMoney = Convert.ToInt32((totalFee) * 100); //} payInfo.total_fee = (weixinMoney < 0 ? 1 : weixinMoney); //payInfo.jsonProduct = JsonHandler.GetJsonStrFromObject(keyJsonInfo, false); payState.TotalMoney = (totalFee < 0 ? Convert.ToDecimal(0.01) : totalFee); //写入交易中转 if (payInfo.total_fee == 0) { payState.RequestState = "2"; payState.RequestData = ""; return(Content(payState)); } RedisHelper helper = new RedisHelper(0); helper.StringSet(payInfo.trade_no.Trim(), JsonHandler.GetJsonStrFromObject(lstProductPay, false), new TimeSpan(0, 10, 30)); // FileHandler.WriteFile("data/", JsApi.payInfo.trade_no + ".wa", JsApi.payInfo.jsonProduct); WxPayData unifiedOrderResult = jsApi.GetUnifiedOrderResult(payInfo, payConfig); // Log.Write("GetDataW", "step step"); string wxJsApiParam = jsApi.GetJsApiParameters(payConfig, payInfo);//获取H5调起JS API参数 payState.RequestState = "1"; payState.RequestData = wxJsApiParam; return(Content(payState)); } catch (Exception ex) { PayStateModel payStateError = new PayStateModel(); payStateError.RequestState = "3"; payStateError.RequestData = ex.Message; return(Content(payStateError)); } return(Content(new PayStateModel())); }