Fleaclass.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 Fleaclass 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.php');
  22. }
  23. /**
  24. * 闲置物品搜索列表
  25. */
  26. public function index()
  27. {
  28. //加载模型
  29. $flea_model = model('flea');
  30. $member_model = model('member');
  31. $fleaclass_model = model('fleaclass');
  32. $fleaarea_model = model('fleaarea');
  33. /**
  34. * 地区切换
  35. */
  36. $area_array = $fleaarea_model->fleaarea_show();
  37. View::assign('area_one_level', $area_array['area_one_level']);
  38. View::assign('area_two_level', $area_array['area_two_level']);
  39. /**
  40. * 查询模块
  41. */
  42. $special_condition = array();
  43. $condition_out = array();
  44. $area_id = intval(input('area_input'));
  45. /* 如果有地区id传入 */
  46. if ($area_id > 0) {
  47. /* 查询父级id为传入id的所有结果 */
  48. $area_result = $fleaarea_model->getFleaareaList(array('fleaarea_parent_id' => $area_id));
  49. /* 增加当前选择地区的检索热度 */
  50. $param['fleaarea_hot']['value'] = 1;
  51. $param['fleaarea_hot']['sign'] = 'increase';
  52. $fleaarea_model->editFleaarea(array('fleaarea_id' => $area_id), $param);
  53. /* 组合查询地区id */
  54. $special_condition['areaid'] = "'" . $area_id . "'";
  55. /* 页面输出可选择地区列表 */
  56. /* 传入的地区 */
  57. $area_current = $fleaarea_model->getOneFleaarea(array('fleaarea_id' => $area_id));
  58. if ($area_result) {
  59. /* 不是最后一级地区 */
  60. foreach ($area_result as $val) {
  61. $special_condition['areaid'] .= ',\'' . $val['fleaarea_id'] . '\'';
  62. }
  63. View::assign('out_area', $area_result);
  64. View::assign('area_main', $area_current);
  65. } else {
  66. $out_area = $fleaarea_model->getFleaareaList(array('fleaarea_parent_id' => $area_current['fleaarea_parent_id']));
  67. $area_main = $fleaarea_model->getOneFleaarea(array('fleaarea_id' => $area_current['fleaarea_parent_id']));
  68. View::assign('out_area', $out_area);
  69. View::assign('area_main', $area_main);
  70. }
  71. $condition_out['area_input'] = $area_id;
  72. } else {
  73. $list_area = array();
  74. $list_area[] = array('fleaarea_deep', '=', 2);
  75. $list_area[] = array('fleaarea_hot', '>', 0);
  76. $result = $fleaarea_model->getFleaareaList($list_area, 'fleaarea_name,fleaarea_id', 'fleaarea_hot desc', 8);
  77. View::assign('out_area', $result);
  78. }
  79. $cate_input = intval(input('cate_input'));
  80. if ($cate_input > 0) {
  81. $fc_result = $fleaclass_model->getNextLevelGoodsclassById($cate_input);
  82. View::assign('out_class', $fc_result);
  83. /* 组合查询分类id */
  84. $condition_out['cate_input'] = $cate_input;
  85. /* 组合查询分类id */
  86. $fleaclass_result = $fleaclass_model->getChildClass($cate_input);
  87. $part = '';
  88. foreach ($fleaclass_result as $v) {
  89. $part .= $v['fleaclass_id'] . ',';
  90. }
  91. $special_condition['fleaclass_id_in'] = rtrim($part, ',');
  92. } else {
  93. $class_list = array();
  94. $class_list['fleaclass_parent_id'] = '0';
  95. $fc_result = $fleaclass_model->getFleaclassList($class_list, 'fleaclass_name,fleaclass_id');
  96. View::assign('out_class', $fc_result);
  97. }
  98. $condition_out['start_input'] = $special_condition['start_input'] = intval(input('start_input'));
  99. $condition_out['end_input'] = $special_condition['end_input'] = intval(input('end_input'));
  100. $condition_out['price_input'] = $special_condition['price_input'] = intval(input('price_input'));
  101. if ($condition_out['price_input'] > 0) {
  102. switch ($condition_out['price_input']) {
  103. case "35":
  104. $special_condition['start_input'] = '20';
  105. $special_condition['end_input'] = '50';
  106. break;
  107. case "75":
  108. $special_condition['start_input'] = '50';
  109. $special_condition['end_input'] = '100';
  110. break;
  111. case "150":
  112. $special_condition['start_input'] = '100';
  113. $special_condition['end_input'] = '200';
  114. break;
  115. case "350":
  116. $special_condition['start_input'] = '200';
  117. $special_condition['end_input'] = '500';
  118. break;
  119. case "750":
  120. $special_condition['start_input'] = '500';
  121. $special_condition['end_input'] = '1000';
  122. break;
  123. case "1000":
  124. $special_condition['start_input'] = '1000';
  125. $special_condition['end_input'] = '';
  126. break;
  127. }
  128. }
  129. $condition_out['quality_input'] = $special_condition['quality_input'] = intval(input('quality_input'));
  130. $condition_out['key_input'] = $special_condition['key_input'] = input('key_input');
  131. $condition_out['seller_input'] = $special_condition['seller_input'] = intval(input('seller_input'));
  132. $condition_out['rank_input'] = $special_condition['rank_input'] = intval(input('rank_input'));
  133. if ($special_condition['rank_input'] == 1) {
  134. $order = 'goods_store_price desc';
  135. }
  136. if ($special_condition['rank_input'] == 2) {
  137. $order = 'goods_store_price asc';
  138. }
  139. $condition_out['pic_input'] = $special_condition['pic_input'] = input('pic_input');
  140. if (!$special_condition['pic_input']) {
  141. $special_condition['pic_input'] = 2;
  142. }
  143. /* 输出保留的前台查询条件 */
  144. View::assign('condition_out', $condition_out);
  145. /**
  146. * 闲置物品显示模块
  147. */
  148. $listgoods = $flea_model->getFleaList($special_condition, 10, '*', 'goods_id desc');
  149. if ($listgoods) {
  150. foreach ($listgoods as $replace_key => $replace_val) {
  151. $listgoods[$replace_key]['member_info'] = $flea_model->getFleaStatistic($replace_val['member_id']);
  152. if ($listgoods[$replace_key]['member_info']['member_avatar']) {
  153. $listgoods[$replace_key]['member_info']['avatar'] = ATTACH_AVATAR . '/' . $listgoods[$replace_key]['member_info']['member_avatar'];
  154. } else {
  155. $listgoods[$replace_key]['member_info']['avatar'] = HOME_SITE_ROOT . '/shop/common/default_user_portrait.gif';
  156. }
  157. if ($replace_val['goods_image']) {
  158. $listgoods[$replace_key]['image_url'] = ds_get_pic(ATTACH_MFLEA . '/' . session('member_id'), $replace_val['goods_image']);
  159. } else {
  160. $listgoods[$replace_key]['image_url'] = HOME_SITE_ROOT . '/images/member/default_image.png';
  161. }
  162. $listgoods[$replace_key]['explain'] = preg_replace("/\<[^\>\<]*\>/", '', htmlspecialchars_decode($replace_val['goods_body']));
  163. $listgoods[$replace_key]['explain'] = str_replace("&nbsp;", ' ', $listgoods[$replace_key]['explain']);
  164. $listgoods[$replace_key]['time'] = $this->time_comb(intval($replace_val['goods_addtime']));
  165. switch ($replace_val['flea_quality']) {
  166. case 10:
  167. $quality = lang('flea_index_new');
  168. break;
  169. case 9:
  170. $quality = lang('flea_index_almost_new');
  171. break;
  172. case 8:
  173. $quality = lang('flea_index_gently_used');
  174. break;
  175. default;
  176. $quality = lang('flea_index_old');
  177. break;
  178. }
  179. $listgoods[$replace_key]['quality'] = $quality;
  180. }
  181. }
  182. View::assign('listgoods', $listgoods);
  183. View::assign('show_page', $flea_model->page_info->render());
  184. /**
  185. * 刚刚发布模块
  186. */
  187. $pre_sale = $flea_model->getSaleFleaList(array());
  188. View::assign('pre_sale', $pre_sale);
  189. /**
  190. * 关注模块
  191. */
  192. $attention = $flea_model->getFleaList(array(), '', '*', 'flea_collect_num desc', 8);
  193. View::assign('attention', $attention);
  194. /**
  195. * 导航模块
  196. */
  197. $navigation = array(
  198. (string)url('Fleaclass/index') => lang('flea_index_all')
  199. );
  200. /* 卖家优先 */
  201. if ($special_condition['seller_input']) {
  202. $seller_info = $member_model->infoMember(array('member_id' => $special_condition['seller_input']));
  203. $key = HOME_SITE_URL . '/Fleaclass/index.html?seller_input=' . $special_condition['seller_input'];
  204. $navigation[$key] = $seller_info['member_name'];
  205. } elseif ($cate_input) {
  206. $class_info = $fleaclass_model->getFleaclassNow($cate_input);
  207. foreach ($class_info as $val) {
  208. $key = HOME_SITE_URL . '/Fleaclass/index.html?cate_input=' . $val['fleaclass_id'];
  209. $navigation[$key] = $val['name'];
  210. }
  211. }
  212. /* 分类次之 */
  213. View::assign('navigation', $navigation);
  214. /* 页面显示所有商品总数 */
  215. $all_num = $flea_model->getFleaList($special_condition);
  216. View::assign('all_num', $all_num);
  217. /**
  218. * 页面输出
  219. */
  220. return View::fetch($this->template_dir . 'flea_class');
  221. }
  222. /**
  223. * 查看成色的划分
  224. */
  225. public function quality_inner()
  226. {
  227. return View::fetch($this->template_dir . 'quality_inner');
  228. }
  229. private function time_comb($goods_addtime)
  230. {
  231. $now_time = TIMESTAMP;
  232. $last_time = $now_time - $goods_addtime;
  233. if ($last_time > 2592000)
  234. return intval($last_time / 2592000) . lang('flea_index_mouth');
  235. if ($last_time > 86400)
  236. return intval($last_time / 86400) . lang('flea_index_day');
  237. if ($last_time > 3600)
  238. return intval($last_time / 3600) . lang('flea_index_hour');
  239. if ($last_time > 60)
  240. return intval($last_time / 60) . lang('flea_index_minute');
  241. return $last_time . lang('flea_index_seconds');
  242. }
  243. }