Parcourir la Source

售后订单表

duhongyu il y a 5 ans
Parent
commit
667b643a7d

+ 108 - 1
代码/TVShoppingCallCenter_ZLJ/Controllers/ManagementCenter/ManagementCenterController.cs

@@ -5,6 +5,7 @@ using System.IRepositories;
5 5
 using System.Linq;
6 6
 using System.Security.Claims;
7 7
 using System.Text;
8
+using System.Threading;
8 9
 using System.Threading.Tasks;
9 10
 using Microsoft.AspNetCore.Mvc;
10 11
 using SqlSugar;
@@ -15,7 +16,7 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.ManagementCenter
15 16
     [Route("api/[controller]")]
16 17
     public class ManagementCenterController : BaseController
17 18
     {
18
-        private readonly IBus_AfterSaleRepository _busAfterSaleRepository;
19
+        private readonly IBus_AfterSaleRepository _busAfterSaleRepository;//售后
19 20
         private readonly IBus_OrderRepository _bus_OrderRepository;//订单
20 21
         private readonly ICus_VipInfoRepository _cus_vip_infoRepository;//客户
21 22
         private readonly ISys_UserAccountRepository _sys_useraccountRepository;//用户
@@ -411,5 +412,111 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.ManagementCenter
411 412
             return week;
412 413
         }
413 414
 
415
+
416
+        private  class AftersaleInput
417
+        {
418
+            public string time;//时间
419
+            public string name;//姓名
420
+            public int total;//总数
421
+            public int  problem;//产品问题
422
+            public int warehousehair;//仓库错发漏发
423
+            public int Saleserror;//销售错发漏发
424
+            public int refund;//退款单数
425
+            public decimal refundamount;//退款金额
426
+            public int Totalaftersales;//售后总计
427
+            public int delivergoods;//月总发货数
428
+            public string exchange;//调换所占总发货比例
429
+        }
430
+
431
+
432
+        /// <summary>
433
+        /// 当月任务总量
434
+        /// </summary>
435
+        /// <param name="time"></param>
436
+        /// <returns></returns>
437
+        [HttpGet("aftersale")]
438
+        public async Task<IActionResult> Aftersale(string month)
439
+        {
440
+            string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
441
+            DateTime time = DateTime.Now;
442
+            if (!string.IsNullOrEmpty(month))
443
+                time = DateTime.Parse (month);
444
+           
445
+            int   days = Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(time.Year, time.Month - 1);//获取天数
446
+            if (time.Month == DateTime.Now.Month)
447
+            {
448
+                days = DateTime.Now.Day;
449
+            }
450
+            var order = _bus_OrderRepository.GetListALL(x => x.F_AddTime >= DateTime.Parse(time.ToString("yyyy-MM-01"))
451
+              && x.F_AddTime <= time && x.F_State == 6).Result;
452
+            var after = _busAfterSaleRepository.GetListALL(x => x.F_AddTime >= DateTime.Parse(time.ToString("yyyy-MM-01"))
453
+             && x.F_AddTime <= time).Result;
454
+            var dept = _sys_departmentRepository.GetListALL(x => x.F_DeptName == "销售").Result;
455
+            int refunds = 0; decimal refundamounts =0;
456
+            if (dept != null)
457
+            {
458
+                var userlist = _sys_useraccountRepository.GetListALL(x => x.F_DeptId == dept.FirstOrDefault().F_DeptId
459
+                && x.F_DeleteFlag == 0).Result;
460
+                List<AftersaleInput> aftersaleInputs = new List<AftersaleInput>();
461
+                if (userlist!=null )
462
+                {
463
+                  for (int i=1;i<=days;i++)
464
+                    {
465
+                        foreach (var it in userlist)
466
+                        {
467
+                            AftersaleInput aftersaleInput = new AftersaleInput();
468
+                            var aftertotal= after.Where
469
+                                (x => x.F_CheckUserXS == it.F_UserId);
470
+                            var aftersale = after.Where
471
+                                (x => x.F_AddTime >= DateTime.Parse(time.ToString("yyyy-MM-" + days))
472
+                           && x.F_AddTime <= DateTime.Parse(time.ToString("yyyy-MM-" + days)));
473
+                            aftersaleInput.time = time.Month + "月" + i + "日";
474
+                            aftersaleInput.name = it.F_UserName;
475
+                            aftersaleInput.total = order.Where (x =>x .F_Belong == it.F_UserId&& x.F_AddTime >= DateTime.Parse(time.ToString("yyyy-MM-" + days))
476
+                           && x.F_AddTime <= DateTime.Parse(time.ToString("yyyy-MM-" + days)) && x.F_Type == "售后订单").Count ();
477
+                            aftersaleInput.problem = aftersale.Where(x => x.F_ReturnType == "产品问题").Count();
478
+
479
+                            aftersaleInput.warehousehair = aftersale.Where(x => x.F_ReturnType == "仓库错发" ||
480
+                             x.F_ReturnType == "仓库漏发").Count();
481
+                            aftersaleInput.Saleserror = aftersale.Where(x => x.F_ReturnType == "销售错发" ||
482
+                            x.F_ReturnType == "销售漏发").Count();
483
+                            aftersaleInput.refund = aftersale.Where(x => x.F_Money <0).Count();
484
+                            aftersaleInput.refundamount =Math .Abs ( aftersale.Where(x => x.F_Money < 0).Select(x => x.F_Money).Sum());
485
+                            refunds += aftersaleInput.refund;
486
+                            refundamounts += aftersaleInput.refundamount;
487
+                            aftersaleInput.Totalaftersales = aftersaleInput.total - aftersaleInput.problem
488
+                              - aftersaleInput.warehousehair + aftersaleInput.refund;
489
+                            aftersaleInput.delivergoods = order.Where(x => x.F_Belong == it.F_UserId).Count();
490
+                            if (aftersaleInput.delivergoods > 0)
491
+                            {
492
+                                aftersaleInput.exchange = string.Format("{0:f2}%", aftersaleInput.Totalaftersales / aftersaleInput.delivergoods * 100);
493
+                            }
494
+                            else
495
+                                aftersaleInput.exchange = "0%";
496
+
497
+                            aftersaleInputs.Add(aftersaleInput);
498
+
499
+
500
+                        }
501
+                    }
502
+                    string msg = time.Year +"年"+ time.Month  + "4月份400销售中心共发货"+order .Count ()+"单, 退款共"+ refunds + "单,退款总金额为"+ refundamounts + "元。";
503
+                    var obj = new
504
+                    {
505
+                        state = "success",
506
+                        message = "成功",
507
+                        aftersaleInputs,
508
+                        msg
509
+                    };
510
+                   return  Content(obj.ToJson());
511
+
512
+                }
513
+                else
514
+                    return Error("暂无销售人员");
515
+            }
516
+            else
517
+                return Error("暂无销售部门");
518
+
519
+        }
520
+
414 521
     }
415 522
 }