123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\hander\HelpHander;
- use think\Db;
- use think\helper\Time;
- class Statistics extends Base
- {
- protected $middleware = [];
- protected $orgId = 4;
- // 用户结构统计
- public function userStructure(){
- // 基建中心人数
- $count1 = model('UserInfo')->getCountByCompany(1);
- // 新华人数
- $count2 = model('UserInfo')->getCountByCompany(2);
- // 其他
- $count0 = model('UserInfo')->getCountByCompany(0);
- $data = [
- [
- "name" => "中心",
- "value" => $count1,
- ],
- [
- "name" => "新华",
- "value" => $count2,
- ],
- [
- "name" => "其他",
- "value" => $count0,
- ]
- ];
- $legend = ['中心','新华','其他'];
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- // 用户性别结构统计
- public function userGenderStructure(){
- // 男
- $count1 = model('UserInfo')->getCountByGender(1);
- // 女
- $count2 = model('UserInfo')->getCountByGender(2);
- $data = [
- [
- "name" => "男",
- "value" => $count1,
- ],
- [
- "name" => "女",
- "value" => $count2,
- ]
- ];
- $legend = ['男','女'];
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- // 用户性别结构统计
- public function userGenderStructure2(){
- $count = model('UserInfo')->getCountByGender2(0);
- $count1 = model('UserInfo')->getCountByGender2(1);
- $count2 = model('UserInfo')->getCountByGender2(2);
- $legend = ['男士','女士'];
- $xdata = ['全部','中心','新华'];
- $data1 = [$count['c1'],$count1['c1'],$count2['c1']];
- $data2 = [$count['c2'],$count1['c2'],$count2['c2']];
- HelpHander::success(['legend' => $legend,'xdata'=>$xdata,'data1'=>$data1,'data2'=>$data2]);
- }
- // 用户党员结构统计
- public function userDangStructure(){
- $count = model('UserInfo')->getDangStructure(0);
- $count1 = model('UserInfo')->getDangStructure(1);
- $count2 = model('UserInfo')->getDangStructure(2);
- $legend = ['党员','非党员'];
- $xdata = ['全部','中心','新华'];
- $data1 = [$count['c1'],$count1['c1'],$count2['c1']];
- $data2 = [$count['c2'],$count1['c2'],$count2['c2']];
- HelpHander::success(['legend' => $legend,'xdata'=>$xdata,'data1'=>$data1,'data2'=>$data2]);
- }
- // 当前个状态人员统计
- public function userSubsidiary(){
- $lists = Db::name('subsidiary')->select();
- $lists = $lists?$lists:[];
- $legend = [];
- $data = [];
- foreach ($lists as $k=>$v){
- $legend[] = $v['title'];
- $data[] = $v['count'];
- }
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- // 人员状态统计
- public function userWorkStructure(){
- $lists = [
- [
- 'id' => 1,
- 'title' => '试用期'
- ],
- [
- 'id' => 2,
- 'title' => '正式'
- ],
- [
- 'id' => 3,
- 'title' => '离职'
- ],
- [
- 'id' => 4,
- 'title' => '退休'
- ],
- ];
- $legend = [];
- $data = [];
- foreach ($lists as $k=>$v){
- $count = model('UserInfo')->getCountByWork($v['id']);
- $legend[] = $v['title'];
- $data[] = $count;
- }
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- // 人员统计
- public function userTypeStructure(){
- $lists = [
- [
- 'id' => 1,
- 'title' => '管理人员'
- ],
- [
- 'id' => 2,
- 'title' => '专业技术人员'
- ],
- [
- 'id' => 3,
- 'title' => '工勤技能人员'
- ]
- ];
- $legend = [];
- $data = [];
- foreach ($lists as $k=>$v){
- $count = model('UserInfo')->getCountByType($v['id']);
- $legend[] = $v['title'];
- $data[] = $count;
- }
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- // 收入支出统计
- public function financeStructure($type = 1){ // 1=当天 2=当月 3=当年
- // 收入
- $income = model('FinanceLog')->financeStructure($this->orgId,$type,1);
- // 支出
- $expenditure = model('FinanceLog')->financeStructure($this->orgId,$type,2);
- $data = [
- [
- "name" => "收入",
- "value" => $income,
- ],
- [
- "name" => "支出",
- "value" => $expenditure,
- ]
- ];
- $yy = $income - $expenditure; // 盈余
- $legend = ['收入','支出'];
- HelpHander::success(['legend' => $legend,'yy'=>$yy,'data'=>$data]);
- }
- // 工资支出统计 $type 1=中心编制 2=新华聘用 3=中心劳务 4=新华劳务 5=中心养老
- public function financeSalaryStructure($type = 1){ // 1=当月 2=当年
- // 中心在编
- $expenditure1 = model('SalaryRecord')->financeSalaryStructure($type,1);
- // 新华聘用
- $expenditure2 = model('SalaryRecord')->financeSalaryStructure($type,2);
- // 中心劳务
- $expenditure3 = model('SalaryRecord')->financeSalaryStructure($type,3);
- // 新华劳务
- $expenditure4 = model('SalaryRecord')->financeSalaryStructure($type,4);
- // 中心养老
- $expenditure5 = model('SalaryRecord')->financeSalaryStructure($type,5);
- $data = [
- [
- "name" => "中心在编",
- "value" => $expenditure1,
- ],
- [
- "name" => "中心养老",
- "value" => $expenditure5,
- ],
- [
- "name" => "新华聘用",
- "value" => $expenditure2,
- ],
- [
- "name" => "新华劳务",
- "value" => $expenditure4,
- ],
- [
- "name" => "中心劳务",
- "value" => $expenditure3,
- ],
- ];
- $total = $expenditure1 + $expenditure2 + $expenditure3 + $expenditure4 + $expenditure5;
- $legend = ['中心在编','中心养老','中心劳务','新华聘用','新华劳务'];
- HelpHander::success(['legend' => $legend,'total'=>$total,'data'=>$data]);
- }
- // 经营性房产统计
- public function house(){
- $lists = [
- [
- 'id' => 0,
- 'title' => '未租赁'
- ],
- [
- 'id' => 1,
- 'title' => '已租赁'
- ]
- ];
- $counts = model('House')->getCountByLessee();
- $legend = [];
- $data = [];
- foreach ($lists as $k=>$v){
- $legend[] = $v['title'];
- if($v['id'] == 0){
- $data[] = [
- 'name' => $v['title'],
- 'value' => $counts['count2']
- ];
- }else{
- $data[] = [
- 'name' => $v['title'],
- 'value' => $counts['count1']
- ];
- }
- }
- HelpHander::success(['legend' => $legend,'total'=>$counts['total'],'data'=>$data]);
- }
- // 经营性房产合同金额统计
- public function houseContractMoney(){
- $count = model('House')->getHouseContractMoney();
- $legend = ['应收合同金额','实收金额'];
- $xdata = ['经营性房产'];
- $data1 = [$count['c1']];
- $data2 = [$count['c2']];
- HelpHander::success(['legend' => $legend,'xdata'=>$xdata,'data1'=>$data1,'data2'=>$data2]);
- }
- // 周转房房产统计
- public function houseTurn(){
- $lists = [
- [
- 'id' => 0,
- 'title' => '未入住'
- ],
- [
- 'id' => 1,
- 'title' => '已入住'
- ]
- ];
- $legend = [];
- $data = [];
- $total = 0;
- foreach ($lists as $k=>$v){
- $count = model('HouseTurn')->getCountByLessee($v['id']);
- $legend[] = $v['title'];
- $data[] = [
- 'name' => $v['title'],
- 'value' => $count
- ];
- $total += $count;
- }
- HelpHander::success(['legend' => $legend,'total'=>$total,'data'=>$data]);
- }
- public function houseTurnArea(){
- // 70及以下
- $count1 = model('HouseTurn')->getArea(1);
- // 70-90
- $count2 = model('HouseTurn')->getArea(2);
- // 90-110
- $count3 = model('HouseTurn')->getArea(3);
- // 110以上
- $count4 = model('HouseTurn')->getArea(4);
- $data = [
- [
- "name" => "70及以下",
- "value" => $count1,
- ],
- [
- "name" => "70-90",
- "value" => $count2,
- ],
- [
- "name" => "90-110",
- "value" => $count3,
- ],
- [
- "name" => "110以上",
- "value" => $count4,
- ]
- ];
- $legend = ['70及以下','70-90','90-110','110以上'];
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- public function contract(){
- $lists = [
- [
- 'id' => 0,
- 'title' => '未办结'
- ],
- [
- 'id' => 1,
- 'title' => '已办结'
- ]
- ];
- $legend = [];
- $data = [];
- foreach ($lists as $k=>$v){
- $count = model('Contract')->getCountByTransferred($v['id']);
- $legend[] = $v['title'];
- $data[] = [
- 'name' => $v['title'],
- 'value' => $count
- ];
- }
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- public function contractMoney(){
- $cur = date('Y-m');
- $curTime = strtotime($cur.'-01');
- $month = [];
- for ($i=5;$i>0;$i--){
- $date = strtotime("-".$i." month",$curTime);
- $month[] = date('Y-m',$date);
- }
- $month[] = $cur;
- $counts = [];
- foreach ($month as $k=>$v){
- $money = model('Contract')->getContractMoneyByMonth($v);
- $counts[] = $money;
- }
- $data = [
- "month" => $month,
- "counts" => $counts
- ];
- ajax_return_ok($data);
- }
- // 资产数量
- public function assetItem(){
- $lists = [
- [
- 'id' => 1,
- 'title' => '中心'
- ],
- [
- 'id' => 2,
- 'title' => '新华'
- ]
- ];
- $legend = [];
- $data = [];
- foreach ($lists as $k=>$v){
- $count = model('AssetItems')->getCountByCompany($v['id']);
- $legend[] = $v['title'];
- $data[] = [
- 'name' => $v['title'],
- 'value' => $count
- ];
- }
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- // 资产价值
- public function assetItemPrice(){
- $lists = [
- [
- 'id' => 1,
- 'title' => '中心'
- ],
- [
- 'id' => 2,
- 'title' => '新华'
- ]
- ];
- $legend = [];
- $data = [];
- foreach ($lists as $k=>$v){
- $count = model('AssetItems')->getMoneyByCompany($v['id']);
- $legend[] = $v['title'];
- $data[] = [
- 'name' => $v['title'],
- 'value' => $count
- ];
- }
- HelpHander::success(['legend' => $legend,'data'=>$data]);
- }
- public function contractPay(){
- $year = date('Y');
- $month = [];
- for ($i = 1;$i <= 12;$i++) {
- if($i >= 10){
- $month[] = $year.'-'.$i;
- }else{
- $month[] = $year.'-0'.$i;
- }
- }
- $money1 = [];
- $money2 = [];
- foreach ($month as $k=>$v){
- $start = $v.'-01 00:00:00';
- $end = date("Y-m-d H:i:s",strtotime("+1 month",strtotime($start)));
- $m1 = Db::name('contract_pay')
- ->where('ispay',1)
- ->where('status',1)
- ->where('create_time','>=',$start)
- ->where('create_time','<',$end)
- ->sum('money');
- $money1[] = [
- 'month' => $v,
- 'money' => $m1
- ];
- $m2 = Db::name('contract_pay')
- ->where('ispay',2)
- ->where('status',1)
- ->where('create_time','>=',$start)
- ->where('create_time','<',$end)
- ->sum('money');
- $money2[] = [
- 'month' => $v,
- 'money' => $m2
- ];
- }
- $data = [
- "month" => $month,
- "money1" => $money1,
- "money2" => $money2,
- ];
- HelpHander::success($data);
- }
- public function car(){
- list($start, $end) = Time::month();
- $start = date('Y-m-d H:i:s',$start);
- $end = date('Y-m-d H:i:s',$end);
- $carids = Db::name('car_record')
- ->where('status',1)
- ->where('start_time','>=',$start)
- ->where('start_time','<=',$end)
- ->group('car_id')
- ->distinct(true)
- ->column('car_id');
- if(!$carids){
- return ['total'=>0,'carcount' => 0, 'cars' => []];
- }
- $total = Db::name('car_record')
- ->where('status',1)
- ->where('start_time','>=',$start)
- ->where('start_time','<=',$end)
- ->count();
- $map[] = ['id','in',$carids];
- $cars = Db::name('car')
- ->where($map)
- ->field('id,title,sn')
- ->order('id asc')
- ->select();
- foreach ($cars as $k=>$v){
- $cars[$k]['count'] = Db::name('car_record')
- ->where('status',1)
- ->where('car_id',1)
- ->where('start_time','>=',$start)
- ->where('start_time','<=',$end)
- ->count();
- }
- return ['total'=>$total,'carcount' => count($carids), 'cars' => $cars?$cars:[]];
- }
- // 本月用印 official_seal ,用印审批id是90
- public function seal(){
- $approval_id = 90;
- list($start, $end) = Time::month();
- $start = date('Y-m-d H:i:s',$start);
- $end = date('Y-m-d H:i:s',$end);
- $applys = Db::name('apply')
- ->where('status',2)
- ->where('del',0)
- ->where('finish_time','>=',$start)
- ->where('finish_time','<=',$end)
- ->where('approval_id',$approval_id)
- ->field('id,form_json')
- ->select();
- $seals = [];
- foreach ($applys as $k=>$v){
- $lists[$k]['seallist'] = [];
- $formJson = json_decode($v['form_json'],true);
- foreach ($formJson as $kk=>$vv){
- if($vv['componentName'] == 'ddofficialsealfield'){
- $seallist = json_decode($vv['values'],true);
- $seallist = $seallist?$seallist:[];
- $slist = [];
- foreach ($seallist as $key=>$val){
- $slist[] = $val['title'];
- if(!in_array($val['title'],$seals)){
- $seals[] = $val['title'];
- }
- }
- $lists[$k]['seallist'] = $slist;
- }
- }
- }
- $sealss = [];
- foreach ($seals as $key=>$val){
- $count = 0;
- foreach ($applys as $k=>$v){
- if(in_array($val,$v['seallist'])){
- $count++;
- }
- }
- $sealss[] = [
- 'title' => $val,
- 'count' => $count
- ];
- }
- $data = ['total'=>count($seals),'count' => count($applys), 'sealss' => $sealss];
- HelpHander::success($data);
- }
- // 本月发文 ,发文审批id是89
- public function posts(){
- $approval_id = 89;
- list($start, $end) = Time::month();
- $start = date('Y-m-d H:i:s',$start);
- $end = date('Y-m-d H:i:s',$end);
- $applys = Db::name('apply')
- ->where('status',2)
- ->where('del',0)
- ->where('finish_time','>=',$start)
- ->where('finish_time','<=',$end)
- ->where('approval_id',$approval_id)
- ->field('id,form_json')
- ->select();
- $seals = [];
- foreach ($applys as $k=>$v){
- $applys[$k]['posts'] = '';
- $formJson = json_decode($v['form_json'],true);
- foreach ($formJson as $kk=>$vv){
- if($vv['componentName'] == 'ddselectfield'){
- if(!in_array($vv['values'],$seals)){
- $seals[] = $vv['values'];
- }
- $applys[$k]['posts'] = $vv['values'];
- }
- }
- }
- $sealss = [];
- foreach ($seals as $key=>$val){
- $count = 0;
- foreach ($applys as $k=>$v){
- if($val ==$v['posts']){
- $count++;
- }
- }
- $sealss[] = [
- 'title' => $val,
- 'count' => $count
- ];
- }
- $data = ['total'=>count($seals),'count' => count($applys), 'posts' => $sealss];
- HelpHander::success($data);
- }
- // 工资统计
- public function salary(){
- $month = input('month','','trim');
- $data = [
- [
- 'id' => 1,
- 'title' => '中心在编',
- 'total' => 0,
- 'money' => 0
- ],
- [
- 'id' => 2,
- 'title' => '新华聘用',
- 'total' => 0,
- 'money' => 0
- ],
- [
- 'id' => 3,
- 'title' => '中心劳务',
- 'total' => 0,
- 'money' => 0
- ],
- [
- 'id' => 4,
- 'title' => '新华劳务',
- 'total' => 0,
- 'money' => 0
- ],
- [
- 'id' => 5,
- 'title' => '中心退休',
- 'total' => 0,
- 'money' => 0
- ],
- ];
- $total = 0;
- $money = 0;
- foreach ($data as $k=>$v){
- if($v['id'] == 5){ // 中心退休
- $count = Db::name('user_retired_salary')
- ->alias('a')
- ->join('salary_record sr','sr.id = a.salary_record_id')
- ->where('sr.status',3)
- ->where('sr.month',$month)
- ->count();
- $data[$k]['total'] = $count;
- $total += $count;
- $salary = Db::name('user_retired_salary')
- ->alias('a')
- ->join('salary_record sr','sr.id = a.salary_record_id')
- ->where('sr.status',3)
- ->where('sr.month',$month)
- ->sum('salary');
- $data[$k]['money'] = $salary;
- $money += $salary;
- }else{
- $count = Db::name('salary_record_log')
- ->alias('a')
- ->join('salary_record sr','sr.id = a.salary_record_id')
- ->where('sr.status',3)
- ->where('sr.type',$v['id'])
- ->where('sr.month',$month)
- ->count();
- $data[$k]['total'] = $count;
- $total += $count;
- $salary = Db::name('salary_record_log')
- ->alias('a')
- ->join('salary_record sr','sr.id = a.salary_record_id')
- ->where('sr.status',3)
- ->where('sr.month',$month)
- ->where('sr.type',$v['id'])
- ->sum('salary');
- $data[$k]['money'] = $salary;
- $money += $salary;
- }
- }
- $json = ['total'=>$total,'money' => $money, 'list' => $data];
- HelpHander::success($json);
- }
- public function houseMoney(){
- $cur = date('Y');
- $curTime = strtotime($cur.'-01-01');
- $month = [];
- for ($i=0;$i<12;$i++){
- $date = strtotime("+".$i." month",$curTime);
- $month[] = date('Y-m',$date);
- }
- // $month[] = $cur;
- $counts = [];
- foreach ($month as $k=>$v){
- $money = model('HouseContractPay')->getPayMoneyByMonth($v);
- $counts[] = $money;
- }
- $data = [
- "month" => $month,
- "counts" => $counts
- ];
- ajax_return_ok($data);
- }
- }
|