足力健后端,使用.netcore版本,合并1个项目使用

CusMsgController.cs 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.IRepositories;
  5. using System.Linq;
  6. using System.Model;
  7. using System.Security.Claims;
  8. using System.Threading.Tasks;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Mvc;
  11. using SqlSugar;
  12. // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  13. namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
  14. {
  15. [Authorize]
  16. [Produces("application/json")]
  17. [Route("api/[controller]")]
  18. public class CusMsgController : BaseController
  19. {
  20. private readonly ICus_MsgRepository _cus_msgRepository;
  21. public CusMsgController(ICus_MsgRepository cus_msgRepository)
  22. {
  23. _cus_msgRepository = cus_msgRepository;
  24. }
  25. [HttpGet]
  26. public IActionResult Index()
  27. {
  28. return Success("成功");
  29. }
  30. /// <summary>
  31. /// 添加消息提醒
  32. /// </summary>
  33. /// <param name="input"></param>
  34. /// <returns></returns>
  35. [HttpPost("add")]
  36. public async Task<IActionResult> AddAsync(int type, int vipid, string toperson, string notifyperson,string notice)
  37. {
  38. var model = new T_Cus_Msg();
  39. model.F_Type = 1;
  40. model.F_VipInfoID = vipid;
  41. model.F_ToPerson = toperson;
  42. model.F_State = 0;
  43. model.F_Notice = notice;
  44. model.F_NotifyPerson = notifyperson;
  45. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  46. model.F_CreateOn = DateTime.Now;
  47. var res = await _cus_msgRepository.Add(model);
  48. if (res > 0)
  49. {
  50. return Success("添加成功");
  51. }
  52. else
  53. {
  54. return Error("添加失败");
  55. }
  56. }
  57. /// <summary>
  58. /// 获取列表分页
  59. /// </summary>
  60. /// <param name="keyword"></param>
  61. /// <param name="pageindex"></param>
  62. /// <param name="pagesize"></param>
  63. /// <returns></returns>
  64. [HttpGet("getlistbypage")]
  65. public async Task<IActionResult> GetListsByPageAsync(int state,string tousercode, string fromusercode, int type,int pageindex = 1, int pagesize = 20)//state传0时获取全部,传1时获取未处理,传2时获取已处理
  66. {
  67. List<IConditionalModel> conModels = new List<IConditionalModel>();
  68. #region 条件筛选
  69. if (state == 1)
  70. {
  71. //conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = state.ToString() });
  72. conModels.Add(new ConditionalCollections()
  73. {
  74. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  75. {
  76. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "0" }),
  77. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "1" })
  78. }
  79. });
  80. }
  81. else if (state == 2)
  82. {
  83. conModels.Add(new ConditionalCollections()
  84. {
  85. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  86. {
  87. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "2" }),
  88. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "3" })
  89. }
  90. });
  91. }
  92. if (!string.IsNullOrEmpty(tousercode))
  93. {
  94. conModels.Add(new ConditionalModel() { FieldName = "F_ToPerson", ConditionalType = ConditionalType.Like , FieldValue = tousercode });
  95. }
  96. if (!string.IsNullOrEmpty(fromusercode))
  97. {
  98. conModels.Add(new ConditionalModel() { FieldName = "F_CreateBy", ConditionalType = ConditionalType.Like, FieldValue = fromusercode });
  99. }
  100. //if (!string.IsNullOrEmpty(keyword))
  101. //{
  102. // conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword });
  103. //}
  104. #endregion
  105. int recordCount = 0;
  106. var list = await _cus_msgRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
  107. var obj = new
  108. {
  109. state = "success",
  110. message = "成功",
  111. rows = list,
  112. total = recordCount,
  113. };
  114. return Content(obj.ToJson());
  115. }
  116. /// <summary>
  117. /// 获取转移消息详情
  118. /// </summary>
  119. /// <param name="id">id</param>
  120. /// <returns></returns>
  121. [HttpGet("getdetails")]
  122. public async Task<IActionResult> GetDetailsAsync(int id)
  123. {
  124. if (id <= 0)
  125. return Error("参数错误");
  126. var model = await _cus_msgRepository.GetSingle(x => x.F_ID == id);
  127. if (model == null)
  128. {
  129. return Error("获取失败");
  130. }
  131. return Success("获取成功!", model);
  132. }
  133. }
  134. }