Flea.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Flea extends BaseFlea
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/flea.lang.php');
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/fleacommon.lang.php');
  19. }
  20. /**
  21. * 闲置市场首页
  22. */
  23. public function index()
  24. {
  25. /**
  26. * 地区
  27. */
  28. $fleaarea_model = model('fleaarea');
  29. $area_array = $fleaarea_model->fleaarea_show();
  30. View::assign('area_one_level', $area_array['area_one_level']);
  31. View::assign('area_two_level', $area_array['area_two_level']);
  32. /**
  33. * 分类
  34. */
  35. $fleaclass_model = model('fleaclass');
  36. $goods_class = $fleaclass_model->getTreeClassList(3, array('fleaclass_show' => 1));
  37. if (is_array($goods_class) and !empty($goods_class)) {
  38. $show_goods_class = array();
  39. $arr = array();
  40. foreach ($goods_class as $val) {
  41. if ($val['fleaclass_parent_id'] == 0) {
  42. $show_goods_class[$val['fleaclass_id']]['class_name'] = $val['fleaclass_name'];
  43. $show_goods_class[$val['fleaclass_id']]['class_id'] = $val['fleaclass_id'];
  44. $show_goods_class[$val['fleaclass_id']]['fleaclass_index_show'] = $val['fleaclass_index_show'];
  45. $arr[$val['fleaclass_id']]['class_name'] = $val['fleaclass_name'];
  46. $arr[$val['fleaclass_id']]['class_id'] = $val['fleaclass_id'];
  47. if (!isset($arr[$val['fleaclass_id']]['fleaclass_id_str'])) {
  48. $arr[$val['fleaclass_id']]['fleaclass_id_str'] = '';
  49. }
  50. $arr[$val['fleaclass_id']]['fleaclass_id_str'] .= ',' . $val['fleaclass_id'];
  51. } else {
  52. if (isset($show_goods_class[$val['fleaclass_parent_id']])) {
  53. $show_goods_class[$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['class_name'] = $val['fleaclass_name'];
  54. $show_goods_class[$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['class_id'] = $val['fleaclass_id'];
  55. $show_goods_class[$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['fleaclass_parent_id'] = $val['fleaclass_parent_id'];
  56. $show_goods_class[$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['fleaclass_index_show'] = $val['fleaclass_index_show'];
  57. $arr[$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['class_name'] = $val['fleaclass_name'];
  58. $arr[$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['class_id'] = $val['fleaclass_id'];
  59. $arr[$val['fleaclass_parent_id']]['fleaclass_id_str'] .= ',' . $val['fleaclass_id'];
  60. } else {
  61. foreach ($show_goods_class as $v) {
  62. if (isset($v['sub_class'][$val['fleaclass_parent_id']])) {
  63. $show_goods_class[$v['sub_class'][$val['fleaclass_parent_id']]['fleaclass_parent_id']]['sub_class'][$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['class_name'] = $val['fleaclass_name'];
  64. $show_goods_class[$v['sub_class'][$val['fleaclass_parent_id']]['fleaclass_parent_id']]['sub_class'][$val['fleaclass_parent_id']]['sub_class'][$val['fleaclass_id']]['class_id'] = $val['fleaclass_id'];
  65. $arr[$v['sub_class'][$val['fleaclass_parent_id']]['fleaclass_parent_id']]['fleaclass_id_str'] .= ',' . $val['fleaclass_id'];
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. $new_arr = array();
  73. $flea_model = model('flea');
  74. $condition = array();
  75. $condition[] = array('flea.goods_image', '<>', '');
  76. if (isset($arr) && !empty($arr)) {
  77. foreach ($arr as $key => $value) {
  78. if (isset($new_arr[4]) && is_array($new_arr[4]) && !empty($new_arr[4]))
  79. break; //只取前5条分类下有的商品
  80. $condition[] = array('flea.fleaclass_id', 'in', $value['fleaclass_id_str']);
  81. $arr[$key]['goods'] = $flea_model->getFleaByClass($condition, 'goods_id,goods_name,goods_store_price,flea_quality,member_id,goods_image', 'goods_id desc', 14);
  82. if (is_array($arr[$key]['goods']) && !empty($arr[$key]['goods']))
  83. $new_arr[] = $arr[$key];
  84. }
  85. }
  86. View::assign('show_flea_goods_class_list', $new_arr);
  87. /**
  88. * js滑动参数
  89. */
  90. $str = '';
  91. $str1 = '';
  92. for ($j = 1; $j <= count($new_arr); $j++) {
  93. $str .= '"m0' . $j . '"' . ',';
  94. $str1 .= '"c0' . $j . '"' . ',';
  95. }
  96. $str = rtrim($str, ",");
  97. $str1 = rtrim($str1, ",");
  98. View::assign('mstr', $str);
  99. View::assign('cstr', $str1);
  100. /**
  101. * 新鲜货
  102. */
  103. $condition = array();
  104. $condition[] = array('goods_image', '<>', '');
  105. $condition[] = array('goods_body', '<>', '');
  106. $new_flea_goods = $flea_model->getOneFlea($condition);
  107. View::assign('new_flea_goods', $new_flea_goods);
  108. /**
  109. * 收藏第一
  110. */
  111. $condition = array();
  112. $condition[] = array('goods_image', '<>', '');
  113. $col_flea_goods = $flea_model->getOneFlea($condition);
  114. View::assign('col_flea_goods', $col_flea_goods);
  115. /**
  116. * 热门搜
  117. */
  118. $new_flea_goods2 = $flea_model->getFleaList(array('pic_input' => '2'), '', '*', 'goods_click desc', 14);
  119. View::assign('new_flea_goods2', $new_flea_goods2);
  120. /**
  121. * 闲置围观区
  122. */
  123. $new_flea_goods3 = $flea_model->getFleaList(array('pic_input' => '2'), '', '*', 'goods_id desc', 14);
  124. View::assign('new_flea_goods3', $new_flea_goods3);
  125. /**
  126. * 导航标识
  127. */
  128. View::assign('index_sign', 'flea');
  129. // 首页幻灯
  130. $loginpic = unserialize(config('ds_config.flea_loginpic'));
  131. View::assign('loginpic', $loginpic);
  132. /**
  133. * 广告图
  134. */
  135. $result = false;
  136. $condition = array();
  137. $condition_1 = array();
  138. $condition_2 = array();
  139. $condition_3 = array();
  140. $condition_4 = array();
  141. $condition_5 = array();
  142. $condition_1[] = ['ap_id', '=', 16];
  143. $condition_2[] = ['ap_id', '=', 17];
  144. $condition_3[] = ['ap_id', '=', 18];
  145. $condition_4[] = ['ap_id', '=', 19];
  146. $condition_5[] = ['ap_id', '=', 20];
  147. $condition[] = ['adv_enabled', '=', 1];
  148. $condition[] = ['adv_startdate', '<', strtotime(date('Y-m-d H:00:00'))];
  149. $condition[] = ['adv_enddate', '>', strtotime(date('Y-m-d H:00:00'))];
  150. $adv_list = model('adv')->getAdvList(array_merge($condition, $condition_1), '', 10, 'adv_sort asc,adv_id asc');
  151. if (!empty($adv_list)) {
  152. $result = $adv_list;
  153. }
  154. $adv_four = array();
  155. $adv_list = model('adv')->getAdvList(array_merge($condition, $condition_2), '', 1, 'adv_sort asc,adv_id asc');
  156. if (!empty($adv_list)) {
  157. $adv_four[] = $adv_list[0];
  158. }
  159. $adv_list = model('adv')->getAdvList(array_merge($condition, $condition_3), '', 1, 'adv_sort asc,adv_id asc');
  160. if (!empty($adv_list)) {
  161. $adv_four[] = $adv_list[0];
  162. }
  163. $adv_list = model('adv')->getAdvList(array_merge($condition, $condition_4), '', 1, 'adv_sort asc,adv_id asc');
  164. if (!empty($adv_list)) {
  165. $adv_four[] = $adv_list[0];
  166. }
  167. $adv_list = model('adv')->getAdvList(array_merge($condition, $condition_5), '', 1, 'adv_sort asc,adv_id asc');
  168. if (!empty($adv_list)) {
  169. $adv_four[] = $adv_list[0];
  170. }
  171. View::assign('adv_slide', $result);
  172. View::assign('adv_four', $adv_four);
  173. /**
  174. * 获取设置信息
  175. */
  176. $fleaclass_model = model('fleaclass');
  177. $fc_index = $fleaclass_model->getFleaclassindex(array());
  178. if (!empty($fc_index) && is_array($fc_index)) {
  179. foreach ($fc_index as $value) {
  180. View::assign($value['fcindex_code'], $value);
  181. }
  182. }
  183. //SEO 设置
  184. $seo = array(
  185. 'html_title' => config('ds_config.flea_site_title'),
  186. 'seo_keywords' => config('ds_config.flea_site_keywords'),
  187. 'seo_description' => config('ds_config.flea_site_description'),
  188. );
  189. $this->_assign_seo($seo);
  190. return View::fetch($this->template_dir . 'flea_index');
  191. }
  192. }