人人商城

multi.ctrl.php 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('site');
  8. load()->model('extension');
  9. $dos = array('display', 'post', 'del', 'default', 'copy', 'switch', 'quickmenu_display', 'quickmenu_post');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. $_W['page']['title'] = '微官网';
  12. permission_check_account_user('platform_site_multi');
  13. $setting = uni_setting($_W['uniacid'], 'default_site');
  14. $default_site = intval($setting['default_site']);
  15. $default_site_status = pdo_getcolumn('site_multi', array('id' => $default_site), 'status');
  16. if ($default_site_status != 1) {
  17. pdo_update('site_multi', array('status' => 1), array('id' => $default_site));
  18. }
  19. if ($do == 'post') {
  20. if ($_W['isajax'] && $_W['ispost']) {
  21. $name = trim($_GPC['name']);
  22. $sql = "SELECT s.*, t.`name` AS `tname`, t.`title`, t.`type` FROM " . tablename('site_styles') . " AS s LEFT JOIN " . tablename('site_templates') . " AS t ON s.`templateid` = t.`id` WHERE s.`uniacid` = :uniacid AND s.`name` LIKE :name";
  23. $styles = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid'], ':name' => "%{$name}%"));
  24. iajax(0, $styles, '');
  25. }
  26. $id = intval($_GPC['multiid']);
  27. if (checksubmit('submit')) {
  28. $bindhost = parse_url($_W['siteroot']);
  29. if ($bindhost['host'] == trim($_GPC['bindhost'])) {
  30. itoast('绑定域名有误', referer(), 'error');
  31. }
  32. $data = array(
  33. 'uniacid' => $_W['uniacid'],
  34. 'title' => trim($_GPC['title']),
  35. 'styleid' => intval($_GPC['styleid']),
  36. 'status' => intval($_GPC['status']),
  37. 'site_info' => iserializer(array(
  38. 'thumb' => trim($_GPC['thumb']),
  39. 'keyword' => trim($_GPC['keyword']),
  40. 'description' => trim($_GPC['description']),
  41. 'footer' => htmlspecialchars($_GPC['footer'])
  42. )),
  43. 'bindhost' => trim($_GPC['bindhost']),
  44. );
  45. if (!empty($id)) {
  46. if ($id == $default_site) {
  47. $data['status'] = 1;
  48. }
  49. pdo_update('site_multi', $data, array('id' => $id));
  50. } else {
  51. pdo_insert('site_multi', $data);
  52. $id = pdo_insertid();
  53. }
  54. if (!empty($_GPC['keyword'])) {
  55. $cover = array(
  56. 'uniacid' => $_W['uniacid'],
  57. 'title' => $data['title'],
  58. 'keyword' => trim($_GPC['keyword']),
  59. 'url' => url('home', array('i' => $_W['uniacid'], 't' => $id)),
  60. 'description' => trim($_GPC['description']),
  61. 'thumb' => trim($_GPC['thumb']),
  62. 'module' => 'site',
  63. 'multiid' => $id,
  64. );
  65. site_cover($cover);
  66. }
  67. itoast('更新站点信息成功!', url('site/multi/display'), 'success');
  68. }
  69. if (!empty($id)) {
  70. $multi = pdo_fetch('SELECT * FROM ' . tablename('site_multi') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  71. if (empty($multi)) {
  72. itoast('微站不存在或已删除', referer(), 'error');
  73. }
  74. $multi['site_info'] = iunserializer($multi['site_info']) ? iunserializer($multi['site_info']) : array();
  75. }
  76. $temtypes = ext_template_type();
  77. $temtypes[] = array('name' => 'all', 'title' => '全部');
  78. $sql = 'SELECT `s`.*, `t`.`id` as `tid`, `t`.`name` AS `tname`, `t`.`title`, `t`.`type`, `t`.`sections` FROM ' . tablename('site_styles') . ' AS `s` LEFT JOIN ' . tablename('site_templates') . ' AS `t` ON `s`.`templateid` = `t`.`id` WHERE `s`.`uniacid` = :uniacid';
  79. $styles = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']), 'id');
  80. if (empty($multi)) {
  81. $multi = array(
  82. 'site_info' => array(),
  83. 'status' => 1,
  84. );
  85. }
  86. $multi['style'] = $styles[$multi['styleid']];
  87. template('site/post');
  88. }
  89. if ($do == 'display') {
  90. $pindex = max(1, intval($_GPC['page']));
  91. $psize = 10;
  92. $condition = '';
  93. $params = array();
  94. if (!empty($_GPC['keyword'])) {
  95. $condition .= " AND `title` LIKE :keyword";
  96. $params[':keyword'] = "%{$_GPC['keyword']}%";
  97. }
  98. $templates = uni_templates();
  99. $params[':uniacid'] = $_W['uniacid'];
  100. $multis = pdo_fetchall('SELECT * FROM ' . tablename('site_multi') . ' WHERE uniacid = :uniacid'.$condition.' ORDER BY id ASC LIMIT '.($pindex -1)* $psize.','.$psize, $params);
  101. foreach ($multis as &$li) {
  102. $li['style'] = pdo_fetch('SELECT * FROM ' .tablename('site_styles') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $li['styleid']));
  103. $li['template'] = pdo_fetch("SELECT * FROM ".tablename('site_templates')." WHERE id = :id", array(':id' => $li['style']['templateid']));
  104. $li['site_info'] = (array)iunserializer($li['site_info']);
  105. $li['site_info']['thumb'] = tomedia($li['site_info']['thumb']);
  106. if (file_exists('../app/themes/'.$li['template']['name'].'/preview.jpg')) {
  107. $li['preview_thumb'] = $_W['siteroot'].'app/themes/'.$li['template']['name'].'/preview.jpg';
  108. } else {
  109. $li['preview_thumb'] = $_W['siteroot'].'web/resource/images/nopic-203.png';
  110. }
  111. }
  112. unset($li);
  113. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('site_multi') . " WHERE uniacid = :uniacid".$condition, $params);
  114. $pager = pagination($total, $pindex, $psize);
  115. template('site/display');
  116. }
  117. if ($do == 'del') {
  118. $id = intval($_GPC['id']);
  119. if ($default_site == $id) {
  120. itoast('您删除的微站是默认微站,删除前先指定其他微站为默认微站', referer(), 'error');
  121. }
  122. pdo_delete('site_nav', array('uniacid' => $_W['uniacid'], 'multiid' => $id));
  123. $rid = pdo_fetchcolumn('SELECT rid FROM ' .tablename('cover_reply') . ' WHERE uniacid = :uniacid AND multiid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  124. if(pdo_delete('rule', array('id' => $rid, 'uniacid' => $_W['uniacid'])) !== false) {
  125. pdo_delete('rule_keyword', array('rid' => $rid));
  126. pdo_delete('cover_reply', array('rid' => $rid, 'multiid' => $id));
  127. }
  128. pdo_delete('site_multi', array('uniacid' => $_W['uniacid'], 'id' => $id));
  129. itoast('删除微站成功', referer(), 'success');
  130. }
  131. if ($do == 'copy') {
  132. $id = intval($_GPC['multiid']);
  133. $multi = pdo_fetch('SELECT * FROM ' . tablename('site_multi') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  134. if (empty($multi)) {
  135. itoast('微站不存在或已删除', referer(), 'error');
  136. }
  137. $multi['title'] = $multi['title'] . '_' . random(6);
  138. unset($multi['id']);
  139. pdo_insert('site_multi', $multi);
  140. $multi_id = pdo_insertid();
  141. if (!$multi_id) {
  142. itoast('复制微站出错', '', 'error');
  143. } else {
  144. $navs = pdo_fetchall('SELECT * FROM ' . tablename('site_nav') . ' WHERE uniacid = :uniacid AND multiid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  145. if (!empty($navs)) {
  146. foreach ($navs as &$nav) {
  147. unset($nav['id']);
  148. $nav['multiid'] = $multi_id;
  149. pdo_insert('site_nav', $nav);
  150. }
  151. unset($nav);
  152. }
  153. $cover = pdo_fetch('SELECT * FROM ' . tablename('cover_reply') . ' WHERE uniacid = :uniacid AND multiid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  154. if (!empty($cover)) {
  155. $rule = pdo_fetch('SELECT * FROM ' . tablename('rule') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $cover['rid']));
  156. $keywords = pdo_fetchall('SELECT * FROM ' . tablename('rule_keyword') . ' WHERE uniacid = :uniacid AND rid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $cover['rid']));
  157. if (!empty($rule) && !empty($keywords)) {
  158. $rule['name'] = $multi['title'] . '入口设置';
  159. unset($rule['id']);
  160. pdo_insert('rule', $rule);
  161. $new_rid = pdo_insertid();
  162. foreach($keywords as &$keyword) {
  163. unset($keyword['id']);
  164. $keyword['rid'] = $new_rid;
  165. pdo_insert('rule_keyword', $keyword);
  166. }
  167. unset($keyword);
  168. unset($cover['id']);
  169. $cover['title'] = $multi['title'] . '入口设置';
  170. $cover['multiid'] = $multi_id;
  171. $cover['rid'] = $new_rid;
  172. pdo_insert('cover_reply', $cover);
  173. }
  174. }
  175. itoast('复制微站成功', url('site/multi/post', array('multiid' => $multi_id)), 'success');
  176. }
  177. }
  178. if ($do == 'switch') {
  179. $id = intval($_GPC['id']);
  180. $multi_info = pdo_get('site_multi', array('id' => $id, 'uniacid' => $_W['uniacid']));
  181. if(empty($multi_info)) {
  182. itoast('微站不存在或已删除', referer(), 'error');
  183. }
  184. $data = array('status' => $multi_info['status'] == 1 ? 0 : 1);
  185. $result = pdo_update('site_multi', $data, array('id' => $id));
  186. if(!empty($result)) {
  187. iajax(0, '更新成功!', '');
  188. }else {
  189. iajax(-1, '请求失败!', '');
  190. }
  191. }
  192. if ($do == 'quickmenu_display' && $_W['isajax'] && $_W['ispost'] && $_W['role'] != 'operator') {
  193. $multiid = intval($_GPC['multiid']);
  194. if($multiid > 0){
  195. $page = pdo_get('site_page', array('multiid' => $multiid, 'type' => 2));
  196. }
  197. $params = !empty($page['params']) ? $page['params'] : 'null';
  198. $status = $page['status'] == 1 ? 1 : 0;
  199. $modules = uni_modules();
  200. $modules = !empty($modules) ? $modules : 'null';
  201. iajax(0, array('params' => json_decode($params), 'status' => $status, 'modules' => $modules), '');
  202. }
  203. if ($do == 'quickmenu_post' && $_W['isajax'] && $_W['ispost']) {
  204. $params = $_GPC['postdata']['params'];
  205. if (empty($params)) {
  206. iajax(1, '请您先设计手机端页面.');
  207. }
  208. foreach ($params['position'] as &$val) {
  209. $val = $val == 'true' ? 1 : 0;
  210. }
  211. unset($val);
  212. $html = safe_gpc_html(htmlspecialchars_decode($_GPC['postdata']['html'], ENT_QUOTES));
  213. $html = preg_replace('/background\-image\:(\s)*url\(\"(.*)\"\)/U', 'background-image: url($2)', $html);
  214. $data = array(
  215. 'uniacid' => $_W['uniacid'],
  216. 'multiid' => intval($_GPC['multiid']),
  217. 'title' => '快捷菜单',
  218. 'description' => '',
  219. 'status' => intval($_GPC['status']),
  220. 'type' => 2,
  221. 'params' => json_encode($params),
  222. 'html' => $html,
  223. 'createtime' => TIMESTAMP,
  224. );
  225. $id = pdo_fetchcolumn("SELECT id FROM ".tablename('site_page')." WHERE multiid = :multiid AND type = 2", array(':multiid' => intval($_GPC['multiid'])));
  226. if (!empty($id)) {
  227. $result = pdo_update('site_page', $data, array('id' => $id));
  228. } else {
  229. $result = pdo_insert('site_page', $data);
  230. $id = pdo_insertid();
  231. }
  232. if ($result) {
  233. iajax(0, '保存成功!', '');
  234. } else {
  235. iajax(1, '保存失败!', '');
  236. }
  237. }