Address.php 25 KB

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