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

VIPInfoController.cs 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. conModels.Add(new ConditionalCollections()
  47. {
  48. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  49. {
  50. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  51. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  52. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_VIPCode", ConditionalType = ConditionalType.Like, FieldValue = keyword })
  53. }
  54. });
  55. #endregion
  56. int recordCount = 0;
  57. var list = await _cus_vip_infoRepository.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("getdetailes")]
  73. public async Task<IActionResult> GetDetailsAsync(int id)
  74. {
  75. if (id <= 0)
  76. return Error("参数错误");
  77. var model = await _cus_vip_infoRepository.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(VipInfoInput input)
  91. {
  92. if (string.IsNullOrEmpty(input.name ))
  93. return Error("请输入名字");
  94. if (string.IsNullOrEmpty(input.phone ))
  95. return Error("请输入手机号");
  96. var model = new T_Cus_VipInfo();
  97. model.F_VIPCode = input .vipcode ;//会员卡号
  98. model.F_Name = input.name;
  99. model.F_Birthday = input.birthday ;
  100. model.F_Phone = input.phone;
  101. model.F_Recommender = input.recommender;
  102. model.F_Sex = input.sex;
  103. model.F_Label = input.label;
  104. model.F_State = input.state;
  105. model.F_Note = input.note;
  106. model.F_City = input.city;
  107. model.F_Nickname = input.nickname;
  108. model.F_Address = input.address;
  109. model.F_Address1 = input.address1;
  110. model.F_RegTime = DateTime.Now;
  111. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  112. model.F_CreateOn = DateTime.Now;
  113. if (await _cus_vip_infoRepository.GetCount(x => x.F_VIPCode == model.F_VIPCode && x.F_Name == input.name) > 0)
  114. {
  115. return Error("添加失败,存在相同会员信息");
  116. }
  117. var res = await _cus_vip_infoRepository.Add(model);
  118. if (res > 0)
  119. {
  120. return Success("添加成功");
  121. }
  122. else
  123. {
  124. return Error("添加失败");
  125. }
  126. }
  127. /// <summary>
  128. /// 修改会员信息
  129. /// </summary>
  130. [HttpPost("update")]
  131. public async Task<IActionResult> UpdateAsync(VipInfoInput input)
  132. {
  133. if (string.IsNullOrEmpty(input.name))
  134. return Error("请输入名字");
  135. if (string.IsNullOrEmpty(input.phone))
  136. return Error("请输入手机号");
  137. var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == input.id);
  138. if (model == null)
  139. return Error("操作失败");
  140. //model.F_VIPCode = input.vipcode;//会员卡号
  141. model.F_Name = input.name;
  142. model.F_Birthday = input.birthday;
  143. model.F_Phone = input.phone;
  144. model.F_Recommender = input.recommender;
  145. model.F_Sex = input.sex;
  146. model.F_Label = input.label;
  147. model.F_State = input.state;
  148. model.F_Note = input.note;
  149. model.F_City = input.city;
  150. model.F_Nickname = input.nickname;
  151. model.F_Address = input.address;
  152. model.F_Address1 = input.address1;
  153. model.F_RegTime = DateTime.Now;
  154. model.F_LastModifyOn = DateTime.Now.ToLocalTime();
  155. model.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  156. bool b = await _cus_vip_infoRepository.Update(model);
  157. if (b)
  158. return Success("修改成功");
  159. return Error("修改失败");
  160. }
  161. /// <summary>
  162. /// 删除会员信息 by ids
  163. /// </summary>
  164. /// <param name="ids"></param>
  165. /// <returns></returns>
  166. [HttpPost("delete")]
  167. public async Task<IActionResult> Remove(int[] ids)
  168. {
  169. var res = 0;
  170. if (ids != null && ids.Length > 0)
  171. {
  172. foreach (var item in ids)
  173. {
  174. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
  175. ml.F_State = (int)EnumDelState.Delete;
  176. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  177. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  178. if (_cus_vip_infoRepository.Update(ml).Result)
  179. res += 1;
  180. }
  181. if (res == ids.Length)
  182. return Success("删除成功");
  183. else if (res > 0 && res < ids.Length)
  184. return Error("部分删除失败,请查看后重新操作");
  185. else
  186. return Error("删除失败,请查看后重新操作");
  187. }
  188. else
  189. return Error("请选择要删除的记录");
  190. }
  191. }
  192. }