| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- using System;
- using System.Collections.Generic;
- using System.Common;
- using System.IRepositories;
- using System.Linq;
- using System.Security.Claims;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using SqlSugar;
- namespace TVShoppingCallCenter_ZLJ.Controllers.ManagementCenter
- {
- [Produces("application/json")]
- [Route("api/[controller]")]
- public class ManagementCenterController : BaseController
- {
- private readonly IBus_AfterSaleRepository _busAfterSaleRepository;
- private readonly IBus_OrderRepository _bus_OrderRepository;//订单
- private readonly ICus_VipInfoRepository _cus_vip_infoRepository;//客户
- private readonly ISys_UserAccountRepository _sys_useraccountRepository;//用户
- private readonly ISys_TaskManagementRepository _sys_taskmanagement_Repository;//任务
- private readonly ISys_DepartmentRepository _sys_departmentRepository;//部门
- private readonly ISys_PlanManagemenRepository _sys_planmanagemenRepository;//广告
- private readonly ISys_MarketingRepository _sys_marketing_Repository;//营销活动
- private readonly ISys_TodoManagementRepository _sys_todomanagementrepository;
- public ManagementCenterController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_TaskManagementRepository sys_taskmanagement_Repository, ISys_DepartmentRepository sys_departmentRepository, ISys_UserAccountRepository sys_useraccountRepository,IBus_OrderRepository bus_OrderRepository, ISys_PlanManagemenRepository sys_planmanagemenRepository,ISys_MarketingRepository sys_marketing_Repository, ISys_TodoManagementRepository sys_todomanagementrepository, IBus_AfterSaleRepository busAfterSaleRepository)
- {
- _bus_OrderRepository = bus_OrderRepository;
- _cus_vip_infoRepository = cus_vip_infoRepository;
- _sys_taskmanagement_Repository = sys_taskmanagement_Repository;
- _sys_departmentRepository = sys_departmentRepository;
- _sys_useraccountRepository = sys_useraccountRepository;
- _sys_planmanagemenRepository = sys_planmanagemenRepository;
- _sys_marketing_Repository = sys_marketing_Repository;
- _sys_todomanagementrepository = sys_todomanagementrepository;
- _busAfterSaleRepository = busAfterSaleRepository;
- }
- /// <summary>
- /// 实时销售行为分析
- /// </summary>
- /// <param name="time"></param>
- /// <returns></returns>
- [HttpGet("realtimesales")]
- public async Task<IActionResult> Realtimesales(string time)
- {
- if (string.IsNullOrEmpty(time))
- time = DateTime.Now.ToString("yyyy-MM-dd");
- var todaycustomer = _cus_vip_infoRepository.GetListALL(x => x.F_CreateOn >= DateTime.Parse(time + " 00:00:00") && x.F_CreateOn <= DateTime.Parse(time + " 23:59:59")).Result;//新增客户
- var yesterday= _cus_vip_infoRepository.GetListALL(x => x.F_CreateOn >= DateTime.Parse(time + " 00:00:00").AddDays(-1) && x.F_CreateOn <= DateTime.Parse(time + " 23:59:59").AddDays(-1)).Result;//昨日新增客户
- int newcustomer = todaycustomer != null ? todaycustomer.Count ():0;//新增客户
- int oldcustomer = yesterday != null ? yesterday.Count() : 0;//昨日新增客户
- int neworder = _bus_OrderRepository.GetListALL(x => x.F_AddTime >= DateTime.Parse(time + " 00:00:00") && x.F_AddTime <= DateTime.Parse(time + " 23:59:59")).Result != null ? _bus_OrderRepository.GetListALL(x => x.F_AddTime >= DateTime.Parse(time + " 00:00:00") && x.F_AddTime <= DateTime.Parse(time + " 23:59:59")).Result.Count : 0;
- int oldorder = _bus_OrderRepository.GetListALL(x => x.F_AddTime >= DateTime.Parse(time + " 00:00:00").AddDays(-1) && x.F_AddTime <= DateTime.Parse(time + " 23:59:59").AddDays(-1)).Result != null ? _bus_OrderRepository.GetListALL(x => x.F_AddTime >= DateTime.Parse(time + " 00:00:00").AddDays(-1) && x.F_AddTime <= DateTime.Parse(time + " 23:59:59").AddDays(-1)).Result.Count : 0;
- int newaftersale = _bus_OrderRepository.GetListALL (Aftersale(DateTime.Parse(time)), " F_AddTime DESC").Result !=null ? _bus_OrderRepository.GetListALL(Aftersale(DateTime.Parse(time)), " F_AddTime DESC").Result.Count : 0;//售后订单量
- int oldaftersale = _bus_OrderRepository.GetListALL(Aftersale(DateTime.Parse(time).AddDays(-1)), " F_AddTime DESC").Result != null ? _bus_OrderRepository.GetListALL(Aftersale(DateTime.Parse(time).AddDays(-1)), " F_AddTime DESC").Result.Count:0;//昨日订单量
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- int newcustomers = 0;//新客户下单量
- int oldcustomers = 0;//昨日新客户下单量
- int newcustomerorder = 0;//老客户下单量
- int oldcustomerorder = 0;//昨日老客户下单量
- string vipid = "";
- if (newcustomer>0)
- {
- string F_VipId = "";
- foreach (var it in todaycustomer)
- {
- if (F_VipId == "")
- F_VipId = it.F_ID + "";
- else
- F_VipId +=","+ it.F_ID + "";
- if (vipid == "")
- vipid = it.F_ID + "";
- else
- vipid += "," + it.F_ID + "";
- }
- if (F_VipId == "")
- newcustomers = 0;
- else
- newcustomers = _bus_OrderRepository.GetListALL(ConModels(DateTime .Parse (time), F_VipId,true ), " F_AddTime DESC").Result != null ? _bus_OrderRepository.GetListALL(ConModels(DateTime.Parse(time), F_VipId, true), " F_AddTime DESC").Result.Count : 0;
- }
- if (vipid == "")
- newcustomerorder = 0;
- else
- newcustomerorder = _bus_OrderRepository.GetListALL(ConModels(DateTime.Parse(time), vipid, false), " F_AddTime DESC").Result != null ? _bus_OrderRepository.GetListALL(ConModels(DateTime.Parse(time), vipid, false), " F_AddTime DESC").Result.Count : 0;
- if (oldcustomer > 0)
- {
- string F_VipId = "";
- foreach (var it in yesterday)
- {
- if (F_VipId == "")
- F_VipId = it.F_ID + "";
- else
- F_VipId += "," + it.F_ID + "";
- if (vipid == "")
- vipid = it.F_ID + "";
- else
- vipid += "," + it.F_ID + "";
- }
- if (F_VipId == "")
- oldcustomers = 0;
- else
- oldcustomers = _bus_OrderRepository.GetListALL(ConModels(DateTime.Parse(time).AddDays (-1), F_VipId, true), " F_AddTime DESC").Result != null ? _bus_OrderRepository.GetListALL(ConModels(DateTime.Parse(time).AddDays(-1), F_VipId,true), " F_AddTime DESC").Result.Count : 0;
- }
- if (vipid == "")
- oldcustomerorder = 0;
- else
- oldcustomerorder = _bus_OrderRepository.GetListALL(ConModels(DateTime.Parse(time).AddDays(-1), vipid, false), " F_AddTime DESC").Result != null ? _bus_OrderRepository.GetListALL(ConModels(DateTime.Parse(time).AddDays(-1), vipid, false), " F_AddTime DESC").Result.Count : 0;
- var obj = new
- {
- state = "success",
- message = "成功",
- newcustomer,//新增客户
- oldcustomer,//昨日新增客户
- neworder,//新增客户
- oldorder ,//昨日新增客户
- newaftersale ,//售后订单量
- oldaftersale,//昨日订单量
- newcustomers,//新客户下单量
- oldcustomers,//昨日新客户下单量
- newcustomerorder,//老客户下单量
- oldcustomerorder,//昨日老客户下单量
- };
- return Content(obj.ToJson());
- }
- private List<IConditionalModel> Aftersale(DateTime time)
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "售后订单" });
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 23:59:59") });
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 00:00:00") });
- return conModels;
- }
- private List<IConditionalModel> ConModels (DateTime time,string F_VipId,bool n )
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "0" });
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 23:59:59") });
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 00:00:00") });
- if (n )
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.In, FieldValue = F_VipId });
- }
- else
- {
- conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.NotIn, FieldValue = F_VipId });
- }
- return conModels;
- }
- /// <summary>
- /// 当月任务总量
- /// </summary>
- /// <param name="time"></param>
- /// <returns></returns>
- [HttpGet("totaltasks")]
- public async Task<IActionResult> Totaltasks(string time)
- {
- if (string.IsNullOrEmpty(time))
- time = DateTime.Now.ToString("yyyy-MM");
- string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- int userid= _sys_useraccountRepository.GetSingle(x => x.F_UserCode == user).Result!=null ? _sys_useraccountRepository.GetSingle(x => x.F_UserCode == user).Result.F_UserId:0;
- if (userid > 0)
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal , FieldValue = "0" });
- conModels.Add(new ConditionalModel() { FieldName = "F_CreateTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = DateTime .Parse ( time).AddMonths (1).AddDays (-1).ToString("yyyy-MM-dd 23:59:59") });
- conModels.Add(new ConditionalModel() { FieldName = "F_CreateTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = DateTime.Parse(time).ToString("yyyy-MM-01 00:00:00") });
- conModels.Add(new ConditionalModel() { FieldName = "F_Tasker", ConditionalType = ConditionalType.Equal , FieldValue = userid+"" });
- var task = _sys_taskmanagement_Repository.GetListALL(conModels, " F_CreateTime DESC").Result;
- float tasktotal = 0, taskcurrent = 0;string progress = "0";
- if (task!=null )
- {
- tasktotal =(float )task.Select(x => x.F_Money).Sum();
- taskcurrent = (float)task.Select(x => x.F_Currentamount).Sum();
- if (tasktotal>0)
- progress = string.Format("{0:f2}", taskcurrent / tasktotal * 100);
- }
- var obj = new
- {
- state = "success",
- message = "成功",
- taskcurrent,//当前任务量
- tasktotal,//任务总量
- progress,//进度
- };
- return Content(obj.ToJson());
- }
- else
- return Error("查询失败");
- }
- public class Dictionaries
- {
- public string key;
- public decimal value;
- }
- /// <summary>
- /// 待办事项
- /// </summary>
- /// <param name="time"></param>
- /// <returns></returns>
- [HttpGet("todolist")]
- public async Task<IActionResult> Todolist(string time)
- {
- string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- if (string.IsNullOrEmpty(time))
- time = DateTime.Now.ToString("yyyy-MM");
- var Order = _bus_OrderRepository.GetListALL(x => x.F_State >=0).Result;//订单总量
- int tobeexamine=0/*待审核*/, reviewreturn = 0/*审核退回*/, tobedistribution = 0/*待分配*/,
- aftersale = 0/*售后*/, tobecollected = 0/*待回款*/, toberefunded = 0/*待退款*/, pendingclaims = 0/*待理赔*/, tobecontacted = 0/*待联系客户*/;
- var AfterOrder = _busAfterSaleRepository.GetListALL(x => x.F_Type >= 0 && x.F_State == 0).Result;//订单总量
- List<Dictionaries> tobetask = new List<Dictionaries>();
- if (Order!=null )
- {
- tobeexamine = Order.Where(x => x.F_State == 1).Count();//待审核
- reviewreturn = Order.Where(x => x.F_State == 2).Count();//审核退回
- tobedistribution = Order.Where(x => x.F_State == 3).Count();//审核退回
- tobecollected = Order.Where(x => x.F_PayState == 0).Count();//待回款
- aftersale = Order.Where(x => x.F_Type =="售后订单").Count();//售后订单
- toberefunded = Order.Where(x => x.F_PayState == 2).Count();
- }
- if (AfterOrder!=null )
- {
- toberefunded += AfterOrder.Where(x => x.F_Type == 2 || x.F_Type == 3).Count();
- pendingclaims = AfterOrder.Where(x => x.F_Type ==6).Count();
- }
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal , FieldValue = "0" });
- // conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
- conModels.Add(new ConditionalModel() { FieldName = "F_CreateUser", ConditionalType = ConditionalType.Equal, FieldValue = user });
- var Todo = _sys_todomanagementrepository.GetListALL(conModels, " F_CreateTime DESC").Result;//待办总量
- if (Todo != null)
- {
- tobecontacted = Todo.Where(x => x.F_Type == 1&&x .F_State ==0).Count();//待联系客户
- var tobe = Todo.Where(x => x.F_Type == 0);//审核退回
- if (tobe!=null )
- {
- foreach (var it in tobe)
- {
- Dictionaries dictionaries = new Dictionaries();
- dictionaries.key = it.F_Name;
- dictionaries.value =(int ) it.F_State;
- tobetask.Add(dictionaries);
- }
- }
-
- }
- var obj = new
- {
- state = "success",
- message = "成功",
- tobeexamine,//待审核
- reviewreturn,//审核退回
- tobedistribution,//待分配
- aftersale,//售后
- tobecollected,//待回款
- toberefunded,//待退款
- pendingclaims,//待理赔
- tobecontacted,//待联系客户
- tobetask,
- };
- return Content(obj.ToJson());
- }
- public class Personalranking
- {
- public int Serialnumber;
- public int userid;
- public string name;
- public int Orderquantity;
- public decimal Totalsales;
- }
- /// <summary>
- /// 排行榜
- /// </summary>
- /// <param name="time"></param>
- /// <returns></returns>
- [HttpGet("rankinglist")]
- public async Task<IActionResult> RankingList(int type=0)
- {
- DateTime starttime, endtime;
- if (type==0)
- {
- starttime = DateTime.Now.AddMonths(-1).AddDays(1);
- endtime = DateTime.Now;
- }
- else
- {
- starttime = DateTime.Now;
- endtime = DateTime.Now;
- }
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "0" });
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = endtime.ToString("yyyy-MM-dd 23:59:59") });
- conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = starttime.ToString("yyyy-MM-dd 00:00:00") });
- var Order = _bus_OrderRepository.GetListALL(conModels, " F_AddTime DESC").Result;//订单总量
- List<Dictionaries> tobetask = new List<Dictionaries>();
- List<Personalranking> personalrankings = new List<Personalranking>();
- var query = Order.GroupBy(x => new { x.F_AddUser ,x .F_AddUserName }).Select(x => new { F_RealPrice = x.Select(y => y.F_RealPrice).Sum(), x.Key.F_AddUser ,x.Key .F_AddUserName , total = x .Select (y=>1).Sum () });
- if (query != null)
- {
- var tobetasklist = query.OrderByDescending(x => x.F_RealPrice).ToList();
- int i = 0;
- foreach (var it in tobetasklist)
- {
- i++;
- Personalranking personalranking = new Personalranking();
- personalranking.Serialnumber = i;
- personalranking.name = it.F_AddUserName;
- personalranking.userid = it.F_AddUser;
- personalranking.Orderquantity = it.total;
- personalranking.Totalsales = it.F_RealPrice;
- personalrankings.Add(personalranking);
- }
- foreach ( var it in personalrankings)
- {
- Dictionaries dictionaries = new Dictionaries();
- var user = _sys_useraccountRepository.GetSingle(x => x.F_UserId == it.userid).Result;
- if (user != null )
- {
- dictionaries.key = _sys_departmentRepository.GetSingle(x => x.F_DeptId == user.F_DeptId).Result != null ?
- _sys_departmentRepository.GetSingle(x => x.F_DeptId == user.F_DeptId).Result.F_DeptName : "";
- }
- dictionaries.value = it.Totalsales;
- tobetask.Add(dictionaries);
- }
-
- }
- var totask = tobetask.GroupBy(x => new { x.key }).Select(x => new { F_RealPrice = x.Select(y => y.value).Sum(), x.Key.key });
- var obj = new
- {
- state = "success",
- message = "成功",
- personalrankings,
- totask
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 重要提醒
- /// </summary>
- /// <param name="time"></param>
- /// <returns></returns>
- [HttpGet("reminder")]
- public async Task<IActionResult> Reminder(string time)
- {
- if (string .IsNullOrEmpty (time))
- time = DateTime.Now.ToString("yyyy-MM-dd");
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal , FieldValue = "0" });
- conModels.Add(new ConditionalModel() { FieldName = "F_EndTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time+" 23:59:59" });
- conModels.Add(new ConditionalModel() { FieldName = "F_StartTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time +" 00:00:00" });
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal , FieldValue = "0"});
- conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
-
- string week = Week(DateTime.Parse(time));
- var plan = _sys_planmanagemenRepository.GetListALL(conModels, " F_CreateTime DESC").Result;//广告总量
- List<IConditionalModel> conModel = new List<IConditionalModel>();
- conModel.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
- conModel.Add(new ConditionalModel() { FieldName = "F_EndTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time + " 23:59:59" });
- conModel.Add(new ConditionalModel() { FieldName = "F_StartTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time + " 00:00:00" });
-
- var marketin = _sys_marketing_Repository.GetListALL(conModel, " F_CreateTime DESC").Result;//营销活动
- int advertisement = 0, marketing=0;
- if (plan!=null )
- advertisement = plan.Where (x => x.F_PlayDate.Split(',').Contains(week) == true).Count ();
- if (marketin != null)
- marketing = marketin.Count();
- var obj = new
- {
- state = "success",
- message = "成功",
- advertisement,
- marketing
- };
- return Content(obj.ToJson());
- }
- public string Week(DateTime time)
- {
- string week = "";
- string dt = time.DayOfWeek.ToString();
- switch (dt)
- {
- case "Monday":
- week = "周一";
- break;
- case "Tuesday":
- week = "周二";
- break;
- case "Wednesday":
- week = "周三";
- break;
- case "Thursday":
- week = "周四";
- break;
- case "Friday":
- week = "周五";
- break;
- case "Saturday":
- week = "周六";
- break;
- case "Sunday":
- week = "周日";
- break;
- }
- return week;
- }
- }
- }
|