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

VipLabelInfoController.cs 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. using TVShoppingCallCenter_ZLJ.Models.Inputs;
  13. namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
  14. {
  15. [Authorize]
  16. [Produces("application/json")]
  17. [Route("api/[controller]")]
  18. public class VipLabelInfoController : BaseController
  19. {
  20. private readonly ICus_VipLabelInfoRepository _cus_vip_labelinfoRepository;
  21. private readonly ISys_UserAccountRepository _sys_user_accountRepository;
  22. public VipLabelInfoController(ICus_VipLabelInfoRepository cus_vip_labelinfoRepository, ISys_UserAccountRepository sys_user_accountRepository)
  23. {
  24. _cus_vip_labelinfoRepository = cus_vip_labelinfoRepository;
  25. _sys_user_accountRepository = sys_user_accountRepository;
  26. }
  27. // GET: /<controller>/
  28. public IActionResult Index()
  29. {
  30. return Success("成功");
  31. }
  32. /// <summary>
  33. /// 获取会员标签列表分页
  34. /// </summary>
  35. /// <param name="keyword"></param>
  36. /// <param name="pageindex"></param>
  37. /// <param name="pagesize"></param>
  38. /// <returns></returns>
  39. [HttpGet("getlistbypage")]
  40. public async Task<IActionResult> GetListsByPageAsync(string keyword, int pageindex = 1, int pagesize = 20)
  41. {
  42. List<IConditionalModel> conModels = new List<IConditionalModel>();
  43. #region 条件筛选
  44. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  45. if (!string.IsNullOrEmpty(keyword))
  46. {
  47. conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword });
  48. }
  49. #endregion
  50. int recordCount = 0;
  51. var list = await _cus_vip_labelinfoRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
  52. var obj = new
  53. {
  54. state = "success",
  55. message = "成功",
  56. rows = list,
  57. total = recordCount,
  58. };
  59. return Content(obj.ToJson());
  60. }
  61. /// <summary>
  62. /// 获取会员标签信息详情
  63. /// </summary>
  64. /// <param name="id">id</param>
  65. /// <returns></returns>
  66. [HttpGet("getdetailes")]
  67. public async Task<IActionResult> GetDetailsAsync(int id)
  68. {
  69. if (id <= 0)
  70. return Error("参数错误");
  71. var model = await _cus_vip_labelinfoRepository.GetSingle(x => x.F_ID == id);
  72. if (model == null)
  73. {
  74. return Error("获取失败");
  75. }
  76. return Success("获取成功!", model);
  77. }
  78. /// <summary>
  79. /// 添加会员标签
  80. /// </summary>
  81. /// <param name="input"></param>
  82. /// <returns></returns>
  83. [HttpPost("add")]
  84. public async Task<IActionResult> AddAsync(VipLabelInfoInput input)
  85. {
  86. if (string.IsNullOrEmpty(input.name))
  87. return Error("请输入标签名称");
  88. var model = new T_Cus_VipLabelInfo();
  89. model.F_Name = input.name;
  90. model.F_Type = input.type;
  91. model.F_Kind = input.kind;
  92. model.F_LabelColor = input.labelcolor ;
  93. model.F_FontColor = input.fontcolor ;
  94. model.F_State = input.state;
  95. model.F_Note = input.note;
  96. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  97. model.F_CreateOn = DateTime.Now;
  98. if (await _cus_vip_labelinfoRepository.GetCount(x => x.F_Name == input.name) > 0)
  99. {
  100. return Error("添加失败,存在相同标签信息");
  101. }
  102. var res = await _cus_vip_labelinfoRepository.Add(model);
  103. if (res > 0)
  104. {
  105. return Success("添加成功");
  106. }
  107. else
  108. {
  109. return Error("添加失败");
  110. }
  111. }
  112. /// <summary>
  113. /// 修改会员标签信息
  114. /// </summary>
  115. [HttpPost("update")]
  116. public async Task<IActionResult> UpdateAsync(VipLabelInfoInput input)
  117. {
  118. if (string.IsNullOrEmpty(input.name))
  119. return Error("请输入名字");
  120. var model = await _cus_vip_labelinfoRepository.GetSingle(x => x.F_ID == input.id);
  121. if (model == null)
  122. return Error("操作失败");
  123. //model.F_VIPCode = input.vipcode;//会员卡号
  124. model.F_Name = input.name;
  125. model.F_Type = input.type;
  126. model.F_Kind = input.kind;
  127. model.F_LabelColor = input.labelcolor;
  128. model.F_FontColor = input.fontcolor;
  129. model.F_State = input.state;
  130. model.F_Note = input.note;
  131. bool b = await _cus_vip_labelinfoRepository.Update(model);
  132. if (b)
  133. return Success("修改成功");
  134. return Error("修改失败");
  135. }
  136. /// <summary>
  137. /// 删除会员标签信息 by ids
  138. /// </summary>
  139. /// <param name="ids"></param>
  140. /// <returns></returns>
  141. [HttpPost("delete")]
  142. public async Task<IActionResult> Remove(int[] ids)
  143. {
  144. var res = 0;
  145. if (ids != null && ids.Length > 0)
  146. {
  147. foreach (var item in ids)
  148. {
  149. var ml = await _cus_vip_labelinfoRepository.GetSingle(x => x.F_ID == item);
  150. ml.F_State = (int)EnumDelState.Delete;
  151. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  152. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  153. if (_cus_vip_labelinfoRepository.Update(ml).Result)
  154. res += 1;
  155. }
  156. if (res == ids.Length)
  157. return Success("删除成功");
  158. else if (res > 0 && res < ids.Length)
  159. return Error("部分删除失败,请查看后重新操作");
  160. else
  161. return Error("删除失败,请查看后重新操作");
  162. }
  163. else
  164. return Error("请选择要删除的记录");
  165. }
  166. }
  167. }