public async Task <IActionResult> PostExpenseInfoAsync([FromBody] AddExpenseInfoDto input) { string openId = GetOpenId(); try { var data = await _expenseServices.PostExpenseInfoAsync(input, openId); return(Ok(data)); } catch (Exception err) { _logger.Error(typeof(ExpenseController), "添加消费信息失败!", new Exception(err.Message)); return(FailedMsg("添加消费信息失败!" + err.Message)); } }
/// <summary> /// 添加报销信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> PostExpenseInfoAsync(AddExpenseInfoDto input, string openId) { if (input.TeamId == null) { throw new Exception("团队Id不能为空!"); } var isEnabled = db.Queryable <Team>().Where(a => a.ID == input.TeamId).First()?.IsEnabled; if (isEnabled == false) { throw new Exception("该团队处于禁用状态,不能申请报销!"); } var UserId = db.Queryable <Wx_UserInfo>().Where(a => a.OpenId == openId).First()?.ID; //找到UserId var FreeQuota = db.Queryable <TeamMember>().Where(a => a.TeamId == input.TeamId && a.JoinedUserId == UserId).First()?.FreeQuota; ExpenseInfo expense = iMapper.Map <ExpenseInfo>(input); expense.ID = IdHelper.CreateGuid(); expense.CreateUserId = UserId; expense.IsDeleted = false; if (input.Amount > FreeQuota) { expense.AuditStatus = AppConsts.AuditStatus.UnAudited; } else { expense.AuditStatus = AppConsts.AuditStatus.Audited; } var result = 0; return(await Task.Run(() => { Sheet sheet = new Sheet(); // 附件 if (!string.IsNullOrEmpty(input.ImgNames)) { string[] imgArray = input.ImgNames.Split(','); //字符串转数组 foreach (var img in imgArray) { sheet.ID = IdHelper.CreateGuid(); sheet.ExpenseId = expense.ID; sheet.TeamId = expense.TeamId; sheet.ImgUrl = ImgConfig.img_url + img; sheet.IsDeleted = false; db.Insertable(sheet).ExecuteCommand(); } } result = db.Insertable(expense).ExecuteCommand(); if (result <= 0) { throw new Exception("添加失败"); } return expense.ID; })); }
/// <summary> /// 添加消费信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> PostExpenseInfoAsync(AddExpenseInfoDto input, string openId) { return(await _expenseDal.PostExpenseInfoAsync(input, openId)); }