where("year",date("Y"))->column("depart_id,depart_ment,tips,month,year,total,th_total,profit,rate,prate"); $data=[ [ "depart_ment"=>'总计', "content"=>[ 1=>["tips"=>0,"month"=>1,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 2=>["tips"=>0,"month"=>2,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 3=>["tips"=>0,"month"=>3,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 4=>["tips"=>0,"month"=>4,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 5=>["tips"=>0,"month"=>5,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 6=>["tips"=>0,"month"=>6,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 7=>["tips"=>0,"month"=>7,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 8=>["tips"=>0,"month"=>8,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 9=>["tips"=>0,"month"=>9,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 10=>["tips"=>0,"month"=>10,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 11=>["tips"=>0,"month"=>11,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], 12=>["tips"=>0,"month"=>12,"year"=>date("Y"),"total"=>0,"th_total"=>0,"profit"=>0,"rate"=>0,"prate"=>0], ] ] ]; foreach ($list as $value){ $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']]; $data[0]['content'][$value['month']]["tips"]+=$value['tips']; $data[0]['content'][$value['month']]["total"]+=$value['total']; $data[0]['content'][$value['month']]["th_total"]+=$value['th_total']; $data[0]['content'][$value['month']]["profit"]=$data[0]['content'][$value['month']]["total"] - $data[0]['content'][$value['month']]["th_total"]; $data[0]['content'][$value['month']]["rate"]=round($data[0]['content'][$value['month']]["total"]/$data[0]['content'][$value['month']]["tips"] *100,2); $data[0]['content'][$value['month']]["prate"]=round($data[0]['content'][$value['month']]["profit"]/$data[0]['content'][$value['month']]["tips"] *100,2); if (isset($data[$value['depart_id']])){ $data[$value['depart_id']]['content'][$value['month']]= $temp; }else{ $data[$value['depart_id']]["depart_ment"]=$value['depart_ment']; $data[$value['depart_id']]['content'][$value['month']]= $temp; } } return app_show(0,"获取成功",$data); } public function departEveryDay(){ $post = $this->request->only(["daytime"=>date("Y-m-d H:i:s")],"post","trim"); $depart_tips = Db::connect("mysql_wsm3.0")->name("depart_tips") ->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,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(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; $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; $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); } 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) ->column("*","companyNo"); if(empty($depart_tips)){ return error_show(1004,"未获取到各部门指标"); } $return=[]; $sort=["GS2302231125079621",'GS2302231323386950','GS2304031312553746','GS2302231124114965','GS2203161855277894']; foreach ($sort as $value){ $temp=[]; if(isset($depart_tips[$value])){ $temp["companyName"] = $depart_tips[$value]['companyName']; $temp["total_tips"] = $depart_tips[$value]['total_tips']; $temp["dayinfo"] =Db::name("depart_company") ->where("day_time",date("Y-m-d",strtotime($post["daytime"]))) ->where(["companyNo"=>$value]) ->column("sale_total,th_total,type,cgd_total,cgd_th_total,companyNo");; $temp["monthinfo"] =Db::name("depart_company") ->whereBetween("day_time",[date("Y-m-01",strtotime($post["daytime"])),date("Y-m-t", strtotime($post["daytime"]))]) ->where(["companyNo"=>$value]) ->group("companyNo,type") ->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,companyNo,type"); $return[]=$temp; } } 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"),"companyNo"=>""],"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); } public function DzQrd(){ $post = $this->request->only(["companyNo"=>'GS2203161855277894'],"post","trim"); $list = Db::name("qrd_info") ->where([["createdTime","<=",date("Y-m-d H:i:s",time()-180*24*3600)],["companyNo","=",$post['companyNo']],["wpay_fee",">",0],["platform_type","=",1]]) ->field("sequenceNo,if(cxCode='',sequenceNo,cxCode) cxCode,createdTime,customerName,department,ownerName,goodName,goodNum,goodPrice,totalPrice,apay_fee,wpay_fee,ainv_fee,winv_fee,inv_fee, wpay_fee-winv_fee ainv_wpay,datediff(now(),createdTime) dz_day,pay_status,inv_status,sendStatus") ->select(); return app_show(0,"获取成功",$list); } }