model = new CityModel(); $lockFile = ROOT_PATH . '/data/city.lock'; //如果不存在插件锁,则创建数据表 if(!file_exists($lockFile)){ $this->createTabkle(); } } // 创建数据表 public function createTabkle(){ if (get_db_type() == 'sqlite') { $sql = file_get_contents(ROOT_PATH . '/city_sqlite_update.sql'); $result = $this->model->amd($sql); } else { $sql = file_get_contents(ROOT_PATH . '/city_mysql_update.sql'); //分割sql语句 $sqlArr = explode(';', $sql); foreach ($sqlArr as $v) { if( $v!=='' ){ $this->model->amd($v); } } $result = true; } if($result){ file_put_contents(ROOT_PATH . '/data/city.lock', get_datetime()); } } // 地区列表 public function index() { $this->assign('list', true); $pid = 0; $cur_city = '顶级'; if( get('pid') ){ $pid = get('pid'); $cur_city = $this->model->findCity($pid)->title; } $this->assign('pid', $pid); $this->assign('cur_city', $cur_city); $lists = $this->model->getList($pid); $this->assign('lists', $lists); $city_select = $lists; $this->assign('city_select', $city_select); $this->display('system/city.html'); } // 内容栏目增加 public function add() { // 修改操作 if ($_POST) { if (! ! $mutititle = post('mutititle')) { $mutititle = str_replace(',', ',', $mutititle); //批量城市名 $mutietitle = post('mutietitle'); $mutietitle = str_replace(',', ',', $mutietitle); $pid = post('pid', 'int'); $logo = post('logo'); $weixin = post('weixin'); if (! $mutititle) { alert_back('城市名称不能为空!'); } if (! $mutietitle) { alert_back('英文名称不能为空!'); } $titles = explode(',', $mutititle); $etitles = explode(',', $mutietitle); foreach ($titles as $key => $value) { // 检查名称 if ($this->model->checkName("title='$value' or etitle='$etitles[$key]'")) { alert_back('城市名称已经存在,不能再使用!'); } $data[] = array( 'pid' => $pid, 'title' => $value, 'etitle' => $etitles[$key], 'isurl' => '', 'status' => 1, 'sorting' => 255, 'istop' => 0, 'seo_title' => '', 'seo_keywords' => '', 'seo_description' => '', 'contact' => '', 'mobile' => '', 'phone' => '', 'fax' => '', 'email' => '', 'qq' => '', 'address' => '', 'logo' => $logo, 'weixin' => $weixin ); } }else{ // 获取数据 $title = post('title'); $etitle = post('etitle'); $isurl = post('isurl'); $pid = post('pid', 'int'); $status = post('status', 'int'); $istop = post('istop', 'int', '', '', 0); $seo_title = post('seo_title'); $seo_keywords = post('seo_keywords'); $seo_description = post('seo_description'); $logo = post('logo'); $weixin = post('weixin'); $contact = post('contact'); $mobile = post('mobile'); $phone = post('phone'); $fax = post('fax'); $email = post('email'); $qq = post('qq'); $address = post('address'); if (! $title) { alert_back('名称不能为空!'); } if (! $etitle) { alert_back('英文名不能为空!'); } // 检查名称 if ($this->model->checkName("title='$title' or etitle='$etitle'")) { alert_back('名称已经存在,不能再使用!'); } // 构建数据 $data = array( 'pid' => $pid, 'title' => $title, 'etitle' => $etitle, 'isurl' => $isurl, 'status' => $status, 'sorting' => 255, 'istop' => $istop, 'seo_title' => $seo_title, 'seo_keywords' => $seo_keywords, 'seo_description' => $seo_description, 'contact' => $contact, 'mobile' => $mobile, 'phone' => $phone, 'fax' => $fax, 'email' => $email, 'qq' => $qq, 'address' => $address, 'logo' => $logo, 'weixin' => $weixin ); } // 执行添加 if ($this->model->addCity($data)) { $this->log('新增地区' . $id . '成功!'); $url = $pid?'/pid/'.$pid:''; success('新增成功!', url('/admin/City/index'.$url)); } else { location(- 1); } } } // 修改 public function mod() { // 批量修改排序 if (! ! $submit = post('submit')) { switch ($submit) { case 'sorting': // 修改列表排序 $listall = post('listall'); if ($listall) { $sorting = post('sorting'); foreach ($listall as $key => $value) { if ($sorting[$key] === '' || ! is_numeric($sorting[$key])) $sorting[$key] = 255; $this->model->modCity($value, "sorting=" . $sorting[$key]); } $this->log('批量修改排序成功!'); success('修改成功!', - 1); } else { alert_back('排序失败,无任何内容!'); } break; } } if (! $id = get('id', 'int')) { error('传递的参数值错误!', - 1); } // 单独修改状态 if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) { if ($this->model->modCity($id, "$field='$value'")) { $this->log('修改地区' . $id . '状态' . $value . '成功!'); location(- 1); } else { $this->log('修改地区' . $id . '状态' . $value . '失败!'); alert_back('修改失败!'); } } // 修改操作 if ($_POST) { // 获取数据 $title = post('title'); $etitle = post('etitle'); $isurl = post('isurl'); $pid = post('pid', 'int'); $status = post('status', 'int'); $istop = post('istop', 'int', '', '', 0); $seo_title = post('seo_title'); $seo_keywords = post('seo_keywords'); $seo_description = post('seo_description'); $contact = post('contact'); $mobile = post('mobile'); $phone = post('phone'); $fax = post('fax'); $email = post('email'); $qq = post('qq'); $address = post('address'); $logo = post('logo'); $weixin = post('weixin'); if($id==$pid){ alert_back('区域混乱啦!'); } if (! $title) { alert_back('名称不能为空!'); } if (! $etitle) { alert_back('英文名不能为空!'); } // 构建数据 $data = array( 'pid' => $pid, 'title' => $title, 'etitle' => $etitle, 'isurl' => $isurl, 'status' => $status, 'istop' => $istop, 'seo_title' => $seo_title, 'seo_keywords' => $seo_keywords, 'seo_description' => $seo_description, 'contact' => $contact, 'mobile' => $mobile, 'phone' => $phone, 'fax' => $fax, 'email' => $email, 'qq' => $qq, 'address' => $address, 'logo' => $logo, 'weixin' => $weixin ); // 执行添加 if ($this->model->modCity($id, $data)) { $this->log('修改地区' . $id . '成功!'); $url = $pid?'/pid/'.$pid:''; success('修改成功!', url('/admin/City/index'.$url)); } else { location(- 1); } } else { // 调取修改内容 $this->assign('mod', true); $city = $this->model->findCity($id); if (! $city) { error('编辑的内容已经不存在!', - 1); } if( $city->pid==0 ){ $pid = 0; $cur_city = '顶级'; }else{ $parent_city = $this->model->findCity($city->pid); $pid = $parent_city->pid; $cur_city = $parent_city->title; } $this->assign('pid', $pid); $this->assign('cur_city', $cur_city); $city_select = $this->model->getList($parent_city->pid); $this->assign('city_select', $city_select); $this->assign('city', $city); $this->display('system/city.html'); } } // 地区删除 public function del(){ // 执行批量删除 if ($_POST) { if (! ! $list = post('list')) { if ($this->model->delCityList($list)) { $this->log('批量删除地区成功!'); success('批量删除成功!', - 1); } else { $this->log('批量删除地区失败!'); error('批量删除失败!', - 1); } } else { alert_back('请选择要删除的内容!'); } } if (! $id = get('id', 'int')) { error('传递的参数值错误!', - 1); } if ($this->model->delCity($id)) { $this->log('删除地区' . $id . '成功!'); success('删除成功!', - 1); } else { $this->log('删除地区' . $id . '失败!'); error('删除失败!', - 1); } } /* * https://www.ledaxinli.com/admin.php?p=/City/exportData */ public function exportData(){ //echo ROOT_PATH; //require './strHandle/Pinyin.php'; //$class = new Pinyin(); //取每个汉字的首字母 //$pinyin = $class->str2py('甄工'); //取每个汉字的全部字母 //$pinyin = $class->str2pys('需要转换的汉字'); //var_dump($pinyin);die; //baiduSubmitResource('',''); $pinyin = new Pinyin(); //$res = $pinyin->convert('带着希望去旅行,比到达终点更美好'); //var_dump($res);die; $pid = 386; $filename = './static/backup/data/类型.txt'; $lines = file($filename); $sort = $this->model->getSortLast(); foreach ($lines as $line) { //echo $line.'
'; //判断是否为空 if(!empty($line)){ //var_dump($line); //判断是否存在、 $charToFind = "、"; // 使用 strpos() 来查找字符 $pos = strpos($line, $charToFind); if ($pos !== false) { $str = explode('、',$line); //var_dump($str); } else { $str = [$line]; } //var_dump($str); $loop = 1; foreach ($str as $k=>$v){ $v = trim($v); //去除 //var_dump($v); $length = strlen($v); if(!empty($v) && $loop === 1 && $length>2){ //去除字符 县 市 区 自治县 $po = str_replace('县','',$v); $po = str_replace('市','',$po); $po = str_replace('区','',$po); $po = str_replace('自治','',$po); //转成拼音 $py = $pinyin->convert($po); //var_dump($py);die; //增加排序号 $sort = $sort + 10; //判断是否重复 取前面2个字 重复不加mm 需要不断重复判断 加数字(排序号) 名称也加数字 $etitle = $py[0]; if(isset($py[1])){ $etitle = $etitle.$py[1]; } $etitle = $this->model->etitleIsCf($etitle,$sort); $title = $this->model->titleIsCf($v,$sort); //构建数据插入 $insert_data = [ 'title' => $title, 'pid' => $pid, 'stitle' => $title, 'etitle' => $etitle, 'sorting' => $sort, 'status' => 1, 'istop' => 0, 'isurl' => '', 'seo_title' => '', 'seo_keywords' => '', 'seo_description' => '', 'contact' => '', 'phone' => '', 'fax' => '', 'mobile' => '', 'email' => '', 'address' => '', 'qq' => '', 'logo' => '', 'weixin' => '' ]; $run = $this->model->addRow($insert_data); echo $title.'------'.$run.'
'; } } } } } /* * https://www.ledaxinli.com/admin.php?p=/City/updateData */ public function updateData(){ //384 市 383 区 //$this->model->getList($pid); //$this->model->editRow($insert_data); /* * 替换字符串 * UPDATE ay_city SET title = REPLACE(BINARY title, '区', '') where pid=383; * UPDATE ay_city SET stitle = REPLACE(BINARY stitle, '区', '') where pid=383; * UPDATE ay_city SET title = REPLACE(BINARY title, '市', '') where pid=384; * UPDATE ay_city SET stitle = REPLACE(BINARY stitle, '市', '') where pid=384; */ /* * 判断数据库字段是否含有重复数据 * select etitle from ay_city group by etitle having count(*)>1 * select title from ay_city where pid=386 group by title having count(*)>1 * * SELECT etitle, COUNT(*) as count FROM ay_city GROUP BY etitle HAVING COUNT(*) > 1; * SELECT title, COUNT(*) as count FROM ay_city GROUP BY title HAVING COUNT(*) > 1; * SELECT stitle, COUNT(*) as count FROM ay_city GROUP BY stitle HAVING COUNT(*) > 1; * * */ } }