PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/app/Lib/Action/index/indexAction.class.php

https://gitlab.com/selecterskyphp/58bitao
PHP | 419 lines | 361 code | 49 blank | 9 comment | 51 complexity | f7e1e98db07fe6e2aa19dab9bce5870d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. <?php
  2. class indexAction extends FirstendAction {
  3. public function _initialize() {
  4. parent::_initialize();
  5. $this->_mod = D('items');
  6. $this->_cate_mod = D('items_cate');
  7. }
  8. /**
  9. ** 首页(全部)
  10. **/
  11. public function index() {
  12. $id = I('id','', 'intval');
  13. $p = I('p',1 ,'intval'); //页码
  14. $sort = I('sort', 'default', 'trim'); //排序
  15. $status = I('status', 'all', 'trim'); //排序
  16. $today_str = mktime(0,0,0,date("m"),date("d"),date("Y"));
  17. $tomorr_str = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
  18. $today_wh['coupon_start_time'] = array(array('egt',$today_str),array('elt',$tomorr_str)) ;
  19. $today_wh['pass'] = '1';
  20. $today_wh['isshow'] = '1';
  21. $today_item = $this->_mod->where($today_wh)->count();
  22. $this->assign('today_item', $today_item);
  23. $order = 'ordid asc';
  24. switch ($sort){
  25. case 'new':
  26. $order.= ', coupon_start_time DESC';
  27. break;
  28. case 'price':
  29. $order.= ', price DESC';
  30. break;
  31. case 'rate':
  32. $order.= ', coupon_rate ASC';
  33. break;
  34. case 'hot':
  35. $order.= ', volume DESC';
  36. break;
  37. case 'default':
  38. $order.= ', '.C('ftx_index_sort');
  39. }
  40. switch ($status){
  41. case 'all':
  42. $where['status']="underway";
  43. break;
  44. case 'underway':
  45. $where['status']="underway";
  46. break;
  47. case 'sellout':
  48. $where['status']="sellout";
  49. break;
  50. }
  51. if(C('ftx_index_not_text')){
  52. $not_arr = explode(",",C('ftx_index_not_text'));
  53. $arrs =array();
  54. foreach($not_arr as $key =>$value){
  55. $arrs[] = '%'.$value.'%';
  56. }
  57. $where['title'] =array('notlike',$arrs,'AND');
  58. }
  59. if(C('ftx_index_cids')){
  60. $where['cate_id'] = array('in',C('ftx_index_cids'));
  61. }
  62. if(C('ftx_wait_time') == '1'){
  63. $where['coupon_start_time'] = array('egt',time());
  64. }elseif(C('ftx_wait_time') =='2'){
  65. $where['coupon_start_time'] = array('elt',time());
  66. }
  67. if(C('ftx_end_time') == '1'){
  68. $where['coupon_end_time'] = array('egt',time());
  69. }
  70. if(C('ftx_index_ems') == '1'){
  71. $where['ems'] = '1';
  72. }
  73. if(C('ftx_index_shop_type')){$where['shop_type'] = C('ftx_index_shop_type');}
  74. if(C('ftx_index_mix_price')>0){$where['coupon_price'] = array('egt',C('ftx_index_mix_price'));}
  75. if(C('ftx_index_max_price')>0){$where['coupon_price'] = array('elt',C('ftx_index_max_price'));}
  76. if(C('ftx_index_mix_price')>0 && C('ftx_index_max_price')>0){$where['coupon_price'] = array(array('egt',C('ftx_index_mix_price')),array('elt',C('ftx_index_max_price')),'and');}
  77. if(C('ftx_index_mix_volume')>0){$where['volume'] = array('egt',C('ftx_index_mix_volume'));}
  78. if(C('ftx_index_max_volume')>0){$where['volume'] = array('elt',C('ftx_index_max_volume'));}
  79. if(C('ftx_index_mix_volume')>0 && C('ftx_index_max_volume')>0){$where['volume'] = array(array('egt',C('ftx_index_mix_volume')),array('elt',C('ftx_index_max_volume')),'and');}
  80. $where['pass'] = '1';
  81. $where['isshow'] = '1';
  82. $index_info['sort']=$sort;
  83. $index_info['status']=$status;
  84. $page_size = C('ftx_index_page_size');
  85. $index_info['p']=$p;
  86. $start = $page_size * ($p - 1) ;
  87. if(false === $cate_list = F('cate_list')) {
  88. $cate_list = D('items_cate')->cate_cache();
  89. }
  90. $this->assign('cate_list', $cate_list); //分类
  91. $items_list = $this->_mod->where($where)->order($order)->limit($start . ',' . $page_size)->select();
  92. $items = array();
  93. $pagecount = 0;
  94. foreach($items_list as $key=>$val){
  95. $items[$key] = $val;
  96. $items[$key]['class'] = $this->_mod->status($val['status'],$val['coupon_start_time'],$val['coupon_end_time']);
  97. $items[$key]['zk'] = round(($val['coupon_price']/$val['price'])*10, 1);
  98. $items[$key]['newhot'] = round(date('Ymd')-date("Ymd", $val['coupon_start_time']));
  99. $items[$key]['click_url'] =U('item/index',array('id'=>$val['id']));
  100. if($val['coupon_start_time']>time())
  101. {
  102. $items[$key]['timeleft'] = $val['coupon_start_time']-time();
  103. }else{
  104. $items[$key]['timeleft'] = $val['coupon_end_time']-time();
  105. }
  106. $items[$key]['ccid'] = $val['cate_id'];
  107. if(isset($val['cate_id'])){
  108. $items[$key]['cname'] = D('items_cate')->where(array('id'=>$val['cate_id']))->getField('name');
  109. }
  110. $items[$key]['cate_name'] =$cate_list['p'][$val['cate_id']]['name'];
  111. $url = C('ftx_site_url').U('item/index',array('id'=>$val['id']));
  112. $items[$key]['url'] = urlencode($url);
  113. $items[$key]['urltitle'] = urlencode($val['title']);
  114. $items[$key]['price'] = number_format($val['price'],1);
  115. $items[$key]['coupon_price'] = number_format($val['coupon_price'],1);
  116. $pagecount++;
  117. }
  118. $this->assign('pagecount', $pagecount);
  119. F('items_list', $items);
  120. $this->assign('items_list', $items);
  121. $this->assign('index_info',$index_info);
  122. $count = $this->_mod->where($where)->count();
  123. $pager = $this->_pager($count, $page_size);
  124. $this->assign('page', $pager->kshow());
  125. $this->assign('total_item',$count);
  126. $this->assign('pager','index');
  127. $this->assign('nav_curr', 'index');
  128. $this->_config_seo(C('ftx_seo_config.index'));
  129. $this->display();
  130. }
  131. /**
  132. ** 搜索
  133. **/
  134. public function so() {
  135. $sort = I('sort', 'new', 'trim'); //排序
  136. $status = I('status', 'all', 'trim'); //排序
  137. $cid = I('cid','','intval');
  138. $k = I('k');
  139. $order = 'ordid asc ,id desc';
  140. switch ($sort) {
  141. case 'new':
  142. $order.= ', coupon_start_time DESC';
  143. break;
  144. case 'price':
  145. $order.= ', price DESC';
  146. break;
  147. }
  148. switch ($status) {
  149. case 'all':
  150. $where['status']="underway";
  151. break;
  152. case 'underway':
  153. $where['status']="underway";
  154. break;
  155. case 'sellout':
  156. $where['status']="sellout";
  157. break;
  158. }
  159. if($k){
  160. $where['title'] = array('like', '%' . $k . '%');
  161. $this->assign('k',$k);
  162. }
  163. $today_str = mktime(0,0,0,date("m"),date("d"),date("Y"));
  164. $tomorr_str = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
  165. $today_wh['coupon_start_time'] = array(array('egt',$today_str),array('elt',$tomorr_str)) ;
  166. $today_wh['pass'] = '1';
  167. $today_item = $this->_mod->where($today_wh)->count();
  168. $this->assign('today_item', $today_item);
  169. if ($cid) {
  170. $id_arr = $this->_cate_mod->get_child_ids($cid, true);
  171. $map['cate_id'] = array('IN', $id_arr);
  172. $spid = $this->_cate_mod->where(array('id'=>$cate_id))->getField('spid');
  173. if( $spid==0 ){
  174. $spid = $cid;
  175. }else{
  176. $spid .= $cid;
  177. }
  178. $this->assign('cid',$cid);
  179. }
  180. $where['pass'] = '1';
  181. $index_info['sort']=$sort;
  182. $index_info['status']=$status;
  183. $page_size = C('ftx_index_page_size');
  184. $p = I('p',1, 'intval'); //页码
  185. $index_info['p']=$p;
  186. $start = $page_size * ($p - 1) ;
  187. if (false === $cate_list = F('cate_list')) {
  188. $cate_list = D('items_cate')->cate_cache();
  189. }
  190. $this->assign('cate_list', $cate_list); //分类
  191. $items_list = $this->_mod->where($where)->order($order)->limit($start . ',' . $page_size)->select();
  192. $items = array();
  193. $pagecount = 0;
  194. foreach($items_list as $key=>$val){
  195. $items[$key] = $val;
  196. $items[$key]['class'] = $this->_mod->status($val['status'],$val['coupon_start_time'],$val['coupon_end_time']);
  197. $items[$key]['zk'] = round(($val['coupon_price']/$val['price'])*10, 1);
  198. $items[$key]['newhot'] = round(date('Ymd')-date("Ymd", $val['coupon_start_time']));
  199. $items[$key]['click_url'] =U('item/index',array('id'=>$val['id']));
  200. if($val['coupon_start_time']>time()){
  201. $items[$key]['timeleft'] = $val['coupon_start_time']-time();
  202. }else{
  203. $items[$key]['timeleft'] = $val['coupon_end_time']-time();
  204. }
  205. $items[$key]['ccid'] = $val['cate_id'];
  206. if(isset($val['cate_id']))
  207. {
  208. $items[$key]['cname'] = D('items_cate')->where(array('id'=>$val['cate_id']))->getField('name');
  209. }
  210. $items[$key]['cate_name'] =$cate_list['p'][$val['cate_id']]['name'];
  211. $url = C('ftx_site_url').U('item/index',array('id'=>$val['id']));
  212. $items[$key]['url'] = urlencode($url);
  213. $items[$key]['urltitle'] = urlencode($val['title']);
  214. $items[$key]['price'] = number_format($val['price'],1);
  215. $items[$key]['coupon_price'] = number_format($val['coupon_price'],1);
  216. $pagecount++;
  217. }
  218. $this->assign('pagecount', $pagecount);
  219. F('items_list', $items);
  220. $this->assign('items_list', $items);
  221. $this->assign('index_info',$index_info);
  222. $count = $this->_mod->where($where)->count();
  223. $pager = $this->_pager($count, $page_size);
  224. $this->assign('page', $pager->kshow());
  225. $this->assign('total_item',$count);
  226. $this->assign('nav_curr', 'index');
  227. $page_seo=array(
  228. 'title' => '搜索"'.$k.'"的宝贝结果页 - '.C('ftx_site_name'),
  229. );
  230. $this->assign('page_seo', $page_seo);
  231. $this->assign('pager','so');
  232. $this->display(index);
  233. }
  234. public function shortcut(){
  235. $Shortcut = "[InternetShortcut]
  236. URL=".C('ftx_site_url')."
  237. IDList=
  238. [{000214A0-0000-0000-C000-000000000046}]
  239. Prop3=19,2
  240. ";
  241. Header("Content-type: application/octet-stream");
  242. header("Content-Disposition: attachment; filename=".C('ftx_site_name').".url;");
  243. echo $Shortcut;
  244. }
  245. /**
  246. * 分类
  247. */
  248. public function cate(){
  249. $cid = I('cid','', 'intval');
  250. $sort = I('sort', 'default', 'trim'); //排序
  251. $status = I('status', 'all', 'trim'); //排序
  252. $order = 'ordid asc ';
  253. $cinfo = $this->_cate_mod->where(array('id'=>$cid))->find();
  254. switch ($sort) {
  255. case 'new':
  256. $order.= ', coupon_start_time DESC';
  257. break;
  258. case 'price':
  259. $order.= ', price DESC';
  260. break;
  261. case 'hot':
  262. $order.= ', volume DESC';
  263. break;
  264. case 'rate':
  265. $order.= ', coupon_rate ASC';
  266. break;
  267. case 'default':
  268. $order.= ', '.$cinfo['sort'];
  269. }
  270. switch ($status) {
  271. case 'all':
  272. $map['status']="underway";
  273. break;
  274. case 'underway':
  275. $map['status']="underway";
  276. break;
  277. case 'sellout':
  278. $map['status']="sellout";
  279. break;
  280. }
  281. if($cinfo['shop_type']){$map['shop_type'] = $cinfo['shop_type'];}
  282. if($cinfo['mix_price']>0){$map['coupon_price'] = array('egt',$cinfo['mix_price']);}
  283. if($cinfo['max_price']>0){$map['coupon_price'] = array('elt',$cinfo['max_price']);}
  284. if($cinfo['max_price']>0 && $cinfo['mix_price']>0){$map['coupon_price'] = array(array('egt',$cinfo['mix_price']),array('elt',$cinfo['max_price']),'and');}
  285. if($cinfo['mix_volume']>0){$map['volume'] = array('egt',$cinfo['mix_volume']);}
  286. if($cinfo['max_volume']>0){$map['volume'] = array('elt',$cinfo['max_volume']);}
  287. if($cinfo['max_volume']>0 && $cinfo['mix_volume']>0){$map['volume'] = array(array('egt',$cinfo['mix_volume']),array('elt',$cinfo['max_volume']),'and');}
  288. if($cinfo['thiscid']==0){
  289. $id_arr = $this->_cate_mod->get_child_ids($cid, true);
  290. $map['cate_id'] = array('IN', $id_arr);
  291. $today_wh['cate_id'] = array('IN', $id_arr);
  292. }
  293. $today_str = mktime(0,0,0,date("m"),date("d"),date("Y"));
  294. $tomorr_str = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
  295. $today_wh['coupon_start_time'] = array(array('egt',$today_str),array('elt',$tomorr_str)) ;
  296. $today_wh['pass'] = '1';
  297. $today_wh['isshow'] = '1';
  298. $today_item = $this->_mod->where($today_wh)->count();
  299. $this->assign('today_item', $today_item);
  300. $this->assign('cid',$cid);
  301. $this->assign('pager','cate');
  302. $this->assign('cinfo',$cinfo);
  303. if($cinfo['wait_time'] == '1'){
  304. $map['coupon_start_time'] = array('egt',time());
  305. }elseif($cinfo['wait_time'] =='2'){
  306. $map['coupon_start_time'] = array('elt',time());
  307. }
  308. if($cinfo['end_time'] == '1'){
  309. $map['coupon_end_time'] = array('egt',time());
  310. }
  311. if($cinfo['ems'] == '1'){
  312. $map['ems'] = '1';
  313. }
  314. $map['pass']="1";
  315. $map['isshow'] = '1';
  316. $index_info['sort']=$sort;
  317. $index_info['status']=$status;
  318. $index_info['cid']=$cid;
  319. $page_size = C('ftx_index_page_size');
  320. $p = I('p',1,'intval'); //页码
  321. $index_info['p']=$p;
  322. $start = $page_size * ($p - 1) ;
  323. if (false === $cate_list = F('cate_list')) {
  324. $cate_list = D('items_cate')->cate_cache();
  325. }
  326. $this->assign('cate_list', $cate_list); //分类
  327. $items_list = $this->_mod->where($map)->order($order)->limit($start . ',' . $page_size)->select();
  328. $items = array();
  329. $pagecount = 0;
  330. foreach($items_list as $key=>$val){
  331. $items[$key] = $val;
  332. $items[$key]['class'] = $this->_mod->status($val['status'],$val['coupon_start_time'],$val['coupon_end_time']);
  333. $items[$key]['zk'] = round(($val['coupon_price']/$val['price'])*10, 1);
  334. $items[$key]['newhot'] = round(date('Ymd')-date("Ymd", $val['coupon_start_time']));
  335. $items[$key]['click_url'] =U('item/index',array('id'=>$val['id']));
  336. if($val['coupon_start_time']>time()){
  337. $items[$key]['timeleft'] = $val['coupon_start_time']-time();
  338. }else{
  339. $items[$key]['timeleft'] = $val['coupon_end_time']-time();
  340. }
  341. $items[$key]['ccid'] = $val['cate_id'];
  342. if(isset($val['cate_id'])){
  343. $items[$key]['cname'] = D('items_cate')->where(array('id'=>$val['cate_id']))->getField('name');
  344. }
  345. $items[$key]['cate_name'] =$cate_list['p'][$val['cate_id']]['name'];
  346. $url = C('ftx_site_url').U('jump/index',array('id'=>$val['id']));
  347. $items[$key]['url'] = urlencode($url);
  348. $items[$key]['urltitle'] = urlencode($val['title']);
  349. $items[$key]['price'] = number_format($val['price'],1);
  350. $items[$key]['coupon_price'] = number_format($val['coupon_price'],1);
  351. $pagecount++;
  352. }
  353. $this->assign('pagecount', $pagecount);
  354. F('items_list', $items);
  355. $this->assign('items_list', $items);
  356. $this->assign('index_info',$index_info);
  357. $count = $this->_mod->where($map)->count();
  358. $pager = $this->_pager($count, $page_size);
  359. $this->assign('page', $pager->kshow());
  360. $this->assign('total_item',$count);
  361. $this->assign('nav_curr', 'index');
  362. $this->_config_seo(C('ftx_seo_config.cate'), array(
  363. 'cate_name' => $cinfo['name'],
  364. 'seo_title' => $cinfo['seo_title'],
  365. 'seo_keywords' => $cinfo['seo_keys'],
  366. 'seo_description' => $cinfo['seo_desc'],
  367. ));
  368. $this->display(index);
  369. }
  370. }