心理咨询网
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CityController.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. $weixin = post('weixin');
  73. if (! $mutititle) {
  74. alert_back('城市名称不能为空!');
  75. }
  76. if (! $mutietitle) {
  77. alert_back('英文名称不能为空!');
  78. }
  79. $titles = explode(',', $mutititle);
  80. $etitles = explode(',', $mutietitle);
  81. foreach ($titles as $key => $value) {
  82. // 检查名称
  83. if ($this->model->checkName("title='$value' or etitle='$etitles[$key]'")) {
  84. alert_back('城市名称已经存在,不能再使用!');
  85. }
  86. $data[] = array(
  87. 'pid' => $pid,
  88. 'title' => $value,
  89. 'etitle' => $etitles[$key],
  90. 'isurl' => '',
  91. 'status' => 1,
  92. 'sorting' => 255,
  93. 'istop' => 0,
  94. 'seo_title' => '',
  95. 'seo_keywords' => '',
  96. 'seo_description' => '',
  97. 'contact' => '',
  98. 'mobile' => '',
  99. 'phone' => '',
  100. 'fax' => '',
  101. 'email' => '',
  102. 'qq' => '',
  103. 'address' => '',
  104. 'logo' => $logo,
  105. 'weixin' => $weixin
  106. );
  107. }
  108. }else{
  109. // 获取数据
  110. $title = post('title');
  111. $etitle = post('etitle');
  112. $isurl = post('isurl');
  113. $pid = post('pid', 'int');
  114. $status = post('status', 'int');
  115. $istop = post('istop', 'int', '', '', 0);
  116. $seo_title = post('seo_title');
  117. $seo_keywords = post('seo_keywords');
  118. $seo_description = post('seo_description');
  119. $logo = post('logo');
  120. $weixin = post('weixin');
  121. $contact = post('contact');
  122. $mobile = post('mobile');
  123. $phone = post('phone');
  124. $fax = post('fax');
  125. $email = post('email');
  126. $qq = post('qq');
  127. $address = post('address');
  128. if (! $title) {
  129. alert_back('名称不能为空!');
  130. }
  131. if (! $etitle) {
  132. alert_back('英文名不能为空!');
  133. }
  134. // 检查名称
  135. if ($this->model->checkName("title='$title' or etitle='$etitle'")) {
  136. alert_back('名称已经存在,不能再使用!');
  137. }
  138. // 构建数据
  139. $data = array(
  140. 'pid' => $pid,
  141. 'title' => $title,
  142. 'etitle' => $etitle,
  143. 'isurl' => $isurl,
  144. 'status' => $status,
  145. 'sorting' => 255,
  146. 'istop' => $istop,
  147. 'seo_title' => $seo_title,
  148. 'seo_keywords' => $seo_keywords,
  149. 'seo_description' => $seo_description,
  150. 'contact' => $contact,
  151. 'mobile' => $mobile,
  152. 'phone' => $phone,
  153. 'fax' => $fax,
  154. 'email' => $email,
  155. 'qq' => $qq,
  156. 'address' => $address,
  157. 'logo' => $logo,
  158. 'weixin' => $weixin
  159. );
  160. }
  161. // 执行添加
  162. if ($this->model->addCity($data)) {
  163. $this->log('新增地区' . $id . '成功!');
  164. $url = $pid?'/pid/'.$pid:'';
  165. success('新增成功!', url('/admin/City/index'.$url));
  166. } else {
  167. location(- 1);
  168. }
  169. }
  170. }
  171. // 修改
  172. public function mod()
  173. {
  174. // 批量修改排序
  175. if (! ! $submit = post('submit')) {
  176. switch ($submit) {
  177. case 'sorting': // 修改列表排序
  178. $listall = post('listall');
  179. if ($listall) {
  180. $sorting = post('sorting');
  181. foreach ($listall as $key => $value) {
  182. if ($sorting[$key] === '' || ! is_numeric($sorting[$key]))
  183. $sorting[$key] = 255;
  184. $this->model->modCity($value, "sorting=" . $sorting[$key]);
  185. }
  186. $this->log('批量修改排序成功!');
  187. success('修改成功!', - 1);
  188. } else {
  189. alert_back('排序失败,无任何内容!');
  190. }
  191. break;
  192. }
  193. }
  194. if (! $id = get('id', 'int')) {
  195. error('传递的参数值错误!', - 1);
  196. }
  197. // 单独修改状态
  198. if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
  199. if ($this->model->modCity($id, "$field='$value'")) {
  200. $this->log('修改地区' . $id . '状态' . $value . '成功!');
  201. location(- 1);
  202. } else {
  203. $this->log('修改地区' . $id . '状态' . $value . '失败!');
  204. alert_back('修改失败!');
  205. }
  206. }
  207. // 修改操作
  208. if ($_POST) {
  209. // 获取数据
  210. $title = post('title');
  211. $etitle = post('etitle');
  212. $isurl = post('isurl');
  213. $pid = post('pid', 'int');
  214. $status = post('status', 'int');
  215. $istop = post('istop', 'int', '', '', 0);
  216. $seo_title = post('seo_title');
  217. $seo_keywords = post('seo_keywords');
  218. $seo_description = post('seo_description');
  219. $contact = post('contact');
  220. $mobile = post('mobile');
  221. $phone = post('phone');
  222. $fax = post('fax');
  223. $email = post('email');
  224. $qq = post('qq');
  225. $address = post('address');
  226. $logo = post('logo');
  227. $weixin = post('weixin');
  228. if($id==$pid){
  229. alert_back('区域混乱啦!');
  230. }
  231. if (! $title) {
  232. alert_back('名称不能为空!');
  233. }
  234. if (! $etitle) {
  235. alert_back('英文名不能为空!');
  236. }
  237. // 构建数据
  238. $data = array(
  239. 'pid' => $pid,
  240. 'title' => $title,
  241. 'etitle' => $etitle,
  242. 'isurl' => $isurl,
  243. 'status' => $status,
  244. 'istop' => $istop,
  245. 'seo_title' => $seo_title,
  246. 'seo_keywords' => $seo_keywords,
  247. 'seo_description' => $seo_description,
  248. 'contact' => $contact,
  249. 'mobile' => $mobile,
  250. 'phone' => $phone,
  251. 'fax' => $fax,
  252. 'email' => $email,
  253. 'qq' => $qq,
  254. 'address' => $address,
  255. 'logo' => $logo,
  256. 'weixin' => $weixin
  257. );
  258. // 执行添加
  259. if ($this->model->modCity($id, $data)) {
  260. $this->log('修改地区' . $id . '成功!');
  261. $url = $pid?'/pid/'.$pid:'';
  262. success('修改成功!', url('/admin/City/index'.$url));
  263. } else {
  264. location(- 1);
  265. }
  266. } else { // 调取修改内容
  267. $this->assign('mod', true);
  268. $city = $this->model->findCity($id);
  269. if (! $city) {
  270. error('编辑的内容已经不存在!', - 1);
  271. }
  272. if( $city->pid==0 ){
  273. $pid = 0;
  274. $cur_city = '顶级';
  275. }else{
  276. $parent_city = $this->model->findCity($city->pid);
  277. $pid = $parent_city->pid;
  278. $cur_city = $parent_city->title;
  279. }
  280. $this->assign('pid', $pid);
  281. $this->assign('cur_city', $cur_city);
  282. $city_select = $this->model->getList($parent_city->pid);
  283. $this->assign('city_select', $city_select);
  284. $this->assign('city', $city);
  285. $this->display('system/city.html');
  286. }
  287. }
  288. // 地区删除
  289. public function del(){
  290. // 执行批量删除
  291. if ($_POST) {
  292. if (! ! $list = post('list')) {
  293. if ($this->model->delCityList($list)) {
  294. $this->log('批量删除地区成功!');
  295. success('批量删除成功!', - 1);
  296. } else {
  297. $this->log('批量删除地区失败!');
  298. error('批量删除失败!', - 1);
  299. }
  300. } else {
  301. alert_back('请选择要删除的内容!');
  302. }
  303. }
  304. if (! $id = get('id', 'int')) {
  305. error('传递的参数值错误!', - 1);
  306. }
  307. if ($this->model->delCity($id)) {
  308. $this->log('删除地区' . $id . '成功!');
  309. success('删除成功!', - 1);
  310. } else {
  311. $this->log('删除地区' . $id . '失败!');
  312. error('删除失败!', - 1);
  313. }
  314. }
  315. }