wugg 1 tahun lalu
induk
melakukan
0523a2d5f2

+ 1 - 1
app/admin/controller/Export.php

@@ -90,7 +90,7 @@ class Export extends BaseController
     public function invoicePoolExport()
     {
         $param = $this->request->only(['start' => '', 'end' => '', 'status' => '', 'inv_type' => '', 'inv_out' => '', 'invNo' => '', 'relaComNo' => '', 'inv_number' => '', 'inv_code' => '', 'inv_company' => '', 'buyer_name' => '', 'apply_id' => '', 'apply_name' => '',], 'post', 'trim');
-        $where = [['a.is_del', '=', 0], ['e.status', 'in', [1, 2]]];
+        $where = [['a.is_del', '=', 0], ['e.status', 'in', [1,2]]];
         if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
         if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
         if ($param['inv_type'] != '') $where[] = ['a.inv_type', '=', $param['inv_type']];

+ 5 - 0
app/admin/controller/OrderPay.php

@@ -1104,6 +1104,11 @@ class OrderPay extends BaseController{
                     'addtime' => date("Y-m-d H:i:s"),
                     'updatetime' => date("Y-m-d H:i:s"),
                     ];
+                   $report=ReportCode::where(["qrdNo"=>$value['orderCode']])->find();
+                 if($report){
+                 	$report->setField("logNo",$OrderCodeToLogNo);
+                 	$report->setField("tradNo",$value['tradNo']);
+                 }
         	}
             if ($assoc_insert_data) Db::name('assoc')->insertAll($assoc_insert_data);
             if ($trade_pool_insert_data) Db::name('trade_pool')->insertAll($trade_pool_insert_data);

+ 70 - 8
app/admin/controller/Stat.php

@@ -77,17 +77,19 @@ class Stat extends BaseController{
 		$everyday =Db::name("depart_everyday")
 		             ->where("day_time",date("Y-m-d",strtotime($post["daytime"])))
 		             ->where("companyNo","GS2203161855277894")
-		             ->column("sale_total,th_total,zy_sale_total,channel_sale_total","depart_id");
+		             ->column("sale_total,th_total,zy_sale_total,channel_sale_total,cgd_total,cgd_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,sum(zy_sale_total) as mzy_sale_total,sum(channel_sale_total) as mchannel_sale_total,depart_id","depart_id");
+		             ->column("sum(sale_total) as msale_total,sum(th_total) as mth_total,sum(cgd_total) as mcgd_total,sum(cgd_th_total) as mcgd_th_total,sum(zy_sale_total) as mzy_sale_total,sum(channel_sale_total) as mchannel_sale_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["cgd_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['cgd_total']:0;
+			$temp["cgd_th_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['cgd_th_total']:0;
 			$temp["zy_sale_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['zy_sale_total']:0;
 			$temp["channel_sale_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['channel_sale_total']:0;
 			$temp["th_total"] =isset($everyday[$value['depart_id']])?$everyday[$value['depart_id']]['th_total']:0;
@@ -95,6 +97,8 @@ class Stat extends BaseController{
 			$temp["mth_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mth_total']:0;
 			$temp["mchannel_sale_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mchannel_sale_total']:0;
 			$temp["mzy_sale_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mzy_sale_total']:0;
+			$temp["mcgd_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mcgd_total']:0;
+			$temp["mcgd_th_total"] = isset($everymonth[$value['depart_id']])?$everymonth[$value['depart_id']]['mcgd_th_total']:0;
 			$return[]=$temp;
 		}
 		return app_show(0,"获取成功",$return);
@@ -132,13 +136,71 @@ class Stat extends BaseController{
 			}
 
 		}
-		//1.北京百辰荣达国际科贸有限公司
-		//2.北京泓源广诚国际商贸有限公司
-		//3.北京锦兴弘昌科技有限公司
-		//4.北京普润心堂商贸有限公司
-		//5.北京万宇恒通国际科贸有限公司
-//		$sort=["GS2302231125079621",'GS2302231323386950','GS2304031312553746','GS2302231124114965','GS2203161855277894'];
+		return app_show(0,"获取成功",$return);
+	}
+	//月统计销售额
+	public function departEveryMonth(){
+		$post = $this->request->only(["year"=>date("Y")],"post","trim");
+		$depart_tips = Db::connect("mysql_wsm3.0")->name("depart_tips")
+		->where("year",$post['year'])
+		->group('month')->order("month asc")
+		->column("sum(total_tips)","month");
+		if(empty($depart_tips)){
+			return error_show(1004,"未获取到各月指标");
+		}
+		$return=[];
+		foreach ($depart_tips as $key=>$value){
+			$info = Db::name("depart_everyday")
+			->whereMonth("day_time",$post['year']."-".$key)
+			->field("sum(sale_total)  sum_sale_total,sum(th_total) sum_th_total,sum(cgd_total)  sum_cgd_total,sum(cgd_th_total) sum_cgd_th_total")
+			->findOrEmpty();
+			$temp=[
+				"month"=>$key,
+				"total_tips"=>$value,
+				"sale_total"=>$info["sum_sale_total"]??0,
+				"th_total"=>$info["sum_th_total"]??0,
+				"cgd_total"=>$info["sum_cgd_total"]??0,
+				"cgd_th_total"=>$info["sum_cgd_th_total"]??0,
+				];
+		$return[]=$temp;
+		}
+
+		return app_show(0,"获取成功",$return);
+	}
+
+
+		//月统计销售额
+	public function companyEvery(){
+		$post = $this->request->only(["year"=>date("Y"),"compamyNo"=>""],"post","trim");
+		$where=[];
+		if($post['companyNo']!='') $where=["companyNo"=>$post['companyNo']];
+		$depart_tips = Db::name("depart_tips")
+		->where("year",$post['year'])
+		->where($where)
+		->order("month asc")
+		->column("total_tips","month");
+		if(empty($depart_tips)){
+			return error_show(1004,"未获取到各月指标");
+		}
+		$return=[];
+		foreach ($depart_tips as $key=>$value){
+			$info = Db::name("depart_company")
+			->whereMonth("day_time",$post['year']."-".$key)
+			->where($where)
+			->field("sum(sale_total) sum_sale_total,sum(th_total) sum_th_total,sum(cgd_total) sum_cgd_total,sum(cgd_th_total) sum_cgd_th_total")
+			->findOrEmpty();
+			$temp=[
+				"month"=>$key,
+				"total_tips"=>$value,
+				"sale_total"=>$info["sum_sale_total"]??0,
+				"th_total"=>$info["sum_th_total"]??0,
+				"cgd_total"=>$info["sum_cgd_total"]??0,
+				"cgd_th_total"=>$info["sum_cgd_th_total"]??0,
+				];
+		$return[]=$temp;
+		}
 
 		return app_show(0,"获取成功",$return);
 	}
+
 }

+ 2 - 0
app/admin/middleware/checkToken.php

@@ -17,7 +17,9 @@ class checkToken
 		"admin/stats",
 		"admin/departstat",
 		"admin/departEveryDay",
+		"admin/departEveryMonth",
 		"admin/companyEveryMonth",
+		"admin/companyEvery",
 		"admin/wechat_getinfo",
 		"admin/wechat_getconfig",
 		"admin/totalstat"

+ 2 - 0
app/admin/route/app.php

@@ -251,7 +251,9 @@ route::rule("stats","admin/Stat/stats");//网络部录单分类
 route::rule("departstat","admin/Stat/depart");//网络部录单分类
 route::rule("totalstat","admin/Stat/Total");//网络部录单分类
 route::rule("departEveryDay","admin/Stat/departEveryDay");//网络部录单分类
+route::rule("departEveryMonth","admin/Stat/departEveryMonth");//网络部录单分类
 route::rule("companyEveryMonth","admin/Stat/companyEveryMonth");//网络部录单分类
+route::rule("companyEvery","admin/Stat/companyEvery");//网络部录单分类
 
 route::rule("companytipslist","admin/DepartTips/list");//网络部录单分类
 route::rule("companytipsadd","admin/DepartTips/create");//网络部录单分类

+ 17 - 11
app/command/Report.php

@@ -490,7 +490,7 @@ class Report extends Command
             b.sendType 发货方式,
             a.thNum 退货数量,
             a.fundCode 财务核算编码,
-             a.total_plan_price 预计采购总额')
+            a.total_plan_price 预计采购总额')
 		          ->leftJoin('cgd_info b', 'b.sequenceNo=a.cgdNo and b.is_del=0')
 		          ->where($where)
 		          ->order(['a.id' => 'asc'])
@@ -924,7 +924,6 @@ class Report extends Command
 		$where = [["is_del","=",0],["status","in",[0,1,2]]];
 		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['addtime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
 		strtotime($param['end']))]];
-//		if ($param['companyNo'] != '') $where[] = ['supplierNo', '=', $param['companyNo']];
 		$Db= Db::connect("mysql_wsm");
 		$list =$Db->name("sale")->field("orderCode 销售单号,apply_name 业务人员,apply_id 业务部门,cat_id 分类,total_price 产品货款总额,addtime 日期")
 		->where($where)
@@ -1061,7 +1060,7 @@ class Report extends Command
 		strtotime($param['end']))]];
 		$list = Db::name("qrd_info")->alias("a")
 		->rightJoin("assoc b","a.sequenceNo=b.orderCode")
-		->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
+//		->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
 		->field("	a.department 部门,
 						a.ownerName 销售人员,
 						platName 平台类型,
@@ -1077,7 +1076,7 @@ class Report extends Command
 						a.firstCat 一级分类,
 						a.goodPrice 销售单价,
 						if(a.cxCode='',a.sequenceNo,a.cxCode)  原销售单号,
-						ifnull(c.goodPrice,0) 采购单价,
+						0 采购单价,
 						a.goodNum 下单数量,
 						a.totalPrice 销售总额,
 						a.createdTime 销售下单时间,
@@ -1102,8 +1101,10 @@ class Report extends Command
 			"0.035"=>"X>30%",
 		];
 		foreach ($list as $value){
-			if($value['订单类型']=='库存' &&$value['采购单编号']=='' && $value['采购单价']==0){
+			if($value['订单类型']=='库存'){
 				$value['采购单价'] = Db::name("cgd_info")->where(["goodNo"=>$value['goodNo'],"cgdSource"=>0])->order("id desc")->value("goodPrice",0);
+			}else{
+				$value['采购单价'] = Db::name("cgd_info")->where(["qrdCode"=>$value['原销售单号']])->value("goodPrice",0);
 			}
 			$value['账期回款系数']=getPayRate($value['账期']);
 			$value['毛利率'] = (1-bcdiv($value['采购单价'],$value['销售单价'],4))*100;
@@ -1130,7 +1131,7 @@ class Report extends Command
 		strtotime($param['end']))]];
 		$list = Db::name("qrd_info")->alias("a")
 		->rightJoin("assoc b","a.sequenceNo=b.orderCode")
-		->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
+//		->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
 		->field("	
 		a.department 部门,
 		a.ownerName 销售人员,
@@ -1147,7 +1148,7 @@ class Report extends Command
 		a.firstCat 一级分类,
 		a.goodPrice 销售单价,
 		if(a.cxCode='',a.sequenceNo,a.cxCode)  原销售单号,
-		ifnull(c.goodPrice,0) 采购单价,
+		0 采购单价,
 		a.goodNum 下单数量,
 		a.totalPrice 销售总额,
 		a.createdTime 销售下单时间,
@@ -1156,8 +1157,10 @@ class Report extends Command
 		ceil(DATEDIFF(b.updatetime,a.createdTime)/30) 账期
 		")->where($where)->cursor();
 		foreach ($list as $value){
-			if($value['订单类型']=='库存' &&$value['采购单编号']=='' && $value['采购单价']==0){
+			if($value['订单类型']=='库存'){
 				$value['采购单价'] = Db::name("cgd_info")->where(["goodNo"=>$value['goodNo'],"cgdSource"=>0])->order("id desc")->value("goodPrice",0);
+			}else{
+				$value['采购单价'] = Db::name("cgd_info")->where(["qrdCode"=>$value['原销售单号']])->value("goodPrice",0);
 			}
 			unset($value['goodNo']);
 			yield $value;
@@ -1179,7 +1182,7 @@ class Report extends Command
 		strtotime($param['end']))]];
 		$list = Db::name("qrd_info")->alias("a")
 		->rightJoin("assoc b","a.sequenceNo=b.orderCode")
-		->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
+//		->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
 		->field("	
 		a.department 部门,
 		a.ownerName 销售人员,
@@ -1196,7 +1199,7 @@ class Report extends Command
 		a.firstCat 一级分类,
 		a.goodPrice 销售单价,
 		if(a.cxCode='',a.sequenceNo,a.cxCode)  原销售单号,
-		ifnull(c.goodPrice,0) 采购单价,
+		0 采购单价,
 		a.goodNum 下单数量,
 		a.totalPrice 销售总额,
 		a.createdTime 销售下单时间,
@@ -1205,10 +1208,13 @@ class Report extends Command
 		ceil(DATEDIFF(b.updatetime,a.createdTime)/30) 账期
 		")->where($where)->cursor();
 		foreach ($list as $value){
-			if($value['订单类型']=='库存' &&$value['采购单编号']=='' && $value['采购单价']==0){
+			if($value['订单类型']=='库存'){
 				$value['采购单价'] = Db::name("cgd_info")->where(["goodNo"=>$value['goodNo'],"cgdSource"=>0])->order("id desc")->value("goodPrice",0);
+			}else{
+					$value['采购单价'] = Db::name("cgd_info")->where(["qrdCode"=>$value['原销售单号']])->value("goodPrice",0);
 			}
 			unset($value['goodNo']);
+//			unset($value['companyNo']);
 			yield $value;
 		}
 	}

+ 91 - 79
app/command/companyStats.php

@@ -40,78 +40,86 @@ class companyStats extends Command
 	 * @param $supplierNo
 	 */
     public function checkData($supplierNo):void {
-    	$sup =Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$supplierNo])->field("code,name,relation_code")->findOrEmpty();
-    	if(empty($sup)) return;
-    	$date=date("Y-m-d");
-    	$d=Db::name("depart_company")->where(["companyNo"=>$supplierNo,"day_time"=>$date])->column("*","type");
-    	$temp=[];
-
-		$total =Db::name("qrd_info")
-		->where(["companyNo"=>$supplierNo,"is_del"=>0,"cxCode"=>""])
-		->whereDay("createdTime",$date)
-		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
-		$day_thtotal=Db::name("th_source")->alias("a")
-		 ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo")
-		 ->where([['a.th_companyNo',"=",$supplierNo],["b.is_del","=",0]])
-		 ->whereDay("a.createtime",$date)->field('sum(a.th_qrd_fee) as th_total')->findOrEmpty();;
-		if(isset($d[1]))Db::name("depart_company")->where($d[1])->save(["sale_total"=>$total['total']??0,"th_total"=>$day_thtotal['th_total']??0]);
-		else $temp[]=[
-			"companyNo"=>$supplierNo,
-			"companyName"=>$sup['name']??"",
-			"type"=>1,
-			"day_time"=>$date,
-			"sale_total"=>$total['total']??0,
-			"th_total"=>$day_thtotal['th_total']??0,
-			"addtime"=>date("Y-m-d H:i:s")
-			];
-
-
-		$total_cx =Db::name("qrd_info")
-		->where(["companyNo"=>$supplierNo,"is_del"=>0])
-		->where("cxCode","<>","")
-		->whereDay("createdTime",$date)
-		->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
-		$day_thtotal_cx=Db::name("th_source")->alias("a")
-		 ->leftJoin("qrd_info b","a.th_qrdNo=b.cxCode")
-		 ->where([['a.th_companyNo',"=",$supplierNo],["b.is_del","=",0]])
-		 ->whereDay("a.createtime",$date)
-	    ->field("sum(a.th_num*b.goodPrice) as th_total")->findOrEmpty();
-		if(isset($d[2]))Db::name("depart_company")->where($d[2])->save(["sale_total"=>$total_cx['total']??0,
-		"th_total"=>$day_thtotal_cx['th_total']??0]);
-		else $temp[]=[
-			"companyNo"=>$supplierNo,
-			"companyName"=>$sup['name']??"",
-			"type"=>2,
-			"day_time"=>$date,
-			"sale_total"=>$total_cx['total']??0,
-			"th_total"=>$day_thtotal_cx['th_total']??0,
-			"addtime"=>date("Y-m-d H:i:s")
-			];
-
-		$cgd=$this->cgdData($sup['relation_code'],$date);
-		if(isset($d[3]))Db::name("depart_company")->where($d[3])->save(["sale_total"=>$cgd['cgd_total'],
-		"th_total"=>$cgd['cgd_thtotal']]);
-		else $temp[]=[
-			"companyNo"=>$supplierNo,
-			"companyName"=>$sup['name']??"",
-			"type"=>3,
-			"day_time"=>$date,
-			"sale_total"=>$cgd['cgd_total'],
-			"th_total"=>$cgd['cgd_thtotal'],
-			"addtime"=>date("Y-m-d H:i:s")
-			];
-		$cgdtotal = $this->cgdTotal($supplierNo,$date);
-		if(isset($d[4]))Db::name("depart_company")->where($d[4])->save(["sale_total"=>$cgdtotal['cgd_total'],
-		"th_total"=>$cgdtotal['th_cgd']]);
-		else $temp[]=[
-			"companyNo"=>$supplierNo,
-			"companyName"=>$sup['name']??"",
-			"type"=>4,
-			"day_time"=>$date,
-			"sale_total"=>$cgdtotal['cgd_total'],
-			"th_total"=>$cgdtotal['th_cgd'],
-			"addtime"=>date("Y-m-d H:i:s")
-			];
+        $sup=Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$supplierNo])->field("code,name,relation_code")->findOrEmpty();
+        if (empty($sup)) return;
+        $date=date("Y-m-d");
+//	    $start="20230501";
+//	    $end= date("Ymt",strtotime($start));
+//	    $date_tmp=$start;
+//	    $temp=[];
+//	    while ($date_tmp>=$start && $date_tmp<=$end) {
+//		    $date=date("Y-m-d" , strtotime($date_tmp . ''));
+		    $d=Db::name("depart_company")->where(["companyNo"=>$supplierNo , "day_time"=>$date])->column("*" , "type");
+		    $total=Db::name("qrd_info")
+		             ->where(["companyNo"=>$supplierNo , "is_del"=>0 , "cxCode"=>""])
+		             ->whereDay("createdTime" , $date)
+		             ->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
+		    $day_thtotal=Db::name("th_source")->alias("a")
+		                   ->leftJoin("qrd_info b" , "a.th_qrdNo=b.sequenceNo")
+		                   ->where([['a.th_companyNo' , "=" , $supplierNo] , ["b.is_del" , "=" , 0]])
+		                   ->whereDay("a.createtime" , $date)->field('sum(a.th_qrd_fee) as th_total')->findOrEmpty();
+		    $cgdtotal = $this->cgdTotal($supplierNo,$date,1);
+		    if (isset($d[1])) Db::name("depart_company")->where($d[1])->save([
+		    	"sale_total"=>$total['total'] ?? 0 ,
+			    "th_total"=>$day_thtotal['th_total'] ?? 0,
+			    "cgd_total"=>$cgdtotal['cgd_total']??0,
+			    "cgd_th_total"=>$cgdtotal['cgd_th_total']??0,
+		    ]);
+		    else $temp[]=[
+			    "companyNo"=>$supplierNo ,
+			    "companyName"=>$sup['name'] ?? "" ,
+			    "type"=>1 ,
+			    "day_time"=>$date ,
+			    "sale_total"=>$total['total'] ?? 0 ,
+			    "th_total"=>$day_thtotal['th_total'] ?? 0 ,
+			    "cgd_total"=>$cgdtotal['cgd_total']??0,
+			    "cgd_th_total"=>$cgdtotal['cgd_th_total']??0,
+			    "addtime"=>date("Y-m-d H:i:s")
+		    ];
+		    $total_cx=Db::name("qrd_info")
+		                ->where(["companyNo"=>$supplierNo , "is_del"=>0])
+		                ->where("cxCode" , "<>" , "")
+		                ->whereDay("createdTime" , $date)
+		                ->field("sum(totalPrice+th_fee) as total")->findOrEmpty();
+		    $day_thtotal_cx=Db::name("th_source")->alias("a")
+		                      ->leftJoin("qrd_info b" , "a.th_qrdNo=b.cxCode")
+		                      ->where([['a.th_companyNo' , "=" , $supplierNo] , ["b.is_del" , "=" , 0]])
+		                      ->whereDay("a.createtime" , $date)
+		                      ->field("sum(a.th_num*b.goodPrice) as th_total")->findOrEmpty();
+		    $cgdtotal = $this->cgdTotal($supplierNo,$date,2);
+		    if (isset($d[2])) Db::name("depart_company")->where($d[2])->save([
+		    	"sale_total"=>$total_cx['total'] ?? 0 ,
+			    "th_total"=>$day_thtotal_cx['th_total'] ?? 0,
+			     "cgd_total"=>$cgdtotal['cgd_total']??0,
+				 "cgd_th_total"=>$cgdtotal['cgd_th_total']??0,
+				    ]
+		    );
+		    else $temp[]=[
+			    "companyNo"=>$supplierNo ,
+			    "companyName"=>$sup['name'] ?? "" ,
+			    "type"=>2 ,
+			    "day_time"=>$date ,
+			    "sale_total"=>$total_cx['total'] ?? 0 ,
+			    "th_total"=>$day_thtotal_cx['th_total'] ?? 0 ,
+			    "cgd_total"=>$cgdtotal['cgd_total']??0,
+			    "cgd_th_total"=>$cgdtotal['cgd_th_total']??0,
+			    "addtime"=>date("Y-m-d H:i:s")
+		    ];
+		    $cgd=$this->cgdData($sup['relation_code'] , $date);
+		    if (isset($d[3])) Db::name("depart_company")->where($d[3])->save(["sale_total"=>$cgd['cgd_total'] ,
+			    "th_total"=>$cgd['cgd_thtotal']]
+		    );
+		    else $temp[]=[
+			    "companyNo"=>$supplierNo ,
+			    "companyName"=>$sup['name'] ?? "" ,
+			    "type"=>3 ,
+			    "day_time"=>$date ,
+			    "sale_total"=>$cgd['cgd_total'] ,
+			    "th_total"=>$cgd['cgd_thtotal'] ,
+			    "addtime"=>date("Y-m-d H:i:s")
+		    ];
+//		    $date_tmp++;
+//	    }
 		if(!empty($temp))Db::name("depart_company")->insertAll($temp);
 
     }
@@ -142,19 +150,23 @@ class companyStats extends Command
 	 * @param $date
 	 * @return array
 	 */
-    private function cgdTotal($companyNo,$date): array
+    private function cgdTotal($companyNo,$date,$type): array
     {
-
+			$where=[];
+			if($type==1)$where=[["a.cxCode","=",'']];
+			if($type==2)$where=[["a.cxCode","<>",'']];
 			$day_total =Db::name("qrd_info")->alias("a")
 			->leftJoin('cgd_info b', 'b.sequenceNo=a.cgdNo and b.is_del=0')
 			->where([["a.is_del","=",0],['a.companyNo',"=",$companyNo]])
+			->where($where)
 		    ->whereDay("a.createdTime",$date)
 		    ->sum(Db::raw("(ifnull(b.totalPrice,if(a.total_origin_price=0,a.total_plan_price,a.total_origin_price))+ifnull(b.th_fee,0))"));
-		$day_thtotal=Db::name("th_source")->alias("a")
-		               ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo or a.th_qrdNo=b.cxCode")
-		               ->leftJoin('cgd_info c', 'c.sequenceNo=b.cgdNo and c.is_del=0')
-		               ->where([['b.companyNo',"=",$companyNo]])
-		               ->whereDay("a.createtime",$date)->sum(Db::raw('a.th_num*ifnull(c.goodPrice,0)'));
+		$day_thtotal=Db::name("th_source")->alias("b")
+		               ->leftJoin("qrd_info a","b.th_qrdNo=a.sequenceNo or b.th_qrdNo=a.cxCode")
+		               ->leftJoin('cgd_info c', 'c.sequenceNo=a.cgdNo and c.is_del=0')
+		               ->where([['a.companyNo',"=",$companyNo]])
+		               ->where($where)
+		               ->whereDay("b.createtime",$date)->sum(Db::raw('b.th_num*ifnull(c.goodPrice,0)'));
 		return ["cgd_total"=>$day_total,"th_cgd"=>$day_thtotal];
     }
 }