OrderStatistics.php 36 KB

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