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

VIPInfoController.cs 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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. namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
  18. {
  19. //[Authorize]
  20. [Produces("application/json")]
  21. [Route("api/[controller]")]
  22. public class VipInfoController : BaseController
  23. {
  24. private readonly ICus_VipInfoRepository _cus_vip_infoRepository;
  25. private readonly ISys_UserAccountRepository _sys_user_accountRepository;
  26. private readonly ICus_MsgRepository _cus_msgRepository;
  27. private readonly IConfiguration _configuration;
  28. public VipInfoController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_UserAccountRepository sys_user_accountRepository, ICus_MsgRepository cus_msgRepository,IConfiguration configuration)
  29. {
  30. _cus_vip_infoRepository = cus_vip_infoRepository;
  31. _sys_user_accountRepository = sys_user_accountRepository;
  32. _cus_msgRepository = cus_msgRepository;
  33. _configuration = configuration;
  34. }
  35. [HttpGet]
  36. public IActionResult Index()
  37. {
  38. return Success("成功");
  39. }
  40. /// <summary>
  41. /// 获取会员列表分页
  42. /// </summary>
  43. /// <param name="keyword"></param>
  44. /// <param name="pageindex"></param>
  45. /// <param name="pagesize"></param>
  46. /// <returns></returns>
  47. [HttpGet("getlistbypage")]
  48. 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,int pageindex = 1, int pagesize = 20)
  49. {
  50. List<IConditionalModel> conModels = new List<IConditionalModel>();
  51. #region 条件筛选
  52. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  53. if (!string.IsNullOrEmpty(phone))
  54. conModels.Add(new ConditionalCollections()
  55. {
  56. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  57. {
  58. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  59. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Mobile", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  60. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Mobile1", ConditionalType = ConditionalType.Like, FieldValue = phone })
  61. }
  62. });
  63. if (!string.IsNullOrEmpty(name))
  64. {
  65. conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
  66. }
  67. if (!string.IsNullOrEmpty(type))
  68. {
  69. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type });
  70. }
  71. if (!string.IsNullOrEmpty(province))
  72. {
  73. conModels.Add(new ConditionalModel() { FieldName = "F_Province", ConditionalType = ConditionalType.Like, FieldValue = province });
  74. }
  75. if (!string.IsNullOrEmpty(city))
  76. {
  77. conModels.Add(new ConditionalModel() { FieldName = "F_City", ConditionalType = ConditionalType.Like, FieldValue = city });
  78. }
  79. if (!string.IsNullOrEmpty(area))
  80. {
  81. conModels.Add(new ConditionalModel() { FieldName = "F_Area", ConditionalType = ConditionalType.Like, FieldValue = area });
  82. }
  83. if (!string.IsNullOrEmpty(town))
  84. {
  85. conModels.Add(new ConditionalModel() { FieldName = "F_Town", ConditionalType = ConditionalType.Like, FieldValue = town });
  86. }
  87. if (!string.IsNullOrEmpty(address))
  88. {
  89. conModels.Add(new ConditionalModel() { FieldName = "F_Address", ConditionalType = ConditionalType.Like, FieldValue = address });
  90. new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Address1", ConditionalType = ConditionalType.Like, FieldValue = address });
  91. }
  92. if (!string.IsNullOrEmpty(birthday))
  93. {
  94. conModels.Add(new ConditionalModel() { FieldName = "F_Birthday", ConditionalType = ConditionalType.Equal, FieldValue = birthday });
  95. }
  96. if (!string.IsNullOrEmpty(recommender))
  97. {
  98. conModels.Add(new ConditionalModel() { FieldName = "F_Recommender", ConditionalType = ConditionalType.Like, FieldValue = recommender });
  99. }
  100. if (!string.IsNullOrEmpty(saleperson))
  101. {
  102. conModels.Add(new ConditionalModel() { FieldName = "F_Saleperson", ConditionalType = ConditionalType.Like, FieldValue = saleperson });
  103. }
  104. //if (!string.IsNullOrEmpty(contact))
  105. //{
  106. // conModels.Add(new ConditionalModel() { FieldName = "F_Contact", ConditionalType = ConditionalType.Like, FieldValue = contact });
  107. //}
  108. #endregion
  109. int recordCount = 0;
  110. var list = await _cus_vip_infoRepository.GetListViewByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, "F_CreateOn desc");
  111. var obj = new
  112. {
  113. state = "success",
  114. message = "成功",
  115. rows = list,
  116. total = recordCount,
  117. };
  118. return Content(obj.ToJson());
  119. }
  120. /// <summary>
  121. /// 获取会员信息详情
  122. /// </summary>
  123. /// <param name="id">id</param>
  124. /// <returns></returns>
  125. [HttpGet("getdetails")]
  126. public async Task<IActionResult> GetDetailsAsync(int id)
  127. {
  128. if (id <= 0)
  129. return Error("参数错误");
  130. var model = await _cus_vip_infoRepository.GetSingleV(x => x.F_ID == id && x.F_State == (int)EnumDelState.Enabled);
  131. var newmodel = new V_Cus_VipInfo();
  132. if (model == null)
  133. {
  134. return Error("获取失败");
  135. }
  136. return Success("获取成功!", model);
  137. }
  138. /// <summary>
  139. /// 添加会员
  140. /// </summary>
  141. /// <param name="input"></param>
  142. /// <returns></returns>
  143. [HttpPost("add")]
  144. public async Task<IActionResult> AddAsync(VipInfoInput input)
  145. {
  146. if (string.IsNullOrEmpty(input.name))
  147. return Error("请输入名字");
  148. if (string.IsNullOrEmpty(input.phone))
  149. return Error("请输入联系方式");
  150. var model = new T_Cus_VipInfo();
  151. //model.F_VIPCode = input.vipcode;//会员卡号
  152. model.F_Name = input.name;
  153. model.F_Birthday = input.birthday;
  154. model.F_Phone = input.phone;
  155. model.F_Recommender = input.recommender;
  156. model.F_Sex = input.sex;
  157. model.F_Label = input.label;
  158. model.F_Note = input.note;
  159. model.F_City = input.city;
  160. model.F_Nickname = input.nickname;
  161. model.F_Address = input.address;
  162. model.F_Address1 = input.address1;
  163. model.F_Age = input.age;
  164. model.F_Mobile = input.mobile;
  165. model.F_Mobile1 = input.mobile1;
  166. model.F_Province = input.province;
  167. model.F_Area = input.area;
  168. model.F_Town = input.town;
  169. model.F_Postcode = input.postcode;
  170. model.F_Province1 = input.province1;
  171. model.F_Area1 = input.area1;
  172. model.F_Town1 = input.town1;
  173. model.F_Postcode1 = input.postcode1;
  174. model.F_City1 = input.city1;
  175. model.F_ShoeSize = input.shoesize;
  176. model.F_Score = input.score;
  177. model.F_Money = input.money;
  178. model.F_TotalScore = input.totalscore;
  179. model.F_Saleperson = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";input.saleperson;
  180. model.F_Type = input.type;
  181. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";
  182. model.F_CreateOn = DateTime.Now;
  183. model.F_State = (int)EnumDelState.Enabled;
  184. if (await _cus_vip_infoRepository.GetCount(x => x.F_Mobile == model.F_Mobile && x.F_Name == input.name) > 0)
  185. {
  186. return Error("添加失败,存在相同会员信息");
  187. }
  188. var res = await _cus_vip_infoRepository.Add(model);
  189. if (res > 0)
  190. {
  191. return Success("添加成功");
  192. }
  193. else
  194. {
  195. return Error("添加失败");
  196. }
  197. }
  198. /// <summary>
  199. /// 修改会员信息
  200. /// </summary>
  201. [HttpPost("update")]
  202. public async Task<IActionResult> UpdateAsync(VipInfoInput input)
  203. {
  204. if (string.IsNullOrEmpty(input.name))
  205. return Error("请输入名字");
  206. if (string.IsNullOrEmpty(input.phone))
  207. return Error("请输入联系方式");
  208. var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == input.id && x.F_State == (int)EnumDelState.Enabled);
  209. if (model == null)
  210. return Error("操作失败");
  211. //model.F_VIPCode = input.vipcode;//会员卡号
  212. model.F_Name = input.name;
  213. model.F_Birthday = input.birthday;
  214. model.F_Phone = input.phone;
  215. model.F_Recommender = input.recommender;
  216. model.F_Sex = input.sex;
  217. model.F_Label = input.label;
  218. model.F_State = input.state;
  219. model.F_Note = input.note;
  220. model.F_City = input.city;
  221. model.F_Nickname = input.nickname;
  222. model.F_Address = input.address;
  223. model.F_Address1 = input.address1;
  224. model.F_LastModifyOn = DateTime.Now.ToLocalTime();
  225. model.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  226. model.F_Age = input.age;
  227. model.F_Mobile = input.mobile;
  228. model.F_Mobile1 = input.mobile1;
  229. model.F_Province = input.province;
  230. model.F_Area = input.area;
  231. model.F_Town = input.town;
  232. model.F_Postcode = input.postcode;
  233. model.F_Province1 = input.province1;
  234. model.F_Area1 = input.area1;
  235. model.F_Town1 = input.town1;
  236. model.F_Postcode1 = input.postcode1;
  237. model.F_City1 = input.city1;
  238. model.F_ShoeSize = input.shoesize;
  239. model.F_Score = input.score;
  240. model.F_Money = input.money;
  241. model.F_TotalScore = input.totalscore;
  242. //model.F_Saleperson = input.saleperson;
  243. //model.F_Contact = input.contact;
  244. model.F_Type = input.type;
  245. bool b = await _cus_vip_infoRepository.Update(model);
  246. if (b)
  247. return Success("修改成功");
  248. return Error("修改失败");
  249. }
  250. /// <summary>
  251. /// 删除会员信息 by ids
  252. /// </summary>
  253. /// <param name="ids"></param>
  254. /// <returns></returns>
  255. [HttpPost("delete")]
  256. public async Task<IActionResult> Remove(int[] ids)
  257. {
  258. var res = 0;
  259. if (ids != null && ids.Length > 0)
  260. {
  261. foreach (var item in ids)
  262. {
  263. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
  264. ml.F_State = (int)EnumDelState.Delete;
  265. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  266. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  267. if (_cus_vip_infoRepository.Update(ml).Result)
  268. res += 1;
  269. }
  270. if (res == ids.Length)
  271. return Success("删除成功");
  272. else if (res > 0 && res < ids.Length)
  273. return Error("部分删除失败,请查看后重新操作");
  274. else
  275. return Error("删除失败,请查看后重新操作");
  276. }
  277. else
  278. return Error("请选择要删除的记录");
  279. }
  280. /// <summary>
  281. /// 转移会员信息
  282. /// </summary>
  283. /// <param name="ids"></param>
  284. /// <returns></returns>
  285. [HttpPost("transfer")]
  286. public async Task<IActionResult> Transfer(int[] ids,string toperson)
  287. {
  288. var res = 0;
  289. if (ids != null && ids.Length > 0)
  290. {
  291. foreach (var item in ids)
  292. {
  293. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
  294. if (ml != null)
  295. {
  296. #region 创建消息提醒
  297. string cname = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  298. var model = new T_Cus_Msg();
  299. model.F_Type = 1;
  300. model.F_VipInfoID = item;
  301. model.F_ToPerson = toperson;
  302. model.F_State = 0;
  303. model.F_Notice = cname+"将"+ids .Length +"条会员档案从"+ ml.F_Saleperson+"转移给"+toperson ;
  304. model.F_NotifyPerson = ml.F_Saleperson;
  305. model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  306. model.F_CreateOn = DateTime.Now;
  307. var su = await _cus_msgRepository.Add(model);
  308. if (su > 0)
  309. {
  310. res += 1;
  311. }
  312. #endregion
  313. }
  314. //ml.F_Saleperson = toperson;
  315. //ml.F_LastModifyOn = DateTime.Now.ToLocalTime();
  316. //ml.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  317. //if (_cus_vip_infoRepository.Update(ml).Result)
  318. // res += 1;
  319. }
  320. if (res == ids.Length)
  321. return Success("转移消息创建成功");
  322. else if (res > 0 && res < ids.Length)
  323. return Error("部分转移消息创建失败,请查看后重新操作");
  324. else
  325. return Error("转移消息创建失败,请查看后重新操作");
  326. }
  327. else
  328. return Error("请选择要转移的记录");
  329. }
  330. /// <summary>
  331. /// 转移消息处理
  332. /// </summary>
  333. /// <param name="ids"></param>
  334. /// <returns></returns>
  335. [HttpPost("deal")]
  336. public async Task<IActionResult> Deal(int[] ids, int notagree)//同意传0,不同意传1
  337. {
  338. var res = 0;
  339. if (ids != null && ids.Length > 0)
  340. {
  341. foreach (var item in ids)
  342. {
  343. var ml = await _cus_msgRepository.GetSingle(x => x.F_ID == item);
  344. if (ml != null)
  345. {
  346. #region 创建消息提醒
  347. //var model = new T_Cus_Msg();
  348. ml.F_Type = 1;
  349. ml.F_State = notagree +2;
  350. ml.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  351. ml.F_LastModifyOn = DateTime.Now;
  352. if (_cus_msgRepository.Update(ml).Result)
  353. {
  354. if (notagree == 0)//同意转移时更新会员信息
  355. {
  356. var m = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == ml.F_VipInfoID );
  357. m.F_Saleperson = ml.F_ToPerson ;
  358. m.F_LastModifyOn = DateTime.Now.ToLocalTime();
  359. m.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  360. if (_cus_vip_infoRepository.Update(m).Result)
  361. { }
  362. }
  363. res += 1;
  364. }
  365. #endregion
  366. }
  367. }
  368. if (res == ids.Length)
  369. return Success("处理成功");
  370. else if (res > 0 && res < ids.Length)
  371. return Error("部分消息处理失败,请查看后重新操作");
  372. else
  373. return Error("处理消息失败,请查看后重新操作");
  374. }
  375. else
  376. return Error("请选择要处理的记录");
  377. }
  378. #region 导入、导出
  379. //导出
  380. [Authorize]
  381. [HttpGet("exportexcel")]
  382. [AllowAnonymous]
  383. 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)
  384. {
  385. try
  386. {
  387. List<IConditionalModel> conModels = new List<IConditionalModel>();
  388. #region 条件筛选
  389. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
  390. if (!string.IsNullOrEmpty(phone))
  391. conModels.Add(new ConditionalCollections()
  392. {
  393. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  394. {
  395. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  396. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Mobile", ConditionalType = ConditionalType.Like, FieldValue = phone }),
  397. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Mobile1", ConditionalType = ConditionalType.Like, FieldValue = phone })
  398. }
  399. });
  400. if (!string.IsNullOrEmpty(name))
  401. {
  402. conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
  403. }
  404. if (!string.IsNullOrEmpty(type))
  405. {
  406. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type });
  407. }
  408. if (!string.IsNullOrEmpty(province))
  409. {
  410. conModels.Add(new ConditionalModel() { FieldName = "F_Province", ConditionalType = ConditionalType.Like, FieldValue = province });
  411. }
  412. if (!string.IsNullOrEmpty(city))
  413. {
  414. conModels.Add(new ConditionalModel() { FieldName = "F_City", ConditionalType = ConditionalType.Like, FieldValue = city });
  415. }
  416. if (!string.IsNullOrEmpty(area))
  417. {
  418. conModels.Add(new ConditionalModel() { FieldName = "F_Area", ConditionalType = ConditionalType.Like, FieldValue = area });
  419. }
  420. if (!string.IsNullOrEmpty(town))
  421. {
  422. conModels.Add(new ConditionalModel() { FieldName = "F_Town", ConditionalType = ConditionalType.Like, FieldValue = town });
  423. }
  424. if (!string.IsNullOrEmpty(address))
  425. {
  426. conModels.Add(new ConditionalModel() { FieldName = "F_Address", ConditionalType = ConditionalType.Like, FieldValue = address });
  427. new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Address1", ConditionalType = ConditionalType.Like, FieldValue = address });
  428. }
  429. if (!string.IsNullOrEmpty(birthday))
  430. {
  431. conModels.Add(new ConditionalModel() { FieldName = "F_Birthday", ConditionalType = ConditionalType.Like, FieldValue = birthday });
  432. }
  433. if (!string.IsNullOrEmpty(recommender))
  434. {
  435. conModels.Add(new ConditionalModel() { FieldName = "F_Recommender", ConditionalType = ConditionalType.Like, FieldValue = recommender });
  436. }
  437. if (!string.IsNullOrEmpty(saleperson))
  438. {
  439. conModels.Add(new ConditionalModel() { FieldName = "F_Saleperson", ConditionalType = ConditionalType.Like, FieldValue = saleperson });
  440. }
  441. #endregion
  442. int recordCount = 0;
  443. var list = await _cus_vip_infoRepository.GetListALL(conModels, "F_CreateOn desc");
  444. var dtNew = list.ToList();
  445. if (dtNew != null)
  446. {
  447. var tb = ModelConvertHelper<T_Cus_VipInfo>.ConvertListToDataTable(dtNew);
  448. //导出dtnew
  449. NPOIHelper npoi = new NPOIHelper();
  450. string dbkeys = _configuration["Import:vipkey"].ToString();
  451. string title = _configuration["Import:vipvalue"].ToString();
  452. string[] cols = dbkeys.Split(",");
  453. string[] colname = title.Split(",");
  454. byte[] sm = npoi.ExportToExcel1(tb, cols, colname);
  455. if (sm != null)
  456. {
  457. return File(sm, "application/vnd.ms-excel", "会员信息.xlsx");
  458. }
  459. else
  460. {
  461. return Error("导出失败3");
  462. }
  463. }
  464. return Error("导出失败2");
  465. //return Success("根据条件获取数据成功", tasklist);
  466. }
  467. catch (Exception ex)
  468. {
  469. //_logger.LogError(ex, "导出异常");
  470. return Error("导出失败1");
  471. }
  472. //return Success("导出成功");
  473. }
  474. /// <summary>
  475. /// 上传文件并导入数据库
  476. /// </summary>
  477. /// <returns></returns>
  478. [HttpPost("importexcel")]
  479. public async Task<IActionResult> ImportExcel( int headrow = 0)
  480. {
  481. //string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  482. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  483. 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"))
  484. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  485. NPOIHelper npoi = new NPOIHelper();
  486. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  487. int num = dtExcel.Rows.Count;
  488. var cols = dtExcel.Columns;
  489. int colnum = cols.Count;
  490. string dbkeys = _configuration["Import:vipkey"].ToString();
  491. string title = _configuration["Import:vipvalue"].ToString();
  492. string[] dbcols = dbkeys.Split(",");
  493. string[] titlecols = title.Split(",");
  494. string errmsg = string.Empty;
  495. if (num > 0)
  496. {
  497. int index = 1;
  498. foreach (DataRow dr in dtExcel.Rows)
  499. {
  500. var model = new T_Cus_VipInfo();
  501. model.F_State = 1;
  502. //model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  503. model.F_CreateOn = DateTime.Now;
  504. var dbcolslist = dbcols.ToList();
  505. var titlelist = titlecols.ToList();
  506. Type t = model.GetType();
  507. PropertyInfo[] PropertyList = t.GetProperties();
  508. foreach (PropertyInfo item in PropertyList)
  509. {
  510. if (dbcolslist.Contains(item.Name))
  511. {
  512. Type tType = null;
  513. object o = dr[titlelist[dbcolslist.IndexOf(item.Name)]];
  514. if (item.PropertyType.FullName.Contains(typeof(DateTime).FullName))
  515. {
  516. tType= typeof(DateTime);
  517. }
  518. else if (item.PropertyType.FullName.Contains(typeof(Int64).FullName))
  519. {
  520. tType = typeof(Int64);
  521. }
  522. else if (item.PropertyType.FullName.Contains(typeof(Int32).FullName))
  523. {
  524. tType = typeof(Int32);
  525. }
  526. else if (item.PropertyType.FullName.Contains(typeof(Decimal).FullName))
  527. {
  528. tType = typeof(Decimal);
  529. }
  530. else { tType = item.PropertyType; }
  531. object v = null;
  532. if (o!=null&&o!=DBNull.Value)
  533. v = Convert.ChangeType(dr[titlelist[dbcolslist.IndexOf(item.Name)]].ToString(), tType);
  534. item.SetValue(model, v, null);
  535. }
  536. }
  537. int b = await _cus_vip_infoRepository.Add(model);
  538. if (b<=0)
  539. {
  540. if (!string.IsNullOrEmpty(errmsg))
  541. {
  542. errmsg = errmsg + "\r\n第" + index + "行导入失败!";
  543. }
  544. else
  545. {
  546. errmsg = "第" + index + "行导入失败!";
  547. }
  548. }
  549. index++;
  550. }
  551. }
  552. else
  553. {
  554. return Error("文件中无数据");
  555. }
  556. if (!string.IsNullOrEmpty(errmsg))
  557. {
  558. //删除已导入的部分
  559. return Error(errmsg);
  560. }
  561. return Success("导入成功");
  562. }
  563. #endregion
  564. /// <summary>
  565. /// 更新会员积分
  566. /// </summary>
  567. /// <param name="ids"></param>
  568. /// <returns></returns>
  569. [HttpPost("updatescore")]
  570. public async Task<IActionResult> UpdateScore(string mobile,string money)
  571. {
  572. if (string.IsNullOrEmpty (mobile ))
  573. {
  574. var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_Mobile == mobile||x.F_Mobile1 ==mobile );
  575. ml.F_State = (int)EnumDelState.Delete;
  576. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  577. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  578. if (_cus_vip_infoRepository.Update(ml).Result)
  579. {
  580. return Success("更新成功");
  581. }
  582. else
  583. return Error("更新失败");
  584. }
  585. else
  586. return Error("手机号不能为空");
  587. }
  588. }
  589. }