OrderStatistics.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use think\Exception;
  5. class OrderStatistics extends Auth
  6. {
  7. public function repairItems(){
  8. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  9. $end = input('end',date('Y-m-d'));
  10. if(request()->isAjax()){
  11. $sTime = $start.' 00:00:00';
  12. $eTime = $end.' 23:59:59';
  13. $list = Db::name('order_type')
  14. ->field('id,title')
  15. ->where('enable',1)
  16. ->where('del',0)
  17. ->where('org_id',$this->orgId)
  18. ->where('parent_id','>',0)
  19. ->select();
  20. foreach ($list as $k=>$v){
  21. $list[$k]['nums'] = Db::name('orders')
  22. ->alias('o')
  23. ->join('order_repair or','or.order_id=o.id')
  24. ->where('or.type_id',$v['id'])
  25. ->where('o.del',0)
  26. ->where('o.create_time','>=',$sTime)
  27. ->where('o.create_time','<=',$eTime)
  28. ->count();
  29. }
  30. $data = list_sort_by($list,'nums','desc');
  31. $result['rows'] = $data;
  32. return json($result);
  33. }else{
  34. $this->assign('start',$start);
  35. $this->assign('end',$end);
  36. return $this->fetch();
  37. }
  38. }
  39. public function repairItemsExport(){
  40. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  41. $end = input('end',date('Y-m-d'));
  42. $sTime = $start.' 00:00:00';
  43. $eTime = $end.' 23:59:59';
  44. $list = Db::name('order_type')
  45. ->field('id,title')
  46. ->where('enable',1)
  47. ->where('del',0)
  48. ->where('org_id',$this->orgId)
  49. ->where('parent_id','>',0)
  50. ->select();
  51. foreach ($list as $k=>$v){
  52. $list[$k]['nums'] = Db::name('orders')
  53. ->alias('o')
  54. ->join('order_repair or','or.order_id=o.id')
  55. ->where('or.type_id',$v['id'])
  56. ->where('o.del',0)
  57. ->where('o.create_time','>=',$sTime)
  58. ->where('o.create_time','<=',$eTime)
  59. ->count();
  60. }
  61. $data = list_sort_by($list,'nums','desc');
  62. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  63. //实例化PHPExcel类
  64. $objPHPExcel =new \PHPExcel();
  65. //激活当前的sheet表
  66. $objPHPExcel->setActiveSheetIndex(0);
  67. //设置表格头(即excel表格的第一行)
  68. $objPHPExcel->setActiveSheetIndex(0)
  69. ->setCellValue('A1', '报修事项')
  70. ->setCellValue('B1', '总数');
  71. // 设置表格头水平居中
  72. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  73. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  74. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  75. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  76. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  77. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  78. //设置列水平居中
  79. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  80. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  81. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  82. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  83. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  84. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  85. //设置单元格宽度
  86. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  87. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  88. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  89. //循环刚取出来的数组,将数据逐一添加到excel表格。
  90. for ($i = 0; $i < count($data); $i++) {
  91. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $data[$i]['title']);
  92. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $data[$i]['nums']);
  93. }
  94. //设置保存的Excel表格名称
  95. $filename = '报修事项统计报表_' . date('YmdHis', time()) . '.xls';
  96. //设置当前激活的sheet表格名称
  97. $objPHPExcel->getActiveSheet()->setTitle('报修事项统计报表');
  98. //设置浏览器窗口下载表格
  99. ob_end_clean();
  100. header("Content-Type: application/force-download");
  101. header("Content-Type: application/octet-stream");
  102. header("Content-Type: application/download");
  103. header('Content-Disposition:inline;filename="' . $filename);
  104. //生成excel文件
  105. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  106. //下载文件在浏览器窗口
  107. return $objWriter->save('php://output');
  108. }
  109. public function repairCate(){
  110. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  111. $end = input('end',date('Y-m-d'));
  112. if(request()->isAjax()){
  113. $sTime = $start.' 00:00:00';
  114. $eTime = $end.' 23:59:59';
  115. $list = Db::name('order_type')
  116. ->field('id,title,parent_id')
  117. ->where('enable',1)
  118. ->where('del',0)
  119. ->where('org_id',$this->orgId)
  120. ->where('parent_id','=',0)
  121. ->select();
  122. foreach ($list as $k=>$v){
  123. $type = Db::name('order_type')
  124. ->field('id')
  125. ->where('enable',1)
  126. ->where('del',0)
  127. ->where('org_id',$this->orgId)
  128. ->where('parent_id',$v['id'])
  129. ->select();
  130. $ids = [];
  131. foreach ($type as $kk=>$vv){
  132. $ids[$kk] = $vv['id'];
  133. }
  134. $list[$k]['ids'] = $ids;
  135. }
  136. foreach ($list as $k=>$v){
  137. $list[$k]['nums'] = Db::name('orders')
  138. ->alias('o')
  139. ->join('order_repair or','or.order_id=o.id')
  140. ->whereIn('or.type_id',$v['ids'])
  141. ->where('o.del',0)
  142. ->where('o.org_id',$this->orgId)
  143. ->where('o.create_time','>=',$sTime)
  144. ->where('o.create_time','<=',$eTime)
  145. ->count();
  146. }
  147. $data = list_sort_by($list,'nums','desc');
  148. $result['rows'] = $data;
  149. return json($result);
  150. }else{
  151. $this->assign('start',$start);
  152. $this->assign('end',$end);
  153. return $this->fetch();
  154. }
  155. }
  156. public function repairWorkload($mode){
  157. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  158. $end = input('end',date('Y-m-d'));
  159. $mode = input('mode');
  160. if(request()->isAjax()){
  161. $sTime = $start.' 00:00:00';
  162. $eTime = $end.' 23:59:59';
  163. $list = Db::name('todo')
  164. ->field('id,to_user_id')
  165. ->where('del',0)
  166. ->where('org_id',$this->orgId)
  167. ->where('create_time','>=',$sTime)
  168. ->where('create_time','<=',$eTime)
  169. ->where('work_type_mode',$mode)
  170. ->group('to_user_id')
  171. ->select();
  172. foreach ($list as $k=>$v){
  173. $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  174. $list[$k]['nums'] =Db::name('todo')
  175. ->where('del',0)
  176. ->where('to_user_id',$v['to_user_id'])
  177. ->where('org_id',$this->orgId)
  178. ->where('create_time','>=',$sTime)
  179. ->where('create_time','<=',$eTime)
  180. ->where('work_type_mode',$mode)
  181. ->count();
  182. $list[$k]['nums1'] =Db::name('todo')
  183. ->where('del',0)
  184. ->where('to_user_id',$v['to_user_id'])
  185. ->where('org_id',$this->orgId)
  186. ->where('create_time','>=',$sTime)
  187. ->where('create_time','<=',$eTime)
  188. ->where('work_type_mode',$mode)
  189. ->where('todo_mode',1)
  190. ->count();
  191. $list[$k]['nums2'] =Db::name('todo')
  192. ->where('del',0)
  193. ->where('to_user_id',$v['to_user_id'])
  194. ->where('org_id',$this->orgId)
  195. ->where('create_time','>=',$sTime)
  196. ->where('create_time','<=',$eTime)
  197. ->where('work_type_mode',$mode)
  198. ->where('todo_mode',2)
  199. ->count();
  200. $list[$k]['nums3'] =Db::name('todo')
  201. ->where('del',0)
  202. ->where('to_user_id',$v['to_user_id'])
  203. ->where('org_id',$this->orgId)
  204. ->where('create_time','>=',$sTime)
  205. ->where('create_time','<=',$eTime)
  206. ->where('work_type_mode',$mode)
  207. ->where('todo_mode',3)
  208. ->count();
  209. $list[$k]['nums4'] =Db::name('todo')
  210. ->where('del',0)
  211. ->where('to_user_id',$v['to_user_id'])
  212. ->where('org_id',$this->orgId)
  213. ->where('create_time','>=',$sTime)
  214. ->where('create_time','<=',$eTime)
  215. ->where('work_type_mode',$mode)
  216. ->where('todo_mode',4)
  217. ->count();
  218. $list[$k]['nums5'] =Db::name('todo')
  219. ->where('del',0)
  220. ->where('to_user_id',$v['to_user_id'])
  221. ->where('org_id',$this->orgId)
  222. ->where('create_time','>=',$sTime)
  223. ->where('create_time','<=',$eTime)
  224. ->where('work_type_mode',$mode)
  225. ->where('todo_mode',5)
  226. ->count();
  227. $list[$k]['nums6'] =Db::name('todo')
  228. ->where('del',0)
  229. ->where('to_user_id',$v['to_user_id'])
  230. ->where('org_id',$this->orgId)
  231. ->where('create_time','>=',$sTime)
  232. ->where('create_time','<=',$eTime)
  233. ->where('work_type_mode',$mode)
  234. ->where('todo_mode',6)
  235. ->count();
  236. }
  237. $result['rows'] = $list;
  238. return json($result);
  239. }else{
  240. if($mode == 1){
  241. $title = '报修工作量统计报表';
  242. }elseif ($mode == 2){
  243. $title = '保洁工作量统计报表';
  244. }elseif ($mode == 3){
  245. $title = '运送工作量统计报表';
  246. }elseif ($mode == 4){
  247. $title = '应急工作量统计报表';
  248. }elseif ($mode == 0){
  249. $title = '一键呼叫工作量统计报表';
  250. }
  251. $this->assign('mode',$mode);
  252. $this->assign('title',$title);
  253. $this->assign('start',$start);
  254. $this->assign('end',$end);
  255. return $this->fetch();
  256. }
  257. }
  258. public function repairWorkloadExport(){
  259. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  260. $end = input('end',date('Y-m-d'));
  261. $mode = input('mode');
  262. $sTime = $start.' 00:00:00';
  263. $eTime = $end.' 23:59:59';
  264. if($mode == 1){
  265. $title = '报修工作量统计报表';
  266. }elseif ($mode == 2){
  267. $title = '保洁工作量统计报表';
  268. }elseif ($mode == 3){
  269. $title = '运送工作量统计报表';
  270. }elseif ($mode == 4){
  271. $title = '应急工作量统计报表';
  272. }elseif ($mode == 0){
  273. $title = '一键呼叫工作量统计报表';
  274. }
  275. $list = Db::name('todo')
  276. ->field('id,to_user_id')
  277. ->where('del',0)
  278. ->where('org_id',$this->orgId)
  279. ->where('create_time','>=',$sTime)
  280. ->where('create_time','<=',$eTime)
  281. ->where('work_type_mode',$mode)
  282. ->group('to_user_id')
  283. ->select();
  284. foreach ($list as $k=>$v) {
  285. $list[$k]['user_name'] = Db::name('user')->where('id', $v['to_user_id'])->value('real_name');
  286. $list[$k]['nums'] = Db::name('todo')
  287. ->where('del', 0)
  288. ->where('to_user_id', $v['to_user_id'])
  289. ->where('org_id', $this->orgId)
  290. ->where('create_time', '>=', $sTime)
  291. ->where('create_time', '<=', $eTime)
  292. ->where('work_type_mode', $mode)
  293. ->count();
  294. $list[$k]['nums1'] = Db::name('todo')
  295. ->where('del', 0)
  296. ->where('to_user_id', $v['to_user_id'])
  297. ->where('org_id', $this->orgId)
  298. ->where('create_time', '>=', $sTime)
  299. ->where('create_time', '<=', $eTime)
  300. ->where('work_type_mode', $mode)
  301. ->where('todo_mode', 1)
  302. ->count();
  303. $list[$k]['nums2'] = Db::name('todo')
  304. ->where('del', 0)
  305. ->where('to_user_id', $v['to_user_id'])
  306. ->where('org_id', $this->orgId)
  307. ->where('create_time', '>=', $sTime)
  308. ->where('create_time', '<=', $eTime)
  309. ->where('work_type_mode', $mode)
  310. ->where('todo_mode', 2)
  311. ->count();
  312. $list[$k]['nums3'] = Db::name('todo')
  313. ->where('del', 0)
  314. ->where('to_user_id', $v['to_user_id'])
  315. ->where('org_id', $this->orgId)
  316. ->where('create_time', '>=', $sTime)
  317. ->where('create_time', '<=', $eTime)
  318. ->where('work_type_mode', $mode)
  319. ->where('todo_mode', 3)
  320. ->count();
  321. $list[$k]['nums4'] = Db::name('todo')
  322. ->where('del', 0)
  323. ->where('to_user_id', $v['to_user_id'])
  324. ->where('org_id', $this->orgId)
  325. ->where('create_time', '>=', $sTime)
  326. ->where('create_time', '<=', $eTime)
  327. ->where('work_type_mode', $mode)
  328. ->where('todo_mode', 4)
  329. ->count();
  330. $list[$k]['nums5'] = Db::name('todo')
  331. ->where('del', 0)
  332. ->where('to_user_id', $v['to_user_id'])
  333. ->where('org_id', $this->orgId)
  334. ->where('create_time', '>=', $sTime)
  335. ->where('create_time', '<=', $eTime)
  336. ->where('work_type_mode', $mode)
  337. ->where('todo_mode', 5)
  338. ->count();
  339. $list[$k]['nums6'] = Db::name('todo')
  340. ->where('del', 0)
  341. ->where('to_user_id', $v['to_user_id'])
  342. ->where('org_id', $this->orgId)
  343. ->where('create_time', '>=', $sTime)
  344. ->where('create_time', '<=', $eTime)
  345. ->where('work_type_mode', $mode)
  346. ->where('todo_mode', 6)
  347. ->count();
  348. }
  349. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  350. //实例化PHPExcel类
  351. $objPHPExcel =new \PHPExcel();
  352. //激活当前的sheet表
  353. $objPHPExcel->setActiveSheetIndex(0);
  354. //设置表格头(即excel表格的第一行)
  355. $objPHPExcel->setActiveSheetIndex(0)
  356. ->setCellValue('A1', '姓名')
  357. ->setCellValue('B1', '总数')
  358. ->setCellValue('C1', '待领取')
  359. ->setCellValue('D1', '已接单')
  360. ->setCellValue('E1', '已完成')
  361. ->setCellValue('F1', '被员工驳回')
  362. ->setCellValue('G1', '客观原因无法完成')
  363. ->setCellValue('H1', '已取消');
  364. // 设置表格头水平居中
  365. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  366. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  367. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  368. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  369. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  370. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  371. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  372. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  373. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  374. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  375. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  376. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  377. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  378. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  379. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  380. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  381. //设置列水平居中
  382. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  383. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  384. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  385. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  386. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  387. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  388. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  389. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  390. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  391. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  392. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  393. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  394. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  395. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  396. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  397. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  398. //设置单元格宽度
  399. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  400. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  401. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  402. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
  403. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);
  404. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(30);
  405. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(30);
  406. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(30);
  407. //循环刚取出来的数组,将数据逐一添加到excel表格。
  408. for ($i = 0; $i < count($list); $i++) {
  409. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['user_name']);
  410. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['nums']);
  411. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $list[$i]['nums1']);
  412. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $list[$i]['nums2']);
  413. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $list[$i]['nums3']);
  414. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $list[$i]['nums4']);
  415. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $list[$i]['nums5']);
  416. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $list[$i]['nums6']);
  417. }
  418. //设置保存的Excel表格名称
  419. $filename = $title.'_' . date('YmdHis', time()) . '.xls';
  420. //设置当前激活的sheet表格名称
  421. $objPHPExcel->getActiveSheet()->setTitle($title);
  422. //设置浏览器窗口下载表格
  423. ob_end_clean();
  424. header("Content-Type: application/force-download");
  425. header("Content-Type: application/octet-stream");
  426. header("Content-Type: application/download");
  427. header('Content-Disposition:inline;filename="' . $filename);
  428. //生成excel文件
  429. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  430. //下载文件在浏览器窗口
  431. return $objWriter->save('php://output');
  432. }
  433. public function conveyCateWorkload(){
  434. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  435. $end = input('end',date('Y-m-d'));
  436. if(request()->isAjax()){
  437. $sTime = $start.' 00:00:00';
  438. $eTime = $end.' 23:59:59';
  439. $list = Db::name('address')
  440. ->field('id,title')
  441. ->where('enable',1)
  442. ->where('del',0)
  443. ->where('org_id',$this->orgId)
  444. ->where('find_in_set(2,types)')
  445. ->select();
  446. foreach ($list as $k=>$v){
  447. $list[$k]['nums'] = Db::name('order_convey_lis')
  448. ->where('org_id',$this->orgId)
  449. ->where('addr_id',$v['id'])
  450. ->where('create_time','>=',$sTime)
  451. ->where('create_time','<=',$eTime)
  452. ->count();
  453. }
  454. $result['rows'] = $list;
  455. return json($result);
  456. }else{
  457. $this->assign('start',$start);
  458. $this->assign('end',$end);
  459. return $this->fetch();
  460. }
  461. }
  462. public function conveyCateWorkloadExport(){
  463. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  464. $end = input('end',date('Y-m-d'));
  465. $sTime = $start.' 00:00:00';
  466. $eTime = $end.' 23:59:59';
  467. $list = Db::name('address')
  468. ->field('id,title')
  469. ->where('enable',1)
  470. ->where('del',0)
  471. ->where('org_id',$this->orgId)
  472. ->where('find_in_set(2,types)')
  473. ->select();
  474. foreach ($list as $k=>$v){
  475. $list[$k]['nums'] = Db::name('order_convey_lis')
  476. ->where('org_id',$this->orgId)
  477. ->where('addr_id',$v['id'])
  478. ->where('create_time','>=',$sTime)
  479. ->where('create_time','<=',$eTime)
  480. ->count();
  481. }
  482. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  483. //实例化PHPExcel类
  484. $objPHPExcel =new \PHPExcel();
  485. //激活当前的sheet表
  486. $objPHPExcel->setActiveSheetIndex(0);
  487. //设置表格头(即excel表格的第一行)
  488. $objPHPExcel->setActiveSheetIndex(0)
  489. ->setCellValue('A1', '运送地点')
  490. ->setCellValue('B1', '标本');
  491. // 设置表格头水平居中
  492. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  493. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  494. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  495. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  496. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  497. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  498. //设置列水平居中
  499. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  500. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  501. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  502. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  503. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  504. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  505. //设置单元格宽度
  506. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  507. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  508. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  509. //循环刚取出来的数组,将数据逐一添加到excel表格。
  510. for ($i = 0; $i < count($list); $i++) {
  511. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['title']);
  512. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['nums']);
  513. }
  514. //设置保存的Excel表格名称
  515. $filename = '运送类型工作量统计_'. date('YmdHis', time()) . '.xls';
  516. //设置当前激活的sheet表格名称
  517. $objPHPExcel->getActiveSheet()->setTitle('运送类型工作量统计_');
  518. //设置浏览器窗口下载表格
  519. ob_end_clean();
  520. header("Content-Type: application/force-download");
  521. header("Content-Type: application/octet-stream");
  522. header("Content-Type: application/download");
  523. header('Content-Disposition:inline;filename="' . $filename);
  524. //生成excel文件
  525. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  526. //下载文件在浏览器窗口
  527. return $objWriter->save('php://output');
  528. }
  529. public function conveyCateTodo(){
  530. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  531. $end = input('end',date('Y-m-d'));
  532. if(request()->isAjax()){
  533. $sTime = $start.' 00:00:00';
  534. $eTime = $end.' 23:59:59';
  535. $list = Db::name('convey_cate')
  536. ->field('id,title')
  537. ->where('enable',1)
  538. ->where('del',0)
  539. ->where('org_id',$this->orgId)
  540. ->select();
  541. foreach ($list as $k=>$v){
  542. $todo = Db::name('todo')
  543. ->alias('t')
  544. ->field('t.wc_time')
  545. ->join('order_convey oc','oc.order_id=t.order_id')
  546. ->where('oc.type',$v['id'])
  547. ->where('t.del',0)
  548. ->where('t.create_time','>=',$sTime)
  549. ->where('t.create_time','<=',$eTime)
  550. ->where('t.todo_mode',3)
  551. ->select();
  552. $todoCount = Db::name('todo')
  553. ->alias('t')
  554. ->field('t.wc_time')
  555. ->join('order_convey oc','oc.order_id=t.order_id')
  556. ->where('oc.type',$v['id'])
  557. ->where('t.del',0)
  558. ->where('t.create_time','>=',$sTime)
  559. ->where('t.create_time','<=',$eTime)
  560. ->where('t.todo_mode',3)
  561. ->count();
  562. $totalTime = 0;
  563. foreach ($todo as $key=>$val){
  564. $totalTime +=$val['wc_time'];
  565. }
  566. $aveTime = $totalTime>0?round($totalTime/$todoCount/60,2):0;
  567. $list[$k]['count'] = isset($todoCount)?$todoCount:0;
  568. $list[$k]['total_time'] = isset($totalTime)?round($totalTime/60,2):0;
  569. $list[$k]['ave_time'] = isset($aveTime)&&$aveTime>0?$aveTime:0;
  570. }
  571. $result['rows'] = $list;
  572. return json($result);
  573. }else{
  574. $this->assign('start',$start);
  575. $this->assign('end',$end);
  576. return $this->fetch();
  577. }
  578. }
  579. public function conveyCateTodoExport(){
  580. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  581. $end = input('end',date('Y-m-d'));
  582. $sTime = $start.' 00:00:00';
  583. $eTime = $end.' 23:59:59';
  584. $list = Db::name('convey_cate')
  585. ->field('id,title')
  586. ->where('enable',1)
  587. ->where('del',0)
  588. ->where('org_id',$this->orgId)
  589. ->select();
  590. foreach ($list as $k=>$v){
  591. $todo = Db::name('todo')
  592. ->alias('t')
  593. ->field('t.wc_time')
  594. ->join('order_convey oc','oc.order_id=t.order_id')
  595. ->where('oc.type',$v['id'])
  596. ->where('t.del',0)
  597. ->where('t.create_time','>=',$sTime)
  598. ->where('t.create_time','<=',$eTime)
  599. ->where('t.todo_mode',3)
  600. ->select();
  601. $todoCount = Db::name('todo')
  602. ->alias('t')
  603. ->field('t.wc_time')
  604. ->join('order_convey oc','oc.order_id=t.order_id')
  605. ->where('oc.type',$v['id'])
  606. ->where('t.del',0)
  607. ->where('t.create_time','>=',$sTime)
  608. ->where('t.create_time','<=',$eTime)
  609. ->where('t.todo_mode',3)
  610. ->count();
  611. $totalTime = 0;
  612. foreach ($todo as $key=>$val){
  613. $totalTime +=$val['wc_time'];
  614. }
  615. $aveTime = $totalTime>0?round($totalTime/$todoCount/60,2):0;
  616. $list[$k]['count'] = isset($todoCount)?$todoCount:0;
  617. $list[$k]['total_time'] = isset($totalTime)?round($totalTime/60,2):0;
  618. $list[$k]['ave_time'] = isset($aveTime)&&$aveTime>0?$aveTime:0;
  619. }
  620. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  621. //实例化PHPExcel类
  622. $objPHPExcel =new \PHPExcel();
  623. //激活当前的sheet表
  624. $objPHPExcel->setActiveSheetIndex(0);
  625. //设置表格头(即excel表格的第一行)
  626. $objPHPExcel->setActiveSheetIndex(0)
  627. ->setCellValue('A1', '运送类型')
  628. ->setCellValue('B1', '工单数')
  629. ->setCellValue('C1', '总时长(分)')
  630. ->setCellValue('D1', '平均时长(分)');
  631. // 设置表格头水平居中
  632. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  633. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  634. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  635. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  636. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  637. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  638. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  639. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  640. //设置列水平居中
  641. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  642. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  643. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  644. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  645. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  646. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  647. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  648. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  649. //设置单元格宽度
  650. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  651. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  652. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  653. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
  654. //循环刚取出来的数组,将数据逐一添加到excel表格。
  655. for ($i = 0; $i < count($list); $i++) {
  656. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['title']);
  657. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['count']);
  658. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['total_time']);
  659. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['ave_time']);
  660. }
  661. //设置保存的Excel表格名称
  662. $filename = '运送类型工单统计_'. date('YmdHis', time()) . '.xls';
  663. //设置当前激活的sheet表格名称
  664. $objPHPExcel->getActiveSheet()->setTitle('运送类型工单统计_');
  665. //设置浏览器窗口下载表格
  666. ob_end_clean();
  667. header("Content-Type: application/force-download");
  668. header("Content-Type: application/octet-stream");
  669. header("Content-Type: application/download");
  670. header('Content-Disposition:inline;filename="' . $filename);
  671. //生成excel文件
  672. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  673. //下载文件在浏览器窗口
  674. return $objWriter->save('php://output');
  675. }
  676. }