coupon.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. function get_coupon_location($cate_id = 0, $str = '')
  3. {
  4. global $db;
  5. global $db_mymps;
  6. global $couponclass;
  7. global $areaid;
  8. global $areaname;
  9. global $mymps_global;
  10. global $city;
  11. $raquo = $mymps_global['cfg_raquo'];
  12. $location = '当前位置:<a href="' . $mymps_global['SiteUrl'] . '">' . $city['cityname'] . $GLOBALS['mymps_global']['SiteName'] . '</a>' . ' <code>' . $raquo . '</code> ' . ' <a href="' . plugin_url(CURSCRIPT, array('cate_id' => 0)) . '">' . $city[cityname] . '优惠券</a>';
  13. $page_title = $city['cityname'] . '优惠券-' . $mymps_global['SiteName'];
  14. if (!empty($cate_id)) {
  15. $page_title = htmlspecialchars($couponclass[$cate_id]['cate_name']) . '-' . $page_title;
  16. $location .= ' <code> ' . $raquo . ' </code> <a href="' . $couponclass[$cate_id]['cate_uri'] . '">' . htmlspecialchars($couponclass[$cate_id]['cate_name']) . '</a>';
  17. }
  18. $areaname = $mymps_global['SiteCity'] . ($areaid ? get_areaname($areaid) : '');
  19. $page_title = $areaname . $page_title;
  20. if (!empty($str)) {
  21. $page_title = $str . '-' . $page_title;
  22. $location .= ' <code>' . $raquo . '</code> &nbsp;' . $str;
  23. }
  24. $cur = array('page_title' => $page_title, 'location' => $location);
  25. unset($page_title);
  26. unset($cat);
  27. unset($location);
  28. unset($type);
  29. unset($couponclass);
  30. return $cur;
  31. }
  32. define('IN_SMT', true);
  33. define('CURSCRIPT', 'coupon');
  34. define('IN_MYMPS', true);
  35. define('DIR_NAV', dirname(__FILE__));
  36. require_once DIR_NAV . '/include/global.php';
  37. require_once MYMPS_DATA . '/config.php';
  38. require_once MYMPS_DATA . '/config.db.php';
  39. require_once MYMPS_INC . '/db.class.php';
  40. ifsiteopen();
  41. $cate_id = isset($cate_id) ? intval($cate_id) : '';
  42. $areaid = isset($areaid) ? intval($areaid) : '';
  43. $id = isset($id) ? intval($id) : '';
  44. $orderby = isset($orderby) ? mhtmlspecialchars($orderby) : '';
  45. $data = $pluginsettings = '';
  46. $action = isset($action) ? mhtmlspecialchars($action) : '';
  47. if (!in_array($orderby, array('prints', 'dateline', 'hit'))) {
  48. $orderby = 'hit';
  49. }
  50. $advertisement = get_advertisement('other');
  51. $adveritems = $advertisement['items'];
  52. $advertisement = $advertisement['all'];
  53. !ifplugin(CURSCRIPT) && exit('管理员已禁用或未安装优惠券插件...');
  54. require_once DIR_NAV . '/plugin/coupon/include/functions.php';
  55. $couponclass = $coupon_class = get_coupon_class();
  56. $coupon_class = is_array($coupon_class) ? array_merge(array(
  57. array('cate_id' => 0, 'cate_name' => '全部', 'cate_uri' => plugin_url(CURSCRIPT, array('cate_id' => 0)))
  58. ), $coupon_class) : array();
  59. $area_class = cat_list('area', 0, 0, false, 1);
  60. $area_class = array_merge(array(
  61. array('areaid' => '', 'areaname' => '全部')
  62. ), $area_class);
  63. if (is_array($area_class)) {
  64. foreach ($area_class as $areakey => $areaval) {
  65. $area_class[$areakey]['uri'] = plugin_url(CURSCRIPT, array('cate_id' => $cate_id, 'areaid' => $areaval['areaid']));
  66. $area_class[$areakey]['select'] = $areaval['areaid'] == $areaid ? '1' : 0;
  67. }
  68. }
  69. $advertisement = get_advertisement('other');
  70. $adveritems = $city['advertisement'];
  71. $advertisement = $advertisement['all'];
  72. $where .= $city[cityid] ? ' AND cityid = \'' . $city['cityid'] . '\'' : '';
  73. $counts = $db->getAll('SELECT cate_id,count(id) AS num FROM ' . $db_mymps . 'coupon AS i WHERE status = \'1\' AND grade > \'0\' ' . $where . ' GROUP BY cate_id ');
  74. $count = array();
  75. $count['total'] = $db->getOne('SELECT count(id) FROM ' . $db_mymps . 'coupon WHERE status = \'1\' AND grade > \'0\' ' . $where);
  76. foreach ($counts as $k => $v) {
  77. $count[$v['cate_id']] = !empty($v['num']) ? $v['num'] : 0;
  78. }
  79. if ($id) {
  80. $coupon = $db->getRow('SELECT * FROM `' . $db_mymps . 'coupon` WHERE id = \'' . $id . '\' AND status = \'1\' AND grade > \'0\'');
  81. if (!$coupon['id']) {
  82. write_msg('该优惠券已失效或者尚未通过审核!', 'olmsg');
  83. }
  84. if ($action == 'print') {
  85. $db->query('UPDATE `' . $db_mymps . 'coupon` SET prints = prints + 1 WHERE id = \'' . $id . '\'');
  86. globalassign();
  87. include mymps_tpl('print');
  88. }
  89. else {
  90. $db->query('UPDATE `' . $db_mymps . 'coupon` SET hit = hit + 1 WHERE id = \'' . $id . '\'');
  91. $coupon['content'] = replace_insidelink($coupon['content'], 'coupon');
  92. $space = $db->getRow('SELECT tname,address,busway,tel FROM `' . $db_mymps . 'member` WHERE userid = \'' . $coupon['userid'] . '\'');
  93. $uid = $db->getOne('SELECT id FROM `' . $db_mymps . 'member` WHERE userid = \'' . $coupon['userid'] . '\'');
  94. $space['uri'] = Rewrite('store', array('uid' => $uid, 'action' => 'index'));
  95. $space['tname'] = $space['tname'] ? $space['tname'] : $space['userid'];
  96. $space['address'] = $space['address'] ? $space['address'] : $space['busway'];
  97. $loc = get_coupon_location($coupon['cate_id'], $coupon['title']);
  98. $page_title = $loc['page_title'];
  99. $location = $loc['location'];
  100. globalassign();
  101. include mymps_tpl('view');
  102. }
  103. }
  104. else {
  105. $where = 'WHERE status = \'1\' AND grade > \'0\'';
  106. if ($cate_id) {
  107. $where .= ' AND cate_id = \'' . $cate_id . '\'';
  108. }
  109. if ($areaid) {
  110. $where .= ' AND areaid = \'' . $areaid . '\'';
  111. }
  112. $rows_num = $db->getOne('SELECT count(id) FROM ' . $db_mymps . 'coupon ' . $where);
  113. $param = setParam(array('cateid', 'areaid', 'orderby'));
  114. $coupon = page1('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' ORDER BY ' . $orderby . ' DESC');
  115. $list = array();
  116. foreach ($coupon as $k => $v) {
  117. $list[$v['id']]['id'] = $v['id'];
  118. $list[$v['id']]['title'] = $v['title'];
  119. $list[$v['id']]['des'] = $v['des'];
  120. $list[$v['id']]['enddate'] = $v['enddate'];
  121. $list[$v['id']]['begindate'] = $v['begindate'];
  122. $list[$v['id']]['prints'] = $v['prints'];
  123. $list[$v['id']]['pre_picture'] = $v['pre_picture'];
  124. $list[$v['id']]['sup'] = $v['sup'];
  125. $list[$v['id']]['uri'] = plugin_url('coupon', array('id' => $v['id']));
  126. }
  127. foreach (array('hit' => '默认', 'prints' => '打印', 'dateline' => '最新') as $k => $v) {
  128. $orderby_url[$k]['selected'] = $orderby == $k ? 1 : 0;
  129. $orderby_url[$k]['name'] = $v;
  130. $orderby_url[$k]['url'] = plugin_url(CURSCRIPT, array('cate_id' => $cate_id, 'areaid' => $areaid, 'orderby' => $k));
  131. }
  132. $page_view = page2();
  133. $loc = get_coupon_location($cate_id);
  134. $page_title = empty($cate_id) && empty($areaid) ? ($pluginsettings[CURSCRIPT]['seotitle'] ? $pluginsettings[CURSCRIPT]['seotitle'] : $loc['page_title']) : $loc['page_title'];
  135. $page_title = str_replace('{city}', $city['cityname'], $page_title);
  136. $location = $loc['location'];
  137. $seo = array();
  138. $seo['keywords'] = str_replace('{city}', $city['cityname'], $pluginsettings[CURSCRIPT]['seokeywords']);
  139. $seo['description'] = str_replace('{city}', $city['cityname'], $pluginsettings[CURSCRIPT]['seodescription']);
  140. $currentlocate = $areaname . $couponclass[$cate_id]['cate_name'] . '优惠券';
  141. globalassign();
  142. include mymps_tpl('index');
  143. }
  144. is_object($db) && $db->Close();
  145. ?>