wugg 1 year ago
parent
commit
c069190e06
2 changed files with 72 additions and 5 deletions
  1. 71 4
      app/admin/controller/Stat.php
  2. 1 1
      app/command/stat.php

+ 71 - 4
app/admin/controller/Stat.php

@@ -4,7 +4,11 @@
 namespace app\admin\controller;
 use app\BaseController;
 use think\App;
-use think\facade\Cache;use think\facade\Db;
+use think\facade\Cache;
+use think\facade\Db;
+use think\facade\Response;
+use think\helper\Arr;
+
 
 class Stat extends BaseController{
 	public function __construct(App $app) {parent::__construct($app);}
@@ -60,10 +64,73 @@ class Stat extends BaseController{
 	}
 
 	public  function departEveryDay(){
-		$post = $this->request->only(["daytime"=>date("Y-m-d")],"post","trim");
+		$post = $this->request->only(["daytime"=>date("Y-m-d H:i:s")],"post","trim");
+
 		$depart_tips = Db::connect("mysql_wsm3.0")->name("depart_tips")
-		->whereYear("year",$post['daytime'])
-		->whereMonth("month",$post['daytime'])
+		->where("year",date("Y",strtotime($post["daytime"])))
+		->where("month",date("m",strtotime($post["daytime"])))
 		->select();
+		if($depart_tips->isEmpty()){
+			return error_show(1004,"未获取到各部门指标");
+		}
+		$return=[];
+		$everyday =Db::name("depart_everyday")
+		             ->where("day_time",date("Y-m-d",strtotime($post["daytime"])))
+		             ->where("companyNo","GS2203161855277894")
+		             ->column("sale_total,th_total","depart_id");
+		$everymonth =Db::name("depart_everyday")
+		             ->whereBetween("day_time",[date("Y-m-01",strtotime($post["daytime"])),date("Y-m-t",  strtotime($post["daytime"]))])
+		             ->where("companyNo","GS2203161855277894")
+			->group("depart_id")
+		             ->column("sum(sale_total) as msale_total,sum(th_total) as mth_total,depart_id","depart_id");
+		foreach ($depart_tips as $value){
+			$temp=[];
+			$temp["depart"] = $value['depart_item'];
+			$temp["total_tips"] = $value['total_tips'];
+			$temp["sale_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['sale_total']:0;
+			$temp["th_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['th_total']:0;
+			$temp["msale_total"] =isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['msale_total']:0;
+			$temp["mth_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mth_total']:0;
+			$return[]=$temp;
+		}
+		return app_show(0,"获取成功",$return);
+	}
+
+	public  function companyEveryMonth(){
+		$post = $this->request->only(["daytime"=>date("Y-m-d H:i:s"),"companyNo"=>''],"post","trim");
+		$where=[];
+		if($post['companyNo']!='') $where=["companyNo"=>$post['companyNo']];
+		$depart_tips = Db::name("depart_tips")
+		                 ->where("year",date("Y",strtotime($post["daytime"])))
+		                 ->where("month",date("m",strtotime($post["daytime"])))
+						->where($where)
+		                 ->select();
+		if($depart_tips->isEmpty()){
+			return error_show(1004,"未获取到各部门指标");
+		}
+		$return=[];
+		$everyday =Db::name("depart_company")
+		             ->where("day_time",date("Y-m-d",strtotime($post["daytime"])))
+						->where($where)
+		             ->column("sale_total,th_total,type","companyNo");
+		$everymonth =Db::name("depart_company")
+		               ->whereBetween("day_time",[date("Y-m-01",strtotime($post["daytime"])),date("Y-m-t",  strtotime($post["daytime"]))])
+		               ->where($where)
+		               ->group("companyNo,type")
+		               ->column("sum(sale_total) as msale_total,sum(th_total) as mth_total,companyNo,type");
+		$arr=[];
+		array_walk($everymonth , function ($k)use (&$arr){
+			$arr[$k['companyNo']][] =$k;
+		});
+		foreach ($depart_tips as $value){
+			$temp=[];
+			$temp["companyName"] = $value['companyName'];
+			$temp["total_tips"] = $value['total_tips'];
+			$temp["dayinfo"] =$everyday[$value['companyNo']]??[];
+			$temp["monthinfo"] =$arr[$value['companyNo']]??[];
+			$return[]=$temp;
+		}
+
+		return app_show(0,"获取成功",$return);
 	}
 }

+ 1 - 1
app/command/stat.php

@@ -57,7 +57,7 @@ class stat extends Command
 
 		$day_total =Db::name("qrd_info")->where([["ownerid","in",$uid],["is_del","=",0],['companyNo',"=",$companyNo]])
 		                         ->whereDay("createdTime","today")
-		              ->sum('totalPrice+th_fee');
+		              ->sum(Db::raw('totalPrice+th_fee'));
 		$day_thtotal=Db::name("th_source")->alias("a")
 		               ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo or a.th_qrdNo=b.cxCode")
 		               ->where([["b.ownerid","in",$uid],['a.th_companyNo',"=",$companyNo]])