Todo.php 41 KB

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