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

ManagementCenterController.cs 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.IRepositories;
  5. using System.Linq;
  6. using System.Security.Claims;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Microsoft.AspNetCore.Mvc;
  10. using SqlSugar;
  11. namespace TVShoppingCallCenter_ZLJ.Controllers.ManagementCenter
  12. {
  13. [Produces("application/json")]
  14. [Route("api/[controller]")]
  15. public class ManagementCenterController : BaseController
  16. {
  17. private readonly IBus_AfterSaleRepository _busAfterSaleRepository;
  18. private readonly IBus_OrderRepository _bus_OrderRepository;//订单
  19. private readonly ICus_VipInfoRepository _cus_vip_infoRepository;//客户
  20. private readonly ISys_UserAccountRepository _sys_useraccountRepository;//用户
  21. private readonly ISys_TaskManagementRepository _sys_taskmanagement_Repository;//任务
  22. private readonly ISys_DepartmentRepository _sys_departmentRepository;//部门
  23. private readonly ISys_PlanManagemenRepository _sys_planmanagemenRepository;//广告
  24. private readonly ISys_MarketingRepository _sys_marketing_Repository;//营销活动
  25. private readonly ISys_TodoManagementRepository _sys_todomanagementrepository;
  26. 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)
  27. {
  28. _bus_OrderRepository = bus_OrderRepository;
  29. _cus_vip_infoRepository = cus_vip_infoRepository;
  30. _sys_taskmanagement_Repository = sys_taskmanagement_Repository;
  31. _sys_departmentRepository = sys_departmentRepository;
  32. _sys_useraccountRepository = sys_useraccountRepository;
  33. _sys_planmanagemenRepository = sys_planmanagemenRepository;
  34. _sys_marketing_Repository = sys_marketing_Repository;
  35. _sys_todomanagementrepository = sys_todomanagementrepository;
  36. _busAfterSaleRepository = busAfterSaleRepository;
  37. }
  38. /// <summary>
  39. /// 实时销售行为分析
  40. /// </summary>
  41. /// <param name="time"></param>
  42. /// <returns></returns>
  43. [HttpGet("realtimesales")]
  44. public async Task<IActionResult> Realtimesales(string time)
  45. {
  46. if (string.IsNullOrEmpty(time))
  47. time = DateTime.Now.ToString("yyyy-MM-dd");
  48. 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;//新增客户
  49. 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;//昨日新增客户
  50. int newcustomer = todaycustomer != null ? todaycustomer.Count ():0;//新增客户
  51. int oldcustomer = yesterday != null ? yesterday.Count() : 0;//昨日新增客户
  52. 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;
  53. 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;
  54. 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;//售后订单量
  55. 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;//昨日订单量
  56. List<IConditionalModel> conModels = new List<IConditionalModel>();
  57. int newcustomers = 0;//新客户下单量
  58. int oldcustomers = 0;//昨日新客户下单量
  59. int newcustomerorder = 0;//老客户下单量
  60. int oldcustomerorder = 0;//昨日老客户下单量
  61. string vipid = "";
  62. if (newcustomer>0)
  63. {
  64. string F_VipId = "";
  65. foreach (var it in todaycustomer)
  66. {
  67. if (F_VipId == "")
  68. F_VipId = it.F_ID + "";
  69. else
  70. F_VipId +=","+ it.F_ID + "";
  71. if (vipid == "")
  72. vipid = it.F_ID + "";
  73. else
  74. vipid += "," + it.F_ID + "";
  75. }
  76. if (F_VipId == "")
  77. newcustomers = 0;
  78. else
  79. 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;
  80. }
  81. if (vipid == "")
  82. newcustomerorder = 0;
  83. else
  84. 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;
  85. if (oldcustomer > 0)
  86. {
  87. string F_VipId = "";
  88. foreach (var it in yesterday)
  89. {
  90. if (F_VipId == "")
  91. F_VipId = it.F_ID + "";
  92. else
  93. F_VipId += "," + it.F_ID + "";
  94. if (vipid == "")
  95. vipid = it.F_ID + "";
  96. else
  97. vipid += "," + it.F_ID + "";
  98. }
  99. if (F_VipId == "")
  100. oldcustomers = 0;
  101. else
  102. 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;
  103. }
  104. if (vipid == "")
  105. oldcustomerorder = 0;
  106. else
  107. 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;
  108. var obj = new
  109. {
  110. state = "success",
  111. message = "成功",
  112. newcustomer,//新增客户
  113. oldcustomer,//昨日新增客户
  114. neworder,//新增客户
  115. oldorder ,//昨日新增客户
  116. newaftersale ,//售后订单量
  117. oldaftersale,//昨日订单量
  118. newcustomers,//新客户下单量
  119. oldcustomers,//昨日新客户下单量
  120. newcustomerorder,//老客户下单量
  121. oldcustomerorder,//昨日老客户下单量
  122. };
  123. return Content(obj.ToJson());
  124. }
  125. private List<IConditionalModel> Aftersale(DateTime time)
  126. {
  127. List<IConditionalModel> conModels = new List<IConditionalModel>();
  128. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "售后订单" });
  129. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 23:59:59") });
  130. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 00:00:00") });
  131. return conModels;
  132. }
  133. private List<IConditionalModel> ConModels (DateTime time,string F_VipId,bool n )
  134. {
  135. List<IConditionalModel> conModels = new List<IConditionalModel>();
  136. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "0" });
  137. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 23:59:59") });
  138. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time.ToString("yyyy-MM-dd 00:00:00") });
  139. if (n )
  140. {
  141. conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.In, FieldValue = F_VipId });
  142. }
  143. else
  144. {
  145. conModels.Add(new ConditionalModel() { FieldName = "F_VipId", ConditionalType = ConditionalType.NotIn, FieldValue = F_VipId });
  146. }
  147. return conModels;
  148. }
  149. /// <summary>
  150. /// 当月任务总量
  151. /// </summary>
  152. /// <param name="time"></param>
  153. /// <returns></returns>
  154. [HttpGet("totaltasks")]
  155. public async Task<IActionResult> Totaltasks(string time)
  156. {
  157. if (string.IsNullOrEmpty(time))
  158. time = DateTime.Now.ToString("yyyy-MM");
  159. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  160. int userid= _sys_useraccountRepository.GetSingle(x => x.F_UserCode == user).Result!=null ? _sys_useraccountRepository.GetSingle(x => x.F_UserCode == user).Result.F_UserId:0;
  161. if (userid > 0)
  162. {
  163. List<IConditionalModel> conModels = new List<IConditionalModel>();
  164. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal , FieldValue = "0" });
  165. 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") });
  166. conModels.Add(new ConditionalModel() { FieldName = "F_CreateTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = DateTime.Parse(time).ToString("yyyy-MM-01 00:00:00") });
  167. conModels.Add(new ConditionalModel() { FieldName = "F_Tasker", ConditionalType = ConditionalType.Equal , FieldValue = userid+"" });
  168. var task = _sys_taskmanagement_Repository.GetListALL(conModels, " F_CreateTime DESC").Result;
  169. float tasktotal = 0, taskcurrent = 0;string progress = "0";
  170. if (task!=null )
  171. {
  172. tasktotal =(float )task.Select(x => x.F_Money).Sum();
  173. taskcurrent = (float)task.Select(x => x.F_Currentamount).Sum();
  174. if (tasktotal>0)
  175. progress = string.Format("{0:f2}", taskcurrent / tasktotal * 100);
  176. }
  177. var obj = new
  178. {
  179. state = "success",
  180. message = "成功",
  181. taskcurrent,//当前任务量
  182. tasktotal,//任务总量
  183. progress,//进度
  184. };
  185. return Content(obj.ToJson());
  186. }
  187. else
  188. return Error("查询失败");
  189. }
  190. public class Dictionaries
  191. {
  192. public string key;
  193. public decimal value;
  194. }
  195. /// <summary>
  196. /// 待办事项
  197. /// </summary>
  198. /// <param name="time"></param>
  199. /// <returns></returns>
  200. [HttpGet("todolist")]
  201. public async Task<IActionResult> Todolist(string time)
  202. {
  203. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  204. if (string.IsNullOrEmpty(time))
  205. time = DateTime.Now.ToString("yyyy-MM");
  206. var Order = _bus_OrderRepository.GetListALL(x => x.F_State >=0).Result;//订单总量
  207. int tobeexamine=0/*待审核*/, reviewreturn = 0/*审核退回*/, tobedistribution = 0/*待分配*/,
  208. aftersale = 0/*售后*/, tobecollected = 0/*待回款*/, toberefunded = 0/*待退款*/, pendingclaims = 0/*待理赔*/, tobecontacted = 0/*待联系客户*/;
  209. var AfterOrder = _busAfterSaleRepository.GetListALL(x => x.F_Type >= 0 && x.F_State == 0).Result;//订单总量
  210. List<Dictionaries> tobetask = new List<Dictionaries>();
  211. if (Order!=null )
  212. {
  213. tobeexamine = Order.Where(x => x.F_State == 1).Count();//待审核
  214. reviewreturn = Order.Where(x => x.F_State == 2).Count();//审核退回
  215. tobedistribution = Order.Where(x => x.F_State == 3).Count();//审核退回
  216. tobecollected = Order.Where(x => x.F_PayState == 0).Count();//待回款
  217. aftersale = Order.Where(x => x.F_Type =="售后订单").Count();//售后订单
  218. toberefunded = Order.Where(x => x.F_PayState == 2).Count();
  219. }
  220. if (AfterOrder!=null )
  221. {
  222. toberefunded += AfterOrder.Where(x => x.F_Type == 2 || x.F_Type == 3).Count();
  223. pendingclaims = AfterOrder.Where(x => x.F_Type ==6).Count();
  224. }
  225. List<IConditionalModel> conModels = new List<IConditionalModel>();
  226. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal , FieldValue = "0" });
  227. // conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
  228. conModels.Add(new ConditionalModel() { FieldName = "F_CreateUser", ConditionalType = ConditionalType.Equal, FieldValue = user });
  229. var Todo = _sys_todomanagementrepository.GetListALL(conModels, " F_CreateTime DESC").Result;//待办总量
  230. if (Todo != null)
  231. {
  232. tobecontacted = Todo.Where(x => x.F_Type == 1&&x .F_State ==0).Count();//待联系客户
  233. var tobe = Todo.Where(x => x.F_Type == 0);//审核退回
  234. if (tobe!=null )
  235. {
  236. foreach (var it in tobe)
  237. {
  238. Dictionaries dictionaries = new Dictionaries();
  239. dictionaries.key = it.F_Name;
  240. dictionaries.value =(int ) it.F_State;
  241. tobetask.Add(dictionaries);
  242. }
  243. }
  244. }
  245. var obj = new
  246. {
  247. state = "success",
  248. message = "成功",
  249. tobeexamine,//待审核
  250. reviewreturn,//审核退回
  251. tobedistribution,//待分配
  252. aftersale,//售后
  253. tobecollected,//待回款
  254. toberefunded,//待退款
  255. pendingclaims,//待理赔
  256. tobecontacted,//待联系客户
  257. tobetask,
  258. };
  259. return Content(obj.ToJson());
  260. }
  261. public class Personalranking
  262. {
  263. public int Serialnumber;
  264. public int userid;
  265. public string name;
  266. public int Orderquantity;
  267. public decimal Totalsales;
  268. }
  269. /// <summary>
  270. /// 排行榜
  271. /// </summary>
  272. /// <param name="time"></param>
  273. /// <returns></returns>
  274. [HttpGet("rankinglist")]
  275. public async Task<IActionResult> RankingList(int type=0)
  276. {
  277. DateTime starttime, endtime;
  278. if (type==0)
  279. {
  280. starttime = DateTime.Now.AddMonths(-1).AddDays(1);
  281. endtime = DateTime.Now;
  282. }
  283. else
  284. {
  285. starttime = DateTime.Now;
  286. endtime = DateTime.Now;
  287. }
  288. List<IConditionalModel> conModels = new List<IConditionalModel>();
  289. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "0" });
  290. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = endtime.ToString("yyyy-MM-dd 23:59:59") });
  291. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = starttime.ToString("yyyy-MM-dd 00:00:00") });
  292. var Order = _bus_OrderRepository.GetListALL(conModels, " F_AddTime DESC").Result;//订单总量
  293. List<Dictionaries> tobetask = new List<Dictionaries>();
  294. List<Personalranking> personalrankings = new List<Personalranking>();
  295. 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 () });
  296. if (query != null)
  297. {
  298. var tobetasklist = query.OrderByDescending(x => x.F_RealPrice).ToList();
  299. int i = 0;
  300. foreach (var it in tobetasklist)
  301. {
  302. i++;
  303. Personalranking personalranking = new Personalranking();
  304. personalranking.Serialnumber = i;
  305. personalranking.name = it.F_AddUserName;
  306. personalranking.userid = it.F_AddUser;
  307. personalranking.Orderquantity = it.total;
  308. personalranking.Totalsales = it.F_RealPrice;
  309. personalrankings.Add(personalranking);
  310. }
  311. foreach ( var it in personalrankings)
  312. {
  313. Dictionaries dictionaries = new Dictionaries();
  314. var user = _sys_useraccountRepository.GetSingle(x => x.F_UserId == it.userid).Result;
  315. if (user != null )
  316. {
  317. dictionaries.key = _sys_departmentRepository.GetSingle(x => x.F_DeptId == user.F_DeptId).Result != null ?
  318. _sys_departmentRepository.GetSingle(x => x.F_DeptId == user.F_DeptId).Result.F_DeptName : "";
  319. }
  320. dictionaries.value = it.Totalsales;
  321. tobetask.Add(dictionaries);
  322. }
  323. }
  324. var totask = tobetask.GroupBy(x => new { x.key }).Select(x => new { F_RealPrice = x.Select(y => y.value).Sum(), x.Key.key });
  325. var obj = new
  326. {
  327. state = "success",
  328. message = "成功",
  329. personalrankings,
  330. totask
  331. };
  332. return Content(obj.ToJson());
  333. }
  334. /// <summary>
  335. /// 重要提醒
  336. /// </summary>
  337. /// <param name="time"></param>
  338. /// <returns></returns>
  339. [HttpGet("reminder")]
  340. public async Task<IActionResult> Reminder(string time)
  341. {
  342. if (string .IsNullOrEmpty (time))
  343. time = DateTime.Now.ToString("yyyy-MM-dd");
  344. List<IConditionalModel> conModels = new List<IConditionalModel>();
  345. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal , FieldValue = "0" });
  346. conModels.Add(new ConditionalModel() { FieldName = "F_EndTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time+" 23:59:59" });
  347. conModels.Add(new ConditionalModel() { FieldName = "F_StartTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time +" 00:00:00" });
  348. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal , FieldValue = "0"});
  349. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
  350. string week = Week(DateTime.Parse(time));
  351. var plan = _sys_planmanagemenRepository.GetListALL(conModels, " F_CreateTime DESC").Result;//广告总量
  352. List<IConditionalModel> conModel = new List<IConditionalModel>();
  353. conModel.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
  354. conModel.Add(new ConditionalModel() { FieldName = "F_EndTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = time + " 23:59:59" });
  355. conModel.Add(new ConditionalModel() { FieldName = "F_StartTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = time + " 00:00:00" });
  356. var marketin = _sys_marketing_Repository.GetListALL(conModel, " F_CreateTime DESC").Result;//营销活动
  357. int advertisement = 0, marketing=0;
  358. if (plan!=null )
  359. advertisement = plan.Where (x => x.F_PlayDate.Split(',').Contains(week) == true).Count ();
  360. if (marketin != null)
  361. marketing = marketin.Count();
  362. var obj = new
  363. {
  364. state = "success",
  365. message = "成功",
  366. advertisement,
  367. marketing
  368. };
  369. return Content(obj.ToJson());
  370. }
  371. public string Week(DateTime time)
  372. {
  373. string week = "";
  374. string dt = time.DayOfWeek.ToString();
  375. switch (dt)
  376. {
  377. case "Monday":
  378. week = "周一";
  379. break;
  380. case "Tuesday":
  381. week = "周二";
  382. break;
  383. case "Wednesday":
  384. week = "周三";
  385. break;
  386. case "Thursday":
  387. week = "周四";
  388. break;
  389. case "Friday":
  390. week = "周五";
  391. break;
  392. case "Saturday":
  393. week = "周六";
  394. break;
  395. case "Sunday":
  396. week = "周日";
  397. break;
  398. }
  399. return week;
  400. }
  401. }
  402. }