Todo.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. use think\Exception;
  6. class Todo extends Auth
  7. {
  8. public function __construct(App $app = null) {
  9. parent::__construct($app);
  10. $this->model= new \app\common\model\Todo();
  11. $this->table='todo_view';
  12. }
  13. //工单列表
  14. public function index(){
  15. $mode = input('mode',0);
  16. $quality_type = input('quality_type','');
  17. if(request()->isAjax()){
  18. //分页参数
  19. $length = input('rows',10,'intval'); //每页条数
  20. $page = input('page',1,'intval'); //第几页
  21. $start = ($page - 1) * $length; //分页开始位置
  22. //排序
  23. $sortRow = input('sidx','id','trim'); //排序列
  24. $sort = input('sord','desc','trim'); //排序方式
  25. $order = $sortRow.' '.$sort;
  26. $content = input('content','','trim');
  27. if($content){
  28. $map[] = ['content','like','%'.$content.'%'];
  29. }
  30. $name = input('name','','trim');
  31. if($name){
  32. $map[] = ['to_real_name','like','%'.$name.'%'];
  33. }
  34. $todo_mode = input('todo_mode','','trim');
  35. if($todo_mode != ''){
  36. if($todo_mode==100){//已挂起
  37. $map[] = ['todo_mode','=',2];
  38. $map[] = ['pause','=',1];
  39. }else{
  40. $map[] = ['todo_mode','=',$todo_mode];
  41. }
  42. }
  43. $b = input('start','','trim');
  44. $e = input('end','','trim');
  45. if($b){
  46. $b = date('Ymd',strtotime($b));
  47. $map[] = ['create_yyyymmdd','>=',$b];
  48. }
  49. if($e){
  50. $e = date('Ymd',strtotime($e));
  51. $map[] = ['create_yyyymmdd','<=',$e];
  52. }
  53. $map[] = ['org_id','=',$this->orgId];
  54. if($mode==-1){//一键呼叫订单
  55. $map[] = ['source_type','=',4];
  56. }
  57. if($mode==-2){ //一键呼叫工单
  58. $map[] = ['work_type_mode','=',0];
  59. }
  60. if($mode == 15){ // 品质检查,单独处理
  61. $map[] = ['work_type_mode','=',$mode];
  62. if($quality_type !=''){
  63. $map[] = ['quality_type','=',$quality_type];
  64. }
  65. }else{
  66. $work_type_mode = input('work_type_mode','','trim');
  67. if(!is_admin($this->userId)){
  68. $auth = get_dispatch_auth($this->userId);
  69. if($auth){
  70. $map[] = ['work_type_mode', 'in', $auth];
  71. if($mode > 0){
  72. $map[] = ['work_type_mode', '=', $mode];
  73. }else{
  74. if($work_type_mode!=''){
  75. $map[] = ['work_type_mode','=',$work_type_mode];
  76. }
  77. }
  78. }else{
  79. $map[] = ['work_type_mode', '=', -1];
  80. }
  81. }else{
  82. if($mode > 0){
  83. $map[] = ['work_type_mode', '=', $mode];
  84. }else{
  85. if($work_type_mode!=''){
  86. $map[] = ['work_type_mode','=',$work_type_mode];
  87. }
  88. }
  89. }
  90. }
  91. $sn = input('sn', '', 'trim');
  92. if ($sn) {
  93. $map[] = ['sn', 'like', '%' . $sn . '%'];
  94. }
  95. $order_sn = input('order_sn', '', 'trim');
  96. if ($order_sn) {
  97. $map[] = ['order_sn', 'like', '%' . $order_sn . '%'];
  98. }
  99. $dep_cate = input('dep_cate', '', 'trim');
  100. if ($dep_cate != '') {
  101. $depIds = Db::name('dep')
  102. ->where('org_id',$this->orgId)
  103. ->where('cate_id',$dep_cate)
  104. ->where('del',0)
  105. ->column('id');
  106. if(!empty($depIds)){
  107. $map[] = ['dep_id', 'in', $depIds];
  108. }else{
  109. $map[] = ['dep_id', '=', -1];
  110. }
  111. }
  112. $from = input('from', '', 'trim');
  113. if ($from) {
  114. if($from >3){
  115. $map[] = ['from','=',0];
  116. $map[] = ['work_type_mode','=',$from-3];
  117. }else{
  118. $map[] = ['from','=',$from];
  119. }
  120. }
  121. $map= empty($map) ? true: $map;
  122. //数据查询
  123. $lists = db($this->table)->where($map)
  124. ->limit($start,$length)
  125. ->order($order)->select();
  126. foreach ($lists as $k=>$v){
  127. $lists[$k] = $this->model->newFormatTodo($v);
  128. }
  129. //数据返回
  130. $totalCount = db($this->table)->where($map)->count();
  131. $totalPage = ceil($totalCount/$length);
  132. $result['page'] = $page;
  133. $result['total'] = $totalPage;
  134. $result['records'] = $totalCount;
  135. $result['rows'] = $lists;
  136. return json($result);
  137. }else{
  138. if($mode>0){
  139. $mode_name = $this->getTableField('work_type_mode',['id'=>$mode],'name');
  140. }else{
  141. $mode_name = '';
  142. }
  143. $auths = [1,2,3,4,15,0];
  144. if(!is_admin($this->userId)){
  145. $auth = get_dispatch_auth($this->userId);
  146. if($auth){
  147. $auths = array_intersect($auths,$auth);
  148. if($mode > 0){
  149. $auths = array_intersect($auths,[$mode]);
  150. }
  151. }else{
  152. $auths = [];
  153. }
  154. }
  155. $this->assign('auths',$auths);
  156. $todo_order_mode = Db::name('todo_mode')
  157. ->select();
  158. $this->assign('todo_mode_list',$todo_order_mode);
  159. $this->assign('m_name',$mode_name);
  160. $this->assign('mode',$mode);
  161. $this->assign('quality_type',$quality_type);
  162. $dep_cate = model('DepCate')->getList();
  163. $this->assign('dep_cate',$dep_cate);
  164. $is = 0;
  165. if(!isset($_GET['quality_type']) && $mode==15){
  166. $is = 1;
  167. }
  168. $this->assign('is',$is);
  169. if($mode==1){
  170. return $this->fetch('index1');
  171. }else if ($mode==3){
  172. return $this->fetch('index3');
  173. }else if ($mode==0 || $mode==-1){
  174. return $this->fetch('index0');
  175. }else{
  176. return $this->fetch('index');
  177. }
  178. }
  179. }
  180. //用户取消订单
  181. public function cancel($id){
  182. $res = $this->model->cancel($id,$this->userId);
  183. if(!$res){
  184. $this->error($this->model->getError());
  185. }
  186. $this->success('取消成功');
  187. }
  188. //调度取消订单
  189. public function disCancel($id){
  190. if(request()->isGet()){
  191. $this->assign('id',$id);
  192. return $this->fetch();
  193. }else{
  194. $reason = input('cancel_reason');
  195. $res = $this->model->cancel($id,$reason);
  196. if(!$res){
  197. $this->error($this->model->getError());
  198. }
  199. $this->success('取消成功');
  200. }
  201. }
  202. //工单详情
  203. public function detail($id){
  204. if (!$id) {
  205. $this->error('参数错误');
  206. }
  207. $order = Db::name('todo_view')->where(['id' => $id])->find();
  208. $order = $this->model->formatTodo($order);
  209. $order['images'] = !empty($order['images'])?explode(',',$order['images']):'';
  210. $order['to_ok_images'] = !empty($order['to_ok_images'])?explode(',',$order['to_ok_images']):'';
  211. $this->assign('info', $order);
  212. $workTypeName = $this->getTableField('work_type_mode',['id'=>$order['work_type_mode']],'name');
  213. $this->assign('meta_title', $workTypeName.'工单详情');
  214. return $this->fetch();
  215. }
  216. //调度删除订单
  217. public function del($id=0){
  218. if(!$id){
  219. $this->error('参数错误');
  220. }
  221. $model = (new \app\common\model\Orders());
  222. $res = $model->del($id,$this->userId);
  223. if(!$res){
  224. $this->error($model->getError());
  225. }
  226. $this->success('删除成功');
  227. }
  228. //派单
  229. public function send($id,$mode=1){
  230. if(request()->isGet()){
  231. $this->assign('id',$id);
  232. $this->assign('mode',$mode);
  233. if($mode==1){
  234. $order_type = (new \app\common\model\OrderType())->getList();
  235. $address = (new \app\common\model\Address())->getListByType(1);
  236. $todoInfo = Db::name('todo')
  237. ->where('id',$id)
  238. ->find();
  239. $order_repair = Db::name('order_repair')
  240. ->where('order_id',$todoInfo['order_id'])
  241. ->find();
  242. $this->assign('order_repair',$order_repair);
  243. $this->assign('order_type_list',$order_type);
  244. $this->assign('address_list',$address);
  245. }
  246. $this->assign('send_user_num',model('orders')->sendUserNum($mode,$this->orgId));
  247. $this->assign('user_list',(new \app\common\model\WorkTypeMode())->getRolesUser($mode,$this->orgId,1));
  248. return $this->fetch();
  249. }else{
  250. $data = request()->post();
  251. $data['org_id'] = $this->orgId;
  252. $res = $this->model->send($id,$this->userId,$data);
  253. if(!$res){
  254. $this->error($this->model->getError());
  255. }
  256. $this->success('操作成功');
  257. }
  258. }
  259. //完成工单
  260. public function finish($id){
  261. $res = $this->model->finish($id);
  262. if(!$res){
  263. $this->error($this->model->getError());
  264. }
  265. $this->success('操作成功');
  266. }
  267. public function removeEmojiChar($str)
  268. {
  269. $mbLen = mb_strlen($str);
  270. $strArr = [];
  271. for ($i = 0; $i < $mbLen; $i++) {
  272. $mbSubstr = mb_substr($str, $i, 1, 'utf-8');
  273. if (strlen($mbSubstr) >= 4) {
  274. continue;
  275. }
  276. $strArr[] = $mbSubstr;
  277. }
  278. return implode('', $strArr);
  279. }
  280. //excel导出
  281. public function export($mode) {
  282. set_time_limit(0);
  283. ini_set("memory_limit", "1024M");
  284. $meta_title = '工单列表';
  285. if ($mode == 1) {
  286. $meta_title = '报修' . $meta_title;
  287. }
  288. elseif ($mode == 2) {
  289. $meta_title = '保洁' . $meta_title;
  290. }
  291. elseif ($mode == 3) {
  292. $meta_title = '运送' . $meta_title;
  293. }
  294. elseif ($mode == 4) {
  295. $meta_title = '安保' . $meta_title;
  296. }
  297. elseif ($mode == 15) {
  298. $meta_title = '品质整改' . $meta_title;
  299. }elseif ($mode == -1) {
  300. $meta_title = '一键呼叫' . $meta_title;
  301. }
  302. $quality_type = input('quality_type','');
  303. if (request()->isGet()) {
  304. //排序
  305. $sortRow = input('sidx','id','trim'); //排序列
  306. $sort = input('sord','desc','trim'); //排序方式
  307. $order = $sortRow.' '.$sort;
  308. $content = input('content','','trim');
  309. if($content){
  310. $map[] = ['content','like','%'.$content.'%'];
  311. }
  312. $name = input('name','','trim');
  313. if($name){
  314. $map[] = ['to_real_name','like','%'.$name.'%'];
  315. }
  316. $todo_mode = input('todo_mode','','trim');
  317. if($todo_mode != ''){
  318. if($todo_mode==100){//已挂起
  319. $map[] = ['todo_mode','=',2];
  320. $map[] = ['pause','=',1];
  321. }else{
  322. $map[] = ['todo_mode','=',$todo_mode];
  323. }
  324. }
  325. $b = input('start','','trim');
  326. $e = input('end','','trim');
  327. if($b){
  328. $b = date('Ymd',strtotime($b));
  329. $map[] = ['create_yyyymmdd','>=',$b];
  330. }
  331. if($e){
  332. $e = date('Ymd',strtotime($e));
  333. $map[] = ['create_yyyymmdd','<=',$e];
  334. }
  335. $map[] = ['org_id','=',$this->orgId];
  336. if($mode==-1){//一键呼叫订单
  337. $map[] = ['source_type','=',4];
  338. }
  339. if($mode == 15){ // 品质检查,单独处理
  340. $map[] = ['work_type_mode','=',$mode];
  341. if($quality_type !=''){
  342. $map[] = ['quality_type','=',$quality_type];
  343. }
  344. }else{
  345. $work_type_mode = input('work_type_mode','','trim');
  346. if(!is_admin($this->userId)){
  347. $auth = get_dispatch_auth($this->userId);
  348. if($auth){
  349. $map[] = ['work_type_mode', 'in', $auth];
  350. if($mode > 0){
  351. $map[] = ['work_type_mode', '=', $mode];
  352. }else{
  353. if($work_type_mode!=''){
  354. $map[] = ['work_type_mode','=',$work_type_mode];
  355. }
  356. }
  357. }else{
  358. $map[] = ['work_type_mode', '=', -1];
  359. }
  360. }else{
  361. if($mode > 0){
  362. $map[] = ['work_type_mode', '=', $mode];
  363. }else{
  364. if($work_type_mode!=''){
  365. $map[] = ['work_type_mode','=',$work_type_mode];
  366. }
  367. }
  368. }
  369. }
  370. $sn = input('sn', '', 'trim');
  371. if ($sn) {
  372. $map[] = ['sn', 'like', '%' . $sn . '%'];
  373. }
  374. $order_sn = input('order_sn', '', 'trim');
  375. if ($order_sn) {
  376. $map[] = ['order_sn', 'like', '%' . $order_sn . '%'];
  377. }
  378. $dep_cate = input('dep_cate', '', 'trim');
  379. if ($dep_cate != '') {
  380. $depIds = Db::name('dep')
  381. ->where('org_id',$this->orgId)
  382. ->where('cate_id',$dep_cate)
  383. ->where('del',0)
  384. ->column('id');
  385. if(!empty($depIds)){
  386. $map[] = ['dep_id', 'in', $depIds];
  387. }else{
  388. $map[] = ['dep_id', '=', -1];
  389. }
  390. }
  391. $from = input('from', '', 'trim');
  392. if ($from) {
  393. if($from >3){
  394. $map[] = ['from','=',0];
  395. $map[] = ['work_type_mode','=',$from-3];
  396. }else{
  397. $map[] = ['from','=',$from];
  398. }
  399. }
  400. $map= empty($map) ? true: $map;
  401. //数据查询
  402. $lists = db($this->table)->where($map)
  403. ->order($order)->select();
  404. foreach ($lists as $k=>$v){
  405. $lists[$k] = $this->model->newFormatTodo($v);
  406. $lists[$k]['content'] = $this->removeEmojiChar($v['content']);
  407. }
  408. include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
  409. //实例化PHPExcel类
  410. $objPHPExcel = new \PHPExcel();
  411. //激活当前的sheet表
  412. $objActSheet = $objPHPExcel->setActiveSheetIndex(0);
  413. //设置表格头(即excel表格的第一行)
  414. if ($mode == 1) {
  415. $objPHPExcel->setActiveSheetIndex(0)
  416. ->setCellValue('A1', '编号')
  417. ->setCellValue('B1', '订单编号')
  418. ->setCellValue('C1', '发起人')
  419. ->setCellValue('D1', '执行人')
  420. ->setCellValue('E1', '报修类型')
  421. ->setCellValue('F1', '报修事项')
  422. ->setCellValue('G1', '报修地点')
  423. ->setCellValue('H1', '内容')
  424. ->setCellValue('I1', '订单发起时间')
  425. ->setCellValue('J1', '调度分派时间')
  426. ->setCellValue('K1', '接单时间')
  427. ->setCellValue('L1', '完成时间')
  428. ->setCellValue('M1', '状态')
  429. ->setCellValue('N1', '调度分派时长')
  430. ->setCellValue('O1', '接单时长')
  431. ->setCellValue('P1', '处理时长')
  432. ->setCellValue('Q1', '挂起开始时间')
  433. ->setCellValue('R1', '挂起结束时间')
  434. ->setCellValue('S1', '挂起时长')
  435. ->setCellValue('T1', '所在科室/部门')
  436. ->setCellValue('U1', '来源')
  437. ->setCellValue('V1', '部门分类')
  438. ->setCellValue('w1', '签名图');
  439. }
  440. else {
  441. if ($mode == 3) {
  442. $objPHPExcel->setActiveSheetIndex(0)
  443. ->setCellValue('A1', '编号')
  444. ->setCellValue('B1', '订单编号')
  445. ->setCellValue('C1', '发起人')
  446. ->setCellValue('D1', '执行人')
  447. ->setCellValue('E1', '内容')
  448. ->setCellValue('F1', '订单发起时间')
  449. ->setCellValue('G1', '调度分派时间')
  450. ->setCellValue('H1', '接单时间')
  451. ->setCellValue('I1', '完成时间')
  452. ->setCellValue('J1', '取件地点')
  453. ->setCellValue('K1', '取件时间')
  454. ->setCellValue('L1', '送达地点')
  455. ->setCellValue('M1', '送达时间')
  456. ->setCellValue('N1', '运送类型')
  457. ->setCellValue('O1', '状态')
  458. ->setCellValue('P1', '调度分派时长')
  459. ->setCellValue('Q1', '接单时长')
  460. ->setCellValue('R1', '处理时长')
  461. ->setCellValue('S1', '所在科室/部门')
  462. ->setCellValue('T1', '来源')
  463. ->setCellValue('U1', '部门分类');
  464. }
  465. else {
  466. if($mode==0){
  467. $objPHPExcel->setActiveSheetIndex(0)
  468. ->setCellValue('A1', '编号')
  469. ->setCellValue('B1', '订单编号')
  470. ->setCellValue('C1', '发起人')
  471. ->setCellValue('D1', '执行人')
  472. ->setCellValue('E1', '内容')
  473. ->setCellValue('F1', '订单发起时间')
  474. ->setCellValue('G1', '调度分派时间')
  475. ->setCellValue('H1', '接单时间')
  476. ->setCellValue('I1', '完成时间')
  477. ->setCellValue('J1', '状态')
  478. ->setCellValue('K1', '工单类型')
  479. ->setCellValue('L1', '调度分派时长')
  480. ->setCellValue('M1', '接单时长')
  481. ->setCellValue('N1', '处理时长')
  482. ->setCellValue('O1', '所在科室/部门')
  483. ->setCellValue('P1', '来源')
  484. ->setCellValue('Q1', '部门分类');
  485. }else{
  486. $objPHPExcel->setActiveSheetIndex(0)
  487. ->setCellValue('A1', '编号')
  488. ->setCellValue('B1', '订单编号')
  489. ->setCellValue('C1', '发起人')
  490. ->setCellValue('D1', '执行人')
  491. ->setCellValue('E1', '内容')
  492. ->setCellValue('F1', '订单发起时间')
  493. ->setCellValue('G1', '调度分派时间')
  494. ->setCellValue('H1', '接单时间')
  495. ->setCellValue('I1', '完成时间')
  496. ->setCellValue('J1', '状态')
  497. ->setCellValue('K1', '调度分派时长')
  498. ->setCellValue('L1', '接单时长')
  499. ->setCellValue('M1', '处理时长')
  500. ->setCellValue('N1', '所在科室/部门')
  501. ->setCellValue('O1', '来源')
  502. ->setCellValue('P1', '部门分类');
  503. }
  504. }
  505. }
  506. // 设置表格头水平居中
  507. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  508. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  509. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  510. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  511. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  512. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  513. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  514. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  515. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  516. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  517. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  518. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  519. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  520. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  521. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  522. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  523. //设置列水平居中
  524. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  525. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  526. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  527. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  528. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  529. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  530. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  531. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  532. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  533. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  534. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  535. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  536. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  537. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  538. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  539. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  540. //设置单元格宽度
  541. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  542. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  543. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  544. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  545. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  546. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  547. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  548. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  549. //循环刚取出来的数组,将数据逐一添加到excel表格。
  550. if ($mode == 1) {
  551. for ($i = 0; $i < count($lists); $i++) {
  552. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  553. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
  554. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
  555. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
  556. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_type']);
  557. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['order_type_matter']);
  558. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['address_title']);
  559. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['content']);
  560. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['create_time']);
  561. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['to_create_time']);
  562. $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['confirm_time']);
  563. $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['done_time']);
  564. $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['todo_mode_in_content']);
  565. $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['dispatch_time']);
  566. $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['jiedan_time']);
  567. $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['time_cost']);
  568. $objPHPExcel->getActiveSheet()->setCellValue('Q' . ($i + 2), $lists[$i]['pause_time']);
  569. $objPHPExcel->getActiveSheet()->setCellValue('R' . ($i + 2), $lists[$i]['pause_end']);
  570. $objPHPExcel->getActiveSheet()->setCellValue('S' . ($i + 2), $lists[$i]['pause_cost']);
  571. $objPHPExcel->getActiveSheet()->setCellValue('T' . ($i + 2), $lists[$i]['dep']);
  572. $objPHPExcel->getActiveSheet()->setCellValue('U' . ($i + 2), $lists[$i]['source_type_text']);
  573. $objPHPExcel->getActiveSheet()->setCellValue('V' . ($i + 2), $lists[$i]['dep_cate_name']);
  574. $signList = explode(".",$lists[$i]['sign']);
  575. if($signList){
  576. $ext = end($signList);
  577. $img ='';
  578. if ($ext == 'jpg' || $ext == 'jpeg'){
  579. $img = @imagecreatefromjpeg($lists[$i]['sign']);
  580. }
  581. if ($ext == 'png'){
  582. $img = @imagecreatefrompng($lists[$i]['sign']);
  583. }
  584. if($img){
  585. //实例化图片操作类
  586. $objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
  587. $objDrawing->setImageResource($img);
  588. $objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);//渲染方法
  589. $objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
  590. $objDrawing->setHeight(40);//照片高度
  591. $objDrawing->setWidth(40); //照片宽度
  592. $objDrawing->setCoordinates('W'.($i+2));//图片要插入的单元格
  593. $objDrawing->setOffsetX(8);//图片X轴偏移
  594. $objDrawing->setOffsetY(8);//图片Y轴偏移
  595. $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
  596. //设置每一行高度
  597. }else{
  598. $objPHPExcel->getActiveSheet()->setCellValue('W' . ($i + 2), '');
  599. }
  600. }else{
  601. $objPHPExcel->getActiveSheet()->setCellValue('W' . ($i + 2), '');
  602. }
  603. $objActSheet->getRowDimension($i + 2)->setRowHeight(40); // 行高
  604. }
  605. }
  606. else {
  607. if ($mode == 3) {
  608. for ($i = 0; $i < count($lists); $i++) {
  609. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  610. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
  611. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
  612. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
  613. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
  614. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
  615. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['to_create_time']);
  616. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['confirm_time']);
  617. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['done_time']);
  618. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['start_name']);
  619. $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['xq_time']);
  620. $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['end_name']);
  621. $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['ywc_time']);
  622. $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['type_name']);
  623. $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['todo_mode_in_content']);
  624. $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['dispatch_time']);
  625. $objPHPExcel->getActiveSheet()->setCellValue('Q' . ($i + 2), $lists[$i]['jiedan_time']);
  626. $objPHPExcel->getActiveSheet()->setCellValue('R' . ($i + 2), $lists[$i]['time_cost']);
  627. $objPHPExcel->getActiveSheet()->setCellValue('S' . ($i + 2), $lists[$i]['dep']);
  628. $objPHPExcel->getActiveSheet()->setCellValue('T' . ($i + 2), $lists[$i]['source_type_text']);
  629. $objPHPExcel->getActiveSheet()->setCellValue('U' . ($i + 2), $lists[$i]['dep_cate_name']);
  630. }
  631. }
  632. else {
  633. if($mode==0){
  634. for ($i = 0; $i < count($lists); $i++) {
  635. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  636. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
  637. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
  638. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
  639. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
  640. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
  641. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['to_create_time']);
  642. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['confirm_time']);
  643. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['done_time']);
  644. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['todo_mode_in_content']);
  645. $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['work_type_mode_text']);
  646. $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['dispatch_time']);
  647. $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['jiedan_time']);
  648. $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['time_cost']);
  649. $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['dep']);
  650. $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['source_type_text']);
  651. $objPHPExcel->getActiveSheet()->setCellValue('Q' . ($i + 2), $lists[$i]['dep_cate_name']);
  652. }
  653. }else{
  654. for ($i = 0; $i < count($lists); $i++) {
  655. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  656. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
  657. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
  658. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
  659. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
  660. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
  661. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['to_create_time']);
  662. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['confirm_time']);
  663. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['done_time']);
  664. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['todo_mode_in_content']);
  665. $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['dispatch_time']);
  666. $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['jiedan_time']);
  667. $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['time_cost']);
  668. $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['dep']);
  669. $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['source_type_text']);
  670. $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['dep_cate_name']);
  671. }
  672. }
  673. }
  674. }
  675. //设置保存的Excel表格名称
  676. $filename = $meta_title . '_' . date('YmdHis', time()) . '.xls';
  677. //设置当前激活的sheet表格名称
  678. $objPHPExcel->getActiveSheet()->setTitle($meta_title);
  679. //设置浏览器窗口下载表格
  680. ob_end_clean();
  681. header("Content-Type: application/force-download");
  682. header("Content-Type: application/octet-stream");
  683. header("Content-Type: application/download");
  684. header('Content-Disposition:inline;filename="' . $filename);
  685. //生成excel文件
  686. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  687. //下载文件在浏览器窗口
  688. return $objWriter->save('php://output');
  689. }
  690. }
  691. public function print($id){
  692. $info = Db::name('todo_view')->where('id',$id)->find();
  693. $depName = Db::name('dep')
  694. ->where('id',$info['dep_id'])
  695. ->value('title');
  696. $info['depName'] = $depName;
  697. $info['cons'] = [];
  698. $info['sign'] = Db::name('todo')->where('id',$id)->value('sign');
  699. $total = $totalPrice = 0;
  700. $mate = Db::name('todo_mate_item')
  701. ->alias('tmi')
  702. ->join('todo_mate tm','tmi.todo_mate_id = tm.id')
  703. ->join('mate_goods mg','mg.id = tmi.items_id')
  704. ->field('tmi.items_id,tmi.total,tmi.money,tmi.total_money,mg.title')
  705. ->where('tm.todo_id',$info['id'])
  706. ->select();
  707. if(!empty($mate)){
  708. foreach ($mate as $kk=>$todo_mate){
  709. $info['cons'][] = [
  710. 'title' =>$todo_mate['title'],
  711. 'total' =>$todo_mate['total'],
  712. 'money' =>$todo_mate['money'],
  713. 'total_money' =>$todo_mate['total_money'],
  714. ];
  715. $total +=$todo_mate['total'];
  716. $totalPrice +=$todo_mate['total_money'];
  717. }
  718. }
  719. $aa = [
  720. 'title'=>'',
  721. 'total'=>'',
  722. 'money'=>'',
  723. 'total_money'=>'',
  724. ];
  725. if(empty($info['cons'])){
  726. for ($i=1;$i<=4;$i++){
  727. $info['cons'][] = $aa;
  728. }
  729. }elseif (count($info['cons']) <4){
  730. $ii = 4-count($info['cons']);
  731. for ($i=1;$i<=$ii;$i++){
  732. $info['cons'][] = $aa;
  733. }
  734. }
  735. $info['total'] = $total;
  736. $info['totalPrice'] = round($totalPrice,2);
  737. $this->assign('info', $info);
  738. return $this->fetch();
  739. }
  740. }