예제 #1
0
        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);
        }