| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883 |
- using System;
- using System.Collections.Generic;
- using System.Common;
- using System.IRepositories;
- using System.Linq;
- using System.Model;
- using System.Security.Claims;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using TVShoppingCallCenter_ZLJ.Models.Inputs;
- using SqlSugar;
- using System.Common.Helpers;
- using Microsoft.Extensions.Configuration;
- using System.Data;
- using System.Reflection;
- using System.Text.RegularExpressions;
- using System.IRepositories.Call;
- using System.Model.Call;
- namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
- {
- [Authorize]
- [Produces("application/json")]
- [Route("api/[controller]")]
- public class VipInfoController : BaseController
- {
- private readonly ICus_VipInfoRepository _cus_vip_infoRepository;
- private readonly ISys_UserAccountRepository _sys_user_accountRepository;
- private readonly ICus_MsgRepository _cus_msgRepository;
- private readonly IConfiguration _configuration;
- private readonly ISMS_InternalMessagesReposytory _sys_internalMessagesrepository;
- private readonly ICall_CallRecordsRepository busCallRecordsRepository;
- private readonly Ipoint_agentRepository _point_agentrepository;
- public VipInfoController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_UserAccountRepository sys_user_accountRepository, ICus_MsgRepository cus_msgRepository,IConfiguration configuration,
- ISMS_InternalMessagesReposytory sys_internalMessagesrepository, ICall_CallRecordsRepository _busCallRecordsRepository, Ipoint_agentRepository point_agentrepository)
- {
- _cus_vip_infoRepository = cus_vip_infoRepository;
- _sys_user_accountRepository = sys_user_accountRepository;
- _cus_msgRepository = cus_msgRepository;
- _configuration = configuration;
- _sys_internalMessagesrepository = sys_internalMessagesrepository;
- busCallRecordsRepository = _busCallRecordsRepository;
- _point_agentrepository = point_agentrepository;
- }
- [HttpGet]
- public IActionResult Index()
- {
- return Success("成功");
- }
- /// <summary>
- /// 获取会员列表分页
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="pageindex"></param>
- /// <param name="pagesize"></param>
- /// <returns></returns>
- [HttpGet("getlistbypage")]
- 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)
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- #region 条件筛选
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
- if (!string.IsNullOrEmpty(phone))
- conModels.Add(new ConditionalCollections()
- {
- ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
- {
- new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = phone }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Mobile", ConditionalType = ConditionalType.Like, FieldValue = phone }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Mobile1", ConditionalType = ConditionalType.Like, FieldValue = phone })
-
- }
- });
- if (!string.IsNullOrEmpty(label))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Label", ConditionalType = ConditionalType.Like, FieldValue = label });
- }
- if (!string.IsNullOrEmpty(name))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
- }
- if (!string.IsNullOrEmpty(type))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type });
- }
- if (!string.IsNullOrEmpty(province))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Province", ConditionalType = ConditionalType.Like, FieldValue = province });
- }
- if (!string.IsNullOrEmpty(city))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_City", ConditionalType = ConditionalType.Like, FieldValue = city });
- }
- if (!string.IsNullOrEmpty(area))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Area", ConditionalType = ConditionalType.Like, FieldValue = area });
- }
- if (!string.IsNullOrEmpty(town))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Town", ConditionalType = ConditionalType.Like, FieldValue = town });
- }
- if (!string.IsNullOrEmpty(address))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Address", ConditionalType = ConditionalType.Like, FieldValue = address });
- new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Address1", ConditionalType = ConditionalType.Like, FieldValue = address });
- }
- if (!string.IsNullOrEmpty(birthday))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Birthday", ConditionalType = ConditionalType.Equal, FieldValue = birthday });
- }
- if (!string.IsNullOrEmpty(recommender))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Recommender", ConditionalType = ConditionalType.Like, FieldValue = recommender });
- }
- if (!string.IsNullOrEmpty(saleperson))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Saleperson", ConditionalType = ConditionalType.Like, FieldValue = saleperson });
- }
- //if (!string.IsNullOrEmpty(contact))
- //{
- // conModels.Add(new ConditionalModel() { FieldName = "F_Contact", ConditionalType = ConditionalType.Like, FieldValue = contact });
- //}
- #endregion
- int recordCount = 0;
- var list = await _cus_vip_infoRepository.GetListViewByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, "F_CreateOn desc");
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = list,
- total = recordCount,
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取会员信息详情
- /// </summary>
- /// <param name="id">id</param>
- /// <returns></returns>
- [HttpGet("getdetails")]
- public async Task<IActionResult> GetDetailsAsync(int id)
- {
- if (id <= 0)
- return Error("参数错误");
- var model = await _cus_vip_infoRepository.GetSingleV(x => x.F_ID == id && x.F_State == (int)EnumDelState.Enabled);
-
- var newmodel = new V_Cus_VipInfo();
- if (model != null)
- {
- var modellist = await _cus_msgRepository.GetListALL(x => x.F_VipInfoID == model.F_ID);
- var obj =new
- {
- model,
- modellist
- };
- return Content(obj.ToJson());
- }
- return Error("获取失败");
-
- }
- /// <summary>
- /// 根据电话号码获取会员详情
- /// </summary>
- /// <param name="id">id</param>
- /// <returns></returns>
- [HttpGet("getphonedetails")]
- public async Task<IActionResult> GetDetai(string phone)
- {
- if (string .IsNullOrEmpty (phone))
- return Error("参数错误");
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
- conModels.Add(new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Equal, FieldValue = phone });
- int recordCount=0;
- var model = await _cus_vip_infoRepository.GetListViewByPage(conModels,new MyPageModel() { PageIndex = 1, PageSize = 1, PageCount = recordCount }, "F_CreateOn desc");
- var newmodel = new V_Cus_VipInfo();
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = model,
- total = recordCount,
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 添加会员
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("add")]
- public async Task<IActionResult> AddAsync(VipInfoInput input)
- {
- if (string.IsNullOrEmpty(input.name))
- return Error("请输入名字");
- if (string.IsNullOrEmpty(input.phone))
- return Error("请输入联系方式");
- if (await _cus_vip_infoRepository.GetCount(q => q.F_Phone == input.phone&&q.F_State== (int)EnumDelState.Enabled) >0)
- {
- return Error("手机号已存在");
- }
- string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- var model = new T_Cus_VipInfo();
- //model.F_VIPCode = input.vipcode;//会员卡号
- model.F_Name = input.name;
- model.F_Birthday = input.birthday;
- if(!valtel(input.phone))
- return Error("手机号必须为11位数字");
- model.F_Phone = input.phone;
- var point = await _point_agentrepository.GetListALL(x => x.caller == input.phone);
- if (point == null && point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.phone;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- model.F_Recommender = input.recommender;
- if (!string .IsNullOrEmpty (input.recommendertel))
- {
- if (!valtel(input.recommendertel))
- return Error("手机号必须为11位数字");
- model.F_RecommenderTel = input.recommendertel;
- }
-
- model.F_Sex = input.sex;
- model.F_Label = input.label;
- model.F_Note = input.note;
- model.F_City = input.city;
- model.F_Nickname = input.nickname;
- model.F_Address = input.address;
- model.F_Address1 = input.address1;
- model.F_Age = input.age;
- if (!string .IsNullOrEmpty (input .mobile ))
- {
- if (!valtel(input.mobile))
- return Error("手机号必须为11位数字");
- model.F_Mobile = input.mobile;
- var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile);
- if (_point == null && _point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.mobile;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- }
- if (!string.IsNullOrEmpty(input.mobile1))
- {
- if (!valtel(input.mobile1))
- return Error("手机号必须为11位数字");
- model.F_Mobile1 = input.mobile1;
- var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile1);
- if (_point == null && _point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.mobile1;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- }
- if (!string.IsNullOrEmpty(input.mobile2))
- {
- if (!valtel(input.mobile2))
- return Error("手机号必须为11位数字");
- model.F_Mobile2 = input.mobile2;
- var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile2);
- if (_point == null && _point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.mobile2;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- }
-
- model.F_Province = input.province;
- model.F_Area = input.area;
- model.F_Town = input.town;
- model.F_Postcode = input.postcode;
- model.F_Province1 = input.province1;
- model.F_Area1 = input.area1;
- model.F_Town1 = input.town1;
- model.F_Postcode1 = input.postcode1;
- model.F_City1 = input.city1;
- model.F_ShoeSize = input.shoesize;
- model.F_Score = input.score;
- model.F_Money = input.money;
- model.F_TotalScore = input.totalscore;
- model.F_Saleperson = user; //"8000";input.saleperson;
- model.F_Type = input.type;
- model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";
- model.F_CreateOn = DateTime.Now;
- model.F_State = (int)EnumDelState.Enabled;
- model.F_GiftYear = DateTime.Now.AddYears(-1).Year.ToString();
- if (input.birthday != null)
- {
- //今年生日已过
- 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))
- {
- model.F_GiftYear = DateTime.Now.Year.ToString();
- }
- }
- 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));
- if (call!=null && call.Count >0)
- {
- model.F_Firstcalltime = call[0].BeginTime;
- model.F_Lastholetime = call[call.Count -1].BeginTime;
- }
-
-
- if (await _cus_vip_infoRepository.GetCount(x => x.F_Mobile == model.F_Mobile && x.F_Name == input.name) > 0)
- {
- return Error("添加失败,存在相同会员信息");
- }
- var res = await _cus_vip_infoRepository.Add(model);
- if (res > 0)
- {
- return Success("添加成功");
- }
- else
- {
- return Error("添加失败");
- }
- }
- /// <summary>
- /// 修改会员信息
- /// </summary>
- [HttpPost("update")]
- public async Task<IActionResult> UpdateAsync(VipInfoInput input)
- {
- if (input.id == 0)
- return Error("请输入ID");
- if (string.IsNullOrEmpty(input.name))
- return Error("请输入名字");
- if (string.IsNullOrEmpty(input.phone))
- return Error("请输入联系方式");
- if (await _cus_vip_infoRepository.GetCount(q => q.F_Phone == input.phone&&q.F_ID!= input.id && q.F_State == (int)EnumDelState.Enabled) > 0)
- {
- return Error("手机号已存在");
- }
- string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == input.id && x.F_State == (int)EnumDelState.Enabled);
- if (model == null)
- return Error("操作失败");
- //model.F_VIPCode = input.vipcode;//会员卡号
- model.F_Name = input.name;
- model.F_Birthday = input.birthday;
- if (!valtel(input.phone))
- return Error("手机号必须为11位数字");
- model.F_Phone = input.phone;
- var point = await _point_agentrepository.GetListALL(x => x.caller == input.phone);
- if (point == null && point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.phone;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- model.F_Recommender = input.recommender;
- if (!string.IsNullOrEmpty(input.recommendertel))
- {
- if (!valtel(input.recommendertel))
- return Error("手机号必须为11位数字");
- model.F_RecommenderTel = input.recommendertel;
- }
- model.F_Sex = input.sex;
- model.F_Label = input.label;
- model.F_State = input.state;
- model.F_Note = input.note;
- model.F_City = input.city;
- model.F_Nickname = input.nickname;
- model.F_Address = input.address;
- model.F_Address1 = input.address1;
- model.F_LastModifyOn = DateTime.Now.ToLocalTime();
- model.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- model.F_Age = input.age;
- if (!string.IsNullOrEmpty(input.mobile))
- {
- if (!valtel(input.mobile))
- return Error("手机号必须为11位数字");
- model.F_Mobile = input.mobile;
- var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile);
- if (_point == null && _point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.mobile;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- }
- if (!string.IsNullOrEmpty(input.mobile1))
- {
- if (!valtel(input.mobile1))
- return Error("手机号必须为11位数字");
- model.F_Mobile1 = input.mobile1; var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile1);
- if (_point == null && _point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.mobile1;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- }
- if (!string.IsNullOrEmpty(input.mobile2))
- {
- if (!valtel(input.mobile2))
- return Error("手机号必须为11位数字");
- model.F_Mobile2 = input.mobile2;
- model.F_Mobile1 = input.mobile1; var _point = await _point_agentrepository.GetListALL(x => x.caller == input.mobile2);
- if (_point == null && _point.Count() <= 0)
- {
- point_agent point_Agent = new point_agent();
- point_Agent.caller = input.mobile2;
- point_Agent.agent = user;
- var phone = _point_agentrepository.Add(point_Agent);
- }
- }
- model.F_Province = input.province;
- model.F_Area = input.area;
- model.F_Town = input.town;
- model.F_Postcode = input.postcode;
- model.F_Province1 = input.province1;
- model.F_Area1 = input.area1;
- model.F_Town1 = input.town1;
- model.F_Postcode1 = input.postcode1;
- model.F_City1 = input.city1;
- model.F_ShoeSize = input.shoesize;
- model.F_Score = input.score;
- model.F_Money = input.money;
- model.F_TotalScore = input.totalscore;
- //model.F_Saleperson = input.saleperson;
- //model.F_Contact = input.contact;
- model.F_Type = input.type;
- if (model.F_GiftYear != DateTime.Now.Year.ToString())
- {
- model.F_GiftYear = DateTime.Now.AddYears(-1).Year.ToString();
- if (input.birthday != null)
- {
- //今年生日已过
- 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))
- {
- model.F_GiftYear = DateTime.Now.Year.ToString();
- }
- }
- }
- 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));
- if (call != null && call.Count > 0)
- {
- model.F_Firstcalltime = call[0].BeginTime;
- model.F_Lastholetime = call[call.Count - 1].BeginTime;
- }
- bool b = await _cus_vip_infoRepository.Update(model);
- if (b)
- return Success("修改成功");
- return Error("修改失败");
- }
- /// <summary>
- /// 删除会员信息 by ids
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost("delete")]
- public async Task<IActionResult> Remove(int[] ids)
- {
- var res = 0;
- if (ids != null && ids.Length > 0)
- {
- foreach (var item in ids)
- {
- var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
- ml.F_State = (int)EnumDelState.Delete;
- ml.F_DeleteOn = DateTime.Now.ToLocalTime();
- ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- if (_cus_vip_infoRepository.Update(ml).Result)
- res += 1;
- }
- if (res == ids.Length)
- return Success("删除成功");
- else if (res > 0 && res < ids.Length)
- return Error("部分删除失败,请查看后重新操作");
- else
- return Error("删除失败,请查看后重新操作");
- }
- else
- return Error("请选择要删除的记录");
- }
- /// <summary>
- /// 判断号码必须为十一位数字
- /// </summary>
- /// <param name="tel"></param>
- /// <returns></returns>
- public bool valtel(string tel)
- {
- var res = false;
- //11位数字
- if (tel.Length == 11 && Regex.IsMatch(tel, @"^\d{11}$"))
- res = true;
- return res;
- }
- /// <summary>
- /// 转移会员信息
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost("transfer")]
- public async Task<IActionResult> Transfer(int[] ids,string toperson)
- {
- var res = 0;
- string msg = "";
- if (ids != null && ids.Length > 0)
- {
- foreach (var item in ids)
- {
- var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
- if (ml != null)
- {
- #region 创建消息提醒
- string cname = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- var model = new T_Cus_Msg();
- model.F_Type = 1;
- model.F_VipInfoID = item;
- model.F_ToPerson = toperson;
- model.F_State = 0;
- model.F_Notice = cname+"将"+ids .Length +"条会员档案从"+ ml.F_Saleperson+"转移给"+toperson ;
- msg = cname + "将" + ids.Length + "条会员档案从" + ml.F_Saleperson + "转移给" + toperson;
- model.F_NotifyPerson = ml.F_Saleperson;
- model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- model.F_CreateOn = DateTime.Now;
- var su = await _cus_msgRepository.Add(model);
- if (su > 0)
- {
- res += 1;
- }
- #endregion
- }
- //ml.F_Saleperson = toperson;
- //ml.F_LastModifyOn = DateTime.Now.ToLocalTime();
- //ml.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- //if (_cus_vip_infoRepository.Update(ml).Result)
- // res += 1;
- }
- if (res == ids.Length)
- {
- 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);
- return Success("转移消息创建成功");
-
- }
-
- else if (res > 0 && res < ids.Length)
- return Error("部分转移消息创建失败,请查看后重新操作");
- else
- return Error("转移消息创建失败,请查看后重新操作");
- }
- else
- return Error("请选择要转移的记录");
- }
- /// <summary>
- /// 转移消息处理
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost("deal")]
- public async Task<IActionResult> Deal(int[] ids, int notagree=0)//同意传0,不同意传1
- {
-
- var res = 0;
- if (ids != null && ids.Length > 0)
- {
- foreach (var item in ids)
- {
- var ml = await _cus_msgRepository.GetSingle(x => x.F_ID == item);
-
- if (ml != null)
- {
- #region 创建消息提醒
- //var model = new T_Cus_Msg();
- ml.F_Type = 1;
- ml.F_State = notagree +2;
- ml.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- ml.F_LastModifyOn = DateTime.Now;
- if (notagree == 0)//同意转移时更新会员信息
- {
- var m = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == ml.F_VipInfoID);
- if (m != null)
- {
- if (_cus_msgRepository.Update(ml).Result)
- {
- res += 1;
- m.F_Saleperson = ml.F_ToPerson;
- m.F_LastModifyOn = DateTime.Now.ToLocalTime();
- m.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- if (_cus_vip_infoRepository.Update(m).Result)
- { }
- }
-
- }
- else
- {
- return Error("该会员已删除或不存在");
- }
- }
-
- #endregion
- }
-
- }
- if (res == ids.Length)
- return Success("处理成功");
- else if (res > 0 && res < ids.Length)
- return Error("部分消息处理失败,请查看后重新操作");
- else
- return Error("处理消息失败,请查看后重新操作");
- }
- else
- return Error("请选择要处理的记录");
- }
- #region 导入、导出
- //导出
- [Authorize]
- [HttpGet("exportexcel")]
- [AllowAnonymous]
- 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)
- {
- try
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- #region 条件筛选
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
- if (!string.IsNullOrEmpty(phone))
- conModels.Add(new ConditionalCollections()
- {
- ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
- {
- new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = phone }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Mobile", ConditionalType = ConditionalType.Like, FieldValue = phone }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Mobile1", ConditionalType = ConditionalType.Like, FieldValue = phone })
- }
- });
- if (!string.IsNullOrEmpty(name))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
- }
- if (!string.IsNullOrEmpty(type))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type });
- }
- if (!string.IsNullOrEmpty(province))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Province", ConditionalType = ConditionalType.Like, FieldValue = province });
- }
- if (!string.IsNullOrEmpty(city))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_City", ConditionalType = ConditionalType.Like, FieldValue = city });
- }
- if (!string.IsNullOrEmpty(area))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Area", ConditionalType = ConditionalType.Like, FieldValue = area });
- }
- if (!string.IsNullOrEmpty(town))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Town", ConditionalType = ConditionalType.Like, FieldValue = town });
- }
- if (!string.IsNullOrEmpty(address))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Address", ConditionalType = ConditionalType.Like, FieldValue = address });
- new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Address1", ConditionalType = ConditionalType.Like, FieldValue = address });
- }
- if (!string.IsNullOrEmpty(birthday))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Birthday", ConditionalType = ConditionalType.Like, FieldValue = birthday });
- }
- if (!string.IsNullOrEmpty(recommender))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Recommender", ConditionalType = ConditionalType.Like, FieldValue = recommender });
- }
- if (!string.IsNullOrEmpty(saleperson))
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_Saleperson", ConditionalType = ConditionalType.Like, FieldValue = saleperson });
- }
- #endregion
- int recordCount = 0;
- var list = await _cus_vip_infoRepository.GetListALL(conModels, "F_CreateOn desc");
- var dtNew = list.ToList();
- if (dtNew != null)
- {
- var tb = ModelConvertHelper<T_Cus_VipInfo>.ConvertListToDataTable(dtNew);
- //导出dtnew
- NPOIHelper npoi = new NPOIHelper();
- string dbkeys = _configuration["Import:vipkey"].ToString();
- string title = _configuration["Import:vipvalue"].ToString();
- string[] colname = dbkeys.Split(",");
- string[] cols = title.Split(",");
- byte[] sm = npoi.ExportToExcel1(tb, cols, colname);
- if (sm != null)
- {
- return File(sm, "application/vnd.ms-excel", "会员信息.xlsx");
- }
- else
- {
- return Error("导出失败3");
- }
- }
- return Error("导出失败2");
- //return Success("根据条件获取数据成功", tasklist);
- }
- catch (Exception ex)
- {
- //_logger.LogError(ex, "导出异常");
- return Error("导出失败1");
- }
- //return Success("导出成功");
- }
- /// <summary>
- /// 上传文件并导入数据库
- /// </summary>
- /// <returns></returns>
- [HttpPost("importexcel")]
- public async Task<IActionResult> ImportExcel( int headrow = 0)
- {
-
- //string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
- 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"))
- return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
- NPOIHelper npoi = new NPOIHelper();
- var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
- int num = dtExcel.Rows.Count;
- var cols = dtExcel.Columns;
- int colnum = cols.Count;
- string dbkeys = _configuration["Import:vipkey"].ToString();
- string title = _configuration["Import:vipvalue"].ToString();
- string[] dbcols = dbkeys.Split(",");
- string[] titlecols = title.Split(",");
- string errmsg = string.Empty;
- if (num > 0)
- {
- int index = 1;
- foreach (DataRow dr in dtExcel.Rows)
- {
- var model = new T_Cus_VipInfo();
-
- model.F_State = 1;
- //model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- model.F_CreateOn = DateTime.Now;
- var dbcolslist = dbcols.ToList();
- var titlelist = titlecols.ToList();
- Type t = model.GetType();
- PropertyInfo[] PropertyList = t.GetProperties();
- foreach (PropertyInfo item in PropertyList)
- {
- try
- {
- if (dbcolslist.Contains(item.Name))
- {
- Type tType = null;
- object o = dr[titlelist[dbcolslist.IndexOf(item.Name)]];
- if (item.PropertyType.FullName.Contains(typeof(DateTime).FullName))
- {
- tType = typeof(DateTime);
- }
- else if (item.PropertyType.FullName.Contains(typeof(Int64).FullName))
- {
- tType = typeof(Int64);
- }
- else if (item.PropertyType.FullName.Contains(typeof(Int32).FullName))
- {
- tType = typeof(Int32);
- }
- else if (item.PropertyType.FullName.Contains(typeof(Decimal).FullName))
- {
- tType = typeof(Decimal);
- }
- else { tType = item.PropertyType; }
- object v = null;
- if (o != null && o != DBNull.Value)
- v = Convert.ChangeType(dr[titlelist[dbcolslist.IndexOf(item.Name)]].ToString(), tType);
- item.SetValue(model, v, null);
- }
- }
- catch
- {
- return Error("模板错误,请选择正确的模板");
- }
- }
- int b = await _cus_vip_infoRepository.Add(model);
-
- if (b<=0)
- {
- if (!string.IsNullOrEmpty(errmsg))
- {
- errmsg = errmsg + "\r\n第" + index + "行导入失败!";
- }
- else
- {
- errmsg = "第" + index + "行导入失败!";
- }
- }
- index++;
-
- }
- }
- else
- {
- return Error("文件中无数据");
- }
- if (!string.IsNullOrEmpty(errmsg))
- {
- //删除已导入的部分
- return Error(errmsg);
- }
- return Success("导入成功");
- }
- #endregion
- /// <summary>
- /// 更新会员积分
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost("updatescore")]
- public async Task<IActionResult> UpdateScore(string mobile,string money)
- {
-
- if (string.IsNullOrEmpty (mobile ))
- {
-
- var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_Mobile == mobile||x.F_Mobile1 ==mobile );
- ml.F_State = (int)EnumDelState.Delete;
- ml.F_DeleteOn = DateTime.Now.ToLocalTime();
- ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- if (_cus_vip_infoRepository.Update(ml).Result)
- {
- return Success("更新成功");
- }
- else
- return Error("更新失败");
- }
- else
- return Error("手机号不能为空");
- }
- }
- }
|