人人商城

home.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. if (!(defined('ES_PATH'))) {
  3. exit('Access Denied');
  4. }
  5. class HomeController extends Controller
  6. {
  7. protected $type = 'set';
  8. protected $site;
  9. public function __construct()
  10. {
  11. $this->init();
  12. }
  13. public function init()
  14. {
  15. $set = pdo_fetch('select * from ' . tablename('ewei_shop_system_site') . ' where `type`=:type', array(':type' => $this->type));
  16. if (empty($set)) {
  17. exit('请先到【系统设置】->【网站】->【基础设置】 配置网站数据.');
  18. }
  19. if (!(empty($set['content'])) && !(is_array($set['content']))) {
  20. if (strexists($set['content'], '{"')) {
  21. $data = json_decode($set['content'], true);
  22. }
  23. else {
  24. $data = unserialize($set['content']);
  25. }
  26. }
  27. if (!(is_array($data))) {
  28. $data = array();
  29. }
  30. $this->site = $data;
  31. if (empty($data['status'])) {
  32. $this->shutdown($data);
  33. }
  34. }
  35. public function index()
  36. {
  37. global $_W;
  38. $site = $this->site;
  39. $banner = $this->banner(1);
  40. $casus = $this->casus(1);
  41. $link = $this->link(1);
  42. $article = $this->article(1);
  43. $companyArticle = $this->companyArticle();
  44. $basicset = $this->basicset();
  45. $title = $basicset['title'];
  46. include $this->template('index');
  47. }
  48. public function ajaxguestbook()
  49. {
  50. global $_GPC;
  51. $guestbookform['nickname'] = trim($_GPC['nickname']);
  52. $guestbookform['mobile'] = trim($_GPC['mobile']);
  53. $guestbookform['email'] = trim($_GPC['email']);
  54. $guestbookform['content'] = trim($_GPC['content']);
  55. if (empty($guestbookform['nickname'])) {
  56. exit(json_encode(array('status' => 'error', 'message' => '姓名不能为空!', 'type' => 'nickname')));
  57. }
  58. if (empty($guestbookform['mobile'])) {
  59. exit(json_encode(array('status' => 'error', 'message' => '电话不能为空!', 'type' => 'mobile')));
  60. }
  61. if (empty($guestbookform['email'])) {
  62. exit(json_encode(array('status' => 'error', 'message' => '邮箱不能为空!', 'type' => 'email')));
  63. }
  64. if (empty($guestbookform['content'])) {
  65. exit(json_encode(array('status' => 'error', 'message' => '内容不能为空!', 'type' => 'content')));
  66. }
  67. $guestbook = pdo_fetch('SELECT * FROM' . tablename('ewei_shop_system_guestbook') . ' WHERE clientip=:clientip ORDER BY createtime DESC LIMIT 1', array(':clientip' => ES_CLIENT_IP));
  68. if (!(empty($guestbook)) && (TIMESTAMP <= $guestbook['createtime'] + 60)) {
  69. exit(json_encode(array('status' => 'error', 'message' => '距离上次留言时间小于1分钟!')));
  70. }
  71. $guestbookform['createtime'] = TIMESTAMP;
  72. $guestbookform['clientip'] = ES_CLIENT_IP;
  73. pdo_insert('ewei_shop_system_guestbook', $guestbookform);
  74. if (pdo_insertid()) {
  75. echo json_encode(array('status' => 'success', 'message' => '留言成功!'));
  76. }
  77. else {
  78. echo json_encode(array('status' => 'error', 'message' => '留言失败!'));
  79. }
  80. }
  81. protected function shutdown(array $data)
  82. {
  83. $url = $this->site['closeurl'];
  84. if (empty($url)) {
  85. exit('网站已经关闭');
  86. }
  87. else {
  88. header('location: ' . $url);
  89. exit();
  90. }
  91. }
  92. protected function banner($status = 'all')
  93. {
  94. $statusSql = $this->statusSql($status);
  95. $result = pdo_fetchall('SELECT * FROM ' . tablename('ewei_shop_system_banner') . ' WHERE 1 ' . $statusSql['sql'] . ' ORDER BY displayorder DESC', $statusSql['param']);
  96. return $result;
  97. }
  98. protected function casus($status = 'all')
  99. {
  100. $statusSql = $this->statusSql($status);
  101. $result = pdo_fetchall('SELECT * FROM ' . tablename('ewei_shop_system_case') . ' WHERE 1 ' . $statusSql['sql'] . ' ORDER BY displayorder DESC', $statusSql['param']);
  102. return $result;
  103. }
  104. protected function link($status = 'all')
  105. {
  106. $statusSql = $this->statusSql($status);
  107. $result = pdo_fetchall('SELECT * FROM ' . tablename('ewei_shop_system_link') . ' WHERE 1 ' . $statusSql['sql'] . ' ORDER BY displayorder DESC', $statusSql['param']);
  108. return $result;
  109. }
  110. protected function article($status = 'all', $limit = 6)
  111. {
  112. $statusSql = $this->statusSql($status);
  113. $statusSql['sql'] = str_replace(' status ', ' a.status ', $statusSql['sql']);
  114. $result = pdo_fetchall('SELECT a.id,a.title,a.content,a.createtime,c.name FROM ' . tablename('ewei_shop_system_article') . ' AS a LEFT JOIN ' . tablename('ewei_shop_system_category') . ' AS c ON a.cate = c.id WHERE 1 ' . $statusSql['sql'] . ' ORDER BY a.displayorder DESC LIMIT ' . $limit, $statusSql['param']);
  115. return $result;
  116. }
  117. protected function companyArticle($status = 'all', $limit = 6)
  118. {
  119. $statusSql = $this->statusSql($status);
  120. $statusSql['sql'] = str_replace(' status ', ' a.status ', $statusSql['sql']);
  121. $result = pdo_fetchall('SELECT a.*,c.id as cid,c.name FROM ' . tablename('ewei_shop_system_company_article') . ' AS a LEFT JOIN ' . tablename('ewei_shop_system_company_category') . ' AS c ON a.cate = c.id WHERE 1 ' . $statusSql['sql'] . ' ORDER BY a.displayorder DESC LIMIT ' . $limit, $statusSql['param']);
  122. return $result;
  123. }
  124. /**
  125. * 拼接sql status语句
  126. * @param $status
  127. * @return array
  128. */
  129. protected function statusSql($status)
  130. {
  131. $condition = '';
  132. $param = array();
  133. if ($status != 'all') {
  134. $status = intval($status);
  135. $condition .= 'AND status = :status';
  136. $param[':status'] = $status;
  137. }
  138. return array('sql' => $condition, 'param' => $param);
  139. }
  140. }
  141. ?>