/// <summary> /// 会员积分相关 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult MemberCredit(long id) { var svc = Service; Collection <MemberCredit> MemberCreditVM = new Collection <MemberCredit>(); //获取积分获取方式 var creditTypeQuery = new FanCreditsTypeQuery { OrderField = "ID", OrderDirection = OrderDirection.Asc }; var creditType = svc.SelectOrEmpty(creditTypeQuery); //获取积分明细 var creditQuery = new FanCreditsQuery() { FanIds = new long[] { id }, Take = PageSize, OrderField = "CreatedAt", OrderDirection = OrderDirection.Asc }; var creditList = svc.SelectOrEmpty(creditQuery); if (creditList != null && creditList.Any()) { FanCreditsType _type = new FanCreditsType(); MemberCredit _Model = new MemberCredit(); foreach (var item in creditList) { _Model = new MemberCredit(); if (creditType != null && creditType.Any()) { _type = creditType.Where(c => c.TypeCode == item.CreditTypeCode).FirstOrDefault(); } _Model.RemainAmount = item.RemainAmount; _Model.CreditAmount = item.CreditAmount; _Model.CreditReason = (_type == null) ? "" : _type.TypeName; _Model.CreateTime = item.CreatedAt; MemberCreditVM.Add(_Model); } } ViewData["Pagination"] = Pagination.FromQuery(creditQuery); ViewData["CId"] = id; return(View(MemberCreditVM)); }
/// <summary> /// 积分修改 /// 翻页等 /// </summary> /// <param name="FCQuery"></param> /// <returns></returns> public ActionResult AjaxMemberCredit(FanCreditsQuery FCQuery) { long id = -1; //获取查看用户编号 if (Request.Form["FanId"] != null) { if (!long.TryParse(Request.Form["FanId"].ToString(), out id)) { id = -1; } } var svc = Service; if (Request.Form["modifyCredits"] != null) { int CreditAdd = 0; if (int.TryParse(Request.Form["modifyCredits"].ToString(), out CreditAdd)) { //增加手动修改积分记录 var addCreditQuery = new FanCreditsQuery { FanIds = new long[] { id }, OrderField = "ID", OrderDirection = OrderDirection.Desc }; var lastCredit = svc.SelectOrEmpty(addCreditQuery).FirstOrDefault(); FanCredits _creditForCreate = new FanCredits(); _creditForCreate.FanId = id; _creditForCreate.CreditAmount = CreditAdd; _creditForCreate.RemainAmount = (lastCredit == null) ? CreditAdd : CreditAdd + lastCredit.RemainAmount; _creditForCreate.CreditTypeCode = 4; svc.Create(_creditForCreate); //更新Fans表中用户积分信息 var fanForUpdate = svc.SelectOrEmpty(new FanQuery() { IDs = new long[] { id } }).FirstOrDefault(); if (fanForUpdate != null) { fanForUpdate.Credits = _creditForCreate.RemainAmount; svc.Update(fanForUpdate); } } } Collection <MemberCredit> MemberCreditVM = new Collection <MemberCredit>(); //获取积分获取方式 var creditTypeQuery = new FanCreditsTypeQuery { OrderField = "ID", OrderDirection = OrderDirection.Asc }; var creditType = svc.SelectOrEmpty(creditTypeQuery); //获取积分明细 var creditQuery = new FanCreditsQuery() { FanIds = new long[] { id }, Take = PageSize, Skip = FCQuery.Skip, OrderField = "CreatedAt", OrderDirection = OrderDirection.Asc }; var creditList = svc.SelectOrEmpty(creditQuery); if (creditList != null && creditList.Any()) { FanCreditsType _type = new FanCreditsType(); MemberCredit _Model = new MemberCredit(); foreach (var item in creditList) { _Model = new MemberCredit(); if (creditType != null && creditType.Any()) { _type = creditType.Where(c => c.TypeCode == item.CreditTypeCode).FirstOrDefault(); } _Model.RemainAmount = item.RemainAmount; _Model.CreditAmount = item.CreditAmount; _Model.CreditReason = (_type == null) ? "" : _type.TypeName; _Model.CreateTime = item.CreatedAt; MemberCreditVM.Add(_Model); } } ViewData["Pagination"] = Pagination.FromQuery(creditQuery); ViewData["CId"] = id; return(View("Member/MemberCreditList", MemberCreditVM)); }