EffController.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  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\FCarScrap;
  6. use app\modules\car\models\FInputPolicy;
  7. use app\modules\car\models\FMileageAttend;
  8. use app\modules\car\models\FOneCarOneTable;
  9. use app\modules\car\models\FSpcCar;
  10. use Yii;
  11. class EffController extends BController
  12. {
  13. public $layout = 'main';
  14. public function actionTotal()
  15. {
  16. $type = Yii::$app->request->get('type', 1);
  17. $koujing = '这里是口径描述';
  18. //效能统计
  19. if ($type == 1) {
  20. $query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  21. $params = Yii::$app->request->get();
  22. $where = $this->getCityWhere($params);
  23. //$where['is_special_car'] = 0;
  24. $_query = clone $query;
  25. //账期
  26. if(!empty($params['statistical_month'])){
  27. $statistical_month = explode('-',$params['statistical_month']);
  28. $_where['year_info'] = intval($statistical_month[0]);
  29. $_where['month_info'] = intval($statistical_month[1]);
  30. }else{
  31. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  32. $_where['year_info'] = intval($res['year_info']);
  33. $_where['month_info'] = intval($res['month_info']);
  34. }
  35. $_query->where(['and',['=','year_info',intval($_where['year_info'])],['<=','month_info',intval($_where['month_info'])]]);
  36. //$_where['is_special_car'] = 0;
  37. //$month = $_query->select('COUNT(DISTINCT month_info) as month_num,MAX(month_info) as month_info')->asArray()->one();
  38. //$month_num = max(intval($month['month_num']),1);
  39. //$month_info = max($month['month_info'],1);
  40. //if($_where['month_info']>$month_info) $_where['month_info'] = $month_info;
  41. $query->where($where);
  42. $sum_field = ['city'=>'city',
  43. 'sum_mileage'=>'cast(sum("sum_mileage") as decimal(10,2))',
  44. 'sum_attend_days'=>'cast(sum("attend_days") as decimal(10,0))',
  45. 'sum_work_days'=>'cast(sum("work_days") as decimal(10,0))',
  46. ];
  47. $sum_data = ['sum_mileage'=>0,'sum_attend_days'=>0,'sum_work_days'=>0];
  48. $city_arr = [];
  49. $chart1data = [];
  50. $rows = [];
  51. $needgetall = false;
  52. if(empty($where['city'])){
  53. $needgetall = true;
  54. $citydata = $query->select(['city','sum_car'=>'count("one"."id")'])->andWhere($_where)->groupBy('city')->orderBy($this->citySort)->asArray()->all();
  55. $total = $sum_data;
  56. $total_hash = md5('全省');
  57. $res = $_query->select($sum_field)->groupBy('city')->asArray()->all();
  58. $_citydata = [];
  59. foreach ($res as $v) {
  60. $hash = md5($v['city'].'_city');
  61. $_citydata[$hash] = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash]);
  62. }
  63. if($params['getall']==1) {
  64. $needgetall = false;
  65. $sum_field['city'] = 'dpt_sec';
  66. $res = $_query->select($sum_field)->groupBy('dpt_sec')->asArray()->all();
  67. $secdata = [];
  68. foreach ($res as $v) {
  69. $hash = md5($v['city'].'_dpt_sec');
  70. $secdata[$hash] = $v;
  71. }
  72. }
  73. foreach ($citydata as $v) {
  74. if(!in_array($v['city'],$this->cityOptions)) break;
  75. $hash = md5($v['city'].'_city');
  76. $v['sum_car'] = intval($v['sum_car']);
  77. if (isset($_citydata[$hash])) {
  78. $v = array_merge($v, $_citydata[$hash]);
  79. } else {
  80. $v = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash], $sum_data);
  81. }
  82. if($v['city']=='省公司本部'){
  83. $v['avg_mileage'] = strval(round($v['sum_mileage']/$v['sum_work_days'],2));
  84. $v['per_attend'] = strval(round($total['sum_attend_days']/$total['sum_work_days']*100,2));
  85. }else{
  86. $v['avg_mileage'] = strval(round($v['sum_mileage']/$v['sum_work_days'],2));
  87. $v['per_attend'] = strval(round($v['sum_attend_days']/$v['sum_work_days']*100,2));
  88. }
  89. foreach ($total as $key => $_v) {
  90. $total[$key] += $v[$key];
  91. }
  92. $rows[] = $v;
  93. $city_arr[$v['city']] = $v['per_attend'];
  94. $chart1data[] = ['value' => round($v['sum_mileage']/10000), 'name' => $v['city']];
  95. if($params['getall']==1) {
  96. $res = $query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where(['city' => $v['city']])->andWhere($_where)->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  97. foreach ($res as $_k => $_v) {
  98. $hash = md5($_v['city'].'_dpt_sec');
  99. $_v['sum_car'] = intval($_v['sum_car']);
  100. if (isset($secdata[$hash])) {
  101. $_v = array_merge($_v, $secdata[$hash]);
  102. } else {
  103. $_v = array_merge($_v, $sum_data);
  104. }
  105. $_v['hash'] = '';
  106. $_v['parent_hash'] = md5($v['city'].'_city');
  107. if($_v['city']=='省公司本部'){
  108. $_v['avg_mileage'] = $v['avg_mileage'];
  109. $_v['per_attend'] = $v['per_attend'];
  110. }else{
  111. $_v['avg_mileage'] = strval(round($_v['sum_mileage']/$_v['sum_work_days'],2));
  112. $_v['per_attend'] = strval(round($_v['sum_attend_days']/$_v['sum_work_days']*100,2));
  113. }
  114. $rows[] = $_v;
  115. }
  116. }else{
  117. $_v = [];
  118. $_v['hash'] = '';
  119. $_v['parent_hash'] = md5($v['city'].'_city');
  120. $_v = array_merge($_v, $sum_data);
  121. $rows[] = $_v;
  122. }
  123. }
  124. $total['city'] = '全省';
  125. $total['hash'] = $total_hash;
  126. $total['parent_hash'] = md5('全国');
  127. $res = $query->select(['sum_car'=>'count("one"."id")'])->filterWhere($_where)->groupBy('')->orderBy(['sum_car' => SORT_DESC])->asArray()->one();
  128. $total['sum_car'] = $res['sum_car'];
  129. $total['avg_mileage'] = strval(round($total['sum_mileage']/$total['sum_work_days'],2));
  130. $total['per_attend'] = strval(round($total['sum_attend_days']/$total['sum_work_days']*100,2));
  131. array_unshift($rows, $total);
  132. }else{
  133. $citydata = $query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->andWhere($_where)->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  134. $parent_hash = md5($where['city'].'_city');
  135. $sum_field['city'] = 'dpt_sec';
  136. $res = $_query->select($sum_field)->groupBy('dpt_sec')->asArray()->all();
  137. $_citydata = [];
  138. foreach ($res as $v) {
  139. $hash = md5($v['city'].'_dpt_sec');
  140. $_citydata[$hash] = array_merge($v, ['hash' => $hash, 'parent_hash' => $parent_hash]);
  141. }
  142. foreach ($citydata as $v) {
  143. $hash = md5($v['city'].'_dpt_sec');
  144. $v['sum_car'] = intval($v['sum_car']);
  145. $v['rent_car'] = intval($v['rent_car']);
  146. if (isset($_citydata[$hash])) {
  147. $v = array_merge($v, $_citydata[$hash]);
  148. } else {
  149. $v = array_merge($v, ['hash' => $hash, 'parent_hash' => $parent_hash], $sum_data);
  150. }
  151. $v['avg_mileage'] = strval(round($v['sum_mileage']/$v['sum_work_days'],2));
  152. $v['per_attend'] = strval(round($v['sum_attend_days']/$v['sum_work_days']*100,2));
  153. $rows[] = $v;
  154. $city_arr[$v['city']] = $v['per_attend'];
  155. $chart1data[] = ['value' => round($v['sum_mileage']/10000), 'name' => $v['city']];
  156. }
  157. $res = $query->select(['city','sum_car'=>'count("one"."id")'])->where($_where)->andWhere(['city'=>$where['city']])->groupBy('city')->orderBy(['sum_car' => SORT_DESC])->asArray()->one();
  158. $sum_field['city'] = 'city';
  159. $total = $_query->select($sum_field)->andWhere(['city'=>$where['city']])->groupBy('city')->asArray()->one();
  160. $total['sum_car'] = $res['sum_car'];
  161. $total['avg_mileage'] = strval(round($total['sum_mileage']/$total['sum_work_days'],2));
  162. $total['per_attend'] = strval(round($total['sum_attend_days']/$total['sum_work_days']*100,2));
  163. $total['hash'] = $parent_hash;
  164. $total['parent_hash'] = md5('全省');
  165. array_unshift($rows, $total);
  166. }
  167. arsort($city_arr);
  168. foreach ($city_arr as $k=>$v){
  169. $xAxis[] = $k;
  170. $series[] = $v;
  171. }
  172. $result = ["total" => null, "totalNotFiltered" => null, "rows" => $rows, 'needgetall'=> $needgetall,'date'=>$_where];
  173. $result['chartdata'] = [
  174. 'chart1' => $this->getChart1Option([
  175. 'title' => [
  176. 'text' => '行驶里程',
  177. ],
  178. 'series' => [
  179. [
  180. 'name' => '行驶里程(万公里)',
  181. 'data' => $chart1data
  182. ]
  183. ]
  184. ]),
  185. 'chart2' => $this->getChart2Option([
  186. 'title' => [
  187. 'text' => '出勤率(%)',
  188. ],
  189. 'xAxis' => [
  190. [
  191. 'data' => $xAxis,
  192. ]
  193. ],
  194. 'series' => [
  195. [
  196. 'name' => '出勤率(%)',
  197. 'data' => $series,
  198. ]
  199. ]
  200. ])
  201. ];
  202. if (Yii::$app->request->isAjax) echo_json($result);
  203. $this->tableTitle = array(
  204. array('field' => 'city', 'title' => '地市', 'align' => 'left'),
  205. array('field' => 'sum_car', 'title' => '车辆总数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  206. array('field' => 'sum_mileage', 'title' => '行驶里程(公里)', 'align' => 'right', 'formatter'=>'numeric1Formatter'),
  207. array('field' => 'sum_attend_days', 'title' => '行驶天数', 'align' => 'right', 'formatter'=>'numericFormatter'),
  208. array('field' => 'sum_work_days', 'title' => '工作日天数', 'align' => 'right', 'formatter'=>'numericFormatter'),
  209. array('field' => 'avg_mileage', 'title' => '平均单车日里程', 'align' => 'right', 'formatter'=>'numeric1Formatter'),
  210. array('field' => 'per_attend', 'title' => '出勤率(%)', 'align' => 'right', 'formatter'=>'numeric1Formatter'),
  211. );
  212. $this->tableConfig = array('table' => 'total_eff', 'url' => $this->createRealUrl(['car/eff/total', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/fee/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);
  213. $this->result = $result;
  214. }
  215. //效能详单
  216. if ($type == 2) {
  217. $query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  218. if (Yii::$app->request->isAjax) {
  219. $params = Yii::$app->request->get();
  220. $where = $this->getCityWhere($params);
  221. //账期
  222. if(!empty($params['statistical_month'])){
  223. $statistical_month = explode('-',$params['statistical_month']);
  224. $_where['year_info'] = intval($statistical_month[0]);
  225. $_where['month_info'] = intval($statistical_month[1]);
  226. }else{
  227. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  228. $_where['year_info'] = intval($res['year_info']);
  229. $_where['month_info'] = intval($res['month_info']);
  230. }
  231. //车牌
  232. if(!empty($params['card_num'])){
  233. $where['card_num'] = $params['card_num'];
  234. }
  235. if ($params['card_num']!=$params['card_num_text']){
  236. unset($where['card_num']);
  237. $query->where($where)->andWhere(['like','card_num',strtoupper($params['card_num_text'])]);
  238. }else{
  239. $query->where($where);
  240. }
  241. $query->andWhere(['and',['=','year_info',intval($_where['year_info'])],['<=','month_info',intval($_where['month_info'])]]);
  242. $query->select(['one.car_id',
  243. 'year_info'=>'max("year_info")',
  244. 'month_info'=>'max("month_info")',
  245. //'oil_costs'=>'sum("oil_costs")',
  246. //'repair_costs'=>'sum("repair_costs")',
  247. //'insurance_costs'=>'sum("insurance_costs")',
  248. //'rent_costs'=>'sum("rent_costs")',
  249. //'year_check_costs'=>'sum("year_check_costs")',
  250. //'road_bridge_costs'=>'sum("road_bridge_costs")',
  251. //'other_costs'=>'sum("other_costs")',
  252. 'attend_days'=>'sum("attend_days")',
  253. 'work_days'=>'sum("work_days")',
  254. 'sum_mileage'=>'sum("sum_mileage")',
  255. ])->groupBy('one.car_id');
  256. $sql = $query->createCommand()->getRawSql();
  257. $query = FCarInfo::find()->alias('car')->leftJoin("({$sql}) as os", 'car.car_id = os.car_id');
  258. if ($params['card_num']!=$params['card_num_text']){
  259. unset($where['card_num']);
  260. $query->where($where)->andWhere(['like','card_num',$params['card_num_text']]);
  261. }else{
  262. $query->where($where);
  263. }
  264. $countQuery = clone $query;
  265. //分页
  266. if (isset($_GET['limit'])) {
  267. $query->limit(intval($_GET['limit']));
  268. }
  269. if (isset($_GET['offset'])) {
  270. $query->offset(intval($_GET['offset']));
  271. }
  272. $field = ['os.*','car.*',
  273. 'avg_mileage'=>'cast((case when "work_days">0 then ("sum_mileage")/"work_days" else 0 end) as decimal(10,2))',
  274. 'per_attendance'=>'cast((case when "work_days">0 then ("attend_days"/"work_days"::float8)*100 else 0 end) as decimal(10,2))',
  275. 'statistical_month'=>'concat("year_info",LPAD("month_info"::text,2,\'0\'))'];
  276. //'\''.($_where['year_info']*100+$_where['month_info']).'\' as "statistical_month"'];
  277. //排序
  278. if (isset($_GET['sort']) && isset($_GET['sortOrder'])) {
  279. $resultList = $query->select($field)->orderBy([$_GET['sort'] => ($_GET['sortOrder'] == 'asc' ? SORT_ASC : SORT_DESC)])->asArray()->all();
  280. } else {
  281. $resultList = $query->select($field)->orderBy(['statistical_month' => SORT_DESC])->asArray()->all();
  282. }
  283. $result = ["total" => $countQuery->count(), "totalNotFiltered" => $countQuery->count(), "rows" => $resultList];
  284. echo_json($result);
  285. }
  286. $this->tableTitle = array(
  287. array('field' => 'statistical_month', 'title' => '截止账期', 'align' => 'center', 'sortable' => true),
  288. array('field' => 'card_num', 'title' => '车牌号', 'align' => 'center', 'sortable' => true),
  289. array('field' => 'city', 'title' => '单位', 'align' => 'center', 'sortable' => true),
  290. array('field' => 'dpt_sec', 'title' => '二级单位', 'align' => 'center', 'sortable' => true),
  291. array('field' => 'grid', 'title' => '三级单位', 'align' => 'center', 'sortable' => true),
  292. array('field' => 'self_rent', 'title' => '车辆来源', 'align' => 'center', 'sortable' => true),
  293. array('field' => 'car_type', 'title' => '车辆类型', 'align' => 'center', 'sortable' => true),
  294. array('field' => 'using_tag', 'title' => '车辆使用性质', 'align' => 'center', 'sortable' => true),
  295. array('field' => 'sum_mileage', 'title' => '行驶里程(公里)', 'align' => 'right', 'formatter'=>'numeric1Formatter', 'sortable' => true,),
  296. array('field' => 'avg_mileage', 'title' => '日均行驶里程(公里)', 'align' => 'right', 'formatter'=>'numeric1Formatter', 'sortable' => true,),
  297. array('field' => 'per_attendance', 'title' => '出勤率(%)', 'align' => 'right', 'formatter'=>'numeric1Formatter', 'sortable' => true,),
  298. array('field' => 'attend_days', 'title' => '行驶天数', 'align' => 'right', 'formatter'=>'numericFormatter', 'sortable' => true),
  299. array('field' => 'work_days', 'title' => '工作日天数', 'align' => 'right', 'formatter'=>'numericFormatter', 'sortable' => true),
  300. );
  301. $this->tableConfig = array('table' => "fone_car_one_table", 'url' => $this->createRealUrl(['car/eff/total', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/eff/setfield']), 'idField' => "id", 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => true, 'pagesize' => 20, 'refresh' => true, 'exportFileName' => '效能详单', 'height' => 500);
  302. }
  303. return $this->render('total', array('type' => $type, 'koujing' => $koujing));
  304. }
  305. public function actionLow()
  306. {
  307. $type = Yii::$app->request->get('type', 1);
  308. $res = FSpcCar::find()->where(['is_spec'=>1])->asArray()->all();
  309. $spc_cars = [];
  310. foreach ($res as $v){
  311. $spc_cars[] = $v['card_num'];
  312. }
  313. $res = FCarScrap::find()->asArray()->all();
  314. //$spc_cars = [];
  315. foreach ($res as $v){
  316. $spc_cars[] = $v['card_num'];
  317. }
  318. if ($type == 1) {
  319. $query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  320. $params = Yii::$app->request->get();
  321. $where = $this->getCityWhere($params);
  322. //$where['is_special_car'] = 0;
  323. //$where['is_inefficient'] = 1;
  324. $_query = clone $query;
  325. $policy = FInputPolicy::find()->where(['is_active'=>1])->asArray()->one();
  326. if(empty($policy)){
  327. $policy = ['thd_km_per_day'=>20,'thd_att'=>50];
  328. }
  329. $cale = 'sum(case when coalesce((attend_days/nullif(work_days, 0)::float8*100),0)<'.$policy['thd_att'].' and coalesce((sum_mileage/nullif(work_days, 0)::float8),0)<'.$policy['thd_km_per_day'].($spc_cars?' and "card_num" not in (\''.implode('\',\'',$spc_cars).'\')':'').' and "is_special_car"<>0 then 1 else 0 end)';
  330. //$cale = 'sum(case when is_inefficient=1 then 1 else 0 end)';
  331. //->andWhere('(CASE WHEN ("car_new"=1 OR "car_move"=1) THEN (to_date(to_char(allocation_in_date,\'9999-99\'),\'yyyy-MM\')+INTERVAL\'3 month\')<=to_date(to_char("year_info"*100+"month_info",\'9999-99\'),\'yyyy-MM\') ELSE 1=1 END)');
  332. //账期
  333. if(!empty($params['statistical_month'])){
  334. $statistical_month = explode('-',$params['statistical_month']);
  335. $_where['year_info'] = intval($statistical_month[0]);
  336. $_where['month_info'] = intval($statistical_month[1]);
  337. }else{
  338. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  339. $_where['year_info'] = intval($res['year_info']);
  340. $_where['month_info'] = intval($res['month_info']);
  341. }
  342. //$_query->leftJoin('(SELECT car_id FROM {{%f_one_car_one_table}} WHERE ("year_info" = '.intval($_where['year_info']).') AND ("month_info" <= '.intval($_where['month_info']).') GROUP BY "car_id"
  343. // HAVING coalesce((sum(attend_days)/nullif(sum(work_days), 0)::float8*100),0)<'.$policy['thd_att'].' and coalesce((sum(sum_mileage)/nullif(sum(work_days), 0)::float8),0)<'.$policy['thd_km_per_day'].') as "oc"','one.car_id = oc.car_id');
  344. //$_query->where(['and',['=','year_info',intval($_where['year_info'])],['<=','month_info',intval($_where['month_info'])],['=','is_special_car',0],['not in','card_num',$spc_cars]]);
  345. //$_query->andWhere('(CASE WHEN ("car_new"=1 OR "car_move"=1) THEN (to_date(to_char(allocation_in_date,\'9999-99\'),\'yyyy-MM\')+INTERVAL\'3 month\')<=to_date(to_char("year_info"*100+"month_info",\'9999-99\'),\'yyyy-MM\') ELSE 1=1 END)');
  346. //$_where['is_special_car'] = 0;
  347. $res = FCarInfo::find()->where(['car_move'=>1])->andWhere('(to_date(to_char(allocation_in_date,\'9999-99\'),\'yyyy\'))=to_date(to_char('.(intval($_where['year_info'])*100).',\'9999-99\'),\'yyyy\')')->asArray()->all();
  348. $car_ids = [];
  349. foreach ($res as $v){
  350. $_res = FCarInfo::find()->where(['and',['=','card_num',$v['card_num']],['<','car_id',$v['car_id']],['<>','city',$v['city']]])->asArray()->all();
  351. foreach ($_res as $_v){
  352. $car_ids[] = $_v['car_id'];
  353. }
  354. }
  355. $_query->andWhere('"year_info" = '.intval($_where['year_info']).' AND "month_info" =:mi')
  356. ->andWhere('(CASE WHEN ("car_new"=1 OR "car_move"=1) THEN (to_date(to_char(allocation_in_date,\'9999-99\'),\'yyyy-MM\')+INTERVAL\'3 month\')<=to_date(to_char("year_info"*100+"month_info",\'9999-99\'),\'yyyy-MM\') ELSE 1=1 END)');
  357. $_query->select(['c_card_num'=>'card_num', 'c_city'=>'city',
  358. 'car_id'=>'max("one"."car_id")',
  359. 'year_info'=>'max("year_info")',
  360. 'month_info'=>'max("month_info")',
  361. //'oil_costs'=>'sum("oil_costs")',
  362. //'repair_costs'=>'sum("repair_costs")',
  363. //'insurance_costs'=>'sum("insurance_costs")',
  364. //'rent_costs'=>'sum("rent_costs")',
  365. //'year_check_costs'=>'sum("year_check_costs")',
  366. //'road_bridge_costs'=>'sum("road_bridge_costs")',
  367. //'other_costs'=>'sum("other_costs")',
  368. 'attend_days'=>'sum("attend_days")',
  369. 'work_days'=>'sum("work_days")',
  370. 'sum_mileage'=>'sum("sum_mileage")',
  371. ])->groupBy('card_num,city');
  372. $base_sql = $_query->createCommand()->getRawSql();
  373. $sql = str_replace('=:mi','<= '.intval($_where['month_info']),$base_sql);
  374. $_sql = str_replace('=:mi','= '.intval($_where['month_info']),$base_sql);
  375. $_query = FCarInfo::find()->alias('car')->leftJoin("({$sql}) as os", 'car.car_id = os.car_id');
  376. $__query = FCarInfo::find()->alias('car')->leftJoin("({$_sql}) as os", 'car.car_id = os.car_id');
  377. $query->where($where);
  378. $where['is_special_car'] = 0;
  379. $_query->where($where);
  380. $__query->where($where);
  381. $cale_where = '(coalesce((attend_days/nullif(work_days, 0)::float8*100),0)<'.$policy['thd_att'].' and coalesce((sum_mileage/nullif(work_days, 0)::float8),0)<'.$policy['thd_km_per_day'].')';
  382. $_query->andWhere($cale_where)->andWhere(['>','os.car_id',0]);
  383. $__query->andWhere($cale_where)->andWhere(['>','os.car_id',0]);
  384. if(!empty($spc_cars)){
  385. $_query->andWhere(['not in','car.card_num',$spc_cars]);
  386. $__query->andWhere(['not in','car.card_num',$spc_cars]);
  387. }
  388. if(!empty($car_ids)){
  389. $_query->andWhere(['not in','car.car_id',$car_ids]);
  390. $__query->andWhere(['not in','car.car_id',$car_ids]);
  391. }
  392. $sum_field = ['city'=>'city',
  393. //'sum_mileage'=>'cast(sum("sum_mileage") as decimal(10,2))',
  394. //'sum_attend_days'=>'cast(sum("attend_days") as decimal(10,0))',
  395. //'sum_work_days'=>'cast(sum("work_days") as decimal(10,0))',
  396. 'sum_inefficient_car'=>'count(DISTINCT os.car_id)'
  397. ];
  398. $sum_data = ['sum_mileage'=>0,'sum_attend_days'=>0,'sum_work_days'=>0,'sum_inefficient_car'=>0,'month_inefficient_car'=>0,'sum_car'=>0];
  399. $city_arr = [];
  400. $chart1data = [];
  401. $rows = [];
  402. $needgetall = false;
  403. if(empty($where['city'])){
  404. $needgetall = true;
  405. $citydata = $query->select(['city','sum_car'=>'count("one"."id")'])->andWhere($_where)->groupBy('city')->orderBy($this->citySort)->asArray()->all();
  406. $total = $sum_data;
  407. $total_hash = md5('全省');
  408. $res = $_query->select($sum_field)->groupBy('city')->asArray()->all();
  409. $_citydata = [];
  410. foreach ($res as $v) {
  411. $hash = md5($v['city'].'_city');
  412. $_citydata[$hash] = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash], ['month_inefficient_car'=>0]);
  413. }
  414. $res = $__query->select(['city','month_inefficient_car'=>'count(DISTINCT os.car_id)'])->groupBy('city')->asArray()->all();
  415. foreach ($res as $v) {
  416. $hash = md5($v['city'].'_city');
  417. $_citydata[$hash] = array_merge(['hash' => $hash, 'parent_hash' => $total_hash], ($_citydata[$hash]?$_citydata[$hash]:['sum_inefficient_car'=>0]),$v);
  418. }
  419. if($params['getall']==1) {
  420. $needgetall = false;
  421. $sum_field['city'] = 'dpt_sec';
  422. $res = $_query->select($sum_field)->groupBy('dpt_sec')->asArray()->all();
  423. $secdata = [];
  424. foreach ($res as $v) {
  425. $hash = md5($v['city'].'_dpt_sec');
  426. $secdata[$hash] = array_merge($v, ['month_inefficient_car'=>0]);
  427. }
  428. $res = $__query->select(['city'=>'dpt_sec','month_inefficient_car'=>'count(DISTINCT os.car_id)'])->groupBy('dpt_sec')->asArray()->all();
  429. foreach ($res as $v) {
  430. $hash = md5($v['city'].'_dpt_sec');
  431. $secdata[$hash] = array_merge(($secdata[$hash]?$secdata[$hash]:['sum_inefficient_car'=>0]),$v);
  432. }
  433. }
  434. foreach ($citydata as $v) {
  435. if(!in_array($v['city'],$this->cityOptions)) break;
  436. $hash = md5($v['city'].'_city');
  437. $v['sum_car'] = $sum_data['sum_car'] = intval($v['sum_car']);
  438. if (isset($_citydata[$hash])) {
  439. $v = array_merge($v, $_citydata[$hash]);
  440. } else {
  441. $v = array_merge($v, ['hash' => $hash, 'parent_hash' => $total_hash], $sum_data);
  442. }
  443. /*if($v['city']=='省公司本部'){
  444. $v['month_inefficient_car'] = ceil($v['sum_car']*round($total['month_inefficient_car']/$total['sum_car']*100,2)/100);
  445. $v['sum_inefficient_car'] = ceil($v['sum_car']*round($total['sum_inefficient_car']/$total['sum_car']*100,2)/100);
  446. }*/
  447. $v['per_month'] = strval(round($v['month_inefficient_car']/$v['sum_car']*100,2));
  448. $v['per_inefficient'] = strval(round($v['sum_inefficient_car']/$v['sum_car']*100,2));
  449. foreach ($total as $key => $_v) {
  450. $total[$key] += $v[$key];
  451. }
  452. $v['year_info'] = $_where['year_info'];
  453. $v['month_info'] = $_where['month_info'];
  454. $rows[] = $v;
  455. $chart1data[] = ['value' => $v['sum_inefficient_car'], 'name' => $v['city']];
  456. if($params['getall']==1) {
  457. $res = $query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->where(['city' => $v['city']])->andWhere($_where)->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  458. foreach ($res as $_k => $_v) {
  459. $hash = md5($_v['city'].'_dpt_sec');
  460. $_v['sum_car'] = $sum_data['sum_car'] = intval($_v['sum_car']);
  461. if (isset($secdata[$hash])) {
  462. $_v = array_merge($_v, $secdata[$hash]);
  463. } else {
  464. $_v = array_merge($_v, $sum_data);
  465. }
  466. $_v['hash'] = '';
  467. $_v['parent_hash'] = md5($v['city'].'_city');
  468. /*if($_v['city']=='省公司本部'){
  469. $_v['month_inefficient_car'] = $v['month_inefficient_car'];
  470. $_v['sum_inefficient_car'] = $v['sum_inefficient_car'];
  471. }*/
  472. $_v['per_month'] = strval(round($_v['month_inefficient_car']/$_v['sum_car']*100,2));
  473. $_v['per_inefficient'] = strval(round($_v['sum_inefficient_car']/$_v['sum_car']*100,2));
  474. $_v['year_info'] = $_where['year_info'];
  475. $_v['month_info'] = $_where['month_info'];
  476. $rows[] = $_v;
  477. }
  478. }else{
  479. $_v = [];
  480. $_v['hash'] = '';
  481. $_v['parent_hash'] = md5($v['city'].'_city');
  482. $sum_data['sum_car'] = 0;
  483. $_v = array_merge($_v, $sum_data);
  484. $rows[] = $_v;
  485. }
  486. }
  487. $total['city'] = '全省';
  488. $total['hash'] = $total_hash;
  489. $total['parent_hash'] = md5('全国');
  490. $res = $query->select(['sum_car'=>'count("one"."id")'])->filterWhere($_where)->groupBy('')->orderBy(['sum_car' => SORT_DESC])->asArray()->one();
  491. $total['sum_car'] = intval($res['sum_car']);
  492. $res = $__query->select(['month_inefficient_car'=>'count(DISTINCT os.car_id)'])->groupBy('')->asArray()->one();
  493. $total['month_inefficient_car'] = $res['month_inefficient_car'];
  494. $total['per_month'] = strval(round($total['month_inefficient_car']/$total['sum_car']*100,2));
  495. $total['per_inefficient'] = strval(round($total['sum_inefficient_car']/$total['sum_car']*100,2));
  496. $total['year_info'] = $_where['year_info'];
  497. $total['month_info'] = $_where['month_info'];
  498. array_unshift($rows, $total);
  499. }else{
  500. $citydata = $query->select(['city'=>'dpt_sec','sum_car'=>'count("one"."id")'])->andWhere($_where)->orderBy(['sum_car' => SORT_DESC])->groupBy('dpt_sec')->asArray()->all();
  501. $parent_hash = md5($where['city'].'_city');
  502. $sum_field['city'] = 'dpt_sec';
  503. $res = $_query->select($sum_field)->groupBy('dpt_sec')->asArray()->all();
  504. $_citydata = [];
  505. foreach ($res as $v) {
  506. $hash = md5($v['city'].'_dpt_sec');
  507. $_citydata[$hash] = array_merge($v, ['hash' => $hash, 'parent_hash' => $parent_hash], ['month_inefficient_car'=>0]);
  508. }
  509. $res = $__query->select(['city'=>'dpt_sec','month_inefficient_car'=>'count(DISTINCT os.car_id)'])->groupBy('dpt_sec')->asArray()->all();
  510. foreach ($res as $v) {
  511. $hash = md5($v['city'].'_dpt_sec');
  512. $_citydata[$hash] = array_merge(['hash' => $hash, 'parent_hash' => $parent_hash], ($_citydata[$hash]?$_citydata[$hash]:['sum_inefficient_car'=>0]),$v);
  513. }
  514. foreach ($citydata as $v) {
  515. $hash = md5($v['city'].'_dpt_sec');
  516. $v['sum_car'] = $sum_data['sum_car'] = intval($v['sum_car']);
  517. if (isset($_citydata[$hash])) {
  518. $v = array_merge($v, $_citydata[$hash]);
  519. } else {
  520. $v = array_merge($v, ['hash' => $hash, 'parent_hash' => $parent_hash], $sum_data);
  521. }
  522. $v['per_month'] = strval(round($v['month_inefficient_car']/$v['sum_car']*100,2));
  523. $v['per_inefficient'] = strval(round($v['sum_inefficient_car']/$v['sum_car']*100,2));
  524. $v['year_info'] = $_where['year_info'];
  525. $v['month_info'] = $_where['month_info'];
  526. $rows[] = $v;
  527. $chart1data[] = ['value' => $v['sum_inefficient_car'], 'name' => $v['city']];
  528. }
  529. $res = $query->select(['city','sum_car'=>'count("one"."id")'])->where($_where)->andWhere(['city'=>$where['city']])->groupBy('city')->orderBy(['sum_car' => SORT_DESC])->asArray()->one();
  530. $sum_field['city'] = 'city';
  531. $total = $_query->select($sum_field)->andWhere(['city'=>$where['city']])->groupBy('city')->asArray()->one();
  532. $total['sum_car'] = intval($res['sum_car']);
  533. $res = $__query->select(['month_inefficient_car'=>'count(DISTINCT os.car_id)'])->andWhere(['city'=>$where['city']])->groupBy('city')->asArray()->one();
  534. $total['month_inefficient_car'] = intval($res['month_inefficient_car']);
  535. $total['per_month'] = strval(round($total['month_inefficient_car']/$total['sum_car']*100,2));
  536. $total['per_inefficient'] = strval(round($total['sum_inefficient_car']/$total['sum_car']*100,2));
  537. $total['year_info'] = $_where['year_info'];
  538. $total['month_info'] = $_where['month_info'];
  539. $total['hash'] = $parent_hash;
  540. $total['parent_hash'] = md5('全省');
  541. array_unshift($rows, $total);
  542. }
  543. $result = ["total" => null, "totalNotFiltered" => null, "rows" => $rows, 'needgetall'=> $needgetall,'date'=>$_where];
  544. for ($i=1;$i<=$_where['month_info'];$i++){
  545. $xAxis[] = $_where['year_info'].'/'.str_pad($i,2,'0',STR_PAD_LEFT);
  546. $city_where = [];
  547. if($where['city']) $city_where['city'] = $where['city'];
  548. $sql = str_replace('=:mi','<= '.$i,$base_sql);
  549. $_sql = str_replace('=:mi','= '.$i,$base_sql);
  550. $_query = FCarInfo::find()->alias('car')->leftJoin("({$sql}) as os", 'car.car_id = os.car_id');
  551. $__query = FCarInfo::find()->alias('car')->leftJoin("({$_sql}) as os", 'car.car_id = os.car_id');
  552. $city_where['is_special_car'] = 0;
  553. $_query->where($city_where);
  554. $__query->where($city_where);
  555. $cale_where = '(coalesce((attend_days/nullif(work_days, 0)::float8*100),0)<'.$policy['thd_att'].' and coalesce((sum_mileage/nullif(work_days, 0)::float8),0)<'.$policy['thd_km_per_day'].')';
  556. $_query->andWhere($cale_where)->andWhere(['>','os.car_id',0]);
  557. $__query->andWhere($cale_where)->andWhere(['>','os.car_id',0]);
  558. if(!empty($spc_cars)){
  559. $_query->andWhere(['not in','car.card_num',$spc_cars]);
  560. $__query->andWhere(['not in','car.card_num',$spc_cars]);
  561. }
  562. if(!empty($car_ids)){
  563. $_query->andWhere(['not in','car.car_id',$car_ids]);
  564. $__query->andWhere(['not in','car.car_id',$car_ids]);
  565. }
  566. $res = $_query->select(['sum_inefficient_car'=>'count(DISTINCT os.car_id)'])->asArray()->one();
  567. $data_month[] = $res['sum_inefficient_car'];
  568. $res = $__query->select(['month_inefficient_car'=>'count(DISTINCT os.car_id)'])->asArray()->one();;
  569. $data_sum[] = $res['month_inefficient_car'];
  570. }
  571. $result['chartdata'] = [
  572. 'chart1' => $this->getChart1Option([
  573. 'title' => [
  574. 'text' => '低效车地市占比',
  575. ],
  576. 'series' => [
  577. [
  578. 'name' => '低效车数量',
  579. 'data' => $chart1data
  580. ]
  581. ]
  582. ]),
  583. 'chart2' => $this->getChart2Option([
  584. 'title' => [
  585. 'text' => '',
  586. ],
  587. 'legend' => [
  588. 'data' => ['累计算法低效', '单月算法低效']
  589. ],
  590. 'xAxis' => [
  591. [
  592. 'type' => 'category',
  593. 'data' => $xAxis,
  594. 'axisPointer' => [
  595. 'type' => 'shadow'
  596. ]
  597. ]
  598. ],
  599. 'yAxis' => [
  600. [
  601. 'type' => 'value',
  602. 'name' => '累计算法低效',
  603. 'min' => 0,
  604. 'max' => 200,
  605. 'interval' => 50,
  606. 'axisLabel' => [
  607. 'formatter' => '{value} 辆'
  608. ]
  609. ],
  610. [
  611. 'type' => 'value',
  612. 'name' => '单月算法低效',
  613. 'min' => 0,
  614. 'max' => 200,
  615. 'interval' => 50,
  616. 'axisLabel' => [
  617. 'formatter' => '{value} 辆'
  618. ]
  619. ]
  620. ],
  621. 'series' => [
  622. [
  623. 'name' => '累计算法低效',
  624. 'type' => 'bar',
  625. 'tooltip' => json_decode("{
  626. valueFormatter: function (value) {
  627. return value + ' 辆';
  628. }",true),
  629. 'data' => $data_sum
  630. ],
  631. [
  632. 'name' => '单月算法低效',
  633. 'type' => 'line',
  634. 'yAxisIndex' => 1,
  635. 'tooltip' => json_decode("{
  636. valueFormatter: function (value) {
  637. return value + ' 辆';
  638. }",true),
  639. 'data' => $data_month
  640. ]
  641. ]
  642. ])
  643. ];
  644. if (Yii::$app->request->isAjax) echo_json($result);
  645. $this->tableTitle = array(
  646. array('field' => 'city', 'title' => '地市', 'align' => 'left'),
  647. array('field' => 'sum_car', 'title' => '车辆总数量', 'align' => 'right', 'formatter'=>'numericFormatter'),
  648. array('field' => 'month_inefficient_car', 'title' => '单月算法低效车辆', 'align' => 'right'),
  649. array('field' => 'per_month', 'title' => '单月低效车占比', 'align' => 'right', 'formatter'=>'numeric1Formatter'),
  650. array('field' => 'sum_inefficient_car', 'title' => '累计算法低效车辆', 'align' => 'right'),
  651. array('field' => 'per_inefficient', 'title' => '累计低效车占比', 'align' => 'right', 'formatter'=>'numeric1Formatter'),
  652. array('field' => 'year_info', 'title' => '年份', 'align' => 'right'),
  653. array('field' => 'month_info', 'title' => '截止月份', 'align' => 'right'),
  654. );
  655. $this->tableConfig = array('table' => 'low_eff', 'url' => $this->createRealUrl(['car/eff/low', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/fee/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);
  656. $this->result = $result;
  657. }
  658. if ($type == 2) {
  659. $query = FOneCarOneTable::find()->alias('one')->leftJoin('{{%f_car_info}} as c', 'one.car_id = c.car_id');
  660. if (Yii::$app->request->isAjax) {
  661. $params = Yii::$app->request->get();
  662. $where = $this->getCityWhere($params);
  663. //账期
  664. if(!empty($params['statistical_month'])){
  665. $statistical_month = explode('-',$params['statistical_month']);
  666. $_where['year_info'] = intval($statistical_month[0]);
  667. $_where['month_info'] = intval($statistical_month[1]);
  668. }else{
  669. $res = FOneCarOneTable::find()->orderBy('year_info desc,month_info desc' )->asArray()->one();
  670. $_where['year_info'] = intval($res['year_info']);
  671. $_where['month_info'] = intval($res['month_info']);
  672. }
  673. $res = FCarInfo::find()->where(['car_move'=>1])->andWhere('(to_date(to_char(allocation_in_date,\'9999-99\'),\'yyyy\'))=to_date(to_char('.(intval($_where['year_info'])*100).',\'9999-99\'),\'yyyy\')')->asArray()->all();
  674. $car_ids = [];
  675. foreach ($res as $v){
  676. $_res = FCarInfo::find()->where(['and',['=','card_num',$v['card_num']],['<','car_id',$v['car_id']],['<>','city',$v['city']]])->asArray()->all();
  677. foreach ($_res as $_v){
  678. $car_ids[] = $_v['car_id'];
  679. }
  680. }
  681. //车牌
  682. if(!empty($params['card_num'])){
  683. $where['c.card_num'] = $params['card_num'];
  684. }
  685. if ($params['card_num']!=$params['card_num_text']){
  686. unset($where['c.card_num']);
  687. $query->where($where)->andWhere(['like','c.card_num',strtoupper($params['card_num_text'])]);
  688. }else{
  689. $query->where($where);
  690. }
  691. $query->andWhere(['and',['=','year_info',intval($_where['year_info'])],['<=','month_info',intval($_where['month_info'])]])
  692. ->andWhere('(CASE WHEN ("car_new"=1 OR "car_move"=1) THEN (to_date(to_char(allocation_in_date,\'9999-99\'),\'yyyy-MM\')+INTERVAL\'3 month\')<=to_date(to_char("year_info"*100+"month_info",\'9999-99\'),\'yyyy-MM\') ELSE 1=1 END)');
  693. $query->select(['c_card_num'=>'card_num', 'c_city'=>'city',
  694. 'car_id'=>'max("one"."car_id")',
  695. 'year_info'=>'max("year_info")',
  696. 'month_info'=>'max("month_info")',
  697. //'oil_costs'=>'sum("oil_costs")',
  698. //'repair_costs'=>'sum("repair_costs")',
  699. //'insurance_costs'=>'sum("insurance_costs")',
  700. //'rent_costs'=>'sum("rent_costs")',
  701. //'year_check_costs'=>'sum("year_check_costs")',
  702. //'road_bridge_costs'=>'sum("road_bridge_costs")',
  703. //'other_costs'=>'sum("other_costs")',
  704. 'attend_days'=>'sum("attend_days")',
  705. 'work_days'=>'sum("work_days")',
  706. 'sum_mileage'=>'sum("sum_mileage")',
  707. ])->groupBy('card_num,city');
  708. $sql = $query->createCommand()->getRawSql();
  709. $query = FCarInfo::find()->alias('car')->leftJoin("({$sql}) as os", 'car.car_id = os.car_id');
  710. $where['is_special_car'] = 0;
  711. //车牌
  712. if(!empty($params['card_num'])){
  713. unset($where['c.card_num']);
  714. $where['car.card_num'] = $params['card_num'];
  715. }
  716. if ($params['card_num']!=$params['card_num_text']){
  717. unset($where['car.card_num']);
  718. $query->where($where)->andWhere(['like','car.card_num',$params['card_num_text']]);
  719. }else{
  720. $query->where($where);
  721. }
  722. $policy = FInputPolicy::find()->where(['is_active'=>1])->asArray()->one();
  723. if(empty($policy)){
  724. $policy = ['thd_km_per_day'=>20,'thd_att'=>50];
  725. }
  726. $cale_where = '(coalesce((attend_days/nullif(work_days, 0)::float8*100),0)<'.$policy['thd_att'].' and coalesce((sum_mileage/nullif(work_days, 0)::float8),0)<'.$policy['thd_km_per_day'].')';
  727. $query->andWhere($cale_where)->andWhere(['>','os.car_id',0]);
  728. if(!empty($spc_cars)) $query->andWhere(['not in','car.card_num',$spc_cars]);
  729. if(!empty($car_ids)){
  730. $query->andWhere(['not in','car.car_id',$car_ids]);
  731. }
  732. $countQuery = clone $query;
  733. //分页
  734. if (isset($_GET['limit'])) {
  735. $query->limit(intval($_GET['limit']));
  736. }
  737. if (isset($_GET['offset'])) {
  738. $query->offset(intval($_GET['offset']));
  739. }
  740. $field = ['os.*','car.*',
  741. 'avg_mileage'=>'cast((case when "work_days">0 then ("sum_mileage")/"work_days" else 0 end) as decimal(10,2))',
  742. 'per_attendance'=>'cast((case when "work_days">0 then ("attend_days"/"work_days"::float8)*100 else 0 end) as decimal(10,2))',
  743. '\''.($_where['year_info']*100+$_where['month_info']).'\' as "statistical_month"'];
  744. //排序
  745. if (isset($_GET['sort']) && isset($_GET['sortOrder'])) {
  746. $resultList = $query->select($field)->orderBy([$_GET['sort'] => ($_GET['sortOrder'] == 'asc' ? SORT_ASC : SORT_DESC)])->asArray()->all();
  747. } else {
  748. $resultList = $query->select($field)->orderBy(['statistical_month' => SORT_DESC])->asArray()->all();
  749. }
  750. $result = ["total" => $countQuery->count(), "totalNotFiltered" => $countQuery->count(), "rows" => $resultList];
  751. echo_json($result);
  752. }
  753. $this->tableTitle = array(
  754. array('field' => 'statistical_month', 'title' => '截止账期', 'align' => 'center', 'sortable' => true),
  755. array('field' => 'card_num', 'title' => '车牌号', 'align' => 'center', 'sortable' => true),
  756. array('field' => 'city', 'title' => '单位', 'align' => 'center', 'sortable' => true),
  757. array('field' => 'dpt_sec', 'title' => '二级单位', 'align' => 'center', 'sortable' => true),
  758. array('field' => 'grid', 'title' => '三级单位', 'align' => 'center', 'sortable' => true),
  759. array('field' => 'self_rent', 'title' => '车辆来源', 'align' => 'center', 'sortable' => true),
  760. array('field' => 'car_type', 'title' => '车辆类型', 'align' => 'center', 'sortable' => true),
  761. array('field' => 'using_tag', 'title' => '车辆使用性质', 'align' => 'center', 'sortable' => true),
  762. array('field' => 'sum_mileage', 'title' => '行驶里程(公里)', 'align' => 'right', 'formatter'=>'numeric1Formatter', 'sortable' => true,),
  763. array('field' => 'avg_mileage', 'title' => '日均行驶里程(公里)', 'align' => 'right', 'formatter'=>'numeric1Formatter', 'sortable' => true,),
  764. array('field' => 'per_attendance', 'title' => '出勤率(%)', 'align' => 'right', 'formatter'=>'numeric1Formatter', 'sortable' => true,),
  765. array('field' => 'attend_days', 'title' => '行驶天数', 'align' => 'right', 'formatter'=>'numericFormatter', 'sortable' => true),
  766. array('field' => 'work_days', 'title' => '工作日天数', 'align' => 'right', 'formatter'=>'numericFormatter', 'sortable' => true),
  767. );
  768. $this->tableConfig = array('table' => "fone_car_one_table", 'url' => $this->createRealUrl(['car/eff/low', 'type' => $type]), 'setFieldUrl' => $this->createRealUrl(['car/eff/setfield']), 'idField' => 'id', 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => true, 'pagesize' => 20, 'refresh' => true, 'exportFileName' => '低效详单', 'height' => 500);
  769. }
  770. $koujing = '低效车辆指,以年累计里程、年出勤天数计算,日均行驶里程<20公里且出勤率<50%的车辆。出现低效车辆,发管理工单,预警到县分领导。市分低效车辆占比超过5%,发管理工单,预警到市分办公室主任,超过10%,预警升级,预警到市分主管领导。';
  771. return $this->render('low', array('type' => $type, 'koujing' => $koujing));
  772. }
  773. }