You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

670 regels
31 KiB

  1. <?php
  2. namespace backend\modules\motorcade\controllers;
  3. use backend\modules\motorcade\models\BusDepartment;
  4. use backend\modules\motorcade\models\BusOrder;
  5. use backend\modules\motorcade\models\DriverFeeSearch;
  6. use backend\modules\motorcade\models\ReportModel;
  7. use backend\modules\motorcade\models\search\searchBusIncome;
  8. use backend\modules\motorcade\models\BusReport;
  9. use common\components\zPhpExcel;
  10. use Yii;
  11. use yii\data\SqlDataProvider;
  12. use yii\filters\AccessControl;
  13. use yii\helpers\ArrayHelper;
  14. class ReportController extends BaseController
  15. {
  16. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  17. /**
  18. * @inheritdoc
  19. */
  20. public function behaviors()
  21. {
  22. return [
  23. 'access' => [
  24. 'class' => AccessControl::className(),
  25. 'rules' => [
  26. [
  27. 'actions' => ['bus-income', 'hybrid', 'hybrid-detail', 'road-bridge', 'driver-fee', 'driver-fee-detail', 'bus-detail', 'export', 'excel'],
  28. 'allow' => true,
  29. 'roles' => ['@'],
  30. ],
  31. ],
  32. ]
  33. ];
  34. }
  35. public function actionIndex()
  36. {
  37. return $this->render('index');
  38. }
  39. /**
  40. * 出车收统计
  41. * @return string
  42. */
  43. public function actionBusIncome()
  44. {
  45. $searchModel = new searchBusIncome();
  46. $searchModel->date_from = date('Y-m-01');
  47. $searchModel->date_to = date('Y-m-t');
  48. $searchModel->line_type = 1;
  49. $searchModel->date_type = 1;
  50. $searchModel->search_type = 0;
  51. $search = Yii::$app->request->queryParams;
  52. $dataProvider = $searchModel->search($search);
  53. return $this->render('report', ['view' => '_busIncome', 'dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
  54. }
  55. // /*by luocj
  56. // * 油电费用统计
  57. // */
  58. // public function actionHybrid()
  59. // {
  60. // $obj = new BusReport();
  61. // $cur_date = date('Y-m-d');
  62. // $start_date = $obj->getCurMonthFirstDay($cur_date);
  63. // $end_date = $obj->getCurMonthLastDay($cur_date);
  64. // //获取数据
  65. // $get_start_date = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : $start_date;
  66. // $get_end_date = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : $end_date;
  67. // $get_bus_license = isset($_REQUEST['bus_license']) && $_REQUEST['bus_license'] != '' ? $_REQUEST['bus_license'] : -1;
  68. // $get_status = isset($_REQUEST['status']) && $_REQUEST['status'] != '' ? $_REQUEST['status'] : 479;
  69. // $bus_license = $obj->getBusLicense();
  70. // $data = $obj->getHybrid($get_start_date, $get_end_date, $get_bus_license, $get_status);
  71. // $dataProvider1 = new SqlDataProvider([
  72. // 'sql' => $data['sql_jiayou'],
  73. // 'pagination' => [
  74. // 'pagesize' => '50',
  75. // ],
  76. // 'totalCount' => $data['data_total_jiayou'],
  77. // ]);
  78. // $dataProvider2 = new SqlDataProvider([
  79. // 'sql' => $data['sql_chongdian'],
  80. // 'pagination' => [
  81. // 'pagesize' => '50',
  82. // ],
  83. // 'totalCount' => $data['data_total_chongdian'],
  84. // ]);
  85. // return $this->render('report', ['view' => '_hybrid', 'bus_license' => $bus_license, 'dataProvider1' => $dataProvider1, 'dataProvider2' => $dataProvider2, 'status' => $get_status, 'start_date' => $get_start_date, 'end_date' => $get_end_date]);
  86. // }
  87. /*by luocj
  88. * 油电费用统计
  89. */
  90. public function actionHybrid()
  91. {
  92. $obj1 = new BusOrder();
  93. $obj2 = new BusOrder();
  94. $cur_date = date('Y-m-d');
  95. $start_date = BusReport::getCurMonthFirstDay($cur_date);
  96. $end_date = BusReport::getCurMonthLastDay($cur_date);
  97. //获取数据
  98. $get_start_date = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : $start_date;
  99. $get_end_date = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : $end_date;
  100. $get_bus_license = isset($_REQUEST['bus_license']) && $_REQUEST['bus_license'] != '' ? $_REQUEST['bus_license'] : -1;
  101. $get_status = isset($_REQUEST['status']) && $_REQUEST['status'] != '' ? $_REQUEST['status'] : 479;
  102. $op_you = 'hybrid_you';
  103. $op_dian = 'hybrid_dian';
  104. $show = true;
  105. $params1 = ['start_date' => $get_start_date, 'end_date' => $get_end_date, 'bus_id' => $get_bus_license, 'op' => $op_you, 'show' => $show];
  106. $params2 = ['start_date' => $get_start_date, 'end_date' => $get_end_date, 'bus_id' => $get_bus_license, 'op' => $op_dian, 'show' => $show];
  107. $dataProvider1 = $obj1->getExport($params1);
  108. $dataProvider2 = $obj2->getExport($params2);
  109. $bus_license = BusReport::getBusLicense();
  110. return $this->render('report', ['view' => '_hybrid', 'bus_license' => $bus_license, 'dataProvider1' => $dataProvider1, 'dataProvider2' => $dataProvider2, 'status' => $get_status, 'start_date' => $get_start_date, 'end_date' => $get_end_date]);
  111. }
  112. /**
  113. * by luocj
  114. * 油电费用详情统计
  115. */
  116. public function actionHybridDetail()
  117. {
  118. $obj = new BusReport();
  119. $cur_date = date('Y-m-d');
  120. $start_date = $obj->getCurMonthFirstDay($cur_date);
  121. $end_date = $obj->getCurMonthLastDay($cur_date);
  122. //获取数据
  123. $get_start_date = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : $start_date;
  124. $get_end_date = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : $end_date;
  125. $get_bus_license = isset($_REQUEST['bus_license']) && $_REQUEST['bus_license'] != '' ? $_REQUEST['bus_license'] : -1;
  126. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'jiayou';
  127. $data = $obj->getHybridDetail($get_start_date, $get_end_date, $get_bus_license);
  128. $dataProvider1 = new SqlDataProvider([
  129. 'sql' => $data['sql_jiayou'],
  130. 'pagination' => [
  131. 'pagesize' => '15',
  132. ],
  133. 'totalCount' => $data['data_total_jiayou'],
  134. ]);
  135. $dataProvider2 = new SqlDataProvider([
  136. 'sql' => $data['sql_chongdian'],
  137. 'pagination' => [
  138. 'pagesize' => '10',
  139. ],
  140. 'totalCount' => $data['data_total_chongdian'],
  141. ]);
  142. return $this->render('report', ['view' => '_hybridDetail', 'dataProvider1' => $dataProvider1, 'dataProvider2' => $dataProvider2, 'start_date' => $get_start_date, 'end_date' => $get_end_date, 'bus_license' => $get_bus_license, 'type' => $type]);
  143. }
  144. /*by luocj
  145. * 路桥费用统计
  146. */
  147. public function actionRoadBridge()
  148. {
  149. $obj = new BusOrder();
  150. $cur_date = date('Y-m-d');
  151. $start_date = BusReport::getCurMonthFirstDay($cur_date);
  152. $end_date = BusReport::getCurMonthLastDay($cur_date);
  153. //获取数据
  154. $get_start_date = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : $start_date;
  155. $get_end_date = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : $end_date;
  156. $get_bus_license = isset($_REQUEST['bus_license']) && $_REQUEST['bus_license'] != '' ? $_REQUEST['bus_license'] : -1;
  157. $op = 'road-bridge';
  158. $show = true;
  159. $params = ['start_date' => $get_start_date, 'end_date' => $get_end_date, 'bus_id' => $get_bus_license, 'op' => $op, 'show' => $show];
  160. $dataProvider = $obj->getExport($params);
  161. $bus_license = BusReport::getBusLicense();
  162. return $this->render('report', ['view' => '_roadBridge', 'dataProvider' => $dataProvider, 'bus_license' => $bus_license, 'start_date' => $get_start_date, 'end_date' => $get_end_date]);
  163. }
  164. // /**
  165. // * User: wangxj
  166. // *
  167. // * 司机费用统计
  168. // *
  169. // * @return string
  170. // */
  171. // public function actionDriverFee()
  172. // {
  173. // $searchModel = new DriverFeeSearch();
  174. // $dataProvider = $searchModel->search(Yii::$app->request->post('DriverFeeSearch'));
  175. // $driver_name = ReportModel::getBusDriver();
  176. // return $this->render('report', [
  177. // 'view' => '_driverFee',
  178. // 'searchModel' => $searchModel,
  179. // 'dataProvider' => $dataProvider,
  180. // 'driver_name' => $driver_name,
  181. // ]);
  182. // }
  183. /**
  184. * User: wangxj
  185. *
  186. * 司机费用统计
  187. *
  188. * @return string
  189. */
  190. public function actionDriverFee()
  191. {
  192. $obj = new BusOrder();
  193. $cur_date = date('Y-m-d');
  194. $start_date = BusReport::getCurMonthFirstDay($cur_date);
  195. $end_date = BusReport::getCurMonthLastDay($cur_date);
  196. //获取数据
  197. $tmp = Yii::$app->request->post('BusOrder');
  198. $get_date_type = isset($tmp['date_type']) ? $tmp['date_type'] : 1;
  199. $get_start_date = isset($tmp['start_date']) ? $tmp['start_date'] : $start_date;
  200. $get_end_date = isset($tmp['end_date']) ? $tmp['end_date'] : $end_date;
  201. $get_driver_id = isset($tmp['driver_id']) ? $tmp['driver_id'] : -1;
  202. $op = 'driver-fee';
  203. $show = true;
  204. $params = ['get_date_type' => $get_date_type, 'start_date' => $get_start_date, 'end_date' => $get_end_date, 'driver_id' => $get_driver_id, 'op' => $op, 'show' => $show];
  205. $dataProvider = $obj->getExport($params);
  206. $driver_name = ReportModel::getBusDriver();
  207. return $this->render('report', [
  208. 'view' => '_driverFee',
  209. 'searchModel' => $obj,
  210. 'dataProvider' => $dataProvider,
  211. 'driver_name' => $driver_name,
  212. ]);
  213. }
  214. /**
  215. * User: wangxj
  216. *
  217. * 司机费用中的明细
  218. *
  219. * @param $driver_id integer 司机id
  220. *
  221. * @return
  222. */
  223. public function actionDriverFeeDetail($bus_driver_res_id)
  224. {
  225. $searchModel = new DriverFeeSearch();
  226. $dataProvider = $searchModel->detailSearch($bus_driver_res_id, Yii::$app->request->post('DriverFeeSearch'));
  227. $dataProvider->setSort(false);
  228. //用车单位搜索
  229. $depart = BusDepartment::findAll(['cancel_flag' => 0]);
  230. return $this->render('report', [
  231. 'view' => '_driverDetailFee',
  232. 'searchModel' => $searchModel,
  233. 'dataProvider' => $dataProvider,
  234. 'data' => ['depart' => $depart]
  235. ]);
  236. }
  237. /**
  238. * 出车收入统计详情
  239. * @return string
  240. */
  241. public function actionBusDetail()
  242. {
  243. $obj = new BusOrder();
  244. $cur_date = date('Y-m-d');
  245. $start_date = BusReport::getCurMonthFirstDay($cur_date);
  246. $end_date = BusReport::getCurMonthLastDay($cur_date);
  247. $get_start_date = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : $start_date;
  248. $get_end_date = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : $end_date;
  249. $get_bus_license = isset($_REQUEST['bus_id']) ? $_REQUEST['bus_id'] : '-1';
  250. $get_bus_license = isset($_REQUEST['bus_license']) ? $_REQUEST['bus_license'] : $get_bus_license;
  251. $get_bus_number = isset($_REQUEST['bus_number']) ? $_REQUEST['bus_number'] : '';
  252. $get_date_type = isset($_REQUEST['date_type']) ? $_REQUEST['date_type'] : '1';
  253. $get_bus_user = isset($_REQUEST['bus_user']) ? $_REQUEST['bus_user'] : '-1';
  254. $get_line_type = isset($_REQUEST['line_type']) ? $_REQUEST['line_type'] : '-1';
  255. $get_driver_id = isset($_REQUEST['bus_driver_res_id']) ? $_REQUEST['bus_driver_res_id'] : '-1';
  256. $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : 'detail';
  257. $show = true;
  258. $params = ['date_type' => $get_date_type, 'start_date' => $get_start_date, 'end_date' => $get_end_date,
  259. 'bus_id' => $get_bus_license, 'driver_id' => $get_driver_id, 'line_type' => $get_line_type,
  260. 'use_bus_org_id' => $get_bus_user, 'op' => $op, 'show' => $show, 'bus_number' => $get_bus_number];
  261. $dataProvider = $obj->getExport($params);
  262. $dataProvider->pagination = ['pagesize' => 10];
  263. $bus_user = BusReport::getBusDepartment();
  264. return $this->render('report', ['view' => '_busDetail', 'dataProvider' => $dataProvider, 'bus_user' => $bus_user, 'bus_id' => $get_bus_license, 'start_date' => $get_start_date, 'end_date' => $get_end_date]);
  265. }
  266. //车管报表导出
  267. public function actionExport()
  268. {
  269. $date_type = isset($_REQUEST['date_type']) ? $_REQUEST['date_type'] : '1';
  270. $start_date = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : '';
  271. $end_date = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : '';
  272. // $use_bus_org_id = isset($_POST['use_bus_org_id']) ? $_POST['use_bus_org_id'] : (isset($_GET['use_bus_org_id']) ? $_GET['use_bus_org_id'] : -1);
  273. $use_bus_org_id = $_POST['bus_user'];
  274. $driver_id = isset($_REQUEST['driver_id']) ? $_REQUEST['driver_id'] : -1;
  275. $bus_id = isset($_REQUEST['bus_id']) ? $_REQUEST['bus_id'] : -1;
  276. $line_type = isset($_REQUEST['line_type']) ? $_REQUEST['line_type'] : -1;
  277. $bus_number = isset($_REQUEST['bus_number']) ? $_REQUEST['bus_number'] : -1;
  278. //op
  279. //bus-income 出车收入
  280. //hybrid 油电费用
  281. //road-bridge 路桥
  282. //driver-fee 司机费用
  283. //detail 订单明细
  284. $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
  285. $obj = new BusOrder();
  286. $params = array(
  287. 'date_type' => $date_type,
  288. 'start_date' => $start_date,
  289. 'end_date' => $end_date,
  290. 'use_bus_org_id' => $use_bus_org_id,
  291. 'driver_id' => $driver_id,
  292. 'bus_id' => $bus_id,
  293. 'line_type' => $line_type,
  294. 'op' => $op
  295. );
  296. $data = $obj->getExport($params);
  297. if ($op == 'bus-income') {
  298. $res = $this->actionExportBusIncome($data);
  299. } elseif ($op == 'road-bridge') {
  300. $res = $this->actionExportRoadBridge($data);
  301. } elseif ($op == 'driver-fee') {
  302. $res = $this->actionExportDriverFee($data);
  303. } elseif ($op == 'detail') {
  304. $res = $this->actionExportDetail($data);
  305. } elseif (in_array($op, ['hybrid_you', 'hybrid_dian'])) {
  306. $res = $this->actionExportHybrid($op, $data);
  307. } else {
  308. }
  309. if (in_array($op, ['bus-income', 'road-bridge', 'driver-fee', 'detail', 'hybrid_you', 'hybrid_dian']) &&
  310. isset($obj) && isset($res['file_name']) && isset($res['data_title']) && isset($res['data_all']) && isset($res['data_list'])
  311. ) {
  312. $this->exportExcel($obj, $res['file_name'], $res['data_title'], $res['data_all'], $res['data_list']);
  313. } else {
  314. return "<script>Command: parent.toastr[\"warning\"](\"报表导出失败\");</script>";
  315. }
  316. }
  317. private function actionExportBusIncome($data)
  318. {
  319. $res['file_name'] = '出车收入统计';
  320. $res['data_title'] = array('用车单位', '结算方式', '结算周期', '出车数', '收入', '运营成本', '毛利', '公里数', '预估油电费', '路桥费', '司贴', '停车费', '餐饮费', '住宿费');
  321. $res['data_all'][0]['heji'] = '总计';
  322. $res['data_all'][0]['heji1'] = '-';
  323. $res['data_all'][0]['heji2'] = '-';
  324. $res['data_all'][0]['chuche_count'] = 0;
  325. $res['data_all'][0]['income'] = 0;
  326. $res['data_all'][0]['all_cost'] = 0;
  327. $res['data_all'][0]['maoli'] = 0;
  328. $res['data_all'][0]['lichengshu'] = 0;
  329. $res['data_all'][0]['youdian'] = 0;
  330. $res['data_all'][0]['luqiao'] = 0;
  331. $res['data_all'][0]['sitie'] = 0;
  332. $res['data_all'][0]['tingche'] = 0;
  333. $res['data_all'][0]['canyin'] = 0;
  334. $res['data_all'][0]['zhusu'] = 0;
  335. foreach ($data as $k => $v) {
  336. $res['data_list'][$k][] = $v['use_bus_org_name'];
  337. $res['data_list'][$k][] = $v['depart_type'];
  338. $res['data_list'][$k][] = $v['depart_cycle'];
  339. $res['data_list'][$k][] = $v['chuche_count'];
  340. $res['data_list'][$k][] = $v['income'];
  341. $res['data_list'][$k][] = $v['all_cost'];
  342. $res['data_list'][$k][] = $v['maoli'];
  343. $res['data_list'][$k][] = $v['lichengshu'];
  344. $res['data_list'][$k][] = $v['youdian'];
  345. $res['data_list'][$k][] = $v['luqiao'];
  346. $res['data_list'][$k][] = $v['sitie'];
  347. $res['data_list'][$k][] = $v['tingche'];
  348. $res['data_list'][$k][] = $v['canyin'];
  349. $res['data_list'][$k][] = $v['zhusu'];
  350. $res['data_all'][0]['chuche_count'] += $v['chuche_count'];
  351. $res['data_all'][0]['income'] += $v['income'];
  352. $res['data_all'][0]['all_cost'] += $v['all_cost'];
  353. $res['data_all'][0]['maoli'] += $v['maoli'];
  354. $res['data_all'][0]['lichengshu'] += $v['lichengshu'];
  355. $res['data_all'][0]['youdian'] += $v['youdian'];
  356. $res['data_all'][0]['luqiao'] += $v['luqiao'];
  357. $res['data_all'][0]['sitie'] += $v['sitie'];
  358. $res['data_all'][0]['tingche'] += $v['tingche'];
  359. $res['data_all'][0]['canyin'] += $v['canyin'];
  360. $res['data_all'][0]['zhusu'] += $v['zhusu'];
  361. }
  362. return $res;
  363. }
  364. private function actionExportRoadBridge($data)
  365. {
  366. $res['file_name'] = '路桥费用统计';
  367. $res['data_title'] = array('车辆', '品牌', '座位', '出车数', '出车公里数', '出车路桥费');
  368. $res['data_all'][0]['heji'] = '总计';
  369. $res['data_all'][0]['heji1'] = '-';
  370. $res['data_all'][0]['heji2'] = '-';
  371. $res['data_all'][0]['chuche_count'] = 0;
  372. $res['data_all'][0]['lichengshu'] = 0;
  373. $res['data_all'][0]['luqiao'] = 0;
  374. foreach ($data as $k => $v) {
  375. $res['data_list'][$k][] = $v['bus_name'];
  376. $res['data_list'][$k][] = $v['brand_name'];
  377. $res['data_list'][$k][] = $v['seat_desc'];
  378. $res['data_list'][$k][] = $v['chuche_count'];
  379. $res['data_list'][$k][] = $v['lichengshu'];
  380. $res['data_list'][$k][] = $v['luqiao'];
  381. $res['data_all'][0]['chuche_count'] += $v['chuche_count'];
  382. $res['data_all'][0]['lichengshu'] += $v['lichengshu'];
  383. $res['data_all'][0]['luqiao'] += $v['luqiao'];
  384. }
  385. return $res;
  386. }
  387. private function actionExportDriverFee($data)
  388. {
  389. $res['file_name'] = '司机费用统计';
  390. $res['data_title'] = array('司机姓名', '出车数', '公里数', '司贴', '停车费', '餐饮费', '住宿费');
  391. $res['data_all'][0]['heji'] = '总计';
  392. $res['data_all'][0]['chuche_count'] = 0;
  393. $res['data_all'][0]['lichengshu'] = 0;
  394. $res['data_all'][0]['sitie'] = 0;
  395. $res['data_all'][0]['tingche'] = 0;
  396. $res['data_all'][0]['canyin'] = 0;
  397. $res['data_all'][0]['zhusu'] = 0;
  398. foreach ($data as $k => $v) {
  399. $res['data_list'][$k][] = $v['driver_name'];
  400. $res['data_list'][$k][] = $v['chuche_count'];
  401. $res['data_list'][$k][] = $v['lichengshu'];
  402. $res['data_list'][$k][] = $v['sitie'];
  403. $res['data_list'][$k][] = $v['tingche'];
  404. $res['data_list'][$k][] = $v['canyin'];
  405. $res['data_list'][$k][] = $v['zhusu'];
  406. $res['data_all'][0]['chuche_count'] += $v['chuche_count'];
  407. $res['data_all'][0]['lichengshu'] += $v['lichengshu'];
  408. $res['data_all'][0]['sitie'] += $v['sitie'];
  409. $res['data_all'][0]['tingche'] += $v['tingche'];
  410. $res['data_all'][0]['canyin'] += $v['canyin'];
  411. $res['data_all'][0]['zhusu'] += $v['zhusu'];
  412. }
  413. return $res;
  414. }
  415. private function actionExportDetail($data)
  416. {
  417. $res['file_name'] = '出车明细';
  418. $res['data_title'] = array('出车日期', '收车日期', '出车单号', '车辆', '司机', '线路', '用车单位', '收入', '运营成本', '毛利', '公里数', '开始公里数', '结束公里数', '预估油电费', '路桥费', '司贴', '停车费', '餐饮费', '住宿费', '报账状态');
  419. $res['data_all'][0]['heji'] = '总计';
  420. $res['data_all'][0]['heji1'] = '-';
  421. $res['data_all'][0]['heji2'] = '-';
  422. $res['data_all'][0]['heji3'] = '-';
  423. $res['data_all'][0]['heji4'] = '-';
  424. $res['data_all'][0]['heji5'] = '-';
  425. $res['data_all'][0]['heji6'] = '-';
  426. $res['data_all'][0]['income'] = 0;
  427. $res['data_all'][0]['all_cost'] = 0;
  428. $res['data_all'][0]['maoli'] = 0;
  429. $res['data_all'][0]['lichengshu'] = 0;
  430. $res['data_all'][0]['start_lichengshu'] = 0;
  431. $res['data_all'][0]['end_lichengshu'] = 0;
  432. $res['data_all'][0]['youdian'] = 0;
  433. $res['data_all'][0]['luqiao'] = 0;
  434. $res['data_all'][0]['sitie'] = 0;
  435. $res['data_all'][0]['tingche'] = 0;
  436. $res['data_all'][0]['canyin'] = 0;
  437. $res['data_all'][0]['zhusu'] = 0;
  438. $res['data_all'][0]['heji8'] = '-';
  439. foreach ($data as $k => $v) {
  440. $res['data_list'][$k][] = $v['run_date'];
  441. $res['data_list'][$k][] = $v['finish_date'];
  442. $res['data_list'][$k][] = $v['bus_number'];
  443. $res['data_list'][$k][] = $v['bus_name'];
  444. $res['data_list'][$k][] = $v['driver_name'];
  445. $res['data_list'][$k][] = $v['itinerary_name'];
  446. $res['data_list'][$k][] = $v['use_bus_org_name'];
  447. $res['data_list'][$k][] = $v['income'];
  448. $res['data_list'][$k][] = $v['all_cost'];
  449. $res['data_list'][$k][] = $v['maoli'];
  450. $res['data_list'][$k][] = $v['lichengshu'];
  451. $res['data_list'][$k][] = $v['start_lichengshu'];
  452. $res['data_list'][$k][] = $v['end_lichengshu'];
  453. $res['data_list'][$k][] = $v['youdian'];
  454. $res['data_list'][$k][] = $v['luqiao'];
  455. $res['data_list'][$k][] = $v['sitie'];
  456. $res['data_list'][$k][] = $v['tingche'];
  457. $res['data_list'][$k][] = $v['canyin'];
  458. $res['data_list'][$k][] = $v['zhusu'];
  459. $res['data_list'][$k][] = $v['finance_status'];
  460. $res['data_all'][0]['income'] += $v['income'];
  461. $res['data_all'][0]['all_cost'] += $v['all_cost'];
  462. $res['data_all'][0]['maoli'] += $v['maoli'];
  463. $res['data_all'][0]['lichengshu'] += $v['lichengshu'];
  464. $res['data_all'][0]['start_lichengshu'] += $v['start_lichengshu'];
  465. $res['data_all'][0]['end_lichengshu'] += $v['end_lichengshu'];
  466. $res['data_all'][0]['youdian'] += $v['youdian'];
  467. $res['data_all'][0]['luqiao'] += $v['luqiao'];
  468. $res['data_all'][0]['sitie'] += $v['sitie'];
  469. $res['data_all'][0]['tingche'] += $v['tingche'];
  470. $res['data_all'][0]['canyin'] += $v['canyin'];
  471. $res['data_all'][0]['zhusu'] += $v['zhusu'];
  472. }
  473. return $res;
  474. }
  475. private function actionExportHybrid($op, $data)
  476. {
  477. $res['file_name'] = '油电费用统计';
  478. if ($op == 'hybrid_you') {
  479. $res['data_title'] = array('车辆', '车龄', '品牌', '座位', '加油量(升)', '加油金额', '总里程数', '出车里程数', '平均油耗(升/百公里)');
  480. } else {
  481. $res['data_title'] = array('车辆', '车龄', '品牌', '座位', '充电量(度)', '充电金额', '总里程数', '出车里程数', '平均电耗(度/百公里)');
  482. }
  483. $res['data_all'][0]['heji'] = '总计';
  484. $res['data_all'][0]['heji1'] = '-';
  485. $res['data_all'][0]['heji2'] = '-';
  486. $res['data_all'][0]['heji3'] = '-';
  487. $res['data_all'][0]['receive_value'] = 0;
  488. $res['data_all'][0]['expense_price'] = 0;
  489. $res['data_all'][0]['all_lichengshu'] = 0;
  490. $res['data_all'][0]['lichengshu'] = 0;
  491. $res['data_all'][0]['ave'] = 0;
  492. foreach ($data as $k => $v) {
  493. $res['data_list'][$k][] = $v['bus_no'];
  494. $res['data_list'][$k][] = $v['buy_date'];
  495. $res['data_list'][$k][] = $v['brand_name'];
  496. $res['data_list'][$k][] = $v['seat_desc'];
  497. $res['data_list'][$k][] = $v['receive_value'];
  498. $res['data_list'][$k][] = $v['expense_price'];
  499. $res['data_list'][$k][] = $v['all_lichengshu'];
  500. $res['data_list'][$k][] = $v['lichengshu'];
  501. if ($v['all_lichengshu'] != 0) {
  502. $res['data_list'][$k][] = $v['receive_value'] / $v['all_lichengshu'] * 100;
  503. } else {
  504. $res['data_list'][$k][] = 0;
  505. }
  506. $res['data_all'][0]['receive_value'] += $v['receive_value'];
  507. $res['data_all'][0]['expense_price'] += $v['expense_price'];
  508. $res['data_all'][0]['all_lichengshu'] += $v['all_lichengshu'];
  509. $res['data_all'][0]['lichengshu'] += $v['lichengshu'];
  510. }
  511. if ($res['data_all'][0]['all_lichengshu'] != 0) {
  512. $res['data_all'][0]['ave'] += $res['data_all'][0]['receive_value'] / $res['data_all'][0]['all_lichengshu'] * 100;
  513. } else {
  514. $res['data_all'][0]['ave'] = 0;
  515. }
  516. return $res;
  517. }
  518. /**
  519. * User:Steven
  520. *
  521. * 导出Excel文件
  522. * @param $obj Report report对象
  523. * @param $file_name string 导出文件名称后缀
  524. * @param $data_title array 数据表头,title
  525. * @param $data_all array 合计数据列表
  526. * @param $data_list array 数据列表
  527. */
  528. public function exportExcel($obj, $file_name, $data_title, $data_all, $data_list)
  529. {
  530. require Yii::getAlias('@backend') . "/common/PHPExcel/PHPExcel.php";
  531. $objPHPExcel = new \PHPExcel(); //实例化PHPExcel类
  532. $objSheet = $objPHPExcel->getActiveSheet(); //获取当前活动sheet的操作对象
  533. $sheet_title = $obj['start_date'] . '~' . $obj['end_date'] . ($obj['date_type'] == 1 ? '(出车日期)' : '收车日期');
  534. $objSheet->setTitle($file_name); //给当前活动sheet的操作对象
  535. $directory = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
  536. $cell_num = count($data_title) - 1;
  537. $cell = $directory[$cell_num];
  538. $objSheet->mergeCells("A1:{$cell}1"); //合并单元格
  539. $objSheet->setCellValue('A1', $sheet_title . $file_name);
  540. $objSheet->getStyle("A1:{$cell}1")->getFont()->setName('微软雅黑')->setSize(15)->setBold(True);
  541. $objSheet->getStyle("A1:{$cell}1")->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);;
  542. $objSheet->getStyle("A1:{$cell}1")->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('A6A6A6');
  543. $objSheet->getStyle("A2:{$cell}2")->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('CCCCCC');
  544. foreach ($data_title as $k => $v) {
  545. $objSheet->setCellValue($directory[$k] . '2', $v);
  546. }
  547. // $objSheet->setCellValue('A3', '-');
  548. // $objSheet->setCellValue('B3', '合计');
  549. for ($i = 0; $i < count($data_all); $i++) {
  550. $list = array_values($data_all[$i]);
  551. foreach ($list as $k => $v) {
  552. $objSheet->setCellValue($directory[$k] . '3', $v);
  553. }
  554. }
  555. for ($j = 0; $j < count($data_list); $j++) {
  556. $list = array_values($data_list[$j]);
  557. foreach ($list as $k => $v) {
  558. $objSheet->setCellValue($directory[$k] . ($j + 4), $v);
  559. }
  560. }
  561. $objWrite = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); //按照指定格式生成excel文件
  562. $this->browserExport('05', $sheet_title . $file_name . '.xls');
  563. $objWrite->save('php://output');
  564. }
  565. /**
  566. * 导出到浏览器
  567. * @param $type
  568. * @param $fileName
  569. */
  570. private function browserExport($type, $fileName)
  571. {
  572. if ($type == '05') { //输出xls文件
  573. header('Content-Type: application/vnd.ms-excel;');
  574. } else { //输出xlsx文件
  575. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  576. }
  577. header('Content-Disposition: attachment;filename="' . $fileName . '"');
  578. header('Cache-Control: max-age=0');//禁止缓存
  579. }
  580. /**
  581. * 新统计报表导出
  582. */
  583. public function actionExcel()
  584. {
  585. $searchModel = new searchBusIncome();
  586. $search = Yii::$app->request->queryParams;
  587. $dataProvider = $searchModel->search($search);
  588. /* $query ActiveQuery */
  589. // $query = $dataProvider->query;
  590. $dataProvider->pagination = false;
  591. $models = $dataProvider->getModels();
  592. $objPHPExcel = new zPhpExcel(); //实例化PHPExcel类
  593. $objSheet = $objPHPExcel->getActiveSheet(); //获取当前活动sheet的操作对象
  594. $objPHPExcel->file_name = '报表' . ($searchModel->date_type == 1 ? '出车日期' : '收车日期') . ' ' . ($searchModel->date_from . '-' . $searchModel->date_to);
  595. $objSheet->setTitle('报表');
  596. if ($searchModel->search_type == 0) {
  597. $order_sort = ['department.depart_name', 'department.settleType.TYPE_NAME', 'department.settleCycle.TYPE_NAME',
  598. 'chuche_count', 'income', 'all_cost', 'maoli', 'lichengshu', 'youdian', 'luqiao', 'sitie', 'tingche', 'canyin', 'zhusu'];
  599. $title = array('用车单位', '结算方式', '结算周期', '出车数', '收入', '运营成本', '毛利', '公里数', '预估油电费', '路桥费', '司贴', '停车费', '餐饮费', '住宿费');
  600. } else {
  601. $order_sort = ['bus.BUS_NO', 'bus.SEAT_DESC', 'bus.brand.RES_NAME', 'chuche_count', 'income', 'all_cost', 'maoli',
  602. 'lichengshu', 'youdian', 'luqiao', 'sitie', 'tingche', 'canyin', 'zhusu'];
  603. $title = array('车牌号', '车座数', '品牌', '出车数', '收入', '运营成本', '毛利', '公里数', '预估油电费', '路桥费', '司贴', '停车费', '餐饮费', '住宿费');
  604. }
  605. //表头
  606. $a_k = range('B', 'O');
  607. foreach ($a_k as $key => $item) {
  608. $objSheet->setCellValue($item . '1', $title[$key]);
  609. }
  610. //数据
  611. ini_set("memory_limit", "-1");
  612. $count = 0;
  613. foreach ($models as $key => $datum) {
  614. $objSheet->setCellValue('A' . ($key + 2), $key + 1);
  615. foreach ($a_k as $index => $item) {
  616. $objSheet->setCellValue($item . ($key + 2), ArrayHelper::getValue($datum, $order_sort[$index]));
  617. }
  618. $count = $key + 2;
  619. }
  620. //合计
  621. $objSheet->setCellValue('B' . ($count + 1), '合计');
  622. foreach (range('E', 'O') as $item) {
  623. $objSheet->setCellValue($item . ($count + 1), "=sum({$item}2:{$item}" . $count . ')');
  624. }
  625. $count += 1;
  626. $objSheet->getStyle("B{$count}:O{$count}")->getFont()->setBold(true);
  627. //设置宽度
  628. $objPHPExcel->setColumnSize(range('B', 'O'), [25, 12, 12, 12, 12, 10, 10, 10, 15, 10, 10, 10, 10]);
  629. $objPHPExcel->output();
  630. }
  631. }
  632. ?>