Promotion.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*
  3. * 前台促销列表
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Promotion extends BaseMall
  16. {
  17. const PAGESIZE = 16;
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/promotion.lang.php');
  22. }
  23. public function index()
  24. {
  25. $xianshigoods_model = model('pxianshigoods');
  26. $goods_model = model('goods');
  27. $condition = array();
  28. $condition[] = array('xianshigoods_state', '=', 1);
  29. $condition[] = array('xianshigoods_starttime', '<=', TIMESTAMP);
  30. $condition[] = array('xianshigoods_end_time', '>', TIMESTAMP);
  31. $gc_id = intval(input('param.gc_id'));
  32. if ($gc_id) {
  33. $condition[] = array('gc_id_1', '=', intval($gc_id));
  34. }
  35. $goods_list = $xianshigoods_model->getXianshigoodsExtendList($condition, self::PAGESIZE, 'xianshigoods_id desc');
  36. $xs_goods_list = array();
  37. foreach ($goods_list as $k => $goods_info) {
  38. $xs_goods_list[$goods_info['goods_id']] = $goods_info;
  39. $xs_goods_list[$goods_info['goods_id']]['image_url_240'] = goods_cthumb($goods_info['goods_image'], 240, $goods_info['store_id']);
  40. $xs_goods_list[$goods_info['goods_id']]['down_price'] = $goods_info['goods_price'] - $goods_info['xianshigoods_price'];
  41. }
  42. $condition = array(array('goods_id', 'in', array_keys($xs_goods_list)));
  43. $goods_list = $goods_model->getGoodsOnlineList($condition, 'goods_id,gc_id_1,evaluation_good_star,store_id,store_name', 0, '', self::PAGESIZE, null, false);
  44. $last_goods_list = array();
  45. foreach ($goods_list as $k => $goods_info) {
  46. $last_goods_list[$goods_info['goods_id']] = $xs_goods_list[$goods_info['goods_id']];
  47. $last_goods_list[$goods_info['goods_id']]['evaluation_good_star'] = $goods_info['evaluation_good_star'];
  48. $last_goods_list[$goods_info['goods_id']]['store_name'] = $goods_info['store_name'];
  49. if ($last_goods_list[$goods_info['goods_id']]['gc_id_1'] != $goods_info['gc_id_1']) {
  50. //兼容以前版本,如果秒杀商品表没有保存一级分类ID,则马上保存
  51. $xianshigoods_model->editXianshigoods(array('gc_id_1' => $goods_info['gc_id_1']), array('xianshigoods_id' => $last_goods_list[$goods_info['goods_id']]['xianshigoods_id']));
  52. }
  53. }
  54. //查询商品评分信息
  55. $goodsevallist = model('evaluategoods')->getEvaluategoodsList(array(array('geval_goodsid', 'in', array_keys($last_goods_list))));
  56. $eval_list = array();
  57. if (!empty($goodsevallist)) {
  58. foreach ($goodsevallist as $v) {
  59. if ($v['geval_content'] == '' || (isset($eval_list[$v['geval_goodsid']]) && count($eval_list[$v['geval_goodsid']]) >= 2))
  60. continue;
  61. $eval_list[$v['geval_goodsid']][] = $v;
  62. }
  63. }
  64. View::assign('goodsevallist', $eval_list);
  65. View::assign('goods_list', $last_goods_list);
  66. if (!empty(input('get.curpage'))) {
  67. return View::fetch($this->template_dir . 'item');
  68. } else {
  69. //导航
  70. $nav_link = array(
  71. 0 => array(
  72. 'title' => lang('homepage'),
  73. 'link' => HOME_SITE_URL,
  74. ),
  75. 1 => array(
  76. 'title' => lang('limited_time_discount')
  77. )
  78. );
  79. View::assign('nav_link_list', $nav_link);
  80. //查询商品分类
  81. $goods_class = model('goodsclass')->getGoodsclassListByParentId(0);
  82. View::assign('goods_class', $goods_class);
  83. View::assign('total_page', $xianshigoods_model->page_info->render());
  84. return View::fetch($this->template_dir . 'index');
  85. }
  86. }
  87. }