Stat.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Cache;
  6. use think\facade\Db;use think\facade\Validate;
  7. class Stat extends BaseController{
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. }
  11. public function stats(){
  12. $data=Cache::get("statContent");
  13. return app_show(0,"获取成功",$data);
  14. }
  15. public function depart(){
  16. $data=Cache::get("departContent");
  17. return app_show(0,"获取成功",$data);
  18. }
  19. //每月业绩报表
  20. public function total(){
  21. $list =Db::name("total_tips")->where("year",date("Y"))->column("depart_id,depart_ment,tips,month,year,total,th_total,profit,rate,prate");
  22. $data=[
  23. [
  24. "depart_ment"=>'总计',
  25. "content"=>[
  26. 1=>["tips"=>0,"month"=>1,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  27. 2=>["tips"=>0,"month"=>2,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  28. 3=>["tips"=>0,"month"=>3,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  29. 4=>["tips"=>0,"month"=>4,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  30. 5=>["tips"=>0,"month"=>5,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  31. 6=>["tips"=>0,"month"=>6,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  32. 7=>["tips"=>0,"month"=>7,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  33. 8=>["tips"=>0,"month"=>8,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  34. 9=>["tips"=>0,"month"=>9,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  35. 10=>["tips"=>0,"month"=>10,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  36. 11=>["tips"=>0,"month"=>11,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  37. 12=>["tips"=>0,"month"=>12,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0],
  38. ]
  39. ]
  40. ];
  41. foreach ($list as $value){
  42. $temp=["tips"=>$value['tips'],"month"=>$value['month'],"year"=>date("Y"),"total"=>$value['total'],"th_total"=>$value['th_total'],"profit"=>$value['profit'],"rate"=>$value['rate'],"prate"=>$value['prate']];
  43. $data[0]['content'][$value['month']]["tips"]+=$value['tips'];
  44. $data[0]['content'][$value['month']]["total"]+=$value['total'];
  45. $data[0]['content'][$value['month']]["th_total"]+=$value['th_total'];
  46. $data[0]['content'][$value['month']]["profit"]=$data[0]['content'][$value['month']]["total"] - $data[0]['content'][$value['month']]["th_total"];
  47. $data[0]['content'][$value['month']]["rate"]=round($data[0]['content'][$value['month']]["total"]/$data[0]['content'][$value['month']]["tips"] *100,2);
  48. $data[0]['content'][$value['month']]["prate"]=round($data[0]['content'][$value['month']]["profit"]/$data[0]['content'][$value['month']]["tips"] *100,2);
  49. if (isset($data[$value['depart_id']])){
  50. $data[$value['depart_id']]['content'][$value['month']]= $temp;
  51. }else{
  52. $data[$value['depart_id']]["depart_ment"]=$value['depart_ment'];
  53. $data[$value['depart_id']]['content'][$value['month']]= $temp;
  54. }
  55. }
  56. return app_show(0,"获取成功",$data);
  57. }
  58. //
  59. // public function performance(){
  60. // $param = $this->request->only(["start"=>"","end"=>""],"post","trim");
  61. // $valid =Validate::rule([
  62. // "start|起始时间"=>"require|date",
  63. // "end|结束时间"=>"require|date|gt:start",
  64. // ]);
  65. // if($valid->check($param)==false) return error_show(1005,$valid->getError());
  66. // $list =Db::name("trade_pool")->alias("a")
  67. // ->leftJoin("assoc b","a.logNo = b.viceCode and b.is_del=0 and b.status=2 and b.type=2")
  68. // ->leftJoin("qrd_info c","b.orderCode=c.sequenceNo and c.is_del=0")
  69. // ->where(["a.status"=>2,"a.is_del"=>0])
  70. // ->whereBetween("a.addtime",[date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
  71. // strtotime($param['end']))])
  72. // ->field("
  73. // a.logNo 回款单号,
  74. // c.ownerName 销售人员,
  75. // c.department 部门,
  76. // c.qrdType 订单类型,
  77. // if(c.cxCode='',c.sequenceNo,c.cxCode) 确认单编号,
  78. // c.cgdNo 采购单号,
  79. // c.customerAttr 客户属性,
  80. // c.branch 客户分公司,
  81. // c.customerName 客户名称,
  82. // c.goodName 产品名称,
  83. // c.firstCat 一级分类,
  84. // c.goodPrice 销售单价,
  85. // c.goodNum-c.thNum 下单数量,
  86. // c.totalPrice 销售总额,
  87. // c.createdTime 确认单下单时间,
  88. // a.addtime 回款日期,
  89. // a.total_fee 回款金额,
  90. // ( timestampdiff( DAY, a.addtime, now())) 账期")
  91. // ->order("a.addtime desc")
  92. // ->cursor();
  93. // $header=["回款单号","销售人员","部门","订单类型","确认单编号","采购单号","客户属性","客户分公司","客户名称","产品名称","一级分类",
  94. // "销售单价","下单数量","销售总额","确认单下单时间","回款日期","回款金额","账期"];
  95. // excelExport("业绩报表",$header,$list);
  96. // }
  97. //
  98. // public function cgdPerformance(){
  99. // $param = $this->request->only(["start"=>"","end"=>""],"post","trim");
  100. // $valid =Validate::rule([
  101. // "start|起始时间"=>"require|date",
  102. // "end|结束时间"=>"require|date|gt:start",
  103. // ]);
  104. // if($valid->check($param)==false) return error_show(1005,$valid->getError());
  105. // $db =Db::connect("mysql_wsm");
  106. // $list =$db->name("order_out")->alias("a")
  107. // ->leftJoin("sale b","a.orderCode=b.orderCode")
  108. // ->leftJoin("order_send c","a.outCode=c.outCode")
  109. // ->where(["a.status"=>2,"a.is_del"=>0,"b.is_stock"=>0])
  110. // ->whereBetween("a.sendtime",[date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
  111. // strtotime($param['end']))])
  112. // ->field("
  113. // a.outCode 发货单号,
  114. // c.cgdNo 采购单号,
  115. // a.orderCode 销售单号,
  116. // b.platform_id,
  117. // b.apply_id ,
  118. // b.apply_name,
  119. // b.order_source,
  120. // a.sendtime ,
  121. // b.cat_id,
  122. // b.good_name,
  123. // a.post_name,
  124. // a.post_code,
  125. // a.send_num,
  126. // b.sale_price,
  127. // b.good_num,
  128. // b.total_price,
  129. // b.supplierNo
  130. // ")
  131. // ->order("a.addtime desc")
  132. // ->cursor();
  133. // $header=["回款单号","销售人员","部门","订单类型","确认单编号","采购单号","客户属性","客户分公司","客户名称","产品名称","一级分类",
  134. // "销售单价","下单数量","销售总额","确认单下单时间","回款日期","回款金额","账期"];
  135. // excelExport("业绩报表",$header,$list);
  136. // }
  137. }