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

VIPInfoController.cs 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 TVShoppingCallCenter_ZLJ.Models.Inputs;
  12. using SqlSugar;
  13. namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
  14. {
  15. //[Authorize]
  16. [Produces("application/json")]
  17. [Route("api/[controller]")]
  18. public class VipInfoController : BaseController
  19. {
  20. private readonly ICus_VipInfoRepository _cus_vip_infoRepository;
  21. private readonly ISys_UserAccountRepository _sys_user_accountRepository;
  22. public VipInfoController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_UserAccountRepository sys_user_accountRepository)
  23. {
  24. _cus_vip_infoRepository = cus_vip_infoRepository;
  25. _sys_user_accountRepository = sys_user_accountRepository;
  26. }
  27. [HttpGet]
  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_infoRepository.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_infoRepository.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(VipInfoInput input)
  85. {
  86. if (string.IsNullOrEmpty(input.name ))
  87. return Error("请输入名字");
  88. if (string.IsNullOrEmpty(input.phone ))
  89. return Error("请输入手机号");
  90. var model = new T_Cus_VipInfo();
  91. model.F_VIPCode = input .vipcode ;//会员卡号
  92. model.F_Name = input.name;
  93. model.F_Birthday = input.birthday ;
  94. model.F_Phone = input.phone;
  95. model.F_Recommender = input.recommender;
  96. model.F_Sex = input.sex;
  97. model.F_Label = input.label;
  98. model.F_State = input.state;
  99. model.F_Note = input.note;
  100. model.F_City = input.city;
  101. model.F_Nickname = input.nickname;
  102. model.F_Address = input.address;
  103. model.F_Address1 = input.address1;
  104. model.F_RegTime = DateTime.Now;
  105. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  106. model.F_CreateOn = DateTime.Now;
  107. if (await _cus_vip_infoRepository.GetCount(x => x.F_VIPCode == model.F_VIPCode && x.F_Name == input.name) > 0)
  108. {
  109. return Error("添加失败,存在相同会员信息");
  110. }
  111. var res = await _cus_vip_infoRepository.Add(model);
  112. if (res > 0)
  113. {
  114. return Success("添加成功");
  115. }
  116. else
  117. {
  118. return Error("添加失败");
  119. }
  120. }
  121. /// <summary>
  122. /// 修改会员信息
  123. /// </summary>
  124. [HttpPost("update")]
  125. public async Task<IActionResult> UpdateAsync(VipInfoInput input)
  126. {
  127. if (string.IsNullOrEmpty(input.name))
  128. return Error("请输入名字");
  129. if (string.IsNullOrEmpty(input.phone))
  130. return Error("请输入手机号");
  131. var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == input.id);
  132. if (model == null)
  133. return Error("操作失败");
  134. //model.F_VIPCode = input.vipcode;//会员卡号
  135. model.F_Name = input.name;
  136. model.F_Birthday = input.birthday;
  137. model.F_Phone = input.phone;
  138. model.F_Recommender = input.recommender;
  139. model.F_Sex = input.sex;
  140. model.F_Label = input.label;
  141. model.F_State = input.state;
  142. model.F_Note = input.note;
  143. model.F_City = input.city;
  144. model.F_Nickname = input.nickname;
  145. model.F_Address = input.address;
  146. model.F_Address1 = input.address1;
  147. model.F_RegTime = DateTime.Now;
  148. model.F_LastModifyOn = DateTime.Now.ToLocalTime();
  149. model.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  150. bool b = await _cus_vip_infoRepository.Update(model);
  151. if (b)
  152. return Success("修改成功");
  153. return Error("修改失败");
  154. }
  155. /// <summary>
  156. /// 删除会员信息 by ids
  157. /// </summary>
  158. /// <param name="ids"></param>
  159. /// <returns></returns>
  160. [HttpPost("delete")]
  161. public async Task<IActionResult> Remove(int[] ids)
  162. {
  163. var res = 0;
  164. if (ids != null && ids.Length > 0)
  165. {
  166. foreach (var item in ids)
  167. {
  168. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
  169. ml.F_State = (int)EnumDelState.Delete;
  170. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  171. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  172. if (_cus_vip_infoRepository.Update(ml).Result)
  173. res += 1;
  174. }
  175. if (res == ids.Length)
  176. return Success("删除成功");
  177. else if (res > 0 && res < ids.Length)
  178. return Error("部分删除失败,请查看后重新操作");
  179. else
  180. return Error("删除失败,请查看后重新操作");
  181. }
  182. else
  183. return Error("请选择要删除的记录");
  184. }
  185. }
  186. }