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

CusMsgController.cs 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. private readonly ICus_VipInfoRepository _cus_vip_infoRepository;
  22. public CusMsgController(ICus_MsgRepository cus_msgRepository, ICus_VipInfoRepository cus_vip_infoRepository)
  23. {
  24. _cus_msgRepository = cus_msgRepository;
  25. _cus_vip_infoRepository = cus_vip_infoRepository;
  26. }
  27. [HttpGet]
  28. public IActionResult Index()
  29. {
  30. return Success("成功");
  31. }
  32. /// <summary>
  33. /// 添加消息提醒
  34. /// </summary>
  35. /// <param name="input"></param>
  36. /// <returns></returns>
  37. [HttpPost("add")]
  38. public async Task<IActionResult> AddAsync(int type, int vipid, string toperson, string notifyperson,string notice)
  39. {
  40. var model = new T_Cus_Msg();
  41. model.F_Type = 1;
  42. model.F_VipInfoID = vipid;
  43. model.F_ToPerson = toperson;
  44. model.F_State = 0;
  45. model.F_Notice = notice;
  46. model.F_NotifyPerson = notifyperson;
  47. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  48. model.F_CreateOn = DateTime.Now;
  49. var res = await _cus_msgRepository.Add(model);
  50. if (res > 0)
  51. {
  52. return Success("添加成功");
  53. }
  54. else
  55. {
  56. return Error("添加失败");
  57. }
  58. }
  59. /// <summary>
  60. /// 获取列表分页
  61. /// </summary>
  62. /// <param name="keyword"></param>
  63. /// <param name="pageindex"></param>
  64. /// <param name="pagesize"></param>
  65. /// <returns></returns>
  66. [HttpGet("getlistbypage")]
  67. public async Task<IActionResult> GetListsByPageAsync(int state,string tousercode, string fromusercode, int type,int pageindex = 1, int pagesize = 20)//state传0时获取全部,传1时获取未处理,传2时获取已处理
  68. {
  69. List<IConditionalModel> conModels = new List<IConditionalModel>();
  70. #region 条件筛选
  71. if (state == 1)
  72. {
  73. //conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = state.ToString() });
  74. conModels.Add(new ConditionalCollections()
  75. {
  76. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  77. {
  78. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "0" }),
  79. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "1" })
  80. }
  81. });
  82. }
  83. else if (state == 2)
  84. {
  85. conModels.Add(new ConditionalCollections()
  86. {
  87. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  88. {
  89. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "2" }),
  90. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "3" })
  91. }
  92. });
  93. }
  94. if (!string.IsNullOrEmpty(tousercode))
  95. {
  96. conModels.Add(new ConditionalModel() { FieldName = "F_ToPerson", ConditionalType = ConditionalType.Like, FieldValue = tousercode });
  97. }
  98. if (!string.IsNullOrEmpty(fromusercode))
  99. {
  100. conModels.Add(new ConditionalModel() { FieldName = "F_NotifyPerson", ConditionalType = ConditionalType.Like, FieldValue = fromusercode });
  101. }
  102. //if (!string.IsNullOrEmpty(keyword))
  103. //{
  104. // conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword });
  105. //}
  106. #endregion
  107. int recordCount = 0;
  108. var list = await _cus_msgRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
  109. var obj = new
  110. {
  111. state = "success",
  112. message = "成功",
  113. rows = list,
  114. total = recordCount,
  115. };
  116. return Content(obj.ToJson());
  117. }
  118. /// <summary>
  119. /// 获取转移消息详情
  120. /// </summary>
  121. /// <param name="id">id</param>
  122. /// <returns></returns>
  123. [HttpGet("getdetails")]
  124. public async Task<IActionResult> GetDetailsAsync(int id)
  125. {
  126. if (id <= 0)
  127. return Error("参数错误");
  128. var model = await _cus_msgRepository.GetSingle(x => x.F_ID == id);
  129. if (model == null)
  130. {
  131. return Error("获取失败");
  132. }
  133. var infomodel=await _cus_vip_infoRepository.GetSingleV(x => x.F_ID == model.F_VipInfoID && x.F_State == (int)EnumDelState.Enabled);
  134. if(infomodel==null)
  135. return Error("相关的会员信息已不存在,请查询后处理!");
  136. if (model.F_State==0)
  137. {
  138. model.F_State = 1;
  139. await _cus_msgRepository.Update(model);
  140. }
  141. var obj = new
  142. {
  143. model,
  144. infomodel
  145. };
  146. return Success("获取成功!", obj);
  147. }
  148. /// <summary>
  149. /// 更新消息状态
  150. /// </summary>
  151. /// <param name="ids"></param>
  152. /// <returns></returns>
  153. [HttpPost("updatescore")]
  154. public async Task<IActionResult> UpdateScore(int id,int state)
  155. {
  156. if (id <= 0)
  157. return Error("参数错误");
  158. else
  159. {
  160. var ml = await _cus_msgRepository.GetSingle(x => x.F_ID == id);
  161. ml.F_State = state;
  162. if (await _cus_msgRepository.Update(ml))
  163. {
  164. return Success("状态更新成功");
  165. }
  166. else
  167. return Error("状态更新失败");
  168. }
  169. }
  170. }
  171. }