Statistics.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. use think\helper\Time;
  7. class Statistics extends Base
  8. {
  9. protected $middleware = [];
  10. protected $orgId = 4;
  11. // 用户结构统计
  12. public function userStructure(){
  13. // 基建中心人数
  14. $count1 = model('UserInfo')->getCountByCompany(1);
  15. // 新华人数
  16. $count2 = model('UserInfo')->getCountByCompany(2);
  17. // 其他
  18. $count0 = model('UserInfo')->getCountByCompany(0);
  19. $data = [
  20. [
  21. "name" => "中心",
  22. "value" => $count1,
  23. ],
  24. [
  25. "name" => "新华",
  26. "value" => $count2,
  27. ],
  28. [
  29. "name" => "其他",
  30. "value" => $count0,
  31. ]
  32. ];
  33. $legend = ['中心','新华','其他'];
  34. HelpHander::success(['legend' => $legend,'data'=>$data]);
  35. }
  36. // 用户性别结构统计
  37. public function userGenderStructure(){
  38. // 男
  39. $count1 = model('UserInfo')->getCountByGender(1);
  40. // 女
  41. $count2 = model('UserInfo')->getCountByGender(2);
  42. $data = [
  43. [
  44. "name" => "男",
  45. "value" => $count1,
  46. ],
  47. [
  48. "name" => "女",
  49. "value" => $count2,
  50. ]
  51. ];
  52. $legend = ['男','女'];
  53. HelpHander::success(['legend' => $legend,'data'=>$data]);
  54. }
  55. // 用户性别结构统计
  56. public function userGenderStructure2(){
  57. $count = model('UserInfo')->getCountByGender2(0);
  58. $count1 = model('UserInfo')->getCountByGender2(1);
  59. $count2 = model('UserInfo')->getCountByGender2(2);
  60. $legend = ['男士','女士'];
  61. $xdata = ['全部','中心','新华'];
  62. $data1 = [$count['c1'],$count1['c1'],$count2['c1']];
  63. $data2 = [$count['c2'],$count1['c2'],$count2['c2']];
  64. HelpHander::success(['legend' => $legend,'xdata'=>$xdata,'data1'=>$data1,'data2'=>$data2]);
  65. }
  66. // 用户党员结构统计
  67. public function userDangStructure(){
  68. $count = model('UserInfo')->getDangStructure(0);
  69. $count1 = model('UserInfo')->getDangStructure(1);
  70. $count2 = model('UserInfo')->getDangStructure(2);
  71. $legend = ['党员','非党员'];
  72. $xdata = ['全部','中心','新华'];
  73. $data1 = [$count['c1'],$count1['c1'],$count2['c1']];
  74. $data2 = [$count['c2'],$count1['c2'],$count2['c2']];
  75. HelpHander::success(['legend' => $legend,'xdata'=>$xdata,'data1'=>$data1,'data2'=>$data2]);
  76. }
  77. // 当前个状态人员统计
  78. public function userSubsidiary(){
  79. $lists = Db::name('subsidiary')->select();
  80. $lists = $lists?$lists:[];
  81. $legend = [];
  82. $data = [];
  83. foreach ($lists as $k=>$v){
  84. $legend[] = $v['title'];
  85. $data[] = $v['count'];
  86. }
  87. HelpHander::success(['legend' => $legend,'data'=>$data]);
  88. }
  89. // 人员状态统计
  90. public function userWorkStructure(){
  91. $lists = [
  92. [
  93. 'id' => 1,
  94. 'title' => '试用期'
  95. ],
  96. [
  97. 'id' => 2,
  98. 'title' => '正式'
  99. ],
  100. [
  101. 'id' => 3,
  102. 'title' => '离职'
  103. ],
  104. [
  105. 'id' => 4,
  106. 'title' => '退休'
  107. ],
  108. ];
  109. $legend = [];
  110. $data = [];
  111. foreach ($lists as $k=>$v){
  112. $count = model('UserInfo')->getCountByWork($v['id']);
  113. $legend[] = $v['title'];
  114. $data[] = $count;
  115. }
  116. HelpHander::success(['legend' => $legend,'data'=>$data]);
  117. }
  118. // 人员统计
  119. public function userTypeStructure(){
  120. $lists = [
  121. [
  122. 'id' => 1,
  123. 'title' => '管理人员'
  124. ],
  125. [
  126. 'id' => 2,
  127. 'title' => '专业技术人员'
  128. ],
  129. [
  130. 'id' => 3,
  131. 'title' => '工勤技能人员'
  132. ]
  133. ];
  134. $legend = [];
  135. $data = [];
  136. foreach ($lists as $k=>$v){
  137. $count = model('UserInfo')->getCountByType($v['id']);
  138. $legend[] = $v['title'];
  139. $data[] = $count;
  140. }
  141. HelpHander::success(['legend' => $legend,'data'=>$data]);
  142. }
  143. // 收入支出统计
  144. public function financeStructure($type = 1){ // 1=当天 2=当月 3=当年
  145. // 收入
  146. $income = model('FinanceLog')->financeStructure($this->orgId,$type,1);
  147. // 支出
  148. $expenditure = model('FinanceLog')->financeStructure($this->orgId,$type,2);
  149. $data = [
  150. [
  151. "name" => "收入",
  152. "value" => $income,
  153. ],
  154. [
  155. "name" => "支出",
  156. "value" => $expenditure,
  157. ]
  158. ];
  159. $yy = $income - $expenditure; // 盈余
  160. $legend = ['收入','支出'];
  161. HelpHander::success(['legend' => $legend,'yy'=>$yy,'data'=>$data]);
  162. }
  163. // 工资支出统计 $type 1=中心编制 2=新华聘用 3=中心劳务 4=新华劳务 5=中心养老
  164. public function financeSalaryStructure($type = 1){ // 1=当月 2=当年
  165. // 中心在编
  166. $expenditure1 = model('SalaryRecord')->financeSalaryStructure($type,1);
  167. // 新华聘用
  168. $expenditure2 = model('SalaryRecord')->financeSalaryStructure($type,2);
  169. // 中心劳务
  170. $expenditure3 = model('SalaryRecord')->financeSalaryStructure($type,3);
  171. // 新华劳务
  172. $expenditure4 = model('SalaryRecord')->financeSalaryStructure($type,4);
  173. // 中心养老
  174. $expenditure5 = model('SalaryRecord')->financeSalaryStructure($type,5);
  175. $data = [
  176. [
  177. "name" => "中心在编",
  178. "value" => $expenditure1,
  179. ],
  180. [
  181. "name" => "中心养老",
  182. "value" => $expenditure5,
  183. ],
  184. [
  185. "name" => "新华聘用",
  186. "value" => $expenditure2,
  187. ],
  188. [
  189. "name" => "新华劳务",
  190. "value" => $expenditure4,
  191. ],
  192. [
  193. "name" => "中心劳务",
  194. "value" => $expenditure3,
  195. ],
  196. ];
  197. $total = $expenditure1 + $expenditure2 + $expenditure3 + $expenditure4 + $expenditure5;
  198. $legend = ['中心在编','中心养老','中心劳务','新华聘用','新华劳务'];
  199. HelpHander::success(['legend' => $legend,'total'=>$total,'data'=>$data]);
  200. }
  201. // 经营性房产统计
  202. public function house(){
  203. $lists = [
  204. [
  205. 'id' => 0,
  206. 'title' => '未租赁'
  207. ],
  208. [
  209. 'id' => 1,
  210. 'title' => '已租赁'
  211. ]
  212. ];
  213. $counts = model('House')->getCountByLessee();
  214. $legend = [];
  215. $data = [];
  216. foreach ($lists as $k=>$v){
  217. $legend[] = $v['title'];
  218. if($v['id'] == 0){
  219. $data[] = [
  220. 'name' => $v['title'],
  221. 'value' => $counts['count2']
  222. ];
  223. }else{
  224. $data[] = [
  225. 'name' => $v['title'],
  226. 'value' => $counts['count1']
  227. ];
  228. }
  229. }
  230. HelpHander::success(['legend' => $legend,'total'=>$counts['total'],'data'=>$data]);
  231. }
  232. // 经营性房产合同金额统计
  233. public function houseContractMoney(){
  234. $count = model('House')->getHouseContractMoney();
  235. $legend = ['应收合同金额','实收金额'];
  236. $xdata = ['经营性房产'];
  237. $data1 = [$count['c1']];
  238. $data2 = [$count['c2']];
  239. HelpHander::success(['legend' => $legend,'xdata'=>$xdata,'data1'=>$data1,'data2'=>$data2]);
  240. }
  241. // 周转房房产统计
  242. public function houseTurn(){
  243. $lists = [
  244. [
  245. 'id' => 0,
  246. 'title' => '未入住'
  247. ],
  248. [
  249. 'id' => 1,
  250. 'title' => '已入住'
  251. ]
  252. ];
  253. $legend = [];
  254. $data = [];
  255. $total = 0;
  256. foreach ($lists as $k=>$v){
  257. $count = model('HouseTurn')->getCountByLessee($v['id']);
  258. $legend[] = $v['title'];
  259. $data[] = [
  260. 'name' => $v['title'],
  261. 'value' => $count
  262. ];
  263. $total += $count;
  264. }
  265. HelpHander::success(['legend' => $legend,'total'=>$total,'data'=>$data]);
  266. }
  267. public function houseTurnArea(){
  268. // 70及以下
  269. $count1 = model('HouseTurn')->getArea(1);
  270. // 70-90
  271. $count2 = model('HouseTurn')->getArea(2);
  272. // 90-110
  273. $count3 = model('HouseTurn')->getArea(3);
  274. // 110以上
  275. $count4 = model('HouseTurn')->getArea(4);
  276. $data = [
  277. [
  278. "name" => "70及以下",
  279. "value" => $count1,
  280. ],
  281. [
  282. "name" => "70-90",
  283. "value" => $count2,
  284. ],
  285. [
  286. "name" => "90-110",
  287. "value" => $count3,
  288. ],
  289. [
  290. "name" => "110以上",
  291. "value" => $count4,
  292. ]
  293. ];
  294. $legend = ['70及以下','70-90','90-110','110以上'];
  295. HelpHander::success(['legend' => $legend,'data'=>$data]);
  296. }
  297. public function contract(){
  298. $lists = [
  299. [
  300. 'id' => 0,
  301. 'title' => '未办结'
  302. ],
  303. [
  304. 'id' => 1,
  305. 'title' => '已办结'
  306. ]
  307. ];
  308. $legend = [];
  309. $data = [];
  310. foreach ($lists as $k=>$v){
  311. $count = model('Contract')->getCountByTransferred($v['id']);
  312. $legend[] = $v['title'];
  313. $data[] = [
  314. 'name' => $v['title'],
  315. 'value' => $count
  316. ];
  317. }
  318. HelpHander::success(['legend' => $legend,'data'=>$data]);
  319. }
  320. public function contractMoney(){
  321. $cur = date('Y-m');
  322. $curTime = strtotime($cur.'-01');
  323. $month = [];
  324. for ($i=5;$i>0;$i--){
  325. $date = strtotime("-".$i." month",$curTime);
  326. $month[] = date('Y-m',$date);
  327. }
  328. $month[] = $cur;
  329. $counts = [];
  330. foreach ($month as $k=>$v){
  331. $money = model('Contract')->getContractMoneyByMonth($v);
  332. $counts[] = $money;
  333. }
  334. $data = [
  335. "month" => $month,
  336. "counts" => $counts
  337. ];
  338. ajax_return_ok($data);
  339. }
  340. // 资产数量
  341. public function assetItem(){
  342. $lists = [
  343. [
  344. 'id' => 1,
  345. 'title' => '中心'
  346. ],
  347. [
  348. 'id' => 2,
  349. 'title' => '新华'
  350. ]
  351. ];
  352. $legend = [];
  353. $data = [];
  354. foreach ($lists as $k=>$v){
  355. $count = model('AssetItems')->getCountByCompany($v['id']);
  356. $legend[] = $v['title'];
  357. $data[] = [
  358. 'name' => $v['title'],
  359. 'value' => $count
  360. ];
  361. }
  362. HelpHander::success(['legend' => $legend,'data'=>$data]);
  363. }
  364. // 资产价值
  365. public function assetItemPrice(){
  366. $lists = [
  367. [
  368. 'id' => 1,
  369. 'title' => '中心'
  370. ],
  371. [
  372. 'id' => 2,
  373. 'title' => '新华'
  374. ]
  375. ];
  376. $legend = [];
  377. $data = [];
  378. foreach ($lists as $k=>$v){
  379. $count = model('AssetItems')->getMoneyByCompany($v['id']);
  380. $legend[] = $v['title'];
  381. $data[] = [
  382. 'name' => $v['title'],
  383. 'value' => $count
  384. ];
  385. }
  386. HelpHander::success(['legend' => $legend,'data'=>$data]);
  387. }
  388. public function contractPay(){
  389. $year = date('Y');
  390. $month = [];
  391. for ($i = 1;$i <= 12;$i++) {
  392. if($i >= 10){
  393. $month[] = $year.'-'.$i;
  394. }else{
  395. $month[] = $year.'-0'.$i;
  396. }
  397. }
  398. $money1 = [];
  399. $money2 = [];
  400. foreach ($month as $k=>$v){
  401. $start = $v.'-01 00:00:00';
  402. $end = date("Y-m-d H:i:s",strtotime("+1 month",strtotime($start)));
  403. $m1 = Db::name('contract_pay')
  404. ->where('ispay',1)
  405. ->where('status',1)
  406. ->where('create_time','>=',$start)
  407. ->where('create_time','<',$end)
  408. ->sum('money');
  409. $money1[] = [
  410. 'month' => $v,
  411. 'money' => $m1
  412. ];
  413. $m2 = Db::name('contract_pay')
  414. ->where('ispay',2)
  415. ->where('status',1)
  416. ->where('create_time','>=',$start)
  417. ->where('create_time','<',$end)
  418. ->sum('money');
  419. $money2[] = [
  420. 'month' => $v,
  421. 'money' => $m2
  422. ];
  423. }
  424. $data = [
  425. "month" => $month,
  426. "money1" => $money1,
  427. "money2" => $money2,
  428. ];
  429. HelpHander::success($data);
  430. }
  431. public function car(){
  432. list($start, $end) = Time::month();
  433. $start = date('Y-m-d H:i:s',$start);
  434. $end = date('Y-m-d H:i:s',$end);
  435. $carids = Db::name('car_record')
  436. ->where('status',1)
  437. ->where('start_time','>=',$start)
  438. ->where('start_time','<=',$end)
  439. ->group('car_id')
  440. ->distinct(true)
  441. ->column('car_id');
  442. if(!$carids){
  443. return ['total'=>0,'carcount' => 0, 'cars' => []];
  444. }
  445. $total = Db::name('car_record')
  446. ->where('status',1)
  447. ->where('start_time','>=',$start)
  448. ->where('start_time','<=',$end)
  449. ->count();
  450. $map[] = ['id','in',$carids];
  451. $cars = Db::name('car')
  452. ->where($map)
  453. ->field('id,title,sn')
  454. ->order('id asc')
  455. ->select();
  456. foreach ($cars as $k=>$v){
  457. $cars[$k]['count'] = Db::name('car_record')
  458. ->where('status',1)
  459. ->where('car_id',1)
  460. ->where('start_time','>=',$start)
  461. ->where('start_time','<=',$end)
  462. ->count();
  463. }
  464. return ['total'=>$total,'carcount' => count($carids), 'cars' => $cars?$cars:[]];
  465. }
  466. // 本月用印 official_seal ,用印审批id是90
  467. public function seal(){
  468. $approval_id = 90;
  469. list($start, $end) = Time::month();
  470. $start = date('Y-m-d H:i:s',$start);
  471. $end = date('Y-m-d H:i:s',$end);
  472. $applys = Db::name('apply')
  473. ->where('status',2)
  474. ->where('del',0)
  475. ->where('finish_time','>=',$start)
  476. ->where('finish_time','<=',$end)
  477. ->where('approval_id',$approval_id)
  478. ->field('id,form_json')
  479. ->select();
  480. $seals = [];
  481. foreach ($applys as $k=>$v){
  482. $lists[$k]['seallist'] = [];
  483. $formJson = json_decode($v['form_json'],true);
  484. foreach ($formJson as $kk=>$vv){
  485. if($vv['componentName'] == 'ddofficialsealfield'){
  486. $seallist = json_decode($vv['values'],true);
  487. $seallist = $seallist?$seallist:[];
  488. $slist = [];
  489. foreach ($seallist as $key=>$val){
  490. $slist[] = $val['title'];
  491. if(!in_array($val['title'],$seals)){
  492. $seals[] = $val['title'];
  493. }
  494. }
  495. $lists[$k]['seallist'] = $slist;
  496. }
  497. }
  498. }
  499. $sealss = [];
  500. foreach ($seals as $key=>$val){
  501. $count = 0;
  502. foreach ($applys as $k=>$v){
  503. if(in_array($val,$v['seallist'])){
  504. $count++;
  505. }
  506. }
  507. $sealss[] = [
  508. 'title' => $val,
  509. 'count' => $count
  510. ];
  511. }
  512. $data = ['total'=>count($seals),'count' => count($applys), 'sealss' => $sealss];
  513. HelpHander::success($data);
  514. }
  515. // 本月发文 ,发文审批id是89
  516. public function posts(){
  517. $approval_id = 89;
  518. list($start, $end) = Time::month();
  519. $start = date('Y-m-d H:i:s',$start);
  520. $end = date('Y-m-d H:i:s',$end);
  521. $applys = Db::name('apply')
  522. ->where('status',2)
  523. ->where('del',0)
  524. ->where('finish_time','>=',$start)
  525. ->where('finish_time','<=',$end)
  526. ->where('approval_id',$approval_id)
  527. ->field('id,form_json')
  528. ->select();
  529. $seals = [];
  530. foreach ($applys as $k=>$v){
  531. $applys[$k]['posts'] = '';
  532. $formJson = json_decode($v['form_json'],true);
  533. foreach ($formJson as $kk=>$vv){
  534. if($vv['componentName'] == 'ddselectfield'){
  535. if(!in_array($vv['values'],$seals)){
  536. $seals[] = $vv['values'];
  537. }
  538. $applys[$k]['posts'] = $vv['values'];
  539. }
  540. }
  541. }
  542. $sealss = [];
  543. foreach ($seals as $key=>$val){
  544. $count = 0;
  545. foreach ($applys as $k=>$v){
  546. if($val ==$v['posts']){
  547. $count++;
  548. }
  549. }
  550. $sealss[] = [
  551. 'title' => $val,
  552. 'count' => $count
  553. ];
  554. }
  555. $data = ['total'=>count($seals),'count' => count($applys), 'posts' => $sealss];
  556. HelpHander::success($data);
  557. }
  558. // 工资统计
  559. public function salary(){
  560. $month = input('month','','trim');
  561. $data = [
  562. [
  563. 'id' => 1,
  564. 'title' => '中心在编',
  565. 'total' => 0,
  566. 'money' => 0
  567. ],
  568. [
  569. 'id' => 2,
  570. 'title' => '新华聘用',
  571. 'total' => 0,
  572. 'money' => 0
  573. ],
  574. [
  575. 'id' => 3,
  576. 'title' => '中心劳务',
  577. 'total' => 0,
  578. 'money' => 0
  579. ],
  580. [
  581. 'id' => 4,
  582. 'title' => '新华劳务',
  583. 'total' => 0,
  584. 'money' => 0
  585. ],
  586. [
  587. 'id' => 5,
  588. 'title' => '中心退休',
  589. 'total' => 0,
  590. 'money' => 0
  591. ],
  592. ];
  593. $total = 0;
  594. $money = 0;
  595. foreach ($data as $k=>$v){
  596. if($v['id'] == 5){ // 中心退休
  597. $count = Db::name('user_retired_salary')
  598. ->alias('a')
  599. ->join('salary_record sr','sr.id = a.salary_record_id')
  600. ->where('sr.status',3)
  601. ->where('sr.month',$month)
  602. ->count();
  603. $data[$k]['total'] = $count;
  604. $total += $count;
  605. $salary = Db::name('user_retired_salary')
  606. ->alias('a')
  607. ->join('salary_record sr','sr.id = a.salary_record_id')
  608. ->where('sr.status',3)
  609. ->where('sr.month',$month)
  610. ->sum('salary');
  611. $data[$k]['money'] = $salary;
  612. $money += $salary;
  613. }else{
  614. $count = Db::name('salary_record_log')
  615. ->alias('a')
  616. ->join('salary_record sr','sr.id = a.salary_record_id')
  617. ->where('sr.status',3)
  618. ->where('sr.type',$v['id'])
  619. ->where('sr.month',$month)
  620. ->count();
  621. $data[$k]['total'] = $count;
  622. $total += $count;
  623. $salary = Db::name('salary_record_log')
  624. ->alias('a')
  625. ->join('salary_record sr','sr.id = a.salary_record_id')
  626. ->where('sr.status',3)
  627. ->where('sr.month',$month)
  628. ->where('sr.type',$v['id'])
  629. ->sum('salary');
  630. $data[$k]['money'] = $salary;
  631. $money += $salary;
  632. }
  633. }
  634. $json = ['total'=>$total,'money' => $money, 'list' => $data];
  635. HelpHander::success($json);
  636. }
  637. public function houseMoney(){
  638. $cur = date('Y');
  639. $curTime = strtotime($cur.'-01-01');
  640. $month = [];
  641. for ($i=0;$i<12;$i++){
  642. $date = strtotime("+".$i." month",$curTime);
  643. $month[] = date('Y-m',$date);
  644. }
  645. // $month[] = $cur;
  646. $counts = [];
  647. foreach ($month as $k=>$v){
  648. $money = model('HouseContractPay')->getPayMoneyByMonth($v);
  649. $counts[] = $money;
  650. }
  651. $data = [
  652. "month" => $month,
  653. "counts" => $counts
  654. ];
  655. ajax_return_ok($data);
  656. }
  657. }