Fleaclass.php 11 KB

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