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

VipLabelInfoController.cs 7.9KB

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