/// <summary> /// 缴费通知Json方式获取 /// </summary> /// <param name="pageIndex"></param> /// <returns></returns> public JsonResult ExpenseNoticeJsonList(int pageIndex) { PageResultModel model = new PageResultModel(); var owner = GetCurrentUser(); //初始化查询条件 var DoorIds = owner.PropertyIdentityVerification.Where(v => v.DoorId != null && v.IsVerified == 1).Select(m => m.DoorId); var CompanyIds = owner.PropertyIdentityVerification.Where(v => v.BuildCompanyId != null && v.IsVerified == 1).Select(m => m.BuildCompanyId); Expression <Func <T_HouseUserExpenseDetails, bool> > where = u => (DoorIds.Contains(u.BuildDoorId) || CompanyIds.Contains(u.BuildCompanyId)); // 获取当前用户对应业主的缴费记录 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); model.Result = expenseDetailsBLL.GetPageList(where, "CreateDate", false, pageIndex).Select(m => new { Id = m.Id, ExpenseTitle = string.Format("{0}缴费通知", m.PropertyExpenseType.Name), ExpenseContent = string.Format("{0}{1}{2}{3}的业主你好, 您{4}总计{5}元。请及时到物业办公室或登录Ai我家App缴费, 谢谢!", m.BuildDoor.BuildUnit.Build.PropertyPlace.Name, m.BuildDoor.BuildUnit.Build.BuildName, m.BuildDoor.BuildUnit.UnitName, m.BuildDoor.DoorName, m.ExpenseDateDes, m.Expense), CreateDate = m.CreateDate, strCreateDate = m.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") }).ToList(); model.Total = expenseDetailsBLL.Count(where); return(Json(model, JsonRequestBehavior.AllowGet)); }
public JsonResult Paying(ExpenseDetailsModel model) { JsonModel jm = new JsonModel(); //获取要去缴费的缴费明细 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var expenseDetails = expenseDetailsBLL.GetEntity(u => u.Id == model.Id); if (expenseDetails == null) { jm.Msg = "该缴费记录不存在"; } else if (expenseDetails.IsPayed == ConstantParam.PAYED_TRUE) { jm.Msg = "该缴费记录已缴费"; } else { expenseDetails.IsPayed = ConstantParam.PAYED_TRUE; expenseDetails.PaymentType = 1; expenseDetails.PayedDate = DateTime.Now; expenseDetails.Operator = GetSessionModel().UserID; expenseDetails.InvoiceType = model.InvoiceType; //编辑成功 if (expenseDetailsBLL.Update(expenseDetails)) { //记录操作日志 jm.Content = PropertyUtils.ModelToJsonString(model); } } return(Json(jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 公众号首页 /// </summary> /// <returns></returns> public ActionResult Index() { HomeDataModel model = new HomeDataModel(); var owner = GetCurrentUser(); var PlaceIds = GetVerifiedPlaceIds(); //初始化查询条件 var DoorIds = owner.PropertyIdentityVerification.Where(v => v.DoorId != null && v.IsVerified == 1).Select(m => m.DoorId); var CompanyIds = owner.PropertyIdentityVerification.Where(v => v.BuildCompanyId != null && v.IsVerified == 1).Select(m => m.BuildCompanyId); Expression <Func <T_HouseUserExpenseDetails, bool> > where = u => u.IsPayed == ConstantParam.PAYED_FALSE && (DoorIds.Contains(u.BuildDoorId) || CompanyIds.Contains(u.BuildCompanyId)); // 获取当前用户对应业主的缴费记录 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); model.ExpenseList = expenseDetailsBLL.GetPageList(where, "CreateDate", false, 1, 1).Select(e => new ExpenseNoticeModel { ExpenseType = e.PropertyExpenseType.Name, PlaceName = e.BuildCompanyId == null ? e.BuildDoor.BuildUnit.Build.PropertyPlace.Name : e.BuildCompany.PropertyPlace.Name, OwnerDoor = e.BuildCompanyId == null ? (e.BuildDoor.BuildUnit.Build.BuildName + e.BuildDoor.BuildUnit.UnitName + e.BuildDoor.DoorName) : e.BuildCompany.Name, ExpenseDateDes = e.ExpenseDateDes, Cost = e.Expense + "元" }).ToList(); // 获取用户关联小区的公告列表 IPostBLL postBll = BLLFactory <IPostBLL> .GetBLL("PostBLL"); var placeList = owner.UserPlaces.Select(m => m.PropertyPlaceId); Expression <Func <T_Post, bool> > where1 = u => placeList.Contains(u.PropertyPlaceId) && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && u.PublishedFlag == ConstantParam.PUBLISHED_TRUE; model.NewsList = postBll.GetPageList(where1, "PublishedTime", false, 1, 3).Select(p => new NewsModel { Id = p.Id, PlaceName = p.PropertyPlace.Name, propertyPic = string.IsNullOrEmpty(p.PropertyPlace.ImgThumbnail) ? "/Images/news_item_default.png" : p.PropertyPlace.ImgThumbnail, PublishTime = p.PublishedTime.Value.ToString("yyyy-MM-dd HH:mm:ss"), Title = p.Title }).ToList(); //获取最新上报的问题 IQuestionBLL questionBll = BLLFactory <IQuestionBLL> .GetBLL("QuestionBLL"); Expression <Func <T_Question, bool> > where2 = u => u.UploadUserId == owner.Id && PlaceIds.Contains(u.PropertyPlaceId); model.QuestionList = questionBll.GetPageList(where2, "Id", false, 1, 2).ToList().Select(q => new QuestionModel { Id = q.Id, PlaceName = q.PropertyPlace.Name, Title = q.Title, Desc = string.IsNullOrEmpty(q.Desc) ? "" : q.Desc, Status = q.Status, UploadTime = q.UploadTime.ToString("yyyy-MM-dd HH:mm:ss"), Imgs = string.IsNullOrEmpty(q.Imgs) ? new string[] { } : q.Imgs.Split(';'), AudioPath = q.AudioPath, VoiceDuration = q.VoiceDuration }).ToList(); return(View(model)); }
public ApiPageResultModel ExpensedRecordList([FromUri] PagedSearchModel model) { ApiPageResultModel resultModel = new ApiPageResultModel(); try { //根据用户ID查找业主 IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); T_User owner = ownerBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果业主存在 if (owner != null) { //如果验证Token不通过或已过期 if (DateTime.Now > owner.TokenInvalidTime || model.Token != owner.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 owner.LatelyLoginTime = DateTime.Now; owner.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); ownerBll.Update(owner); //初始化查询条件 var DoorIds = owner.PropertyIdentityVerification.Where(v => v.DoorId != null).Select(m => m.DoorId); var CompanyIds = owner.PropertyIdentityVerification.Where(v => v.BuildCompanyId != null).Select(m => m.BuildCompanyId); Expression <Func <T_HouseUserExpenseDetails, bool> > where = u => u.IsPayed == ConstantParam.PAYED_TRUE && (DoorIds.Contains(u.BuildDoorId) || CompanyIds.Contains(u.BuildCompanyId)); // 获取当前用户对应业主的缴费记录 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var list = expenseDetailsBLL.GetPageList(where, "PayedDate", false, model.PageIndex).Select(e => new { RecordId = e.Id, ExpenseTypeName = e.PropertyExpenseType.Name, ExpenseDateDes = e.ExpenseDateDes, PlaceName = e.BuildCompanyId == null ? e.BuildDoor.BuildUnit.Build.PropertyPlace.Name : e.BuildCompany.PropertyPlace.Name, Expense = e.Expense, PayedTime = e.PayedDate.Value.ToString("yyyy-MM-dd HH:mm:ss") }).ToList(); resultModel.result = list; resultModel.Total = expenseDetailsBLL.GetList(where).Count(); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ActionResult Paying(int id) { IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var expenseDetails = expenseDetailsBLL.GetEntity(u => u.Id == id); if (expenseDetails != null) { ExpenseDetailsModel model = new ExpenseDetailsModel(); model.Id = expenseDetails.Id; if (expenseDetails.BuildDoorId != null) { model.UnitDoor = expenseDetails.BuildDoor.BuildUnit.Build.BuildName + " " + expenseDetails.BuildDoor.BuildUnit.UnitName + " " + expenseDetails.BuildDoor.DoorName; } else if (expenseDetails.BuildCompanyId != null) { model.UnitDoor = expenseDetails.BuildCompany.Name; } model.ExpenseTypeName = expenseDetails.PropertyExpenseType.Name; switch (expenseDetails.ExpenseCycleId) { case ConstantParam.ExpenseCycle_ONE_MONTH: model.ExpenseCycle = "每月"; break; case ConstantParam.ExpenseCycle_TWO_MONTH: model.ExpenseCycle = "每两月"; break; case ConstantParam.ExpenseCycle_ONE_QUARTER: model.ExpenseCycle = "每季度"; break; case ConstantParam.ExpenseCycle_HARF_YEAR: model.ExpenseCycle = "每半年"; break; case ConstantParam.ExpenseCycle_ONE_YEAR: model.ExpenseCycle = "每年"; break; } model.Expense = expenseDetails.Expense; model.ExpenseDateDesc = expenseDetails.ExpenseDateDes; model.InvoiceTypeList = GetInvoiceTypeList(); return(View(model)); } else { return(RedirectToAction("ExpenseList")); } }
public ApiResultModel SetRecordToExpensed(DetailSearchModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //根据用户ID查找业主 IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); T_User owner = ownerBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果业主存在 if (owner != null) { //如果验证Token不通过或已过期 if (DateTime.Now > owner.TokenInvalidTime || model.Token != owner.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 owner.LatelyLoginTime = DateTime.Now; owner.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); ownerBll.Update(owner); //设置缴费记录为已在线缴费 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var record = expenseDetailsBLL.GetEntity(e => e.Id == model.Id); if (record != null) { record.IsPayed = ConstantParam.PAYED_TRUE; record.PaymentType = 2; record.PayedDate = DateTime.Now; expenseDetailsBLL.Update(record); } else { resultModel.Msg = APIMessage.EXPENSE_RECORD_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
/// <summary> /// 缴费通知列表 /// </summary> /// <returns></returns> public ActionResult ExpenseNoticeList() { var owner = GetCurrentUser(); //初始化查询条件 var DoorIds = owner.PropertyIdentityVerification.Where(v => v.DoorId != null && v.IsVerified == 1).Select(m => m.DoorId); var CompanyIds = owner.PropertyIdentityVerification.Where(v => v.BuildCompanyId != null && v.IsVerified == 1).Select(m => m.BuildCompanyId); Expression <Func <T_HouseUserExpenseDetails, bool> > where = u => (DoorIds.Contains(u.BuildDoorId) || CompanyIds.Contains(u.BuildCompanyId)); IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); ViewBag.ExpenseNoticeCount = expenseDetailsBLL.Count(where); return(View()); }
public JsonResult PayRemind(int id) { JsonModel jm = new JsonModel(); IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var expenseDetails = expenseDetailsBLL.GetEntity(u => u.Id == id); if (expenseDetails == null) { jm.Msg = "该缴费记录不存在"; } else if (expenseDetails.IsPayed == ConstantParam.PAYED_TRUE) { jm.Msg = "该缴费记录已缴费"; } else { List <int> userIds = null; IUserBLL userBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); if (expenseDetails.BuildDoorId != null) { userIds = expenseDetails.BuildDoor.PropertyIdentityVerifications.Where(v => v.IsVerified == 1 && v.User.DelFlag == ConstantParam.DEL_FLAG_DEFAULT) .Select(v => v.AppUserId).Distinct().ToList(); } else if (expenseDetails.BuildCompanyId != null) { userIds = expenseDetails.BuildCompany.PropertyIdentityVerification.Where(v => v.IsVerified == 1 && v.User.DelFlag == ConstantParam.DEL_FLAG_DEFAULT) .Select(v => v.AppUserId).Distinct().ToList(); } //推送缴费提醒 //推送给业主客户端 IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL"); string alert = expenseDetails.ExpenseDateDes + expenseDetails.PropertyExpenseType.Name + "缴费提醒"; var registrationIds = userPushBLL.GetList(p => userIds.Contains(p.UserId)).Select(p => p.RegistrationId).ToArray(); bool flag = PropertyUtils.SendPush("缴费提醒", alert, ConstantParam.MOBILE_TYPE_OWNER, registrationIds); if (!flag) { jm.Msg = "推送发生异常"; } } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public static void ExpenseNotification() { try { var allList = new List <T_HouseUserExpenseTemplate>(); //当前日期 DateTime CurrentDate = DateTime.Now.Date; //明天日期 DateTime TommorrowDate = CurrentDate.AddDays(1).Date; //所有符合发推送的缴费信息列表 IHouseUserExpenseTemplateBLL templateBLL = BLLFactory <IHouseUserExpenseTemplateBLL> .GetBLL("HouseUserExpenseTemplateBLL"); var expenseTemplateList = templateBLL.GetList().ToList(); foreach (var expenseTemplate in expenseTemplateList) { //看看要处理是不是今天,如果不是今天按照推送的周期加周期的天数(每月加30,每两月加60,每季度90...) var isCheck = CurrentDate <= expenseTemplate.NotificationDate && expenseTemplate.NotificationDate < TommorrowDate; if (isCheck) { allList.Add(expenseTemplate); } else { expenseTemplate.NotificationDate = expenseTemplate.NotificationDate.AddDays(expenseTemplate.ExpenseCycleId * 30); isCheck = CurrentDate <= expenseTemplate.NotificationDate && expenseTemplate.NotificationDate < TommorrowDate; if (isCheck) { allList.Add(expenseTemplate); } } } //保存到ExpenseDetail表 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); //缴费周期 应缴费开始时间加上缴费周期天数就是应缴费结束时间 int expensePeriod = int.Parse(ConfigurationManager.AppSettings["ExpensePeriod"].ToString()); var detailsList = expenseDetailsBLL.SaveExpenseDetails(allList, expensePeriod); var registrationIdList = new List <string>(); var title = "缴费提醒"; var content = "您有一条缴费提醒, 请注意查收。"; //将保存成功的ExpenseDetail队列发推送 if (detailsList.Count > 0) { CommonUtils.WriteLogInfo("已经进入到发推送里面"); IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL"); //全部保存成功后,取得所有要推送的用户 foreach (var item in detailsList) { var appUserIds = item.BuildDoor.PropertyIdentityVerifications.Select(p => p.AppUserId); var registrationIds = userPushBLL.GetList(u => appUserIds.Contains(u.UserId)).Select(u => u.RegistrationId); registrationIdList.AddRange(registrationIds); } foreach (var item in registrationIdList) { CommonUtils.WriteLogInfo(string.Format("发推送人的设备是:{0}", item)); } //批量推送出去 bool check = Property.Common.PropertyUtils.SendPush(title, content, ConstantParam.MOBILE_TYPE_OWNER, registrationIdList.ToArray()); CommonUtils.WriteLogInfo(string.Format("调用完推送返回的结果:{0}", check)); CommonUtils.WriteLogInfo("已经完成发推送。"); } } catch (Exception ex) { CommonUtils.WriteLogError(ex); } }
public ActionResult WeixinExpenseNotifyUrl() { Stream st = Request.InputStream; StreamReader sr = new StreamReader(st); string SRstring = sr.ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(SRstring); sr.Close(); string return_code = doc.GetElementsByTagName("return_code")[0].InnerText; //如果返回成功 if (return_code == "SUCCESS") { string result_code = doc.GetElementsByTagName("result_code")[0].InnerText; if (result_code == "SUCCESS") { string expenseOrderNo = doc.GetElementsByTagName("out_trade_no")[0].InnerText; IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var record = expenseDetailsBLL.GetEntity(e => e.PayTradeNo == expenseOrderNo); if (record != null && record.IsPayed == ConstantParam.PAYED_FALSE) { //获取物业微信账户信息 T_PropertyAccount wxAccount = null; if (record.BuildDoorId != null) { wxAccount = record.BuildDoor.BuildUnit.Build.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } else { wxAccount = record.BuildCompany.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } if (wxAccount != null) { string WeixinPayKey = wxAccount.AccountKey; //组装签名字符串 StringBuilder signStr = new StringBuilder(); signStr.Append("appid=" + doc.GetElementsByTagName("appid")[0].InnerText + "&"); signStr.Append("bank_type=" + doc.GetElementsByTagName("bank_type")[0].InnerText + "&"); signStr.Append("cash_fee=" + doc.GetElementsByTagName("cash_fee")[0].InnerText + "&"); signStr.Append("fee_type=" + doc.GetElementsByTagName("fee_type")[0].InnerText + "&"); signStr.Append("is_subscribe=" + doc.GetElementsByTagName("is_subscribe")[0].InnerText + "&"); signStr.Append("mch_id=" + doc.GetElementsByTagName("mch_id")[0].InnerText + "&"); signStr.Append("nonce_str=" + doc.GetElementsByTagName("nonce_str")[0].InnerText + "&"); signStr.Append("openid=" + doc.GetElementsByTagName("openid")[0].InnerText + "&"); signStr.Append("out_trade_no=" + expenseOrderNo + "&"); signStr.Append("result_code=" + result_code + "&"); signStr.Append("return_code=" + return_code + "&"); signStr.Append("time_end=" + doc.GetElementsByTagName("time_end")[0].InnerText + "&"); signStr.Append("total_fee=" + doc.GetElementsByTagName("total_fee")[0].InnerText + "&"); signStr.Append("trade_type=" + doc.GetElementsByTagName("trade_type")[0].InnerText + "&"); signStr.Append("transaction_id=" + doc.GetElementsByTagName("transaction_id")[0].InnerText + "&"); signStr.Append("key=" + WeixinPayKey); string sign = PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper(); //签名验证成功 if (doc.GetElementsByTagName("sign")[0].InnerText == sign) { record.IsPayed = ConstantParam.PAYED_TRUE; record.PaymentType = 2; record.PayedDate = DateTime.Now; expenseDetailsBLL.Update(record); } } } return(Content("success")); } } return(Content("fail")); }
public ApiResultModel ExpenseRecordDetail([FromUri] DetailSearchModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //根据用户ID查找业主 IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); T_User owner = ownerBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果业主存在 if (owner != null) { //如果验证Token不通过或已过期 if (DateTime.Now > owner.TokenInvalidTime || model.Token != owner.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 owner.LatelyLoginTime = DateTime.Now; owner.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); ownerBll.Update(owner); IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var record = expenseDetailsBLL.GetEntity(e => e.Id == model.Id); if (record != null) { //返回详细数据 resultModel.result = new { RecordId = record.Id, ExpenseTypeName = record.PropertyExpenseType.Name, ExpenseDateDes = record.ExpenseDateDes, Expense = record.Expense, PayedTime = record.PayedDate != null?record.PayedDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", PaymentType = record.PaymentType != null ? (record.PaymentType.Value == 1 ? "前台缴费" : "在线缴费") : "", PlaceName = record.BuildCompanyId == null ? record.BuildDoor.BuildUnit.Build.PropertyPlace.Name : record.BuildCompany.PropertyPlace.Name, Door = record.BuildCompanyId == null ? record.BuildDoor.BuildUnit.Build.BuildName + record.BuildDoor.BuildUnit.UnitName + record.BuildDoor.DoorName : record.BuildCompany.Name, OwnerName = record.BuildDoor != null && record.BuildDoor.HouseUsers.Count > 0 ? record.BuildDoor.HouseUsers.FirstOrDefault().Name : "", Tel = record.BuildDoor != null ? (record.BuildDoor.HouseUsers.Count > 0 ? record.BuildDoor.HouseUsers.FirstOrDefault().Phone : "") : record.BuildCompany.Phone, }; } else { resultModel.Msg = APIMessage.EXPENSE_RECORD_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
/// <summary> /// Post请求 生成订单 /// </summary> /// <returns></returns> private string CreateTradePost(T_HouseUserExpenseDetails record, string WeixinAppId, string WeixinMchId, string WeixinPayKey) { Random r = new Random(); #region 组装参数 //组装签名字符串 StringBuilder signStr = new StringBuilder(); //组装xml格式 StringBuilder varBody = new StringBuilder(); varBody.Append("<xml>"); //APP应用ID varBody.Append("<appid>" + WeixinAppId + "</appid>"); signStr.Append("appid=" + WeixinAppId + "&"); //商品描述 string body = record.PropertyExpenseType.Name + "(" + record.ExpenseDateDes + ")"; varBody.Append("<body>" + body + "</body>"); signStr.Append("body=" + body + "&"); //商户号 varBody.Append("<mch_id>" + WeixinMchId + "</mch_id>"); signStr.Append("mch_id=" + WeixinMchId + "&"); //随机字符串 string str = "1234567890abcdefghijklmnopqrstuvwxyz"; string randomStr = ""; for (int i = 0; i < 32; i++) { randomStr = randomStr + str[r.Next(str.Length)].ToString(); } varBody.Append("<nonce_str>" + randomStr + "</nonce_str>"); signStr.Append("nonce_str=" + randomStr + "&"); //通知地址 string notifyUrl = PropertyUtils.GetConfigParamValue("HostUrl") + "/Common/WeixinExpenseNotifyUrl"; varBody.Append("<notify_url>" + notifyUrl + "</notify_url>"); signStr.Append("notify_url=" + notifyUrl + "&"); //商户订单号 string no = DateTime.Now.ToFileTime().ToString() + new Random().Next(1000); varBody.Append("<out_trade_no>" + no + "</out_trade_no>"); signStr.Append("out_trade_no=" + no + "&"); //保存订单号 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); record.PayTradeNo = no; expenseDetailsBLL.Update(record); //终端ID varBody.Append("<spbill_create_ip>218.58.55.130</spbill_create_ip>"); signStr.Append("spbill_create_ip=" + "218.58.55.130" + "&"); //总金额 int fee = Convert.ToInt32(record.Expense * 100); varBody.Append("<total_fee>" + fee + "</total_fee>"); signStr.Append("total_fee=" + fee + "&"); //交易类型 varBody.Append("<trade_type>APP</trade_type>"); signStr.Append("trade_type=APP&"); //签名 signStr.Append("key=" + WeixinPayKey); varBody.Append("<sign>" + PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper() + "</sign>"); varBody.Append("</xml>"); #endregion //发送HTTP POST请求 string url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "text/xml"; // 信任所有证书 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); byte[] bytes = Encoding.UTF8.GetBytes(varBody.ToString()); request.ContentLength = bytes.Length; using (Stream writer = request.GetRequestStream()) { writer.Write(bytes, 0, bytes.Length); writer.Flush(); writer.Close(); } //处理返回结果 string result = null; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { result = reader.ReadToEnd(); reader.Close(); } } return(result); }
public ApiResultModel CreateWeixinPayTrade(DetailSearchModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //根据用户ID查找业主 IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); T_User owner = ownerBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果业主存在 if (owner != null) { //如果验证Token不通过或已过期 if (DateTime.Now > owner.TokenInvalidTime || model.Token != owner.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 owner.LatelyLoginTime = DateTime.Now; owner.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); ownerBll.Update(owner); //生成微信支付订单 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var record = expenseDetailsBLL.GetEntity(e => e.Id == model.Id); if (record != null) { //获取物业缴费账户信息 T_PropertyAccount wxAccount = null; if (record.BuildDoorId != null) { wxAccount = record.BuildDoor.BuildUnit.Build.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } else { wxAccount = record.BuildCompany.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } if (wxAccount == null) { resultModel.Msg = "该用户所属物业未设置账户信息"; return(resultModel); } //获取物业账户信息 string WeixinAppId = wxAccount.Number; string WeixinMchId = wxAccount.MerchantNo; string WeixinPayKey = wxAccount.AccountKey; //生成预订单 string result = CreateTradePost(record, WeixinAppId, WeixinMchId, WeixinPayKey); //如果请求失败 if (result == null) { resultModel.Msg = APIMessage.WEIXIN_YUORDER_FAIL; return(resultModel); } //解析返回结果 XmlDocument doc = new XmlDocument(); doc.LoadXml(result); string return_code = doc.GetElementsByTagName("return_code")[0].InnerText; //如果返回成功 if (return_code == "SUCCESS") { string result_code = doc.GetElementsByTagName("result_code")[0].InnerText; if (result_code == "SUCCESS") { //预支付交易会话标识 string prepayid = doc.GetElementsByTagName("prepay_id")[0].InnerText; //随机字符串 string str = "1234567890abcdefghijklmnopqrstuvwxyz"; Random r = new Random(); string PayRandomStr = ""; for (int i = 0; i < 32; i++) { PayRandomStr += str[r.Next(str.Length)].ToString(); } //时间戳 var timestamp = Convert.ToInt64(DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds / 10000) * 10; //签名字符串 string PaySignStr = "appid=" + WeixinAppId + "&noncestr=" + PayRandomStr + "&package=Sign=WXPay&partnerid=" + WeixinMchId + "&prepayid=" + prepayid + "×tamp=" + timestamp + "&key=" + WeixinPayKey; resultModel.result = new { appid = WeixinAppId, partnerid = WeixinMchId, package = "Sign=WXPay", prepayid = prepayid, noncestr = PayRandomStr, timestamp = timestamp, sign = PropertyUtils.GetMD5Str(PaySignStr.ToString()).ToUpper() }; } else { string err_code_des = doc.GetElementsByTagName("err_code_des")[0].InnerText; resultModel.Msg = err_code_des; } } else { string return_msg = doc.GetElementsByTagName("return_msg")[0].InnerText; resultModel.Msg = return_msg; } } else { resultModel.Msg = APIMessage.EXPENSE_RECORD_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ActionResult ExpenseList(ExpenseDetailsSearchModel model) { //1.初始化默认查询模型 DateTime today = DateTime.Today; if (model.BeforeDate == null) { model.BeforeDate = today.AddDays(-today.Day + 1); } if (model.EndDate == null) { model.EndDate = today; } int CurrentPlaceId = GetSessionModel().PropertyPlaceId.Value; DateTime endDate = model.EndDate.Value.AddDays(1); //2:初始化查询条件 Expression <Func <T_HouseUserExpenseDetails, bool> > where = u => u.PropertyExpenseType.PropertyPlaceId == CurrentPlaceId && u.ExpenseBeginDate < endDate && u.ExpenseEndDate >= model.BeforeDate; //缴费类型查询 if (model.ExpenseTypeId != null) { where = PredicateBuilder.And(where, u => u.ExpenseTypeId == model.ExpenseTypeId.Value); } //根据缴费状态查询 if (model.IsPayed != null) { where = PredicateBuilder.And(where, u => u.IsPayed == model.IsPayed.Value); } //楼座 单元 单元户,业主信息查询 if (!string.IsNullOrEmpty(model.Kword)) { IPropertyPlaceBLL placeBLL = BLLFactory <IPropertyPlaceBLL> .GetBLL("PropertyPlaceBLL"); var place = placeBLL.GetEntity(p => p.Id == CurrentPlaceId); if (place.PlaceType == ConstantParam.PLACE_TYPE_HOUSE) { where = PredicateBuilder.And(where, u => u.BuildDoor.DoorName.Contains(model.Kword) || u.BuildDoor.BuildUnit.Build.BuildName.Contains(model.Kword) || u.BuildDoor.BuildUnit.UnitName.Contains(model.Kword)); } else if (place.PlaceType == ConstantParam.PLACE_TYPE_COMPANY) { where = PredicateBuilder.And(where, u => u.BuildCompany.Name.Contains(model.Kword)); } } //3.排序 var sortModel = this.SettingSorting("Id", false); //4.调用BLL层获取分页数据 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); model.ResultList = expenseDetailsBLL.GetPageList(where, sortModel.SortName, sortModel.IsAsc, model.PageIndex) as PagedList <T_HouseUserExpenseDetails>; //5.初始化缴费类别下拉列表和缴费状态下拉列表 model.ExpenseTypeList = GetExpenseTypeList(); model.IsPayedList = GetPayedList(); return(View(model)); }