Address.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\util\ExcelUtil;
  4. use think\Db;
  5. class Address extends Auth
  6. {
  7. public function index(){
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','id','trim'); //排序列
  15. $sort = input('sord','desc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort;
  17. $title = input('title','','trim');
  18. if($title){
  19. $map[] = ['title','like','%'.$title.'%'];
  20. }
  21. $enable = input('enable','','trim');
  22. if($enable != ''){
  23. $map[] = ['enable','=',$enable];
  24. }
  25. $type = input('type','','trim');
  26. if($type != ''){
  27. $map[]=['','exp',Db::raw("FIND_IN_SET($type,types)")];
  28. }
  29. $map[] = ['del','=',0];
  30. $map[] = ['org_id','=',$this->orgId];
  31. $map= empty($map) ? true: $map;
  32. //数据查询
  33. $lists = db('address')->where($map)->limit($start,$length)->order($order)->select();
  34. foreach ($lists as $k=>$v){
  35. $ts = $v['types']?explode(',',$v['types']):[];
  36. $lists[$k]['types_text'] = '';
  37. $filteredArray = array_diff($ts, [null, '']);
  38. if(!empty($ts)){
  39. $lists[$k]['types_text'] = model('Address')->getTypeStr($filteredArray);
  40. }
  41. }
  42. //数据返回
  43. $totalCount = db('address')->where($map)->count();
  44. $totalPage = ceil($totalCount/$length);
  45. $result['page'] = $page;
  46. $result['total'] = $totalPage;
  47. $result['records'] = $totalCount;
  48. $result['rows'] = $lists;
  49. return json($result);
  50. }else{
  51. $types = model('Address')->getTypes();
  52. $this->assign('types',$types);
  53. return $this->fetch();
  54. }
  55. }
  56. /**
  57. * 新增/编辑
  58. */
  59. public function add($id=0){
  60. if(request()->isPost()){
  61. $res = model('Address')->updates();
  62. if($res){
  63. $this->success('操作成功',url('index'));
  64. }else{
  65. $this->error(model('Address')->getError());
  66. }
  67. }else{
  68. if($id){
  69. $info = db('address')->where('id',$id)->find();
  70. if($info){
  71. $info['types'] = $info['types']?explode(',',$info['types']):[];
  72. }
  73. $this->assign('info',$info);
  74. }
  75. $ts = model('Address')->getTypes();
  76. $types = [];
  77. foreach ($ts as $k=>$v){
  78. $types[] = [
  79. 'id' => $k,
  80. 'title' => $v
  81. ];
  82. }
  83. $bjUserList = model('User')->getWorkTypeModeUser(2,$this->orgId,-1);
  84. $ysUserList = model('User')->getWorkTypeModeUser(3,$this->orgId,-1);
  85. $this->assign('bjUserList',$bjUserList);
  86. $this->assign('ysUserList',$ysUserList);
  87. $dep = model('dep')->getList();
  88. $this->assign('dep',$dep);
  89. $this->assign('types',$types);
  90. return $this->fetch();
  91. }
  92. }
  93. /**
  94. * 删除记录
  95. * @param int $id
  96. */
  97. public function del($id=0){
  98. if(!$id){
  99. $this->error('参数错误');
  100. }
  101. $res = db('address')->where('id',$id)->setField('del',1);
  102. if($res){
  103. $this->success('删除成功');
  104. }else{
  105. $this->error('删除失败');
  106. }
  107. }
  108. /**
  109. * 改变字段值
  110. * @param int $fv
  111. * @param string $fn
  112. * @param int $fv
  113. */
  114. public function changeField($id=0,$fn='',$fv=0){
  115. if(!$fn||!$id){
  116. $this->error('参数错误');
  117. }
  118. $res = db('address')->where('id',$id)->setField($fn,$fv);
  119. if($res){
  120. $this->success('操作成功');
  121. }else{
  122. $this->error('操作失败');
  123. }
  124. }
  125. public function qrcode($id=0){
  126. $info = Db::name('address')->where('id',$id)->find();
  127. $code = get_qrcode_str('address',$id);
  128. //request()->domain().'/h5/repair/index?code='
  129. $config = config('app.addr_url');
  130. $code = $config.$code;
  131. $this->assign('code',$code);
  132. $this->assign('info',$info);
  133. return $this->fetch();
  134. }
  135. // 地址下载
  136. public function addrdown(){
  137. $orgid = $this->orgId;
  138. $map[] = ['del','=',0];
  139. $map[] = ['org_id','=',$this->orgId];
  140. $title = input('title','','trim');
  141. if($title){
  142. $map[] = ['title','like','%'.$title.'%'];
  143. }
  144. $enable = input('enable','','trim');
  145. if($enable != ''){
  146. $map[] = ['enable','=',$enable];
  147. }
  148. $type = input('type','','trim');
  149. if($type != ''){
  150. $map[]=['','exp',Db::raw("FIND_IN_SET($type,types)")];
  151. }
  152. $ids = input('ids','','trim');
  153. if($ids !=''){
  154. $map[] = ['id','in',explode(',',$ids)];
  155. }
  156. $map= empty($map) ? true: $map;
  157. //数据查询
  158. $lists = db('address')->where($map)->select();
  159. $config = config('app.addr_url');
  160. foreach ($lists as $k=>$v){
  161. $lists[$k]['code'] = $config.get_qrcode_str('address',$v['id']);
  162. }
  163. $path = date('Ymd').'_'.$orgid.'_'.time().mt_rand(1000,9999);
  164. $dir = './uploads/qrcodeimg/'.$path.'/';
  165. foreach ($lists as $v1){
  166. $name = str_ireplace('/','_',$v1['title']).'('.$v1['id'].')'.'.jpg';
  167. $filepath = $dir.'/'.$name;
  168. create_qrcode($v1['code'],$filepath);
  169. }
  170. $zippath = './uploads/qrcodeimg/'.$path.'.zip';
  171. $spath = $dir;
  172. @unlink($zippath);
  173. $zip = new \ZipArchive();
  174. if($zip->open($zippath, \ZipArchive::CREATE)=== TRUE){
  175. add_file_to_zip($spath,$zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
  176. $zip->close(); //关闭处理的zip文件
  177. if(!file_exists($zippath)){
  178. $this->error("打包失败"); //即使创建,仍有可能失败。。。。
  179. }
  180. deldir($dir); // 删除生成的目录
  181. $downname = session('orgName').'地点二维码.zip';
  182. header("Cache-Control: public");
  183. header("Content-Description: File Transfer");
  184. header('Content-disposition: attachment; filename='.$downname); //文件名
  185. header("Content-Type: application/zip"); //zip格式的
  186. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  187. header('Content-Length: '. filesize($zippath)); //告诉浏览器,文件大小
  188. @readfile($zippath);
  189. }else{
  190. $this->error("打包失败");
  191. }
  192. }
  193. public function import(){
  194. return $this->fetch();
  195. }
  196. /**
  197. * 下载点模板
  198. */
  199. public function downloadtem(){
  200. set_time_limit(0);
  201. ini_set("memory_limit","512M");
  202. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  203. $fileName = '地点模板.xlsx';
  204. $excel = new \PHPExcel();
  205. $sheet = $excel->setActiveSheetIndex(0);
  206. $arr = array('A','B','C','D');
  207. $types = model('Address')->getTypes();
  208. ksort($types);
  209. foreach($arr as $k=>$v){
  210. $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
  211. $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
  212. if($k==3){
  213. $excel->getActiveSheet()->getColumnDimension($v)->setWidth(100);
  214. }else{
  215. $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
  216. }
  217. }
  218. $sheet->setCellValueByColumnAndRow(0,1,'名称');
  219. $sheet->setCellValueByColumnAndRow(1,1,'设备编号');
  220. $sheet->setCellValueByColumnAndRow(2,1,'备注');
  221. $sheet->setCellValueByColumnAndRow(3,1,'类型('.implode(',',$types).') 多个用英文逗号隔开');
  222. $excel->getActiveSheet()->setCellValue('A2', '示例地址');
  223. $excel->getActiveSheet()->setCellValue('B2', 'XXX');
  224. $excel->getActiveSheet()->setCellValue('C2', 'XXX');
  225. $excel->getActiveSheet()->setCellValue('D2', '报修,运送');
  226. ob_end_clean();//清除缓冲区,避免乱码
  227. header('Content-Type: application/vnd.ms-excel');
  228. header('Content-Disposition: attachment;filename="'.$fileName.'"');
  229. header('Cache-Control: max-age=0');
  230. $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
  231. $objWriter->save('php://output'); //文件通过浏览器下载
  232. }
  233. /**
  234. * 导入
  235. */
  236. public function importexcel_bak(){
  237. set_time_limit(0);
  238. ini_set("memory_limit", -1);
  239. ob_flush();//清空缓存
  240. flush();//刷新缓存
  241. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  242. $orgId = $this->orgId;
  243. if(request()->file()) {
  244. $file = request()->file('file');
  245. //获取文件后缀
  246. $e = explode('.',$_FILES['file']['name']);
  247. $ext = $e[count($e)-1];
  248. if($ext == 'xls'){
  249. \PHPExcel_IOFactory::createReader( 'Excel5');
  250. }else{
  251. \PHPExcel_IOFactory::createReader('Excel2007');
  252. }
  253. $newArr=['xls','xlsx'];
  254. if(!in_array($ext,$newArr)){
  255. exit('文件格式不正确');
  256. }
  257. // 移动到框架应用根目录/uploads/ 目录下
  258. $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
  259. ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
  260. if(!$info){
  261. exit('文件上传失败');
  262. }
  263. $img = './uploads/files/' . $info->getSaveName();
  264. $filePath = str_replace('\\', '/', $img);
  265. $newPath = \PHPExcel_IOFactory::load($filePath);
  266. $excelArray = $newPath->getsheet(0)->toArray(); //转换为数组格式
  267. array_shift($excelArray); //删除第一个数组(标题);
  268. unset($excelArray[0]);
  269. if(empty($excelArray)){
  270. exit('文件内容为空');
  271. }
  272. foreach ($excelArray as $k => $v) {
  273. if(!$v[1]){
  274. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称为空,未导入</font><br />";
  275. continue;
  276. }
  277. if(!$v[4]){
  278. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型为空,未导入</font><br />";
  279. continue;
  280. }
  281. $check = Db::name('address')
  282. ->where('org_id',$orgId)
  283. ->where('del',0)
  284. ->where('title',$v[1])
  285. ->find();
  286. if($check){
  287. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称已存在,未导入</font><br />";
  288. continue;
  289. }
  290. $typeId = [];
  291. $type = explode(',',$v[4]);
  292. $types = model('Address')->getTypes();
  293. $types = array_flip($types);
  294. foreach ($type as $k1=>$v1){
  295. if(isset($types[$v1])){
  296. $typeId[] = $types[$v1];
  297. }
  298. }
  299. if(count($type)!=count($typeId) || empty($typeId)){
  300. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型字段格式错误,未导入</font><br />";
  301. continue;
  302. }
  303. $rData = [
  304. 'org_id'=>$orgId,
  305. 'title'=>$v[1],
  306. 'sn'=>$v[0],
  307. 'remark'=>'',
  308. 'types'=>implode(',',$typeId),
  309. 'create_time'=>getTime()
  310. ];
  311. $ret=Db::name('address')->insert($rData);
  312. if(!$ret){
  313. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
  314. }else{
  315. echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
  316. }
  317. }
  318. }else{
  319. exit('请上传文件');
  320. }
  321. }
  322. public function importexcel(){
  323. set_time_limit(0);
  324. ini_set("memory_limit", -1);
  325. ob_flush();//清空缓存
  326. flush();//刷新缓存
  327. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  328. $orgId = $this->orgId;
  329. if(request()->file()) {
  330. $file = request()->file('file');
  331. //获取文件后缀
  332. $e = explode('.',$_FILES['file']['name']);
  333. $ext = $e[count($e)-1];
  334. if($ext == 'xls'){
  335. \PHPExcel_IOFactory::createReader( 'Excel5');
  336. }else{
  337. \PHPExcel_IOFactory::createReader('Excel2007');
  338. }
  339. $newArr=['xls','xlsx'];
  340. if(!in_array($ext,$newArr)){
  341. exit('文件格式不正确');
  342. }
  343. // 移动到框架应用根目录/uploads/ 目录下
  344. $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
  345. ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
  346. if(!$info){
  347. exit('文件上传失败');
  348. }
  349. $img = './uploads/files/' . $info->getSaveName();
  350. $filePath = str_replace('\\', '/', $img);
  351. $newPath = \PHPExcel_IOFactory::load($filePath);
  352. $excelArray = $newPath->getsheet(0)->toArray(); //转换为数组格式
  353. array_shift($excelArray); //删除第一个数组(标题);
  354. if(empty($excelArray)){
  355. exit('文件内容为空');
  356. }
  357. foreach ($excelArray as $k => $v) {
  358. if(!$v[0]){
  359. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称为空,未导入</font><br />";
  360. continue;
  361. }
  362. if(!$v[3]){
  363. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型为空,未导入</font><br />";
  364. continue;
  365. }
  366. $check = Db::name('address')
  367. ->where('org_id',$orgId)
  368. ->where('del',0)
  369. ->where('title',$v[0])
  370. ->find();
  371. if($check){
  372. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称已存在,未导入</font><br />";
  373. continue;
  374. }
  375. $typeId = [];
  376. $type = explode(',',$v[3]);
  377. $types = model('Address')->getTypes();
  378. $types = array_flip($types);
  379. foreach ($type as $k1=>$v1){
  380. if(isset($types[$v1])){
  381. $typeId[] = $types[$v1];
  382. }
  383. }
  384. if(count($type)!=count($typeId) || empty($typeId)){
  385. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型字段格式错误,未导入</font><br />";
  386. continue;
  387. }
  388. $rData = [
  389. 'org_id'=>$orgId,
  390. 'title'=>$v[0],
  391. 'sn'=>$v[1],
  392. 'remark'=>$v[2],
  393. 'types'=>implode(',',$typeId),
  394. 'create_time'=>getTime()
  395. ];
  396. $ret=Db::name('address')->insert($rData);
  397. if(!$ret){
  398. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
  399. }else{
  400. echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
  401. }
  402. }
  403. }else{
  404. exit('请上传文件');
  405. }
  406. }
  407. public function three($id=0){
  408. if(request()->isPost()){
  409. $id = input('id/d',0);
  410. $x = input('x','','trim');
  411. $y = input('y','','trim');
  412. $z = input('z','','trim');
  413. $xyz[] = $x;
  414. $xyz[] = $y;
  415. $xyz[] = $z;
  416. $ret = Db::name('address')->where('id',$id)->update(['xyz'=>implode(',',$xyz),'update_time' => date('Y-m-d H:i:s')]);
  417. if($ret){
  418. $this->success('操作成功');
  419. }else{
  420. $this->error('操作失败');
  421. }
  422. }else{
  423. $info = Db::name('address')->where('id',$id)->find();
  424. $arr = $info['xyz']?explode(',',$info['xyz']):[];
  425. $x = '';
  426. $y = '';
  427. $z = '';
  428. if(count($arr) == 3){
  429. $x = $arr[0];
  430. $y = $arr[1];
  431. $z = $arr[2];
  432. }
  433. $this->assign('x',$x);
  434. $this->assign('y',$y);
  435. $this->assign('z',$z);
  436. $this->assign('id',$id);
  437. return $this->fetch();
  438. }
  439. }
  440. public function downImg(){
  441. $id = input('id','');
  442. $config = config('app.addr_url');
  443. $code = $config.get_qrcode_str('address',$id);
  444. $info = db('address')->where('id',$id)->find();
  445. echo "<pre/>";
  446. print_r($code);
  447. die();
  448. }
  449. public function batchEditCate(){
  450. $ids = input('ids','');
  451. if(request()->isPost()){
  452. if(empty($ids)){
  453. $this->error('请选择地点');
  454. }
  455. $types = input('types');
  456. if(empty($types)){
  457. $this->error('请选择选择类型');
  458. }
  459. $res = Db::name('address')
  460. ->where('id','in',explode(',',$ids))
  461. ->update([
  462. 'types'=>$types,
  463. 'update_time'=>getTime()
  464. ]);
  465. if($res){
  466. $this->success('操作成功',url('index'));
  467. }else{
  468. $this->error(model('Address')->getError());
  469. }
  470. }else{
  471. $ts = model('Address')->getTypes();
  472. $types = [];
  473. foreach ($ts as $k=>$v){
  474. $types[] = [
  475. 'id' => $k,
  476. 'title' => $v
  477. ];
  478. }
  479. $this->assign('types',$types);
  480. $address =db('address')->where('id','in',explode(',',$ids))->column('title');
  481. $this->assign('address',implode(';',$address));
  482. $this->assign('ids',$ids);
  483. return $this->fetch();
  484. }
  485. }
  486. public function importexcel1(){
  487. set_time_limit(0);
  488. ini_set("memory_limit", -1);
  489. ob_flush();//清空缓存
  490. flush();//刷新缓存
  491. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  492. $orgId = $this->orgId;
  493. if(request()->file()) {
  494. $file = request()->file('file');
  495. //获取文件后缀
  496. $e = explode('.',$_FILES['file']['name']);
  497. $ext = $e[count($e)-1];
  498. if($ext == 'xls'){
  499. \PHPExcel_IOFactory::createReader( 'Excel5');
  500. }else{
  501. \PHPExcel_IOFactory::createReader('Excel2007');
  502. }
  503. $newArr=['xls','xlsx'];
  504. if(!in_array($ext,$newArr)){
  505. exit('文件格式不正确');
  506. }
  507. // 移动到框架应用根目录/uploads/ 目录下
  508. $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
  509. ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
  510. if(!$info){
  511. exit('文件上传失败');
  512. }
  513. $img = './uploads/files/' . $info->getSaveName();
  514. $filePath = str_replace('\\', '/', $img);
  515. $newPath = \PHPExcel_IOFactory::load($filePath);
  516. $excelArray = $newPath->getsheet(0)->toArray(); //转换为数组格式
  517. array_shift($excelArray); //删除第一个数组(标题);
  518. if(empty($excelArray)){
  519. exit('文件内容为空');
  520. }
  521. foreach ($excelArray as $k => $v) {
  522. if($k > 0){
  523. if(!$v[1]){
  524. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称为空,未导入</font><br />";
  525. continue;
  526. }
  527. // if(!$v[4]){
  528. // echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型为空,未导入</font><br />";
  529. // continue;
  530. // }
  531. $check = Db::name('address')
  532. ->where('org_id',$orgId)
  533. ->where('del',0)
  534. ->where('title',$v[1])
  535. ->find();
  536. if($check){
  537. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称已存在,未导入</font><br />";
  538. continue;
  539. }
  540. $typeId = [];
  541. if($v[4]){
  542. $type = explode('、',$v[4]);
  543. $types = model('Address')->getTypes();
  544. $types = array_flip($types);
  545. foreach ($type as $k1=>$v1){
  546. if(isset($types[$v1])){
  547. $typeId[] = $types[$v1];
  548. }
  549. }
  550. // if(count($type)!=count($typeId) || empty($typeId)){
  551. // echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型字段格式错误,未导入</font><br />";
  552. // continue;
  553. // }
  554. }
  555. $rData = [
  556. 'org_id'=>$orgId,
  557. 'title'=>$v[1],
  558. 'sn'=>'',
  559. 'remark'=>'',
  560. 'types'=>$typeId?implode(',',$typeId):'',
  561. 'create_time'=>getTime()
  562. ];
  563. $ret=Db::name('address')->insert($rData);
  564. if(!$ret){
  565. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
  566. }else{
  567. echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
  568. }
  569. }
  570. }
  571. }else{
  572. exit('请上传文件');
  573. }
  574. }
  575. //excel导出
  576. public function export() {
  577. set_time_limit(0);
  578. ini_set("memory_limit","1024M");
  579. $title = input('title','','trim');
  580. if($title){
  581. $map[] = ['title','like','%'.$title.'%'];
  582. }
  583. $enable = input('enable','','trim');
  584. if($enable != ''){
  585. $map[] = ['enable','=',$enable];
  586. }
  587. $type = input('type','','trim');
  588. if($type != ''){
  589. $map[]=['','exp',Db::raw("FIND_IN_SET($type,types)")];
  590. }
  591. $map[] = ['del','=',0];
  592. $map[] = ['org_id','=',$this->orgId];
  593. $map= empty($map) ? true: $map;
  594. //数据查询
  595. $lists = db('address')->where($map)->order('id desc')->select();
  596. $header = [
  597. ['title' => 'id', 'name' => 'id','width'=>'10'],
  598. ['title' => '名称', 'name' => 'title','width'=>'20'],
  599. ];
  600. $filename = '地点';
  601. ExcelUtil::export($filename,$header,$lists);
  602. }
  603. public function delAll(){
  604. if(request()->isPost()){
  605. $data = request()->post();
  606. $ids = isset($data['ids'])&&!empty($data['ids']) ? $data['ids']:[];
  607. if(!$ids){
  608. $this->error('请选择地点');
  609. }
  610. $res = Db::name('address')->whereIn('id',$ids)->setField('del',1);
  611. if($res){
  612. $this->success('操作成功',url('index'));
  613. }else{
  614. $this->error('操作失败');
  615. }
  616. }else{
  617. $lists = Db::name('address')
  618. ->where('del',0)
  619. ->where('org_id',$this->orgId)
  620. ->select();
  621. $this->assign('lists',$lists);
  622. return $this->fetch();
  623. }
  624. }
  625. }