心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CityController.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. /**
  3. * 城市分站控制器
  4. */
  5. namespace app\admin\controller\system;
  6. use core\basic\Controller;
  7. use app\admin\model\system\CityModel;
  8. class CityController extends Controller
  9. {
  10. private $count;
  11. private $blank;
  12. private $outData = array();
  13. private $model;
  14. public function __construct()
  15. {
  16. $this->model = new CityModel();
  17. $lockFile = ROOT_PATH . '/data/city.lock';
  18. //如果不存在插件锁,则创建数据表
  19. if(!file_exists($lockFile)){
  20. $this->createTabkle();
  21. }
  22. }
  23. // 创建数据表
  24. public function createTabkle(){
  25. if (get_db_type() == 'sqlite') {
  26. $sql = file_get_contents(ROOT_PATH . '/city_sqlite_update.sql');
  27. $result = $this->model->amd($sql);
  28. } else {
  29. $sql = file_get_contents(ROOT_PATH . '/city_mysql_update.sql');
  30. //分割sql语句
  31. $sqlArr = explode(';', $sql);
  32. foreach ($sqlArr as $v) {
  33. if( $v!=='' ){
  34. $this->model->amd($v);
  35. }
  36. }
  37. $result = true;
  38. }
  39. if($result){
  40. file_put_contents(ROOT_PATH . '/data/city.lock', get_datetime());
  41. }
  42. }
  43. // 地区列表
  44. public function index()
  45. {
  46. $this->assign('list', true);
  47. $pid = 0;
  48. $cur_city = '顶级';
  49. if( get('pid') ){
  50. $pid = get('pid');
  51. $cur_city = $this->model->findCity($pid)->title;
  52. }
  53. $this->assign('pid', $pid);
  54. $this->assign('cur_city', $cur_city);
  55. $lists = $this->model->getList($pid);
  56. $this->assign('lists', $lists);
  57. $city_select = $lists;
  58. $this->assign('city_select', $city_select);
  59. $this->display('system/city.html');
  60. }
  61. // 内容栏目增加
  62. public function add()
  63. {
  64. // 修改操作
  65. if ($_POST) {
  66. if (! ! $mutititle = post('mutititle')) {
  67. $mutititle = str_replace(',', ',', $mutititle); //批量城市名
  68. $mutietitle = post('mutietitle');
  69. $mutietitle = str_replace(',', ',', $mutietitle);
  70. $pid = post('pid', 'int');
  71. $logo = post('logo');
  72. if (! $mutititle) {
  73. alert_back('城市名称不能为空!');
  74. }
  75. if (! $mutietitle) {
  76. alert_back('英文名称不能为空!');
  77. }
  78. $titles = explode(',', $mutititle);
  79. $etitles = explode(',', $mutietitle);
  80. foreach ($titles as $key => $value) {
  81. // 检查名称
  82. if ($this->model->checkName("title='$value' or etitle='$etitles[$key]'")) {
  83. alert_back('城市名称已经存在,不能再使用!');
  84. }
  85. $data[] = array(
  86. 'pid' => $pid,
  87. 'title' => $value,
  88. 'etitle' => $etitles[$key],
  89. 'isurl' => '',
  90. 'status' => 1,
  91. 'sorting' => 255,
  92. 'istop' => 0,
  93. 'seo_title' => '',
  94. 'seo_keywords' => '',
  95. 'seo_description' => '',
  96. 'contact' => '',
  97. 'mobile' => '',
  98. 'phone' => '',
  99. 'fax' => '',
  100. 'email' => '',
  101. 'qq' => '',
  102. 'address' => '',
  103. 'logo' => $logo
  104. );
  105. }
  106. }else{
  107. // 获取数据
  108. $title = post('title');
  109. $etitle = post('etitle');
  110. $isurl = post('isurl');
  111. $pid = post('pid', 'int');
  112. $status = post('status', 'int');
  113. $istop = post('istop', 'int', '', '', 0);
  114. $seo_title = post('seo_title');
  115. $seo_keywords = post('seo_keywords');
  116. $seo_description = post('seo_description');
  117. $logo = post('logo');
  118. $contact = post('contact');
  119. $mobile = post('mobile');
  120. $phone = post('phone');
  121. $fax = post('fax');
  122. $email = post('email');
  123. $qq = post('qq');
  124. $address = post('address');
  125. if (! $title) {
  126. alert_back('名称不能为空!');
  127. }
  128. if (! $etitle) {
  129. alert_back('英文名不能为空!');
  130. }
  131. // 检查名称
  132. if ($this->model->checkName("title='$title' or etitle='$etitle'")) {
  133. alert_back('名称已经存在,不能再使用!');
  134. }
  135. // 构建数据
  136. $data = array(
  137. 'pid' => $pid,
  138. 'title' => $title,
  139. 'etitle' => $etitle,
  140. 'isurl' => $isurl,
  141. 'status' => $status,
  142. 'sorting' => 255,
  143. 'istop' => $istop,
  144. 'seo_title' => $seo_title,
  145. 'seo_keywords' => $seo_keywords,
  146. 'seo_description' => $seo_description,
  147. 'contact' => $contact,
  148. 'mobile' => $mobile,
  149. 'phone' => $phone,
  150. 'fax' => $fax,
  151. 'email' => $email,
  152. 'qq' => $qq,
  153. 'address' => $address,
  154. 'logo' => $logo
  155. );
  156. }
  157. // 执行添加
  158. if ($this->model->addCity($data)) {
  159. $this->log('新增地区' . $id . '成功!');
  160. $url = $pid?'/pid/'.$pid:'';
  161. success('新增成功!', url('/admin/City/index'.$url));
  162. } else {
  163. location(- 1);
  164. }
  165. }
  166. }
  167. // 修改
  168. public function mod()
  169. {
  170. // 批量修改排序
  171. if (! ! $submit = post('submit')) {
  172. switch ($submit) {
  173. case 'sorting': // 修改列表排序
  174. $listall = post('listall');
  175. if ($listall) {
  176. $sorting = post('sorting');
  177. foreach ($listall as $key => $value) {
  178. if ($sorting[$key] === '' || ! is_numeric($sorting[$key]))
  179. $sorting[$key] = 255;
  180. $this->model->modCity($value, "sorting=" . $sorting[$key]);
  181. }
  182. $this->log('批量修改排序成功!');
  183. success('修改成功!', - 1);
  184. } else {
  185. alert_back('排序失败,无任何内容!');
  186. }
  187. break;
  188. }
  189. }
  190. if (! $id = get('id', 'int')) {
  191. error('传递的参数值错误!', - 1);
  192. }
  193. // 单独修改状态
  194. if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
  195. if ($this->model->modCity($id, "$field='$value'")) {
  196. $this->log('修改地区' . $id . '状态' . $value . '成功!');
  197. location(- 1);
  198. } else {
  199. $this->log('修改地区' . $id . '状态' . $value . '失败!');
  200. alert_back('修改失败!');
  201. }
  202. }
  203. // 修改操作
  204. if ($_POST) {
  205. // 获取数据
  206. $title = post('title');
  207. $etitle = post('etitle');
  208. $isurl = post('isurl');
  209. $pid = post('pid', 'int');
  210. $status = post('status', 'int');
  211. $istop = post('istop', 'int', '', '', 0);
  212. $seo_title = post('seo_title');
  213. $seo_keywords = post('seo_keywords');
  214. $seo_description = post('seo_description');
  215. $contact = post('contact');
  216. $mobile = post('mobile');
  217. $phone = post('phone');
  218. $fax = post('fax');
  219. $email = post('email');
  220. $qq = post('qq');
  221. $address = post('address');
  222. $logo = post('logo');
  223. if($id==$pid){
  224. alert_back('区域混乱啦!');
  225. }
  226. if (! $title) {
  227. alert_back('名称不能为空!');
  228. }
  229. if (! $etitle) {
  230. alert_back('英文名不能为空!');
  231. }
  232. // 构建数据
  233. $data = array(
  234. 'pid' => $pid,
  235. 'title' => $title,
  236. 'etitle' => $etitle,
  237. 'isurl' => $isurl,
  238. 'status' => $status,
  239. 'istop' => $istop,
  240. 'seo_title' => $seo_title,
  241. 'seo_keywords' => $seo_keywords,
  242. 'seo_description' => $seo_description,
  243. 'contact' => $contact,
  244. 'mobile' => $mobile,
  245. 'phone' => $phone,
  246. 'fax' => $fax,
  247. 'email' => $email,
  248. 'qq' => $qq,
  249. 'address' => $address,
  250. 'logo' => $logo
  251. );
  252. // 执行添加
  253. if ($this->model->modCity($id, $data)) {
  254. $this->log('修改地区' . $id . '成功!');
  255. $url = $pid?'/pid/'.$pid:'';
  256. success('修改成功!', url('/admin/City/index'.$url));
  257. } else {
  258. location(- 1);
  259. }
  260. } else { // 调取修改内容
  261. $this->assign('mod', true);
  262. $city = $this->model->findCity($id);
  263. if (! $city) {
  264. error('编辑的内容已经不存在!', - 1);
  265. }
  266. if( $city->pid==0 ){
  267. $pid = 0;
  268. $cur_city = '顶级';
  269. }else{
  270. $parent_city = $this->model->findCity($city->pid);
  271. $pid = $parent_city->pid;
  272. $cur_city = $parent_city->title;
  273. }
  274. $this->assign('pid', $pid);
  275. $this->assign('cur_city', $cur_city);
  276. $city_select = $this->model->getList($parent_city->pid);
  277. $this->assign('city_select', $city_select);
  278. $this->assign('city', $city);
  279. $this->display('system/city.html');
  280. }
  281. }
  282. // 地区删除
  283. public function del(){
  284. // 执行批量删除
  285. if ($_POST) {
  286. if (! ! $list = post('list')) {
  287. if ($this->model->delCityList($list)) {
  288. $this->log('批量删除地区成功!');
  289. success('批量删除成功!', - 1);
  290. } else {
  291. $this->log('批量删除地区失败!');
  292. error('批量删除失败!', - 1);
  293. }
  294. } else {
  295. alert_back('请选择要删除的内容!');
  296. }
  297. }
  298. if (! $id = get('id', 'int')) {
  299. error('传递的参数值错误!', - 1);
  300. }
  301. if ($this->model->delCity($id)) {
  302. $this->log('删除地区' . $id . '成功!');
  303. success('删除成功!', - 1);
  304. } else {
  305. $this->log('删除地区' . $id . '失败!');
  306. error('删除失败!', - 1);
  307. }
  308. }
  309. }