SafetyController.php 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. <?php
  2. namespace app\modules\car\controllers;
  3. use app\common\controllers\BController;
  4. use app\modules\car\models\FCarInfo;
  5. use app\modules\car\models\FOneCarOneTable;
  6. use app\modules\car\models\FUnDispatchOrdersCrossBorderStatistics;
  7. use app\modules\car\models\FViolationDetails;
  8. use app\modules\car\models\FUnAnnualInspectionleasedVehiclesDetails;
  9. use app\modules\car\models\FSeverelyOverMaintainedLeasedVehiclesDetails;
  10. use app\modules\car\models\FUnDispatchOrdersDetails;
  11. use app\modules\car\models\FUnDispatchOrdersCrossBorder;
  12. use Yii;
  13. class SafetyController extends BController
  14. {
  15. public $layout = 'main';
  16. public function actionDispatch()
  17. {
  18. $type = Yii::$app->request->get('type', 1);
  19. //无派单越界统计
  20. if ($type == 1) {
  21. $query = FUnDispatchOrdersCrossBorderStatistics::find();
  22. $params = Yii::$app->request->get();
  23. $where = $this->getCityWhere($params);
  24. //账期
  25. if(!empty($params['statistical_month'])){
  26. $statistical_month = str_replace('-','',$params['statistical_month']);
  27. }else{
  28. $res = FUnDispatchOrdersCrossBorderStatistics::find()->orderBy(['statistical_month' => SORT_DESC])->asArray()->one();
  29. $statistical_month = $res['statistical_month'];
  30. }
  31. $one_query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  32. $_where['year_info'] = substr($statistical_month,0,4);
  33. $_where['month_info'] = intval(substr($statistical_month,-2));
  34. $res = FOneCarOneTable::find()->where($_where)->asArray()->one();
  35. if(empty($res)){
  36. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  37. $_where['year_info'] = intval($res['year_info']);
  38. $_where['month_info'] = intval($res['month_info']);
  39. }
  40. $where['statistical_month'] = $statistical_month;
  41. $city_arr = [];
  42. $chart1data = [];
  43. $rows = [];
  44. $needgetall = false;
  45. if(empty($where['city'])){
  46. $needgetall = true;
  47. $citydata = $query->where($where)->andWhere('"dpt_sec" is null')->orderBy($this->citySort)->asArray()->all();
  48. $res = $one_query->select(['city','sum_car'=>'count("one"."id")'])->where($_where)->groupBy('city')->asArray()->all();
  49. $_citydata = [];
  50. foreach ($res as $v) {
  51. $hash = md5($v['city'].'_city');
  52. $_citydata[$hash] = $v['sum_car'];
  53. }
  54. $total_hash = md5('全省');
  55. if($params['getall']==1) {
  56. $needgetall = false;
  57. $res = $one_query->select(['dpt_sec','sum_car'=>'count("one"."id")'])->where($_where)->groupBy('dpt_sec')->asArray()->all();
  58. $secdata = [];
  59. foreach ($res as $v) {
  60. $hash = md5($v['dpt_sec'].'_dpt_sec');
  61. $secdata[$hash] = $v['sum_car'];
  62. }
  63. }
  64. foreach ($citydata as $v) {
  65. if(!in_array($v['city'],$this->cityOptions)) break;
  66. $hash = md5($v['city'].'_city');
  67. $v = array_merge($v, ['sum_car'=>$_citydata[$hash],'hash' => $hash, 'parent_hash' => $total_hash]);
  68. $rows[] = $v;
  69. $chart1data[] = ['value' => $v['un_dispatch_cross_border_num_sum'], 'name' => $v['city']];
  70. if($params['getall']==1) {
  71. $res = $query->where($where)->andWhere(['city' => $v['city']])->andWhere('"dpt_sec" is not null')->asArray()->all();
  72. foreach ($res as $_k => $_v) {
  73. $hash = md5($_v['dpt_sec'].'_dpt_sec');
  74. $_v['hash'] = '';
  75. $_v['parent_hash'] = md5($v['city'].'_city');
  76. $_v['city'] = $_v['dpt_sec'];
  77. $_v['sum_car'] = $secdata[$hash];
  78. $rows[] = $_v;
  79. }
  80. }else{
  81. $_v = [];
  82. $_v['hash'] = '';
  83. $_v['parent_hash'] = md5($v['city'].'_city');
  84. $rows[] = $_v;
  85. }
  86. }
  87. $total = $query->where($where)->andWhere(['city' => '全省'])->asArray()->one();
  88. $res = $one_query->select(['sum_car'=>'count("one"."id")'])->filterWhere($_where)->groupBy('')->asArray()->one();
  89. $total['sum_car'] = $res['sum_car'];
  90. $total['hash'] = $total_hash;
  91. $total['parent_hash'] = md5('全国');
  92. }else{
  93. $citydata = $query->where($where)->andWhere('"dpt_sec" is not null')->asArray()->all();
  94. $res = $one_query->select(['dpt_sec','sum_car'=>'count("one"."id")'])->where($_where)->andWhere(['city'=>$where['city']])->groupBy('dpt_sec')->asArray()->all();
  95. $_citydata = [];
  96. foreach ($res as $v) {
  97. $hash = md5($v['dpt_sec'].'_dpt_sec');
  98. $_citydata[$hash] = $v['sum_car'];
  99. }
  100. $parent_hash = md5($where['city'].'_city');
  101. foreach ($citydata as $v) {
  102. $hash = md5($v['dpt_sec'].'_dpt_sec');
  103. $v = array_merge($v, ['sum_car'=>$_citydata[$hash],'hash' => $hash, 'parent_hash' => $parent_hash]);
  104. $v['city'] = $v['dpt_sec'];
  105. $rows[] = $v;
  106. $chart1data[] = ['value' => $v['un_dispatch_cross_border_num_sum'], 'name' => $v['dpt_sec']];
  107. }
  108. $total = $query->where($where)->andWhere('"dpt_sec" is null')->asArray()->one();
  109. $res = $one_query->select(['sum_car'=>'count("one"."id")'])->where($_where)->andWhere(['city'=>$where['city']])->groupBy('')->asArray()->one();
  110. $total['sum_car'] = $res['sum_car'];
  111. $total['hash'] = $parent_hash;
  112. $total['parent_hash'] = md5('全省');
  113. }
  114. array_unshift($rows, $total);
  115. $year = substr($statistical_month,0,4);
  116. for ($i=1;$i<12;$i++){
  117. $month = $year*100+$i;
  118. if($month>$statistical_month) break;
  119. $xAxis[] = $month;
  120. $where['statistical_month'] = $month;
  121. if(empty($where['city'])) $where['city'] = '全省';
  122. $res = $query->where($where)->andWhere('"dpt_sec" is null')->orderBy(['statistical_month' => SORT_ASC])->asArray()->one();
  123. if($res){
  124. $num[$i] = $res['un_dispatch_cross_border_num_sum'];
  125. }else{
  126. $num[$i] = 0;
  127. }
  128. $series[] = $i>1 ? $num[$i]-$num[$i-1] : $num[$i];
  129. }
  130. $result = ["total" => null, "totalNotFiltered" => null, "rows" => $rows, 'needgetall'=> $needgetall, 'date'=>['year_info'=>$year,'month_info'=>substr($statistical_month,-2)]];
  131. $result['chartdata'] = [
  132. 'chart1' => $this->getChart1Option([
  133. 'title' => [
  134. 'text' => '无派单越界累计次数',
  135. ],
  136. 'series' => [
  137. [
  138. 'name' => '无派单越界累计次数',
  139. 'data' => $chart1data
  140. ]
  141. ]
  142. ]),
  143. 'chart2' => $this->getChart2Option([
  144. 'title' => [
  145. 'text' => '无派单越界每月次数',
  146. ],
  147. 'xAxis' => [
  148. [
  149. 'data' => $xAxis,
  150. ]
  151. ],
  152. 'series' => [
  153. [
  154. 'name' => '无派单越界次数',
  155. 'data' => $series,
  156. ]
  157. ]
  158. ])
  159. ];
  160. if (Yii::$app->request->isAjax) echo_json($result);
  161. $this->tableTitle = array(
  162. array('field' => 'city', 'title' => '地市', 'align' => 'left'),
  163. array('field' => 'sum_car', 'title' => '车辆总数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  164. array('field' => 'departures_car_num_sum', 'title' => '出车次数累计', 'align' => 'right', 'formatter'=>'numericFormatter'),
  165. array('field' => 'un_dispatch_num_sum', 'title' => '无派单次数累计', 'align' => 'right', 'formatter'=>'numericFormatter'),
  166. array('field' => 'cross_border__num_sum', 'title' => '越界次数累计', 'align' => 'right', 'formatter'=>'numericFormatter'),
  167. array('field' => 'un_dispatch_cross_border_num_sum', 'title' => '无派单越界次数累计', 'align' => 'right', 'formatter'=>'numericFormatter'),
  168. );
  169. $this->tableConfig = array('table' => 'costs_driving', 'url' => $this->createRealUrl(['car/safety/dispatch', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => 'hash', 'checkbox' => 0, 'dropmenu' => 1, 'refresh' => true, 'fixed' => true, 'fixedNum' => 3, 'fixedRightNumber' => 0, 'tree' => 1, 'parentIdField' => 'parent_hash', 'treeShowField' => 'city', 'treeColumn' => 0, 'expand' => false, 'exportFileName' => '无派单越界统计', 'height' => 500);
  170. $this->result = $result;
  171. }
  172. //无派单越界详单
  173. if ($type == 2) {
  174. $query = FUnDispatchOrdersDetails::find();
  175. if (Yii::$app->request->isAjax) {
  176. $params = Yii::$app->request->get();
  177. $where = $this->getCityWhere($params);
  178. //账期
  179. if(!empty($params['statistical_month'])){
  180. $where['statistical_month'] = str_replace('-','',$params['statistical_month']);
  181. }
  182. //车牌
  183. if(!empty($params['card_num'])){
  184. $where['card_num'] = $params['card_num'];
  185. }
  186. if ($params['card_num']!=$params['card_num_text']){
  187. unset($where['card_num']);
  188. $query->where($where)->andWhere(['like','card_num',strtoupper($params['card_num_text'])]);
  189. }else{
  190. $query->where($where);
  191. }
  192. $countQuery = clone $query;
  193. //分页
  194. if (isset($_GET['limit'])) {
  195. $query->limit(intval($_GET['limit']));
  196. }
  197. if (isset($_GET['offset'])) {
  198. $query->offset(intval($_GET['offset']));
  199. }
  200. $field = ['*'];
  201. //排序
  202. if (isset($_GET['sort']) && isset($_GET['sortOrder'])) {
  203. $resultList = $query->select($field)->orderBy([$_GET['sort'] => ($_GET['sortOrder'] == 'asc' ? SORT_ASC : SORT_DESC)])->asArray()->all();
  204. } else {
  205. $resultList = $query->select($field)->orderBy(['statistical_month' => SORT_DESC])->asArray()->all();
  206. }
  207. $result = ["total" => $countQuery->count(), "totalNotFiltered" => $countQuery->count(), "rows" => $resultList];
  208. echo_json($result);
  209. }
  210. $this->tableTitle = array(
  211. array('field' => 'statistical_month', 'title' => '账期', 'align' => 'center', 'sortable' => true),
  212. array('field' => 'card_num', 'title' => '车牌号', 'align' => 'center', 'sortable' => true),
  213. array('field' => 'city', 'title' => '单位', 'align' => 'center', 'sortable' => true),
  214. array('field' => 'dpt_sec', 'title' => '二级单位', 'align' => 'center', 'sortable' => true),
  215. array('field' => 'grid', 'title' => '三级单位', 'align' => 'center', 'sortable' => true),
  216. //array('field' => 'own_dpt', 'title' => '车辆所属单位', 'align' => 'center', 'sortable' => true),
  217. array('field' => 'violation_time_start', 'title' => '违规开始时间', 'align' => 'center', 'sortable' => true),
  218. array('field' => 'violation_time_end', 'title' => '违规结束时间', 'align' => 'center', 'sortable' => true),
  219. array('field' => 'violation_time_duration', 'title' => '违规持续时间(分)', 'align' => 'right', 'formatter'=>'numericFormatter', 'sortable' => true,),
  220. );
  221. $this->tableConfig = array('table' => FUnDispatchOrdersDetails::shortTableName(), 'url' => $this->createRealUrl(['car/safety/dispatch', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => FUnDispatchOrdersDetails::modelPrimaryKey(), 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => true, 'pagesize' => 20, 'refresh' => true, 'exportFileName' => '无派单越界详单', 'height' => 500);
  222. }
  223. $koujing = '这里是口径描述';
  224. return $this->render('dispatch', array('type' => $type, 'koujing' => $koujing));
  225. }
  226. public function actionViolation()
  227. {
  228. $type = Yii::$app->request->get('type', 1);
  229. //违章统计
  230. if ($type == 1) {
  231. $params = Yii::$app->request->get();
  232. $where = $this->getCityWhere($params);
  233. $_query = FViolationDetails::find();
  234. //账期
  235. if(!empty($params['statistical_month'])){
  236. $statistical_month = str_replace('-','',$params['statistical_month']);
  237. $date = date('Y-m-d',strtotime("+1 months",strtotime($params['statistical_month'].'-01')));
  238. }else{
  239. $res = FViolationDetails::find()->orderBy(['cast("violation_time" as timestamp)' => SORT_DESC])->asArray()->one();
  240. $date = $res['violation_time'];
  241. $res = FViolationDetails::find()->orderBy(['statistical_month' => SORT_DESC])->asArray()->one();
  242. $statistical_month = $res['statistical_month'];
  243. }
  244. $one_query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  245. $one_where['year_info'] = substr($statistical_month,0,4);
  246. $one_where['month_info'] = intval(substr($statistical_month,-2));
  247. $res = FOneCarOneTable::find()->where($one_where)->asArray()->one();
  248. if(empty($res)){
  249. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  250. $one_where['year_info'] = intval($res['year_info']);
  251. $one_where['month_info'] = intval($res['month_info']);
  252. }
  253. //$where['statistical_month'] = $statistical_month;
  254. $start_date = date('Y-01-01',strtotime($date));
  255. $_where = ['and',['>=','cast("violation_time" as timestamp)',$start_date],['<=','cast("violation_time" as timestamp)',$date]];
  256. $sum_field = ["city"=>"city","sum_violation_car"=>"count(DISTINCT card_num)","sum_violation"=>"count(car_id)",
  257. "sum_processing_yes"=>"sum(CASE WHEN offline_actual_processing_status like '已处理%' THEN 1 ELSE 0 END)",
  258. "sum_processing_no"=>"sum(CASE WHEN offline_actual_processing_status like '未处理%' THEN 1 ELSE 0 END)",
  259. //"sum_processing_no_180"=>"sum(CASE WHEN offline_actual_processing_status like '未处理%' AND unprocessed_duration_of_violation>=180 THEN 1 ELSE 0 END)"
  260. ];
  261. $sum_data = ['sum_violation_car'=>0,'sum_violation'=>0,'sum_processing_yes'=>0,'sum_processing_no'=>0,'sum_processing_no_180'=>0];
  262. $chart1data = [];
  263. $rows = [];
  264. $needgetall = false;
  265. if(empty($where['city'])){
  266. $needgetall = true;
  267. $citydata = $one_query->select(['city','sum_car'=>'count("one"."id")'])->where($one_where)->groupBy('city')->orderBy($this->citySort)->asArray()->all();
  268. $total = $sum_data;
  269. $total['sum_car'] = 0;
  270. $total_hash = md5('全省');
  271. $res = $_query->select($sum_field)->where($_where)->groupBy('city')->asArray()->all();
  272. $_citydata = [];
  273. foreach ($res as $v) {
  274. $hash = md5($v['city'].'_city');
  275. $_citydata[$hash] = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash]);
  276. }
  277. $res = $_query->select(["city"=>"city",
  278. "sum_processing_no_180"=>"sum(CASE WHEN offline_actual_processing_status like '未处理%' AND unprocessed_duration_of_violation>=180 THEN 1 ELSE 0 END)"
  279. ])->where(['statistical_month'=>$statistical_month])->groupBy('city')->asArray()->all();
  280. foreach ($res as $v) {
  281. $hash = md5($v['city'].'_city');
  282. $_citydata[$hash] = array_merge($_citydata[$hash],$v);
  283. }
  284. if($params['getall']==1) {
  285. $needgetall = false;
  286. $sum_field['city'] = "dpt_sec";
  287. $res = $_query->select($sum_field)->where($_where)->groupBy('dpt_sec')->asArray()->all();
  288. $secdata = [];
  289. foreach ($res as $v) {
  290. $hash = md5($v['city'].'_dpt_sec');
  291. $secdata[$hash] = $v;
  292. }
  293. $res = $_query->select(["city"=>"dpt_sec",
  294. "sum_processing_no_180"=>"sum(CASE WHEN offline_actual_processing_status like '未处理%' AND unprocessed_duration_of_violation>=180 THEN 1 ELSE 0 END)"
  295. ])->where(['statistical_month'=>$statistical_month])->groupBy('dpt_sec')->asArray()->all();
  296. foreach ($res as $v) {
  297. $hash = md5($v['city'].'_dpt_sec');
  298. $secdata[$hash] = array_merge($secdata[$hash],$v);
  299. }
  300. }
  301. foreach ($citydata as $v) {
  302. if(!in_array($v['city'],$this->cityOptions)) break;
  303. $hash = md5($v['city'].'_city');
  304. if (isset($_citydata[$hash])) {
  305. $v = array_merge($v, $_citydata[$hash]);
  306. } else {
  307. $v = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash], $sum_data);
  308. }
  309. foreach ($total as $key => $_v) {
  310. $total[$key] += $v[$key];
  311. }
  312. $rows[] = $v;
  313. $chart1data[] = ['value' => $v['sum_processing_no_180'], 'name' => $v['city']];
  314. if($params['getall']==1) {
  315. $res = $one_query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where($one_where)->andWhere(['city' => $v['city']])->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  316. foreach ($res as $_v) {
  317. $hash = md5($_v['city'].'_dpt_sec');
  318. if (isset($secdata[$hash])) {
  319. $_v = array_merge($_v, $secdata[$hash]);
  320. } else {
  321. $_v = array_merge($_v, $sum_data);
  322. }
  323. $_v['hash'] = '';
  324. $_v['parent_hash'] = md5($v['city'].'_city');
  325. $rows[] = $_v;
  326. }
  327. }else{
  328. $_v = [];
  329. $_v['hash'] = '';
  330. $_v['parent_hash'] = md5($v['city'].'_city');
  331. $_v = array_merge($_v, $sum_data);
  332. $rows[] = $_v;
  333. }
  334. }
  335. $res = $one_query->select(['sum_car'=>'count("one"."id")'])->where($one_where)->groupBy('')->orderBy('')->asArray()->one();
  336. $total['sum_car'] = $res['sum_car'];
  337. $total['city'] = '全省';
  338. $total['hash'] = $total_hash;
  339. $total['parent_hash'] = md5('全国');
  340. array_unshift($rows, $total);
  341. }else{
  342. $citydata = $one_query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where($one_where)->andWhere(['city' => $where['city']])->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  343. $_where[] = ['=','city',$where['city']];
  344. $parent_hash = md5($where['city'].'_city');
  345. $total['hash'] = $parent_hash;
  346. $total['parent_hash'] = md5('全省');
  347. $total['sum_car'] = $one_query->where($one_where)->andWhere(['city'=>$where['city']])->groupBy('')->orderBy('')->count();
  348. $res = $_query->select($sum_field)->where($_where)->groupBy('city')->asArray()->one();
  349. $res1 = $_query->select(["city"=>"city",
  350. "sum_processing_no_180"=>"sum(CASE WHEN offline_actual_processing_status like '未处理%' AND unprocessed_duration_of_violation>=180 THEN 1 ELSE 0 END)"
  351. ])->where(['statistical_month'=>$statistical_month,'city'=>$where['city']])->groupBy('city')->asArray()->one();
  352. $rows[] = array_merge($total,($res?:$sum_data),$res1,['city'=>$where['city']]);
  353. $sum_field['city'] = "dpt_sec";
  354. $res = $_query->select($sum_field)->where($_where)->groupBy('dpt_sec')->asArray()->all();
  355. $secdata = [];
  356. foreach ($res as $v){
  357. $hash = md5($v['city'].'_dpt_sec');
  358. $secdata[$hash] = $v;
  359. }
  360. $res = $_query->select(["city"=>"dpt_sec",
  361. "sum_processing_no_180"=>"sum(CASE WHEN offline_actual_processing_status like '未处理%' AND unprocessed_duration_of_violation>=180 THEN 1 ELSE 0 END)"
  362. ])->where(['statistical_month'=>$statistical_month,'city'=>$where['city']])->groupBy('dpt_sec')->asArray()->all();
  363. foreach ($res as $v) {
  364. $hash = md5($v['city'].'_dpt_sec');
  365. $secdata[$hash] = array_merge($secdata[$hash],$v);
  366. }
  367. foreach ($citydata as $v){
  368. $hash = md5($v['city'].'_dpt_sec');
  369. if(isset($secdata[$hash])){
  370. $v = array_merge($v,$secdata[$hash]);
  371. }else{
  372. $v = array_merge($v,$sum_data);
  373. }
  374. $v['hash'] = '';
  375. $v['parent_hash'] = $parent_hash;
  376. $rows[] = $v;
  377. $chart1data[] = ['value' => $v['sum_processing_no_180'], 'name' => $v['city']];
  378. }
  379. }
  380. $result = ["total" => null, "totalNotFiltered" => null, "rows" => $rows, 'needgetall'=> $needgetall, 'date'=>['year_info'=>substr($statistical_month,0,4),'month_info'=>substr($statistical_month,-2)]];
  381. $year = substr($date,0,4);
  382. for ($i=1;$i<12;$i++){
  383. $month = $year*100+$i;
  384. if($month>$statistical_month) break;
  385. $xAxis[] = $month;
  386. $where['statistical_month'] = $month;
  387. $res = FViolationDetails::find()->select('statistical_month,sum(CASE WHEN offline_actual_processing_status like \'未处理%\' AND unprocessed_duration_of_violation>=180 THEN 1 ELSE 0 END) as sum_processing_no_180')->where($where)->groupBy('statistical_month')->orderBy(['statistical_month' => SORT_ASC])->asArray()->one();
  388. if($res){
  389. $series[] = $res['sum_processing_no_180'];
  390. }else{
  391. $series[] = 0;
  392. }
  393. }
  394. $result['chartdata'] = [
  395. 'chart1' => $this->getChart1Option([
  396. 'title' => [
  397. 'text' => '违章超180天未处理次数',
  398. ],
  399. 'series' => [
  400. [
  401. 'name' => '违章长期未处理次数',
  402. 'data' => $chart1data
  403. ]
  404. ]
  405. ]),
  406. 'chart2' => $this->getChart2Option([
  407. 'title' => [
  408. 'text' => '违章超180天未处理',
  409. ],
  410. 'xAxis' => [
  411. [
  412. 'data' => $xAxis,
  413. ]
  414. ],
  415. 'series' => [
  416. [
  417. 'name' => '违章长期未处理',
  418. 'data' => $series,
  419. ]
  420. ]
  421. ])
  422. ];
  423. if (Yii::$app->request->isAjax) echo_json($result);
  424. $this->result = $result;
  425. $this->tableTitle = array(
  426. array('field' => 'city', 'title' => '地市', 'align' => 'left'),
  427. array('field' => 'sum_car', 'title' => '车辆总数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  428. array('field' => 'sum_violation_car', 'title' => '违章车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  429. array('field' => 'sum_violation', 'title' => '违章次数', 'align' => 'right', 'formatter'=>'numericFormatter'),
  430. array('field' => 'sum_processing_yes', 'title' => '已处理违章', 'align' => 'right', 'formatter'=>'numericFormatter'),
  431. array('field' => 'sum_processing_no', 'title' => '未处理违章', 'align' => 'right', 'formatter'=>'numericFormatter'),
  432. array('field' => 'sum_processing_no_180', 'title' => '违章超180天未处理', 'align' => 'right', 'formatter'=>'numericFormatter'),
  433. );
  434. $this->tableConfig = array('table' => 'FViolationDetails', 'url' => $this->createRealUrl(['car/safety/violation', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => 'hash', 'checkbox' => 0, 'dropmenu' => 1, 'pagesize' => 20, 'refresh' => true, 'tree' => 1, 'parentIdField' => 'parent_hash', 'treeShowField' => 'city', 'treeColumn' => 0, 'expand' => false, 'exportFileName' => '违章统计', 'height' => 500);
  435. }
  436. //单车违章次数TOP50
  437. if ($type == 2) {
  438. if (Yii::$app->request->isAjax) {
  439. $query = FViolationDetails::find();
  440. $data = [];
  441. $params = Yii::$app->request->get();
  442. $where = $this->getCityWhere($params);
  443. //账期
  444. if(!empty($params['statistical_month'])){
  445. $where['statistical_month'] = str_replace('-','',$params['statistical_month']);
  446. }else{
  447. $res = FViolationDetails::find()->orderBy(['statistical_month' => SORT_DESC])->asArray()->one();
  448. $where['statistical_month'] = $res['statistical_month'];
  449. }
  450. $date = date('Y-m-d',strtotime("+1 months",strtotime($where['statistical_month'].'01')));
  451. $start_date = date('Y-01-01',strtotime($date));
  452. $query->where($where)->andWhere(['and',['>=','cast("violation_time" as timestamp)',$start_date],['<=','cast("violation_time" as timestamp)',$date]]);
  453. $query->limit(100);
  454. $resultList = $query->select('card_num,max(city) as city,max(dpt_sec) as dpt_sec,max(grid) as grid,max(statistical_month) as statistical_month,count(car_id) as cell_num')->groupBy('card_num')->orderBy(['cell_num' => SORT_DESC])->asArray()->all();
  455. $i = 1;
  456. $c = 0;
  457. foreach ($resultList as $v){
  458. if($i==50) $c = $v['cell_num'];
  459. if($i>50 && $v['cell_num']<$c) break;
  460. $data[] = array_merge($v,['idx'=>$i]);
  461. $i++;
  462. }
  463. $result = ["total" => null, "totalNotFiltered" => null, "rows" => $data, 'date'=>['year_info'=>substr($_where['statistical_month'],0,4),'month_info'=>substr($_where['statistical_month'],-2)]];
  464. echo_json($result);
  465. }
  466. $this->tableTitle = array(
  467. array('field' => 'card_num', 'title' => '车牌号', 'align' => 'center'),
  468. array('field' => 'city', 'title' => '单位', 'align' => 'center'),
  469. array('field' => 'dpt_sec', 'title' => '二级单位', 'align' => 'center'),
  470. array('field' => 'grid', 'title' => '三级单位', 'align' => 'center'),
  471. array('field' => 'cell_num', 'title' => '违章次数累计', 'align' => 'center', 'formatter'=>'numericFormatter'),
  472. );
  473. $this->tableConfig = array('table' => FViolationDetails::shortTableName(), 'url' => $this->createRealUrl(['car/safety/violation', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => FViolationDetails::modelPrimaryKey(), 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => false, 'pagesize' => 20, 'refresh' => true, 'exportFileName' => '单车违章次数TOP50', 'height' => 500);
  474. }
  475. //违章详单
  476. if ($type == 3) {
  477. if (Yii::$app->request->isAjax) {
  478. $query = FViolationDetails::find();
  479. $params = Yii::$app->request->get();
  480. $where = $this->getCityWhere($params);
  481. //账期
  482. if(!empty($params['statistical_month'])){
  483. $where['statistical_month'] = str_replace('-','',$params['statistical_month']);
  484. }
  485. //车牌
  486. if(!empty($params['card_num'])){
  487. $where['card_num'] = $params['card_num'];
  488. }
  489. if ($params['card_num']!=$params['card_num_text']){
  490. unset($where['card_num']);
  491. $query->where($where)->andWhere(['like','card_num',strtoupper($params['card_num_text'])]);
  492. }else{
  493. $query->where($where);
  494. }
  495. $countQuery = clone $query;
  496. //分页
  497. if (isset($_GET['limit'])) {
  498. $query->limit(intval($_GET['limit']));
  499. }
  500. if (isset($_GET['offset'])) {
  501. $query->offset(intval($_GET['offset']));
  502. }
  503. //排序
  504. if (isset($_GET['sort']) && isset($_GET['sortOrder'])) {
  505. $resultList = $query->orderBy([$_GET['sort'] => ($_GET['sortOrder'] == 'asc' ? SORT_ASC : SORT_DESC)])->asArray()->all();
  506. } else {
  507. $resultList = $query->orderBy(['car_id' => SORT_DESC])->asArray()->all();
  508. }
  509. $result = ["total" => $countQuery->count(), "totalNotFiltered" => $countQuery->count(), "rows" => $resultList];
  510. echo_json($result);
  511. }
  512. $this->tableTitle = array(
  513. array('field' => 'car_id', 'title' => '序号', 'align' => 'center', 'sortable' => true),
  514. array('field' => 'statistical_month', 'title' => '账期', 'align' => 'center', 'sortable' => true),
  515. array('field' => 'card_num', 'title' => '车牌号', 'align' => 'center', 'sortable' => true),
  516. array('field' => 'city', 'title' => '单位', 'align' => 'center', 'sortable' => true),
  517. array('field' => 'dpt_sec', 'title' => '二级单位', 'align' => 'center', 'sortable' => true),
  518. array('field' => 'grid', 'title' => '三级单位', 'align' => 'center', 'sortable' => true),
  519. array('field' => 'violation_time', 'title' => '违章时间', 'align' => 'center', 'sortable' => true),
  520. array('field' => 'violation_location', 'title' => '违章地点', 'align' => 'center', 'sortable' => true),
  521. array('field' => 'violation_details', 'title' => '违章详情', 'align' => 'center', 'sortable' => true, 'width' => '200px'),
  522. array('field' => 'deduction_points', 'title' => '扣分', 'align' => 'center', 'sortable' => true),
  523. array('field' => 'fine', 'title' => '罚款', 'align' => 'center', 'sortable' => true),
  524. array('field' => 'processing_time', 'title' => '处理时间', 'align' => 'center', 'sortable' => true),
  525. array('field' => 'unprocessed_duration_of_violation', 'title' => '违章未处理时长(天)', 'align' => 'center', 'sortable' => true),
  526. array('field' => 'offline_actual_processing_status', 'title' => '线下实际处理状态(最终状态)', 'align' => 'center', 'sortable' => true),
  527. );
  528. $this->tableConfig = array('table' => FViolationDetails::shortTableName(), 'url' => $this->createRealUrl(['car/safety/violation', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => 'car_id', 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => true, 'refresh' => true, 'exportFileName' => '违章详单', 'height' => 500);
  529. }
  530. $koujing = '这里是口径描述';
  531. return $this->render('violation', array('type' => $type, 'koujing' => $koujing));
  532. }
  533. //年检情况
  534. public function actionAnnually()
  535. {
  536. $type = Yii::$app->request->get('type', 1);
  537. if ($type == 1) {
  538. $params = Yii::$app->request->get();
  539. $where = $this->getCityWhere($params);
  540. $where['self_rent'] = '租赁车辆';
  541. $_query = FUnAnnualInspectionleasedVehiclesDetails::find();
  542. //账期
  543. if(!empty($params['statistical_month'])){
  544. $statistical_month = str_replace('-','',$params['statistical_month']);
  545. }else{
  546. $res = FUnAnnualInspectionleasedVehiclesDetails::find()->orderBy(['statistical_month' => SORT_DESC])->asArray()->one();
  547. $statistical_month = $res['statistical_month'];
  548. }
  549. $_where['statistical_month'] = $statistical_month;
  550. $one_query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  551. $one_where['year_info'] = substr($statistical_month,0,4);
  552. $one_where['month_info'] = intval(substr($statistical_month,-2));
  553. $res = FOneCarOneTable::find()->where($one_where)->asArray()->one();
  554. if(empty($res)){
  555. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  556. $one_where['year_info'] = intval($res['year_info']);
  557. $one_where['month_info'] = intval($res['month_info']);
  558. }
  559. $one_where['self_rent'] = '租赁车辆';
  560. $sum_field = "count(DISTINCT card_num) as sum_annual_car,count(car_id) as sum_annual,
  561. sum(CASE WHEN should_inspection_be_conducted_this_month like '是%' THEN 1 ELSE 0 END) as sum_should_inspection,
  562. sum(CASE WHEN annual_inspection_this_month like '否%' THEN 1 ELSE 0 END) as sum_annual_inspection,
  563. sum(CASE WHEN passed_inspection like '是%' AND statistical_month>cast(inspect_annually_date as int4) THEN 1 ELSE 0 END) as sum_passed_inspection";
  564. $sum_data = ['sum_annual_car'=>0,'sum_annual'=>0,'sum_should_inspection'=>0,'sum_annual_inspection'=>0,'sum_passed_inspection'=>0];
  565. $chart1data = [];
  566. $rows = [];
  567. $needgetall = false;
  568. if(empty($where['city'])){
  569. $needgetall = true;
  570. $citydata = $one_query->select(['city','sum_car'=>'count("one"."id")'])->where($one_where)->groupBy('city')->orderBy($this->citySort)->asArray()->all();
  571. $total = $sum_data;
  572. $total['sum_car'] = 0;
  573. $total_hash = md5('全省');
  574. $res = $_query->select("city,$sum_field")->where($_where)->groupBy('city')->asArray()->all();
  575. $_citydata = [];
  576. foreach ($res as $v) {
  577. $hash = md5($v['city'].'_city');
  578. $_citydata[$hash] = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash]);
  579. }
  580. if($params['getall']==1) {
  581. $needgetall = false;
  582. $res = $_query->select("dpt_sec as city,$sum_field")->where($_where)->groupBy('dpt_sec')->asArray()->all();
  583. $secdata = [];
  584. foreach ($res as $v) {
  585. $hash = md5($v['city'].'_dpt_sec');
  586. $secdata[$hash] = $v;
  587. }
  588. }
  589. foreach ($citydata as $v) {
  590. if(!in_array($v['city'],$this->cityOptions)) break;
  591. $hash = md5($v['city'].'_city');
  592. if (isset($_citydata[$hash])) {
  593. $v = array_merge($v, $_citydata[$hash]);
  594. } else {
  595. $v = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash], $sum_data);
  596. }
  597. foreach ($total as $key => $_v) {
  598. $total[$key] += $v[$key];
  599. }
  600. $rows[] = $v;
  601. $chart1data[] = ['value' => $v['sum_annual_inspection'], 'name' => $v['city']];
  602. if($params['getall']==1) {
  603. $res = $one_query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where($one_where)->andWhere(['city' => $v['city']])->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  604. foreach ($res as $_v) {
  605. $hash = md5($_v['city'].'_dpt_sec');
  606. if (isset($secdata[$hash])) {
  607. $_v = array_merge($_v, $secdata[$hash]);
  608. } else {
  609. $_v = array_merge($_v, $sum_data);
  610. }
  611. $_v['hash'] = '';
  612. $_v['parent_hash'] = md5($v['city'].'_city');
  613. $rows[] = $_v;
  614. }
  615. }else{
  616. $_v = [];
  617. $_v['hash'] = '';
  618. $_v['parent_hash'] = md5($v['city'].'_city');
  619. $_v = array_merge($_v, $sum_data);
  620. $rows[] = $_v;
  621. }
  622. }
  623. $res = $one_query->select(['sum_car'=>'count("one"."id")'])->where($one_where)->groupBy('')->orderBy('')->asArray()->one();
  624. $total['sum_car'] = $res['sum_car'];
  625. $total['city'] = '全省';
  626. $total['hash'] = $total_hash;
  627. $total['parent_hash'] = md5('全国');
  628. array_unshift($rows, $total);
  629. }else{
  630. $citydata = $one_query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where($one_where)->andWhere(['city' => $where['city']])->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  631. $_where['city'] = $where['city'];
  632. $parent_hash = md5($where['city'].'_city');
  633. $total['hash'] = $parent_hash;
  634. $total['parent_hash'] = md5('全省');
  635. $total['sum_car'] = $one_query->where($one_where)->andWhere(['city'=>$where['city']])->groupBy('')->orderBy('')->count();
  636. $res = $_query->select("city,$sum_field")->where($_where)->groupBy('city')->asArray()->one();
  637. $rows[] = array_merge($total,$res?:$sum_data,['city'=>$_where['city']]);
  638. $res = $_query->select("dpt_sec as city,$sum_field")->where($_where)->groupBy('dpt_sec')->asArray()->all();
  639. $secdata = [];
  640. foreach ($res as $v){
  641. $hash = md5($v['city'].'_dpt_sec');
  642. $secdata[$hash] = $v;
  643. }
  644. foreach ($citydata as $v){
  645. $hash = md5($v['city'].'_dpt_sec');
  646. if(isset($secdata[$hash])){
  647. $v = array_merge($v,$secdata[$hash]);
  648. }else{
  649. $v = array_merge($v,$sum_data);
  650. }
  651. $v['hash'] = '';
  652. $v['parent_hash'] = $parent_hash;
  653. $rows[] = $v;
  654. $chart1data[] = ['value' => $v['sum_annual_inspection'], 'name' => $v['city']];
  655. }
  656. }
  657. $result = ["total" => null, "totalNotFiltered" => null, "rows" => $rows, 'needgetall'=> $needgetall, 'date'=>['year_info'=>substr($statistical_month,0,4),'month_info'=>substr($statistical_month,-2)]];
  658. $year = substr($statistical_month,0,4);
  659. for ($i=1;$i<12;$i++){
  660. $month = $year*100+$i;
  661. if($month>$_where['statistical_month']) break;
  662. $xAxis[] = $month;
  663. $where['statistical_month'] = $month;
  664. unset($where['self_rent']);
  665. $res = FUnAnnualInspectionleasedVehiclesDetails::find()->select('statistical_month,sum(CASE WHEN annual_inspection_this_month like \'否%\' THEN 1 ELSE 0 END) as sum_annual_inspection')->where($where)->groupBy('statistical_month')->orderBy(['statistical_month' => SORT_ASC])->asArray()->one();
  666. if($res){
  667. $series[] = $res['sum_annual_inspection'];
  668. }else{
  669. $series[] = 0;
  670. }
  671. }
  672. $result['chartdata'] = [
  673. 'chart1' => $this->getChart1Option([
  674. 'title' => [
  675. 'text' => '未年检租赁车辆统计',
  676. ],
  677. 'series' => [
  678. [
  679. 'name' => '未检租赁车辆',
  680. 'data' => $chart1data
  681. ]
  682. ]
  683. ]),
  684. 'chart2' => $this->getChart2Option([
  685. 'title' => [
  686. 'text' => '未年检租赁车辆统计',
  687. ],
  688. 'xAxis' => [
  689. [
  690. 'data' => $xAxis,
  691. ]
  692. ],
  693. 'series' => [
  694. [
  695. 'name' => '未年检租赁车辆统计',
  696. 'data' => $series,
  697. ]
  698. ]
  699. ])
  700. ];
  701. if (Yii::$app->request->isAjax) echo_json($result);
  702. $this->result = $result;
  703. $this->tableTitle = array(
  704. array('field' => 'city', 'title' => '地市', 'align' => 'left'),
  705. array('field' => 'sum_car', 'title' => '租赁车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  706. array('field' => 'sum_should_inspection', 'title' => '应年检租赁车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  707. array('field' => 'sum_annual_inspection', 'title' => '未年检租赁车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  708. array('field' => 'sum_passed_inspection', 'title' => '过年检租赁车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  709. );
  710. $this->tableConfig = array('table' => 'FUnAnnualInspectionleasedVehiclesDetails', 'url' => $this->createRealUrl(['car/safety/annually', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => 'hash', 'checkbox' => 0, 'dropmenu' => 1, 'pagesize' => 20, 'refresh' => true, 'tree' => 1, 'parentIdField' => 'parent_hash', 'treeShowField' => 'city', 'treeColumn' => 0, 'expand' => false, 'exportFileName' => '未年检租赁车辆统计', 'height' => 500);
  711. }
  712. if ($type == 2) {
  713. if (Yii::$app->request->isAjax) {
  714. $query = FUnAnnualInspectionleasedVehiclesDetails::find();
  715. $params = Yii::$app->request->get();
  716. $where = $this->getCityWhere($params);
  717. //账期
  718. if(!empty($params['statistical_month'])){
  719. $where['statistical_month'] = str_replace('-','',$params['statistical_month']);
  720. }
  721. //车牌
  722. if(!empty($params['card_num'])){
  723. $where['card_num'] = $params['card_num'];
  724. }
  725. if ($params['card_num']!=$params['card_num_text']){
  726. unset($where['card_num']);
  727. $query->where($where)->andWhere(['like','card_num',strtoupper($params['card_num_text'])]);
  728. }else{
  729. $query->where($where);
  730. }
  731. $countQuery = clone $query;
  732. //分页
  733. if (isset($_GET['limit'])) {
  734. $query->limit(intval($_GET['limit']));
  735. }
  736. if (isset($_GET['offset'])) {
  737. $query->offset(intval($_GET['offset']));
  738. }
  739. //排序
  740. if (isset($_GET['sort']) && isset($_GET['sortOrder'])) {
  741. $resultList = $query->orderBy([$_GET['sort'] => ($_GET['sortOrder'] == 'asc' ? SORT_ASC : SORT_DESC)])->asArray()->all();
  742. } else {
  743. $resultList = $query->orderBy(['car_id' => SORT_DESC])->asArray()->all();
  744. }
  745. $result = ["total" => $countQuery->count(), "totalNotFiltered" => $countQuery->count(), "rows" => $resultList];
  746. echo_json($result);
  747. }
  748. $this->tableTitle = array(
  749. array('field' => 'car_id', 'title' => '序号', 'align' => 'center', 'sortable' => true),
  750. array('field' => 'statistical_month', 'title' => '账期', 'align' => 'center', 'sortable' => true),
  751. array('field' => 'card_num', 'title' => '车牌号', 'align' => 'center', 'sortable' => true),
  752. array('field' => 'enable_date', 'title' => '登记日期', 'align' => 'center', 'sortable' => true),
  753. array('field' => 'car_brand', 'title' => '车辆类型', 'align' => 'center', 'sortable' => true),
  754. array('field' => 'city', 'title' => '单位', 'align' => 'center', 'sortable' => true),
  755. array('field' => 'dpt_sec', 'title' => '二级单位', 'align' => 'center', 'sortable' => true),
  756. array('field' => 'grid', 'title' => '三级单位', 'align' => 'center', 'sortable' => true),
  757. array('field' => 'passed_inspection', 'title' => '是否过检', 'align' => 'center', 'sortable' => true),
  758. array('field' => 'should_inspection_be_conducted_this_month', 'title' => '是否本月应检', 'align' => 'center', 'sortable' => true),
  759. array('field' => 'annual_inspection_this_month', 'title' => '本月是否年检', 'align' => 'center', 'sortable' => true),
  760. array('field' => 'inspect_annually_date', 'title' => '年检时间', 'align' => 'center', 'sortable' => true),
  761. );
  762. $this->tableConfig = array('table' => 'FUnAnnualInspectionleasedVehiclesDetails', 'url' => $this->createRealUrl(['car/safety/annually', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => 'car_id', 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => true, 'pagesize' => 20, 'refresh' => true, 'exportFileName' => '未年检租赁车辆详单', 'height' => 500);
  763. }
  764. $koujing = '存在交通违章,6个月以上未处理的车辆为异常。';
  765. return $this->render('annually', array('type' => $type, 'koujing' => $koujing));
  766. }
  767. //保养情况
  768. public function actionMaintain()
  769. {
  770. $type = Yii::$app->request->get('type', 1);
  771. if ($type == 1) {
  772. $params = Yii::$app->request->get();
  773. $where = $this->getCityWhere($params);
  774. $where['self_rent'] = '租赁车辆';
  775. $_query = FSeverelyOverMaintainedLeasedVehiclesDetails::find();
  776. //账期
  777. if(!empty($params['statistical_month'])){
  778. $statistical_month = str_replace('-','',$params['statistical_month']);
  779. }else{
  780. $res = FSeverelyOverMaintainedLeasedVehiclesDetails::find()->orderBy(['statistical_month' => SORT_DESC])->asArray()->one();
  781. $statistical_month = $res['statistical_month'];
  782. }
  783. $_where['statistical_month'] = $statistical_month;
  784. $one_query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  785. $one_where['year_info'] = substr($statistical_month,0,4);
  786. $one_where['month_info'] = intval(substr($statistical_month,-2));
  787. $res = FOneCarOneTable::find()->where($one_where)->asArray()->one();
  788. if(empty($res)){
  789. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  790. $one_where['year_info'] = intval($res['year_info']);
  791. $one_where['month_info'] = intval($res['month_info']);
  792. }
  793. $one_where['self_rent'] = '租赁车辆';
  794. $sum_field = "sum(CASE WHEN should_maintenance_be_carried_out like '是%' THEN 1 ELSE 0 END) as sum_should_maintenance,
  795. sum(CASE WHEN exceeding_the_recommended_maintenance_time > 0 OR exceeding_the_recommended_maintenance_mileage > 0 THEN 1 ELSE 0 END) as sum_exceeding,
  796. sum(CASE WHEN exceeding_the_recommended_maintenance_time > 90 OR exceeding_the_recommended_maintenance_mileage > 3000 THEN 1 ELSE 0 END) as sum_severely_exceeding";
  797. $sum_data = ['sum_should_maintenance'=>0,'sum_exceeding'=>0,'sum_severely_exceeding'=>0];
  798. $chart1data = [];
  799. $rows = [];
  800. $needgetall = false;
  801. if(empty($where['city'])){
  802. $needgetall = true;
  803. $citydata = $one_query->select(['city','sum_car'=>'count("one"."id")'])->where($one_where)->groupBy('city')->orderBy($this->citySort)->asArray()->all();
  804. $total = $sum_data;
  805. $total['sum_car'] = 0;
  806. $total_hash = md5('全省');
  807. $res = $_query->select("city,$sum_field")->where($_where)->groupBy('city')->asArray()->all();
  808. $_citydata = [];
  809. foreach ($res as $v){
  810. $hash = md5($v['city'].'_city');
  811. $_citydata[$hash] = array_merge($v,['hash'=>$hash,'parent_hash'=>$total_hash]);
  812. }
  813. if($params['getall']==1) {
  814. $needgetall = false;
  815. $res = $_query->select("dpt_sec as city,$sum_field")->where($_where)->groupBy('dpt_sec')->asArray()->all();
  816. $secdata = [];
  817. foreach ($res as $v) {
  818. $hash = md5($v['city'].'_dpt_sec');
  819. $secdata[$hash] = $v;
  820. }
  821. }
  822. foreach ($citydata as $v){
  823. if(!in_array($v['city'],$this->cityOptions)) break;
  824. $hash = md5($v['city'].'_city');
  825. if(isset($_citydata[$hash])){
  826. $v = array_merge($v,$_citydata[$hash]);
  827. }else{
  828. $v = array_merge($v,['hash'=>$hash,'parent_hash'=>$total_hash],$sum_data);
  829. }
  830. foreach ($total as $key=>$_v){
  831. $total[$key] += $v[$key];
  832. }
  833. $rows[] = $v;
  834. $chart1data[] = ['value' => $v['sum_severely_exceeding'], 'name' => $v['city']];
  835. if($params['getall']==1) {
  836. $res = $one_query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where($one_where)->andWhere(['city' => $v['city']])->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  837. foreach ($res as $_v) {
  838. $hash = md5($_v['city'].'_dpt_sec');
  839. if (isset($secdata[$hash])) {
  840. $_v = array_merge($_v, $secdata[$hash]);
  841. } else {
  842. $_v = array_merge($_v, $sum_data);
  843. }
  844. $_v['hash'] = '';
  845. $_v['parent_hash'] = md5($v['city'].'_city');
  846. $rows[] = $_v;
  847. }
  848. }else{
  849. $_v = [];
  850. $_v['hash'] = '';
  851. $_v['parent_hash'] = md5($v['city'].'_city');
  852. $_v = array_merge($_v, $sum_data);
  853. $rows[] = $_v;
  854. }
  855. }
  856. $res = $one_query->select(['sum_car'=>'count("one"."id")'])->where($one_where)->groupBy('')->orderBy('')->asArray()->one();
  857. $total['sum_car'] = $res['sum_car'];
  858. $total['city'] = '全省';
  859. $total['hash'] = $total_hash;
  860. $total['parent_hash'] = md5('全国');
  861. array_unshift($rows,$total);
  862. }else{
  863. $citydata = $one_query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where($one_where)->andWhere(['city' => $where['city']])->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  864. $_where['city'] = $where['city'];
  865. $parent_hash = md5($where['city'].'_city');
  866. $total['hash'] = $parent_hash;
  867. $total['parent_hash'] = md5('全省');
  868. $total['sum_car'] = $one_query->where($one_where)->andWhere(['city'=>$where['city']])->groupBy('')->orderBy('')->count();
  869. $res = $_query->select("city,$sum_field")->where($_where)->groupBy('city')->asArray()->one();
  870. $rows[] = array_merge($total,$res?:$sum_data,['city'=>$_where['city']]);
  871. $res = $_query->select("dpt_sec as city,$sum_field")->where($_where)->groupBy('dpt_sec')->asArray()->all();
  872. $secdata = [];
  873. foreach ($res as $v){
  874. $hash = md5($v['city'].'_dpt_sec');
  875. $secdata[$hash] = $v;
  876. }
  877. foreach ($citydata as $v){
  878. $hash = md5($v['city'].'_dpt_sec');
  879. if(isset($secdata[$hash])){
  880. $v = array_merge($v,$secdata[$hash]);
  881. }else{
  882. $v = array_merge($v,$sum_data);
  883. }
  884. $v['hash'] = '';
  885. $v['parent_hash'] = $parent_hash;
  886. $rows[] = $v;
  887. $chart1data[] = ['value' => $v['sum_severely_exceeding'], 'name' => $v['city']];
  888. }
  889. }
  890. $result = ["total" => null, "totalNotFiltered" => null, "rows" => $rows, 'needgetall'=> $needgetall, 'date'=>['year_info'=>substr($_where['statistical_month'],0,4),'month_info'=>substr($_where['statistical_month'],-2)]];
  891. $year = substr($_where['statistical_month'],0,4);
  892. for ($i=1;$i<12;$i++){
  893. $month = $year*100+$i;
  894. if($month>$_where['statistical_month']) break;
  895. $xAxis[] = $month;
  896. $where['statistical_month'] = $month;
  897. unset($where['self_rent']);
  898. $res = FSeverelyOverMaintainedLeasedVehiclesDetails::find()->select('statistical_month,sum(CASE WHEN exceeding_the_recommended_maintenance_time > 90 OR exceeding_the_recommended_maintenance_mileage > 3000 THEN 1 ELSE 0 END) as sum_severely_exceeding')->where($where)->groupBy('statistical_month')->orderBy(['statistical_month' => SORT_ASC])->asArray()->one();
  899. if($res){
  900. $series[] = $res['sum_severely_exceeding'];
  901. }else{
  902. $series[] = 0;
  903. }
  904. }
  905. $result['chartdata'] = [
  906. 'chart1' => $this->getChart1Option([
  907. 'title' => [
  908. 'text' => '严重超保养租赁车辆',
  909. ],
  910. 'series' => [
  911. [
  912. 'name' => '严重超保养租赁车辆数量',
  913. 'data' => $chart1data
  914. ]
  915. ]
  916. ]),
  917. 'chart2' => $this->getChart2Option([
  918. 'title' => [
  919. 'text' => '严重超保养租赁车辆',
  920. ],
  921. 'xAxis' => [
  922. [
  923. 'data' => $xAxis,
  924. ]
  925. ],
  926. 'series' => [
  927. [
  928. 'name' => '严重超保养租赁车辆',
  929. 'data' => $series,
  930. ]
  931. ]
  932. ])
  933. ];
  934. if (Yii::$app->request->isAjax) echo_json($result);
  935. $this->result = $result;
  936. $this->tableTitle = array(
  937. array('field' => 'city', 'title' => '地市', 'align' => 'left'),
  938. array('field' => 'sum_car', 'title' => '租赁车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  939. array('field' => 'sum_should_maintenance', 'title' => '应保养租赁车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  940. array('field' => 'sum_exceeding', 'title' => '超保养租赁车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  941. array('field' => 'sum_severely_exceeding', 'title' => '严重超保养车辆数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  942. );
  943. $this->tableConfig = array('table' => 'FSeverelyOverMaintainedLeasedVehiclesDetails', 'url' => $this->createRealUrl(['car/safety/maintain', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => 'hash', 'checkbox' => 0, 'dropmenu' => 1, 'pagesize' => 20, 'refresh' => true, 'tree' => 1, 'parentIdField' => 'parent_hash', 'treeShowField' => 'city', 'treeColumn' => 0, 'expand' => false, 'exportFileName' => '严重超保养租赁车辆统计', 'height' => 500);
  944. }
  945. if ($type == 2) {
  946. if (Yii::$app->request->isAjax) {
  947. $query = FSeverelyOverMaintainedLeasedVehiclesDetails::find();
  948. $params = Yii::$app->request->get();
  949. $where = $this->getCityWhere($params);
  950. //账期
  951. if(!empty($params['statistical_month'])){
  952. $where['statistical_month'] = str_replace('-','',$params['statistical_month']);
  953. }
  954. //车牌
  955. if(!empty($params['card_num'])){
  956. $where['card_num'] = $params['card_num'];
  957. }
  958. if ($params['card_num']!=$params['card_num_text']){
  959. unset($where['card_num']);
  960. $query->where($where)->andWhere(['like','card_num',strtoupper($params['card_num_text'])]);
  961. }else{
  962. $query->where($where);
  963. }
  964. $query->andWhere(['or',['>','exceeding_the_recommended_maintenance_time',90],['>','exceeding_the_recommended_maintenance_mileage',3000]]);
  965. $countQuery = clone $query;
  966. //分页
  967. if (isset($_GET['limit'])) {
  968. $query->limit(intval($_GET['limit']));
  969. }
  970. if (isset($_GET['offset'])) {
  971. $query->offset(intval($_GET['offset']));
  972. }
  973. //排序
  974. if (isset($_GET['sort']) && isset($_GET['sortOrder'])) {
  975. $resultList = $query->orderBy([$_GET['sort'] => ($_GET['sortOrder'] == 'asc' ? SORT_ASC : SORT_DESC)])->asArray()->all();
  976. } else {
  977. $resultList = $query->orderBy(['statistical_month' => SORT_DESC])->asArray()->all();
  978. }
  979. $result = ["total" => $countQuery->count(), "totalNotFiltered" => $countQuery->count(), "rows" => $resultList];
  980. echo_json($result);
  981. }
  982. $this->tableTitle = array(
  983. array('field' => 'car_id', 'title' => '序号', 'align' => 'center', 'sortable' => true),
  984. array('field' => 'statistical_month', 'title' => '账期', 'align' => 'center', 'sortable' => true),
  985. array('field' => 'card_num', 'title' => '车牌号', 'align' => 'center', 'sortable' => true),
  986. array('field' => 'car_brand', 'title' => '车辆类型', 'align' => 'center', 'sortable' => true),
  987. array('field' => 'city', 'title' => '单位', 'align' => 'center', 'sortable' => true),
  988. array('field' => 'dpt_sec', 'title' => '二级单位', 'align' => 'center', 'sortable' => true),
  989. array('field' => 'grid', 'title' => '三级单位', 'align' => 'center', 'sortable' => true),
  990. array('field' => 'enable_date', 'title' => '登记日期', 'align' => 'center', 'sortable' => true),
  991. array('field' => 'arrival_time', 'title' => '进厂时间', 'align' => 'center', 'sortable' => true),
  992. array('field' => 'kilometers_entering_the_factory', 'title' => '进厂公里数', 'align' => 'right', 'sortable' => true, 'formatter'=>'numeric1Formatter'),
  993. array('field' => 'Mileage_driven_as_of_data_extraction_date', 'title' => '截止数据提取日行驶里程', 'align' => 'right', 'sortable' => true, 'formatter'=>'numeric1Formatter'),
  994. array('field' => 'should_maintenance_be_carried_out', 'title' => '是否应该保养', 'align' => 'center', 'sortable' => true),
  995. array('field' => 'exceeding_the_recommended_maintenance_time', 'title' => '超出建议保养时间(天)', 'align' => 'right', 'sortable' => true, 'formatter'=>'numericFormatter'),
  996. array('field' => 'exceeding_the_recommended_maintenance_mileage', 'title' => '超出建议保养公里数', 'align' => 'right', 'sortable' => true, 'formatter'=>'numeric1Formatter'),
  997. );
  998. $this->tableConfig = array('table' => 'FSeverelyOverMaintainedLeasedVehiclesDetails', 'url' => $this->createRealUrl(['car/safety/maintain', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/safety/setfield']), 'idField' => 'car_id', 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => true, 'pagesize' => 20, 'refresh' => true, 'exportFileName' => '低效车辆明细', 'height' => 500);
  999. }
  1000. $koujing = '严重应保养未保车辆数量=超出建议保养时间90天租赁车辆数量 or 超出建议保养3000公里租赁车辆数量';
  1001. return $this->render('maintain', array('type' => $type, 'koujing' => $koujing));
  1002. }
  1003. }