coupon.php 6.8 KB

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