Statistics.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\index\controller;
  3. use think\Db;
  4. class Statistics extends Base
  5. {
  6. public function apply(){
  7. $map['org_id'] = $this->orgId;
  8. $map['del'] = 0;
  9. $cur = date('Y-m');
  10. $curTime = strtotime($cur.'-01');
  11. $month = [];
  12. for ($i=5;$i>0;$i--){
  13. $date = strtotime("-".$i." month",$curTime);
  14. $month[] = date('Y-m',$date);
  15. }
  16. $month[] = $cur;
  17. $counts = [];
  18. foreach ($month as $k=>$v){
  19. $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($v.'-01'))).'-01 00:00:00';
  20. $c = Db::name('apply')
  21. ->where($map)
  22. ->where('create_time','>=',$v.'-01 00:00:00')
  23. ->where('create_time','<',$nextmonth)
  24. ->count();
  25. $counts[] = $c;
  26. }
  27. $data = [
  28. "month" => $month,
  29. "counts" => $counts
  30. ];
  31. ajax_return_ok($data);
  32. }
  33. public function approval(){
  34. $map['org_id'] = $this->orgId;
  35. $map['del'] = 0;
  36. $lists = Db::name('approval')->where($map)->field('id,title')->select();
  37. $data = [];
  38. $legendData = [];
  39. foreach ($lists as $k=>$v){
  40. $legendData[] = $v['title'];
  41. $map['approval_id'] = $v['id'];
  42. $val = [
  43. 'name' => $v['title'],
  44. 'value' => Db::name('apply')->where($map)->count()
  45. ];
  46. $data[] = $val;
  47. }
  48. $json = [
  49. 'legend' => $legendData,
  50. 'data' => $data
  51. ];
  52. ajax_return_ok($json);
  53. }
  54. public function contract(){
  55. $map['org_id'] = $this->orgId;
  56. $map['del'] = 0;
  57. $map['status'] = 2;
  58. $cur = date('Y-m');
  59. $curTime = strtotime($cur.'-01');
  60. $month = [];
  61. for ($i=5;$i>0;$i--){
  62. $date = strtotime("-".$i." month",$curTime);
  63. $month[] = date('Y-m',$date);
  64. }
  65. $month[] = $cur;
  66. $counts = [];
  67. foreach ($month as $k=>$v){
  68. $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($v.'-01'))).'-01 00:00:00';
  69. $c = Db::name('apply')
  70. ->where($map)
  71. ->where('advanced','in','3,4')
  72. ->where('create_time','>=',$v.'-01 00:00:00')
  73. ->where('create_time','<',$nextmonth)
  74. ->count();
  75. $counts[] = $c;
  76. }
  77. $data = [
  78. "month" => $month,
  79. "counts" => $counts
  80. ];
  81. ajax_return_ok($data);
  82. }
  83. public function contractmoney(){
  84. $map['org_id'] = $this->orgId;
  85. $map['del'] = 0;
  86. $map['status'] = 2;
  87. $cur = date('Y-m');
  88. $curTime = strtotime($cur.'-01');
  89. $month = [];
  90. for ($i=5;$i>0;$i--){
  91. $date = strtotime("-".$i." month",$curTime);
  92. $month[] = date('Y-m',$date);
  93. }
  94. $month[] = $cur;
  95. $advanced = '3,4';
  96. $counts = [];
  97. foreach ($month as $k=>$v){
  98. $money = $this->getApplyMoney($map,$v,$advanced);
  99. $counts[] = $money;
  100. }
  101. $data = [
  102. "month" => $month,
  103. "counts" => $counts
  104. ];
  105. ajax_return_ok($data);
  106. }
  107. public function contractpay(){
  108. $map['org_id'] = $this->orgId;
  109. $map['del'] = 0;
  110. $map['status'] = 2;
  111. $cur = date('Y-m');
  112. $curTime = strtotime($cur.'-01');
  113. $month = [];
  114. for ($i=5;$i>0;$i--){
  115. $date = strtotime("-".$i." month",$curTime);
  116. $month[] = date('Y-m',$date);
  117. }
  118. $month[] = $cur;
  119. $advanced = '5';
  120. $counts = [];
  121. foreach ($month as $k=>$v){
  122. $money = $this->getApplyMoney($map,$v,$advanced);
  123. $counts[] = $money;
  124. }
  125. $data = [
  126. "month" => $month,
  127. "counts" => $counts
  128. ];
  129. ajax_return_ok($data);
  130. }
  131. private function getApplyMoney($map,$v,$advanced){
  132. $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($v.'-01'))).'-01 00:00:00';
  133. $lists = Db::name('apply')
  134. ->where($map)
  135. ->where('advanced','in',$advanced)
  136. ->where('create_time','>=',$v.'-01 00:00:00')
  137. ->where('create_time','<',$nextmonth)
  138. ->field('id,form_json')
  139. ->select();
  140. $money = 0;
  141. foreach ($lists as $v){
  142. $formJson = json_decode($v['form_json'],true);
  143. foreach ($formJson as $kk=>$vv){
  144. if($vv['componentName'] == 'ddjjcontractfield'||$vv['componentName'] == 'ddaddcontractfield'||$vv['componentName'] == 'ddpaycontractfield'){
  145. foreach ($vv['components'] as $kkk=>$vvv){
  146. if($vvv['idx'] === 3){
  147. $money += $vvv['values'];
  148. }
  149. }
  150. break;
  151. }
  152. }
  153. }
  154. return $money;
  155. }
  156. }