You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
7.7 KiB
174 lines
7.7 KiB
<?php
|
|
require_once './wf_common.php';
|
|
|
|
|
|
#遍历所有大区
|
|
$yyyymm = '202306';
|
|
$res_regions = DB::result("select code_name,content from code where field_name='regions' ");
|
|
$region_data = [];
|
|
#遍历所有大区
|
|
foreach ($res_regions as $regions) {
|
|
echo $regions['code_name'];
|
|
$region_data[$regions['code_name']] = [
|
|
'depart_name' => $regions['content'],
|
|
#当月件数
|
|
'd_item_cnt' => 0,
|
|
#当月台数
|
|
'd_mfg_cnt' => 0,
|
|
#直销件数
|
|
'z_item_cnt' => 0,
|
|
#直销台数
|
|
'z_mfg_cnt' => 0,
|
|
#平台件数
|
|
'p_item_cnt' => 0,
|
|
#平台台数
|
|
'p_mfg_cnt' => 0,
|
|
#台数合计
|
|
'mfg_total' => 0,
|
|
#件数合计
|
|
'item_total' => 0,
|
|
#营业人数
|
|
'persons' => 0,
|
|
#人均台数
|
|
'avg_mfg_total' => 0,
|
|
#人均件数
|
|
'avg_item_total' => 0,
|
|
];
|
|
#遍历大区下面所有分公司
|
|
$res_branch = DB::result("select depart_no,depart_name from depart where regions='" . $regions['code_name'] . "' ");
|
|
foreach ($res_branch as $branch) {
|
|
#遍历分公司下面所有人
|
|
$depart_data = [];
|
|
$res_salesman = DB::result("select employee_no,name from employee
|
|
where depart_no='" . $branch['depart_no'] . "' ");
|
|
$depart_data = [
|
|
'depart_name' => $branch['depart_name'],
|
|
|
|
];
|
|
foreach ($res_salesman as $salesman) {
|
|
//当月预定成交台数 件数
|
|
$d_item_cnt = $d_mfg_cnt = $z_item_cnt = $z_mfg_cnt = $p_item_cnt = $p_mfg_cnt = 0;
|
|
list($d_item_cnt, $d_mfg_cnt) = DB::fields("select count(vol_no) item_cnt ,sum(num) mfg_cnt
|
|
From hope_contract_customer where salesman='" . $salesman['employee_no'] . "'
|
|
and pre_order_date between DATE_FORMAT(concat('$yyyymm','01'),'%Y-%m-%d')
|
|
and LAST_DAY(STR_TO_DATE('$yyyymm', '%Y%m'))");
|
|
// 直销 台数 件数
|
|
list($z_item_cnt, $z_mfg_cnt) = DB::fields("select count(vol_no) z_item_cnt ,sum(num)
|
|
z_mfg_cnt From hope_contract_customer where salesman=''" . $salesman['employee_no'] . "'
|
|
and customer_kind='1'");
|
|
// 平台 台数 件数
|
|
list($p_item_cnt, $p_mfg_cnt) = DB::fields("select count(vol_no) p_item_cnt ,sum(num)
|
|
p_mfg_cnt From hope_contract_customer where salesman='" . $salesman['employee_no'] . "'
|
|
and customer_kind!='1'
|
|
");
|
|
#当月件数
|
|
$d_item_cnt = empty($d_item_cnt) ? 0 : $d_item_cnt;
|
|
#当月台数
|
|
$d_mfg_cnt = empty($d_mfg_cnt) ? 0 : $d_mfg_cnt;
|
|
#直销件数
|
|
$z_item_cnt = empty($z_item_cnt) ? 0 : $z_item_cnt;
|
|
#直销台数
|
|
$z_mfg_cnt = empty($z_mfg_cnt) ? 0 : $z_mfg_cnt;
|
|
#平台件数
|
|
$p_item_cnt = empty($p_item_cnt) ? 0 : $p_item_cnt;
|
|
#平台台数
|
|
$p_mfg_cnt = empty($p_mfg_cnt) ? 0 : $p_mfg_cnt;
|
|
#台数合计
|
|
$mfg_total = $z_mfg_cnt + $p_mfg_cnt;
|
|
#件数合计
|
|
$item_total = $z_item_cnt + $p_item_cnt;
|
|
#营业人数
|
|
$persons = 1;
|
|
#人均台数
|
|
$avg_mfg_total = $z_mfg_cnt + $p_mfg_cnt;
|
|
#人均件数
|
|
$avg_item_total = $z_item_cnt + $p_item_cnt;
|
|
|
|
#部门数据
|
|
$depart_data = [
|
|
#当月件数
|
|
'd_item_cnt' => $depart_data['d_item_cnt'] + $d_item_cnt,
|
|
#当月台数
|
|
'd_mfg_cnt' => $depart_data['d_mfg_cnt'] + $d_mfg_cnt,
|
|
#直销件数
|
|
'z_item_cnt' => $depart_data['z_item_cnt'] + $z_item_cnt,
|
|
#直销台数
|
|
'z_mfg_cnt' => $depart_data['z_mfg_cnt'] + $z_mfg_cnt,
|
|
#平台件数
|
|
'p_item_cnt' => $depart_data['p_item_cnt'] + $p_item_cnt,
|
|
#平台台数
|
|
'p_mfg_cnt' => $depart_data['p_mfg_cnt'] + $p_mfg_cnt,
|
|
#台数合计
|
|
'mfg_total' => $depart_data['mfg_total'] + $mfg_total,
|
|
#件数合计
|
|
'item_total' => $depart_data['item_total'] + $item_total,
|
|
#营业人数
|
|
'persons' => $depart_data['persons'] + $persons,
|
|
#人均台数 $z_mfg_cnt + $p_mfg_cnt
|
|
'avg_mfg_total' => ($depart_data['z_mfg_cnt'] + $z_mfg_cnt) / ($depart_data['persons'] + $persons),
|
|
#人均件数
|
|
'avg_item_total' => ($depart_data['z_item_cnt'] + $z_item_cnt) / ($depart_data['persons'] + $persons)
|
|
];
|
|
|
|
|
|
$region_data[$regions['code_name']] = [
|
|
#当月件数
|
|
'd_item_cnt' => $region_data[$regions['code_name']]['d_item_cnt'] + $depart_data['d_item_cnt'],
|
|
#当月台数
|
|
'd_mfg_cnt' => $region_data[$regions['code_name']]['d_mfg_cnt'] + $depart_data['d_mfg_cnt'],
|
|
#直销件数
|
|
'z_item_cnt' => $region_data[$regions['code_name']]['z_item_cnt'] + $depart_data['z_item_cnt'],
|
|
#直销台数
|
|
'z_mfg_cnt' => $region_data[$regions['code_name']]['z_mfg_cnt'] + $depart_data['z_mfg_cnt'],
|
|
#平台件数
|
|
'p_item_cnt' => $region_data[$regions['code_name']]['p_item_cnt'] + $depart_data['p_item_cnt'],
|
|
#平台台数
|
|
'p_mfg_cnt' => $region_data[$regions['code_name']]['p_mfg_cnt'] + $depart_data['p_mfg_cnt'],
|
|
#台数合计
|
|
'mfg_total' => $region_data[$regions['code_name']]['mfg_total'] + $depart_data['mfg_total'],
|
|
#件数合计
|
|
'item_total' => $region_data[$regions['code_name']]['item_total'] + $depart_data['item_total'],
|
|
#营业人数
|
|
'persons' => $region_data[$regions['code_name']]['persons'] + $depart_data['persons'],
|
|
#人均台数 $z_mfg_cnt + $p_mfg_cnt
|
|
'avg_mfg_total' => ($region_data[$regions['code_name']]['z_mfg_cnt'])
|
|
/ ($region_data[$regions['persons']]),
|
|
#人均件数
|
|
'avg_item_total' => ($region_data[$regions['code_name']]['z_item_cnt'])
|
|
/ ($region_data[$regions['persons']]),
|
|
|
|
];
|
|
$depart_data['children'][] = [
|
|
'depart_name' => $salesman['name'],
|
|
#当月件数
|
|
'd_item_cnt' => $d_item_cnt,
|
|
#当月台数
|
|
'd_mfg_cnt' => $d_mfg_cnt,
|
|
#直销件数
|
|
'z_item_cnt' => $z_item_cnt,
|
|
#直销台数
|
|
'z_mfg_cnt' => $z_mfg_cnt,
|
|
#平台件数
|
|
'p_item_cnt' => $p_item_cnt,
|
|
#平台台数
|
|
'p_mfg_cnt' => $p_mfg_cnt,
|
|
#台数合计
|
|
'mfg_total' => $z_mfg_cnt + $p_mfg_cnt,
|
|
#件数合计
|
|
'item_total' => $z_item_cnt + $p_item_cnt,
|
|
#营业人数
|
|
'persons' => 1,
|
|
#人均台数
|
|
'avg_mfg_total' => $z_mfg_cnt + $p_mfg_cnt,
|
|
#人均件数
|
|
'avg_item_total' => $z_item_cnt + $p_item_cnt,
|
|
];
|
|
}
|
|
#大区资料
|
|
if (empty($region_data[$regions['code_name']])) $region_data[$regions['code_name']] = [];
|
|
if ($region_data[$regions['code_name']]['children']) $region_data[$regions['code_name']]['children'] = [];
|
|
array_push($region_data[$regions['code_name']]['children'], $depart_data);
|
|
}
|
|
echo "<pre>";
|
|
var_dump($region_data);
|
|
}
|
|
|