123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace app\index\controller;
- use think\Db;
- class Statistics extends Base
- {
- public function apply(){
- $map['org_id'] = $this->orgId;
- $map['del'] = 0;
- $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){
- $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($v.'-01'))).'-01 00:00:00';
- $c = Db::name('apply')
- ->where($map)
- ->where('create_time','>=',$v.'-01 00:00:00')
- ->where('create_time','<',$nextmonth)
- ->count();
- $counts[] = $c;
- }
- $data = [
- "month" => $month,
- "counts" => $counts
- ];
- ajax_return_ok($data);
- }
- public function approval(){
- $map['org_id'] = $this->orgId;
- $map['del'] = 0;
- $lists = Db::name('approval')->where($map)->field('id,title')->select();
- $data = [];
- $legendData = [];
- foreach ($lists as $k=>$v){
- $legendData[] = $v['title'];
- $map['approval_id'] = $v['id'];
- $val = [
- 'name' => $v['title'],
- 'value' => Db::name('apply')->where($map)->count()
- ];
- $data[] = $val;
- }
- $json = [
- 'legend' => $legendData,
- 'data' => $data
- ];
- ajax_return_ok($json);
- }
- public function contract(){
- $map['org_id'] = $this->orgId;
- $map['del'] = 0;
- $map['status'] = 2;
- $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){
- $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($v.'-01'))).'-01 00:00:00';
- $c = Db::name('apply')
- ->where($map)
- ->where('advanced','in','3,4')
- ->where('create_time','>=',$v.'-01 00:00:00')
- ->where('create_time','<',$nextmonth)
- ->count();
- $counts[] = $c;
- }
- $data = [
- "month" => $month,
- "counts" => $counts
- ];
- ajax_return_ok($data);
- }
- public function contractmoney(){
- $map['org_id'] = $this->orgId;
- $map['del'] = 0;
- $map['status'] = 2;
- $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;
- $advanced = '3,4';
- $counts = [];
- foreach ($month as $k=>$v){
- $money = $this->getApplyMoney($map,$v,$advanced);
- $counts[] = $money;
- }
- $data = [
- "month" => $month,
- "counts" => $counts
- ];
- ajax_return_ok($data);
- }
- public function contractpay(){
- $map['org_id'] = $this->orgId;
- $map['del'] = 0;
- $map['status'] = 2;
- $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;
- $advanced = '5';
- $counts = [];
- foreach ($month as $k=>$v){
- $money = $this->getApplyMoney($map,$v,$advanced);
- $counts[] = $money;
- }
- $data = [
- "month" => $month,
- "counts" => $counts
- ];
- ajax_return_ok($data);
- }
- private function getApplyMoney($map,$v,$advanced){
- $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($v.'-01'))).'-01 00:00:00';
- $lists = Db::name('apply')
- ->where($map)
- ->where('advanced','in',$advanced)
- ->where('create_time','>=',$v.'-01 00:00:00')
- ->where('create_time','<',$nextmonth)
- ->field('id,form_json')
- ->select();
- $money = 0;
- foreach ($lists as $v){
- $formJson = json_decode($v['form_json'],true);
- foreach ($formJson as $kk=>$vv){
- if($vv['componentName'] == 'ddjjcontractfield'||$vv['componentName'] == 'ddaddcontractfield'||$vv['componentName'] == 'ddpaycontractfield'){
- foreach ($vv['components'] as $kkk=>$vvv){
- if($vvv['idx'] === 3){
- $money += $vvv['values'];
- }
- }
- break;
- }
- }
- }
- return $money;
- }
- }
|