Fleaclass.php 12 KB

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