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

VIPInfoController.cs 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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. using System.Common.Helpers;
  14. using Microsoft.Extensions.Configuration;
  15. using System.Data;
  16. using System.Reflection;
  17. using System.Text.RegularExpressions;
  18. using System.IRepositories.Call;
  19. using System.Model.Call;
  20. namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
  21. {
  22. [Authorize]
  23. [Produces("application/json")]
  24. [Route("api/[controller]")]
  25. public class VipInfoController : BaseController
  26. {
  27. private readonly ICus_VipInfoRepository _cus_vip_infoRepository;
  28. private readonly ISys_UserAccountRepository _sys_user_accountRepository;
  29. private readonly ICus_MsgRepository _cus_msgRepository;
  30. private readonly IConfiguration _configuration;
  31. private readonly ISMS_InternalMessagesReposytory _sys_internalMessagesrepository;
  32. private readonly ICall_CallRecordsRepository busCallRecordsRepository;
  33. private readonly Ipoint_agentRepository _point_agentrepository;
  34. public VipInfoController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_UserAccountRepository sys_user_accountRepository, ICus_MsgRepository cus_msgRepository,IConfiguration configuration,
  35. ISMS_InternalMessagesReposytory sys_internalMessagesrepository, ICall_CallRecordsRepository _busCallRecordsRepository, Ipoint_agentRepository point_agentrepository)
  36. {
  37. _cus_vip_infoRepository = cus_vip_infoRepository;
  38. _sys_user_accountRepository = sys_user_accountRepository;
  39. _cus_msgRepository = cus_msgRepository;
  40. _configuration = configuration;
  41. _sys_internalMessagesrepository = sys_internalMessagesrepository;
  42. busCallRecordsRepository = _busCallRecordsRepository;
  43. _point_agentrepository = point_agentrepository;
  44. }
  45. [HttpGet]
  46. public IActionResult Index()
  47. {
  48. return Success("成功");
  49. }
  50. /// <summary>
  51. /// 获取会员列表分页
  52. /// </summary>
  53. /// <param name="keyword"></param>
  54. /// <param name="pageindex"></param>
  55. /// <param name="pagesize"></param>
  56. /// <returns></returns>
  57. [HttpGet("getlistbypage")]
  58. public async Task<IActionResult> GetListsByPageAsync(string keyword,string label, string name,string phone,string type, string province,string city,string area,string town,string address,string birthday,string recommender,string saleperson,int pageindex = 1, int pagesize = 20)
  59. {
  60. List<IConditionalModel> conModels = new List<IConditionalModel>();
  61. #region 条件筛选
  62. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  63. if (!string.IsNullOrEmpty(phone))
  64. conModels.Add(new ConditionalCollections()
  65. {
  66. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  67. {
  68. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  69. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Mobile", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  70. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Mobile1", ConditionalType = ConditionalType.Like, FieldValue = phone })
  71. }
  72. });
  73. if (!string.IsNullOrEmpty(label))
  74. {
  75. conModels.Add(new ConditionalModel() { FieldName = "F_Label", ConditionalType = ConditionalType.Like, FieldValue = label });
  76. }
  77. if (!string.IsNullOrEmpty(name))
  78. {
  79. conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
  80. }
  81. if (!string.IsNullOrEmpty(type))
  82. {
  83. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type });
  84. }
  85. if (!string.IsNullOrEmpty(province))
  86. {
  87. conModels.Add(new ConditionalModel() { FieldName = "F_Province", ConditionalType = ConditionalType.Like, FieldValue = province });
  88. }
  89. if (!string.IsNullOrEmpty(city))
  90. {
  91. conModels.Add(new ConditionalModel() { FieldName = "F_City", ConditionalType = ConditionalType.Like, FieldValue = city });
  92. }
  93. if (!string.IsNullOrEmpty(area))
  94. {
  95. conModels.Add(new ConditionalModel() { FieldName = "F_Area", ConditionalType = ConditionalType.Like, FieldValue = area });
  96. }
  97. if (!string.IsNullOrEmpty(town))
  98. {
  99. conModels.Add(new ConditionalModel() { FieldName = "F_Town", ConditionalType = ConditionalType.Like, FieldValue = town });
  100. }
  101. if (!string.IsNullOrEmpty(address))
  102. {
  103. conModels.Add(new ConditionalModel() { FieldName = "F_Address", ConditionalType = ConditionalType.Like, FieldValue = address });
  104. new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Address1", ConditionalType = ConditionalType.Like, FieldValue = address });
  105. }
  106. if (!string.IsNullOrEmpty(birthday))
  107. {
  108. conModels.Add(new ConditionalModel() { FieldName = "F_Birthday", ConditionalType = ConditionalType.Equal, FieldValue = birthday });
  109. }
  110. if (!string.IsNullOrEmpty(recommender))
  111. {
  112. conModels.Add(new ConditionalModel() { FieldName = "F_Recommender", ConditionalType = ConditionalType.Like, FieldValue = recommender });
  113. }
  114. if (!string.IsNullOrEmpty(saleperson))
  115. {
  116. conModels.Add(new ConditionalModel() { FieldName = "F_Saleperson", ConditionalType = ConditionalType.Like, FieldValue = saleperson });
  117. }
  118. //if (!string.IsNullOrEmpty(contact))
  119. //{
  120. // conModels.Add(new ConditionalModel() { FieldName = "F_Contact", ConditionalType = ConditionalType.Like, FieldValue = contact });
  121. //}
  122. #endregion
  123. int recordCount = 0;
  124. var list = await _cus_vip_infoRepository.GetListViewByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, "F_CreateOn desc");
  125. var obj = new
  126. {
  127. state = "success",
  128. message = "成功",
  129. rows = list,
  130. total = recordCount,
  131. };
  132. return Content(obj.ToJson());
  133. }
  134. /// <summary>
  135. /// 获取会员信息详情
  136. /// </summary>
  137. /// <param name="id">id</param>
  138. /// <returns></returns>
  139. [HttpGet("getdetails")]
  140. public async Task<IActionResult> GetDetailsAsync(int id)
  141. {
  142. if (id <= 0)
  143. return Error("参数错误");
  144. var model = await _cus_vip_infoRepository.GetSingleV(x => x.F_ID == id && x.F_State == (int)EnumDelState.Enabled);
  145. var newmodel = new V_Cus_VipInfo();
  146. if (model != null)
  147. {
  148. var modellist = await _cus_msgRepository.GetListALL(x => x.F_VipInfoID == model.F_ID);
  149. var obj =new
  150. {
  151. model,
  152. modellist
  153. };
  154. return Content(obj.ToJson());
  155. }
  156. return Error("获取失败");
  157. }
  158. /// <summary>
  159. /// 根据电话号码获取会员详情
  160. /// </summary>
  161. /// <param name="id">id</param>
  162. /// <returns></returns>
  163. [HttpGet("getphonedetails")]
  164. public async Task<IActionResult> GetDetai(string phone)
  165. {
  166. if (string .IsNullOrEmpty (phone))
  167. return Error("参数错误");
  168. List<IConditionalModel> conModels = new List<IConditionalModel>();
  169. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  170. conModels.Add(new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Equal, FieldValue = phone });
  171. int recordCount=0;
  172. var model = await _cus_vip_infoRepository.GetListViewByPage(conModels,new MyPageModel() { PageIndex = 1, PageSize = 1, PageCount = recordCount }, "F_CreateOn desc");
  173. var newmodel = new V_Cus_VipInfo();
  174. var obj = new
  175. {
  176. state = "success",
  177. message = "成功",
  178. rows = model,
  179. total = recordCount,
  180. };
  181. return Content(obj.ToJson());
  182. }
  183. /// <summary>
  184. /// 添加会员
  185. /// </summary>
  186. /// <param name="input"></param>
  187. /// <returns></returns>
  188. [HttpPost("add")]
  189. public async Task<IActionResult> AddAsync(VipInfoInput input)
  190. {
  191. if (string.IsNullOrEmpty(input.name))
  192. return Error("请输入名字");
  193. if (string.IsNullOrEmpty(input.phone))
  194. return Error("请输入联系方式");
  195. if (await _cus_vip_infoRepository.GetCount(q => q.F_Phone == input.phone&&q.F_State== (int)EnumDelState.Enabled) >0)
  196. {
  197. return Error("手机号已存在");
  198. }
  199. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  200. var model = new T_Cus_VipInfo();
  201. //model.F_VIPCode = input.vipcode;//会员卡号
  202. model.F_Name = input.name;
  203. model.F_Birthday = input.birthday;
  204. if(!valtel(input.phone))
  205. return Error("手机号必须为11位数字");
  206. model.F_Phone = input.phone;
  207. var point = await _point_agentrepository.GetListALL(x => x.caller == input.phone);
  208. if (point == null && point.Count() <= 0)
  209. {
  210. point_agent point_Agent = new point_agent();
  211. point_Agent.caller = input.phone;
  212. point_Agent.agent = user;
  213. var phone = _point_agentrepository.Add(point_Agent);
  214. }
  215. model.F_Recommender = input.recommender;
  216. if (!string .IsNullOrEmpty (input.recommendertel))
  217. {
  218. if (!valtel(input.recommendertel))
  219. return Error("手机号必须为11位数字");
  220. model.F_RecommenderTel = input.recommendertel;
  221. }
  222. model.F_Sex = input.sex;
  223. model.F_Label = input.label;
  224. model.F_Note = input.note;
  225. model.F_City = input.city;
  226. model.F_Nickname = input.nickname;
  227. model.F_Address = input.address;
  228. model.F_Address1 = input.address1;
  229. model.F_Age = input.age;
  230. if (!string .IsNullOrEmpty (input .mobile ))
  231. {
  232. if (!valtel(input.mobile))
  233. return Error("手机号必须为11位数字");
  234. model.F_Mobile = input.mobile;
  235. var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile);
  236. if (_point == null && _point.Count() <= 0)
  237. {
  238. point_agent point_Agent = new point_agent();
  239. point_Agent.caller = input.mobile;
  240. point_Agent.agent = user;
  241. var phone = _point_agentrepository.Add(point_Agent);
  242. }
  243. }
  244. if (!string.IsNullOrEmpty(input.mobile1))
  245. {
  246. if (!valtel(input.mobile1))
  247. return Error("手机号必须为11位数字");
  248. model.F_Mobile1 = input.mobile1;
  249. var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile1);
  250. if (_point == null && _point.Count() <= 0)
  251. {
  252. point_agent point_Agent = new point_agent();
  253. point_Agent.caller = input.mobile1;
  254. point_Agent.agent = user;
  255. var phone = _point_agentrepository.Add(point_Agent);
  256. }
  257. }
  258. if (!string.IsNullOrEmpty(input.mobile2))
  259. {
  260. if (!valtel(input.mobile2))
  261. return Error("手机号必须为11位数字");
  262. model.F_Mobile2 = input.mobile2;
  263. var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile2);
  264. if (_point == null && _point.Count() <= 0)
  265. {
  266. point_agent point_Agent = new point_agent();
  267. point_Agent.caller = input.mobile2;
  268. point_Agent.agent = user;
  269. var phone = _point_agentrepository.Add(point_Agent);
  270. }
  271. }
  272. model.F_Province = input.province;
  273. model.F_Area = input.area;
  274. model.F_Town = input.town;
  275. model.F_Postcode = input.postcode;
  276. model.F_Province1 = input.province1;
  277. model.F_Area1 = input.area1;
  278. model.F_Town1 = input.town1;
  279. model.F_Postcode1 = input.postcode1;
  280. model.F_City1 = input.city1;
  281. model.F_ShoeSize = input.shoesize;
  282. model.F_Score = input.score;
  283. model.F_Money = input.money;
  284. model.F_TotalScore = input.totalscore;
  285. model.F_Saleperson = user; //"8000";input.saleperson;
  286. model.F_Type = input.type;
  287. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";
  288. model.F_CreateOn = DateTime.Now;
  289. model.F_State = (int)EnumDelState.Enabled;
  290. model.F_GiftYear = DateTime.Now.AddYears(-1).Year.ToString();
  291. if (input.birthday != null)
  292. {
  293. //今年生日已过
  294. if (input.birthday.Value.Month < DateTime.Now.AddDays(-3).Month || (input.birthday.Value.Month == DateTime.Now.Month && input.birthday.Value.Day < DateTime.Now.AddDays(3).Day))
  295. {
  296. model.F_GiftYear = DateTime.Now.Year.ToString();
  297. }
  298. }
  299. var call = await busCallRecordsRepository.GetListALL(x => x.CallState == 1 || (x.Caller == input.phone || x.Caller == input.mobile || x.Caller == input.mobile1 || x.Caller == input.mobile2) || (x.Callee == input.phone || x.Callee == input.mobile || x.Callee == input.mobile1 || x.Callee == input.mobile2));
  300. if (call!=null && call.Count >0)
  301. {
  302. model.F_Firstcalltime = call[0].BeginTime;
  303. model.F_Lastholetime = call[call.Count -1].BeginTime;
  304. }
  305. if (await _cus_vip_infoRepository.GetCount(x => x.F_Mobile == model.F_Mobile && x.F_Name == input.name) > 0)
  306. {
  307. return Error("添加失败,存在相同会员信息");
  308. }
  309. var res = await _cus_vip_infoRepository.Add(model);
  310. if (res > 0)
  311. {
  312. return Success("添加成功");
  313. }
  314. else
  315. {
  316. return Error("添加失败");
  317. }
  318. }
  319. /// <summary>
  320. /// 修改会员信息
  321. /// </summary>
  322. [HttpPost("update")]
  323. public async Task<IActionResult> UpdateAsync(VipInfoInput input)
  324. {
  325. if (input.id == 0)
  326. return Error("请输入ID");
  327. if (string.IsNullOrEmpty(input.name))
  328. return Error("请输入名字");
  329. if (string.IsNullOrEmpty(input.phone))
  330. return Error("请输入联系方式");
  331. if (await _cus_vip_infoRepository.GetCount(q => q.F_Phone == input.phone&&q.F_ID!= input.id && q.F_State == (int)EnumDelState.Enabled) > 0)
  332. {
  333. return Error("手机号已存在");
  334. }
  335. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  336. var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == input.id && x.F_State == (int)EnumDelState.Enabled);
  337. if (model == null)
  338. return Error("操作失败");
  339. //model.F_VIPCode = input.vipcode;//会员卡号
  340. model.F_Name = input.name;
  341. model.F_Birthday = input.birthday;
  342. if (!valtel(input.phone))
  343. return Error("手机号必须为11位数字");
  344. model.F_Phone = input.phone;
  345. var point = await _point_agentrepository.GetListALL(x => x.caller == input.phone);
  346. if (point == null && point.Count() <= 0)
  347. {
  348. point_agent point_Agent = new point_agent();
  349. point_Agent.caller = input.phone;
  350. point_Agent.agent = user;
  351. var phone = _point_agentrepository.Add(point_Agent);
  352. }
  353. model.F_Recommender = input.recommender;
  354. if (!string.IsNullOrEmpty(input.recommendertel))
  355. {
  356. if (!valtel(input.recommendertel))
  357. return Error("手机号必须为11位数字");
  358. model.F_RecommenderTel = input.recommendertel;
  359. }
  360. model.F_Sex = input.sex;
  361. model.F_Label = input.label;
  362. model.F_State = input.state;
  363. model.F_Note = input.note;
  364. model.F_City = input.city;
  365. model.F_Nickname = input.nickname;
  366. model.F_Address = input.address;
  367. model.F_Address1 = input.address1;
  368. model.F_LastModifyOn = DateTime.Now.ToLocalTime();
  369. model.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  370. model.F_Age = input.age;
  371. if (!string.IsNullOrEmpty(input.mobile))
  372. {
  373. if (!valtel(input.mobile))
  374. return Error("手机号必须为11位数字");
  375. model.F_Mobile = input.mobile;
  376. var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile);
  377. if (_point == null && _point.Count() <= 0)
  378. {
  379. point_agent point_Agent = new point_agent();
  380. point_Agent.caller = input.mobile;
  381. point_Agent.agent = user;
  382. var phone = _point_agentrepository.Add(point_Agent);
  383. }
  384. }
  385. if (!string.IsNullOrEmpty(input.mobile1))
  386. {
  387. if (!valtel(input.mobile1))
  388. return Error("手机号必须为11位数字");
  389. model.F_Mobile1 = input.mobile1; var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile1);
  390. if (_point == null && _point.Count() <= 0)
  391. {
  392. point_agent point_Agent = new point_agent();
  393. point_Agent.caller = input.mobile1;
  394. point_Agent.agent = user;
  395. var phone = _point_agentrepository.Add(point_Agent);
  396. }
  397. }
  398. if (!string.IsNullOrEmpty(input.mobile2))
  399. {
  400. if (!valtel(input.mobile2))
  401. return Error("手机号必须为11位数字");
  402. model.F_Mobile2 = input.mobile2;
  403. model.F_Mobile1 = input.mobile1; var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile2);
  404. if (_point == null && _point.Count() <= 0)
  405. {
  406. point_agent point_Agent = new point_agent();
  407. point_Agent.caller = input.mobile2;
  408. point_Agent.agent = user;
  409. var phone = _point_agentrepository.Add(point_Agent);
  410. }
  411. }
  412. model.F_Province = input.province;
  413. model.F_Area = input.area;
  414. model.F_Town = input.town;
  415. model.F_Postcode = input.postcode;
  416. model.F_Province1 = input.province1;
  417. model.F_Area1 = input.area1;
  418. model.F_Town1 = input.town1;
  419. model.F_Postcode1 = input.postcode1;
  420. model.F_City1 = input.city1;
  421. model.F_ShoeSize = input.shoesize;
  422. model.F_Score = input.score;
  423. model.F_Money = input.money;
  424. model.F_TotalScore = input.totalscore;
  425. //model.F_Saleperson = input.saleperson;
  426. //model.F_Contact = input.contact;
  427. model.F_Type = input.type;
  428. if (model.F_GiftYear != DateTime.Now.Year.ToString())
  429. {
  430. model.F_GiftYear = DateTime.Now.AddYears(-1).Year.ToString();
  431. if (input.birthday != null)
  432. {
  433. //今年生日已过
  434. if (input.birthday.Value.Month < DateTime.Now.AddDays(-3).Month || (input.birthday.Value.Month == DateTime.Now.Month && input.birthday.Value.Day < DateTime.Now.AddDays(3).Day))
  435. {
  436. model.F_GiftYear = DateTime.Now.Year.ToString();
  437. }
  438. }
  439. }
  440. var call = await busCallRecordsRepository.GetListALL(x => x.CallState == 1 || (x.Caller == input.phone || x.Caller == input.mobile || x.Caller == input.mobile1 || x.Caller == input.mobile2) || (x.Callee == input.phone || x.Callee == input.mobile || x.Callee == input.mobile1 || x.Callee == input.mobile2));
  441. if (call != null && call.Count > 0)
  442. {
  443. model.F_Firstcalltime = call[0].BeginTime;
  444. model.F_Lastholetime = call[call.Count - 1].BeginTime;
  445. }
  446. bool b = await _cus_vip_infoRepository.Update(model);
  447. if (b)
  448. return Success("修改成功");
  449. return Error("修改失败");
  450. }
  451. /// <summary>
  452. /// 删除会员信息 by ids
  453. /// </summary>
  454. /// <param name="ids"></param>
  455. /// <returns></returns>
  456. [HttpPost("delete")]
  457. public async Task<IActionResult> Remove(int[] ids)
  458. {
  459. var res = 0;
  460. if (ids != null && ids.Length > 0)
  461. {
  462. foreach (var item in ids)
  463. {
  464. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
  465. ml.F_State = (int)EnumDelState.Delete;
  466. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  467. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  468. if (_cus_vip_infoRepository.Update(ml).Result)
  469. res += 1;
  470. }
  471. if (res == ids.Length)
  472. return Success("删除成功");
  473. else if (res > 0 && res < ids.Length)
  474. return Error("部分删除失败,请查看后重新操作");
  475. else
  476. return Error("删除失败,请查看后重新操作");
  477. }
  478. else
  479. return Error("请选择要删除的记录");
  480. }
  481. /// <summary>
  482. /// 判断号码必须为十一位数字
  483. /// </summary>
  484. /// <param name="tel"></param>
  485. /// <returns></returns>
  486. public bool valtel(string tel)
  487. {
  488. var res = false;
  489. //11位数字
  490. if (tel.Length == 11 && Regex.IsMatch(tel, @"^\d{11}$"))
  491. res = true;
  492. return res;
  493. }
  494. /// <summary>
  495. /// 转移会员信息
  496. /// </summary>
  497. /// <param name="ids"></param>
  498. /// <returns></returns>
  499. [HttpPost("transfer")]
  500. public async Task<IActionResult> Transfer(int[] ids,string toperson)
  501. {
  502. var res = 0;
  503. string msg = "";
  504. if (ids != null && ids.Length > 0)
  505. {
  506. foreach (var item in ids)
  507. {
  508. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
  509. if (ml != null)
  510. {
  511. #region 创建消息提醒
  512. string cname = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  513. var model = new T_Cus_Msg();
  514. model.F_Type = 1;
  515. model.F_VipInfoID = item;
  516. model.F_ToPerson = toperson;
  517. model.F_State = 0;
  518. model.F_Notice = cname+"将"+ids .Length +"条会员档案从"+ ml.F_Saleperson+"转移给"+toperson ;
  519. msg = cname + "将" + ids.Length + "条会员档案从" + ml.F_Saleperson + "转移给" + toperson;
  520. model.F_NotifyPerson = ml.F_Saleperson;
  521. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  522. model.F_CreateOn = DateTime.Now;
  523. var su = await _cus_msgRepository.Add(model);
  524. if (su > 0)
  525. {
  526. res += 1;
  527. }
  528. #endregion
  529. }
  530. //ml.F_Saleperson = toperson;
  531. //ml.F_LastModifyOn = DateTime.Now.ToLocalTime();
  532. //ml.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  533. //if (_cus_vip_infoRepository.Update(ml).Result)
  534. // res += 1;
  535. }
  536. if (res == ids.Length)
  537. {
  538. bool n = new InternalMessages.InternalMessagesController(_sys_internalMessagesrepository, _sys_user_accountRepository).AddInternalMessagesInfo(res, "档案转移消息", msg, User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value, DateTime.Now , 6, 1, 0, toperson, 1);
  539. return Success("转移消息创建成功");
  540. }
  541. else if (res > 0 && res < ids.Length)
  542. return Error("部分转移消息创建失败,请查看后重新操作");
  543. else
  544. return Error("转移消息创建失败,请查看后重新操作");
  545. }
  546. else
  547. return Error("请选择要转移的记录");
  548. }
  549. /// <summary>
  550. /// 转移消息处理
  551. /// </summary>
  552. /// <param name="ids"></param>
  553. /// <returns></returns>
  554. [HttpPost("deal")]
  555. public async Task<IActionResult> Deal(int[] ids, int notagree=0)//同意传0,不同意传1
  556. {
  557. var res = 0;
  558. if (ids != null && ids.Length > 0)
  559. {
  560. foreach (var item in ids)
  561. {
  562. var ml = await _cus_msgRepository.GetSingle(x => x.F_ID == item);
  563. if (ml != null)
  564. {
  565. #region 创建消息提醒
  566. //var model = new T_Cus_Msg();
  567. ml.F_Type = 1;
  568. ml.F_State = notagree +2;
  569. ml.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  570. ml.F_LastModifyOn = DateTime.Now;
  571. if (notagree == 0)//同意转移时更新会员信息
  572. {
  573. var m = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == ml.F_VipInfoID);
  574. if (m != null)
  575. {
  576. if (_cus_msgRepository.Update(ml).Result)
  577. {
  578. res += 1;
  579. m.F_Saleperson = ml.F_ToPerson;
  580. m.F_LastModifyOn = DateTime.Now.ToLocalTime();
  581. m.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  582. if (_cus_vip_infoRepository.Update(m).Result)
  583. { }
  584. }
  585. }
  586. else
  587. {
  588. return Error("该会员已删除或不存在");
  589. }
  590. }
  591. #endregion
  592. }
  593. }
  594. if (res == ids.Length)
  595. return Success("处理成功");
  596. else if (res > 0 && res < ids.Length)
  597. return Error("部分消息处理失败,请查看后重新操作");
  598. else
  599. return Error("处理消息失败,请查看后重新操作");
  600. }
  601. else
  602. return Error("请选择要处理的记录");
  603. }
  604. #region 导入、导出
  605. //导出
  606. [Authorize]
  607. [HttpGet("exportexcel")]
  608. [AllowAnonymous]
  609. public async Task<IActionResult> ExportExcelAsync(string keyword, string name, string phone, string type, string province, string city, string area, string town, string address, string birthday, string recommender, string saleperson)
  610. {
  611. try
  612. {
  613. List<IConditionalModel> conModels = new List<IConditionalModel>();
  614. #region 条件筛选
  615. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  616. if (!string.IsNullOrEmpty(phone))
  617. conModels.Add(new ConditionalCollections()
  618. {
  619. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  620. {
  621. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  622. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Mobile", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  623. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Mobile1", ConditionalType = ConditionalType.Like, FieldValue = phone })
  624. }
  625. });
  626. if (!string.IsNullOrEmpty(name))
  627. {
  628. conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
  629. }
  630. if (!string.IsNullOrEmpty(type))
  631. {
  632. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type });
  633. }
  634. if (!string.IsNullOrEmpty(province))
  635. {
  636. conModels.Add(new ConditionalModel() { FieldName = "F_Province", ConditionalType = ConditionalType.Like, FieldValue = province });
  637. }
  638. if (!string.IsNullOrEmpty(city))
  639. {
  640. conModels.Add(new ConditionalModel() { FieldName = "F_City", ConditionalType = ConditionalType.Like, FieldValue = city });
  641. }
  642. if (!string.IsNullOrEmpty(area))
  643. {
  644. conModels.Add(new ConditionalModel() { FieldName = "F_Area", ConditionalType = ConditionalType.Like, FieldValue = area });
  645. }
  646. if (!string.IsNullOrEmpty(town))
  647. {
  648. conModels.Add(new ConditionalModel() { FieldName = "F_Town", ConditionalType = ConditionalType.Like, FieldValue = town });
  649. }
  650. if (!string.IsNullOrEmpty(address))
  651. {
  652. conModels.Add(new ConditionalModel() { FieldName = "F_Address", ConditionalType = ConditionalType.Like, FieldValue = address });
  653. new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Address1", ConditionalType = ConditionalType.Like, FieldValue = address });
  654. }
  655. if (!string.IsNullOrEmpty(birthday))
  656. {
  657. conModels.Add(new ConditionalModel() { FieldName = "F_Birthday", ConditionalType = ConditionalType.Like, FieldValue = birthday });
  658. }
  659. if (!string.IsNullOrEmpty(recommender))
  660. {
  661. conModels.Add(new ConditionalModel() { FieldName = "F_Recommender", ConditionalType = ConditionalType.Like, FieldValue = recommender });
  662. }
  663. if (!string.IsNullOrEmpty(saleperson))
  664. {
  665. conModels.Add(new ConditionalModel() { FieldName = "F_Saleperson", ConditionalType = ConditionalType.Like, FieldValue = saleperson });
  666. }
  667. #endregion
  668. int recordCount = 0;
  669. var list = await _cus_vip_infoRepository.GetListALL(conModels, "F_CreateOn desc");
  670. var dtNew = list.ToList();
  671. if (dtNew != null)
  672. {
  673. var tb = ModelConvertHelper<T_Cus_VipInfo>.ConvertListToDataTable(dtNew);
  674. //导出dtnew
  675. NPOIHelper npoi = new NPOIHelper();
  676. string dbkeys = _configuration["Import:vipkey"].ToString();
  677. string title = _configuration["Import:vipvalue"].ToString();
  678. string[] colname = dbkeys.Split(",");
  679. string[] cols = title.Split(",");
  680. byte[] sm = npoi.ExportToExcel1(tb, cols, colname);
  681. if (sm != null)
  682. {
  683. return File(sm, "application/vnd.ms-excel", "会员信息.xlsx");
  684. }
  685. else
  686. {
  687. return Error("导出失败3");
  688. }
  689. }
  690. return Error("导出失败2");
  691. //return Success("根据条件获取数据成功", tasklist);
  692. }
  693. catch (Exception ex)
  694. {
  695. //_logger.LogError(ex, "导出异常");
  696. return Error("导出失败1");
  697. }
  698. //return Success("导出成功");
  699. }
  700. /// <summary>
  701. /// 上传文件并导入数据库
  702. /// </summary>
  703. /// <returns></returns>
  704. [HttpPost("importexcel")]
  705. public async Task<IActionResult> ImportExcel( int headrow = 0)
  706. {
  707. //string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  708. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  709. if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
  710. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  711. NPOIHelper npoi = new NPOIHelper();
  712. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  713. int num = dtExcel.Rows.Count;
  714. var cols = dtExcel.Columns;
  715. int colnum = cols.Count;
  716. string dbkeys = _configuration["Import:vipkey"].ToString();
  717. string title = _configuration["Import:vipvalue"].ToString();
  718. string[] dbcols = dbkeys.Split(",");
  719. string[] titlecols = title.Split(",");
  720. string errmsg = string.Empty;
  721. if (num > 0)
  722. {
  723. int index = 1;
  724. foreach (DataRow dr in dtExcel.Rows)
  725. {
  726. var model = new T_Cus_VipInfo();
  727. model.F_State = 1;
  728. //model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  729. model.F_CreateOn = DateTime.Now;
  730. var dbcolslist = dbcols.ToList();
  731. var titlelist = titlecols.ToList();
  732. Type t = model.GetType();
  733. PropertyInfo[] PropertyList = t.GetProperties();
  734. foreach (PropertyInfo item in PropertyList)
  735. {
  736. try
  737. {
  738. if (dbcolslist.Contains(item.Name))
  739. {
  740. Type tType = null;
  741. object o = dr[titlelist[dbcolslist.IndexOf(item.Name)]];
  742. if (item.PropertyType.FullName.Contains(typeof(DateTime).FullName))
  743. {
  744. tType = typeof(DateTime);
  745. }
  746. else if (item.PropertyType.FullName.Contains(typeof(Int64).FullName))
  747. {
  748. tType = typeof(Int64);
  749. }
  750. else if (item.PropertyType.FullName.Contains(typeof(Int32).FullName))
  751. {
  752. tType = typeof(Int32);
  753. }
  754. else if (item.PropertyType.FullName.Contains(typeof(Decimal).FullName))
  755. {
  756. tType = typeof(Decimal);
  757. }
  758. else { tType = item.PropertyType; }
  759. object v = null;
  760. if (o != null && o != DBNull.Value)
  761. v = Convert.ChangeType(dr[titlelist[dbcolslist.IndexOf(item.Name)]].ToString(), tType);
  762. item.SetValue(model, v, null);
  763. }
  764. }
  765. catch
  766. {
  767. return Error("模板错误,请选择正确的模板");
  768. }
  769. }
  770. int b = await _cus_vip_infoRepository.Add(model);
  771. if (b<=0)
  772. {
  773. if (!string.IsNullOrEmpty(errmsg))
  774. {
  775. errmsg = errmsg + "\r\n第" + index + "行导入失败!";
  776. }
  777. else
  778. {
  779. errmsg = "第" + index + "行导入失败!";
  780. }
  781. }
  782. index++;
  783. }
  784. }
  785. else
  786. {
  787. return Error("文件中无数据");
  788. }
  789. if (!string.IsNullOrEmpty(errmsg))
  790. {
  791. //删除已导入的部分
  792. return Error(errmsg);
  793. }
  794. return Success("导入成功");
  795. }
  796. #endregion
  797. /// <summary>
  798. /// 更新会员积分
  799. /// </summary>
  800. /// <param name="ids"></param>
  801. /// <returns></returns>
  802. [HttpPost("updatescore")]
  803. public async Task<IActionResult> UpdateScore(string mobile,string money)
  804. {
  805. if (string.IsNullOrEmpty (mobile ))
  806. {
  807. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_Mobile == mobile||x.F_Mobile1 ==mobile );
  808. ml.F_State = (int)EnumDelState.Delete;
  809. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  810. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  811. if (_cus_vip_infoRepository.Update(ml).Result)
  812. {
  813. return Success("更新成功");
  814. }
  815. else
  816. return Error("更新失败");
  817. }
  818. else
  819. return Error("手机号不能为空");
  820. }
  821. }
  822. }