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