路由
routes.php
$router->get('charge', SamProofingController::class.'@charge');
$router->get('totalCharge', SamProofingController::class.'@totalCharge')->name('totalCharge');
$router->get('printCharge', SamProofingController::class.'@printCharge');
控制器代码
public function charge(Content $content)
{
$back_url = $_SERVER["QUERY_STRING"];
$dep = DingBranch::where('name','like','%业务%')->get()->toArray();
return $content
->header($this->charge_title)
->description($this->description['total'])
->breadcrumb(
['text' => $this->charge_title, 'url' => '/samproofing/charge'.$back_url],
['text' => $this->description['total']]
)
->row(view('temp.proofing.chargeCreate',['back_url'=>$back_url,'dep'=>$dep]));
}
// 查询统计
public function totalCharge(Request $request)
{
$type_id = $request->type_id;
$depid = $request->depid;
$start_date = $request->start_date;
$end_date = $request->end_date;
$title = '板房';
if (!$start_date){
//当前月1日 00:00:00
$start_date= date('Y-m-d 00:00:00', strtotime(date('Y-m', time()) . '-01 00:00:00'));
}
if (!$end_date){
$end_date = getDateH(0);
}
try{
$data = ProofingNotice::with(['notice_size','exploit'=>function($qs) use($depid){
if (isset($depid)){
$qs->with(['client','brand','devedep','deveaids','client_branch'])->where('deve_dep',$depid);
}
else{
$qs->with(['client','brand','devedep','deveaids','client_branch']);
}
}, 'colors'=>function($qc){
$qc->with(['place']);
}])
// ->where($where)
->whereBetween('submit_date', [$start_date, $end_date])
// ->select('exploit_id','color_id','properties_id','submit_date')
// ->selectRaw("count(properties_id) as count_qty")
// ->groupBy('exploit_id','color_id','properties_id','submit_date')
->get()->toArray();
//dd($data);
$res = [];
$pattern = 0;
$sample = 0;
if(count($data)>0 && isset($data[0]['exploit'])){
foreach ($data as $k=>$v) {
$res[$k]['client_brach'] = $v['exploit']['client']['name'].'-'.$v['exploit']['client_branch']['title'];
$res[$k]['brand_name'] = $v['exploit']['brand']['title'];
$res[$k]['exploit_no'] = $v['exploit']['exploit_no'];
$res[$k]['deve_dep'] = $v['exploit']['devedep']['name'];
$res[$k]['product_name'] = $v['colors']['place']['title'];
$res[$k]['properties'] = sample_properties()[$v['properties_id']];
$res[$k]['deve_aid'] = $v['exploit']['deveaids']['name'];
// $res[$k]['qty'] = $v['count_qty'];
$res[$k]['submit_date'] = date('Y-m-d',strtotime($v['submit_date'])) ;
$res[$k]['price'] = '';
$res[$k]['total'] = '';
if (count($v['notice_size'])>0){
$pattern = array_sum(array_column($v['notice_size'], 'pattern'));
$sample = array_sum(array_column($v['notice_size'], 'size_qty'));
}
if (!isset($type_id) || $type_id==1) {
//null 或 板房
$res[$k]['count_qty'] = $pattern;
}
else{
// 样品
$title = '打样组';
$res[$k]['count_qty'] = $sample;
}
}
return response()->json(["code" => 100 ,"message" => "成功",'list'=> $res]);
}
else{
return response()->json(["code" => 200 ,"message" => "数据不存在!",'list'=>$res]);
}
}catch (\Exception $e){
$status = 300;
$message = $e->getLine().$e->getMessage()