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