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

VIPInfoController.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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,string name,string phone,string type, string province,string city,string area,string town,string address,string birthday,string recommender,string saleperson,string contact, 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(phone))
  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_Phone", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  51. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Mobile", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  52. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Mobile1", ConditionalType = ConditionalType.Like, FieldValue = phone })
  53. }
  54. });
  55. if (!string.IsNullOrEmpty(name))
  56. {
  57. conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
  58. }
  59. if (!string.IsNullOrEmpty(type))
  60. {
  61. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type });
  62. }
  63. if (!string.IsNullOrEmpty(province))
  64. {
  65. conModels.Add(new ConditionalModel() { FieldName = "F_Province", ConditionalType = ConditionalType.Like, FieldValue = province });
  66. }
  67. if (!string.IsNullOrEmpty(city))
  68. {
  69. conModels.Add(new ConditionalModel() { FieldName = "F_City", ConditionalType = ConditionalType.Like, FieldValue = city });
  70. }
  71. if (!string.IsNullOrEmpty(area))
  72. {
  73. conModels.Add(new ConditionalModel() { FieldName = "F_Area", ConditionalType = ConditionalType.Like, FieldValue = area });
  74. }
  75. if (!string.IsNullOrEmpty(town))
  76. {
  77. conModels.Add(new ConditionalModel() { FieldName = "F_Town", ConditionalType = ConditionalType.Like, FieldValue = town });
  78. }
  79. if (!string.IsNullOrEmpty(address))
  80. {
  81. conModels.Add(new ConditionalModel() { FieldName = "F_Address", ConditionalType = ConditionalType.Like, FieldValue = address });
  82. }
  83. if (!string.IsNullOrEmpty(birthday))
  84. {
  85. conModels.Add(new ConditionalModel() { FieldName = "F_Birthday", ConditionalType = ConditionalType.Like, FieldValue = birthday });
  86. }
  87. if (!string.IsNullOrEmpty(recommender))
  88. {
  89. conModels.Add(new ConditionalModel() { FieldName = "F_Recommender", ConditionalType = ConditionalType.Like, FieldValue = recommender });
  90. }
  91. if (!string.IsNullOrEmpty(saleperson))
  92. {
  93. conModels.Add(new ConditionalModel() { FieldName = "F_Saleperson", ConditionalType = ConditionalType.Like, FieldValue = saleperson });
  94. }
  95. if (!string.IsNullOrEmpty(contact))
  96. {
  97. conModels.Add(new ConditionalModel() { FieldName = "F_Contact", ConditionalType = ConditionalType.Like, FieldValue = contact });
  98. }
  99. #endregion
  100. int recordCount = 0;
  101. var list = await _cus_vip_infoRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
  102. var obj = new
  103. {
  104. state = "success",
  105. message = "成功",
  106. rows = list,
  107. total = recordCount,
  108. };
  109. return Content(obj.ToJson());
  110. }
  111. /// <summary>
  112. /// 获取会员信息详情
  113. /// </summary>
  114. /// <param name="id">id</param>
  115. /// <returns></returns>
  116. [HttpGet("getdetails")]
  117. public async Task<IActionResult> GetDetailsAsync(int id)
  118. {
  119. if (id <= 0)
  120. return Error("参数错误");
  121. var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == id);
  122. if (model == null)
  123. {
  124. return Error("获取失败");
  125. }
  126. return Success("获取成功!", model);
  127. }
  128. /// <summary>
  129. /// 添加会员
  130. /// </summary>
  131. /// <param name="input"></param>
  132. /// <returns></returns>
  133. [HttpPost("add")]
  134. public async Task<IActionResult> AddAsync(VipInfoInput input)
  135. {
  136. if (string.IsNullOrEmpty(input.name ))
  137. return Error("请输入名字");
  138. if (string.IsNullOrEmpty(input.phone ))
  139. return Error("请输入手机号");
  140. var model = new T_Cus_VipInfo();
  141. model.F_VIPCode = input .vipcode ;//会员卡号
  142. model.F_Name = input.name;
  143. model.F_Birthday = input.birthday ;
  144. model.F_Phone = input.phone;
  145. model.F_Recommender = input.recommender;
  146. model.F_Sex = input.sex;
  147. model.F_Label = input.label;
  148. model.F_State = input.state;
  149. model.F_Note = input.note;
  150. model.F_City = input.city;
  151. model.F_Nickname = input.nickname;
  152. model.F_Address = input.address;
  153. model.F_Address1 = input.address1;
  154. model.F_RegTime = DateTime.Now;
  155. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  156. model.F_CreateOn = DateTime.Now;
  157. model.F_Age = input.age;
  158. model.F_Mobile = input.mobile;
  159. model.F_Mobile1 = input.mobile1;
  160. model.F_Province = input.province;
  161. model.F_Area = input.area;
  162. model.F_Town = input.town;
  163. model.F_Postcode = input.postcode;
  164. model.F_ShoeSize = input.shoesize;
  165. model.F_Score = input.score;
  166. model.F_Money = input.money;
  167. model.F_TotalScore = input.totalscore;
  168. model.F_Saleperson = input.saleperson;
  169. model.F_Contact = input.contact;
  170. model.F_Type = input.type;
  171. if (await _cus_vip_infoRepository.GetCount(x => x.F_VIPCode == model.F_VIPCode && x.F_Name == input.name) > 0)
  172. {
  173. return Error("添加失败,存在相同会员信息");
  174. }
  175. var res = await _cus_vip_infoRepository.Add(model);
  176. if (res > 0)
  177. {
  178. return Success("添加成功");
  179. }
  180. else
  181. {
  182. return Error("添加失败");
  183. }
  184. }
  185. /// <summary>
  186. /// 修改会员信息
  187. /// </summary>
  188. [HttpPost("update")]
  189. public async Task<IActionResult> UpdateAsync(VipInfoInput input)
  190. {
  191. if (string.IsNullOrEmpty(input.name))
  192. return Error("请输入名字");
  193. if (string.IsNullOrEmpty(input.phone))
  194. return Error("请输入手机号");
  195. var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == input.id);
  196. if (model == null)
  197. return Error("操作失败");
  198. //model.F_VIPCode = input.vipcode;//会员卡号
  199. model.F_Name = input.name;
  200. model.F_Birthday = input.birthday;
  201. model.F_Phone = input.phone;
  202. model.F_Recommender = input.recommender;
  203. model.F_Sex = input.sex;
  204. model.F_Label = input.label;
  205. model.F_State = input.state;
  206. model.F_Note = input.note;
  207. model.F_City = input.city;
  208. model.F_Nickname = input.nickname;
  209. model.F_Address = input.address;
  210. model.F_Address1 = input.address1;
  211. model.F_RegTime = DateTime.Now;
  212. model.F_LastModifyOn = DateTime.Now.ToLocalTime();
  213. model.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  214. model.F_Age = input.age;
  215. model.F_Mobile = input.mobile;
  216. model.F_Mobile1 = input.mobile1;
  217. model.F_Province = input.province;
  218. model.F_Area = input.area;
  219. model.F_Town = input.town;
  220. model.F_Postcode = input.postcode;
  221. model.F_ShoeSize = input.shoesize;
  222. model.F_Score = input.score;
  223. model.F_Money = input.money;
  224. model.F_TotalScore = input.totalscore;
  225. model.F_Saleperson = input.saleperson;
  226. model.F_Contact = input.contact;
  227. model.F_Type = input.type;
  228. bool b = await _cus_vip_infoRepository.Update(model);
  229. if (b)
  230. return Success("修改成功");
  231. return Error("修改失败");
  232. }
  233. /// <summary>
  234. /// 删除会员信息 by ids
  235. /// </summary>
  236. /// <param name="ids"></param>
  237. /// <returns></returns>
  238. [HttpPost("delete")]
  239. public async Task<IActionResult> Remove(int[] ids)
  240. {
  241. var res = 0;
  242. if (ids != null && ids.Length > 0)
  243. {
  244. foreach (var item in ids)
  245. {
  246. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
  247. ml.F_State = (int)EnumDelState.Delete;
  248. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  249. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  250. if (_cus_vip_infoRepository.Update(ml).Result)
  251. res += 1;
  252. }
  253. if (res == ids.Length)
  254. return Success("删除成功");
  255. else if (res > 0 && res < ids.Length)
  256. return Error("部分删除失败,请查看后重新操作");
  257. else
  258. return Error("删除失败,请查看后重新操作");
  259. }
  260. else
  261. return Error("请选择要删除的记录");
  262. }
  263. }
  264. }