Index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Index extends BaseMall
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/index.lang.php');
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellergroupbuy.lang.php');
  20. }
  21. public function index()
  22. {
  23. View::assign('index_sign', 'index');
  24. $editable_page_model = model('editable_page');
  25. $editable_page_info = $editable_page_model->getOneEditablePage(array('editable_page_path' => 'index/index', 'editable_page_client' => 'pc'));
  26. if ($editable_page_info) {
  27. $editable_page_info['editable_page_theme_config'] = json_decode($editable_page_info['editable_page_theme_config'], true);
  28. View::assign('editable_page', $editable_page_info);
  29. $editable_page_config_model = model('editable_page_config');
  30. $editable_page_config_list = $editable_page_config_model->getEditablePageConfigList(array(array('editable_page_id', '=', $editable_page_info['editable_page_id'])));
  31. $config_list = array();
  32. foreach ($editable_page_config_list as $key => $val) {
  33. $config_info = json_decode($val['editable_page_config_content'], true);
  34. $model_id = $val['editable_page_model_id'];
  35. $var_html = array();
  36. if (!empty($config_info)) {
  37. require_once PLUGINS_PATH . '/editable_page_model/' . $model_id . '/config.php';
  38. $model_name = 'Model' . $model_id;
  39. $model = new $model_name();
  40. $res = $model->filterData($config_info);
  41. if ($res['code']) {
  42. $res = $model->formatData(json_encode($res['data']));
  43. if ($res['code']) {
  44. $var_html['config_info'] = $res['data'];
  45. }
  46. }
  47. }
  48. $html = View::fetch('../../../plugins/editable_page_model/' . $model_id . '/index', $var_html);
  49. $config_list[] = array(
  50. 'val' => $val,
  51. 'html' => $html,
  52. );
  53. }
  54. View::assign('config_list', $config_list);
  55. View::assign('editable_page', $editable_page_info);
  56. } else {
  57. $this->getIndexData();
  58. //楼层广告
  59. $result = false;
  60. $condition = array();
  61. $condition[] = ['ap_id', '=', 1];
  62. $condition[] = ['adv_enabled', '=', 1];
  63. $condition[] = ['adv_startdate', '<', strtotime(date('Y-m-d H:00:00'))];
  64. $condition[] = ['adv_enddate', '>', strtotime(date('Y-m-d H:00:00'))];
  65. $adv_list = model('adv')->getAdvList($condition, '', 10, 'adv_sort asc,adv_id asc');
  66. if (!empty($adv_list)) {
  67. $result = $adv_list;
  68. }
  69. View::assign('adv_index_1', $result);
  70. $result = false;
  71. $condition = array();
  72. $condition[] = ['ap_id', '=', 2];
  73. $condition[] = ['adv_enabled', '=', 1];
  74. $condition[] = ['adv_startdate', '<', strtotime(date('Y-m-d H:00:00'))];
  75. $condition[] = ['adv_enddate', '>', strtotime(date('Y-m-d H:00:00'))];
  76. $adv_list = model('adv')->getAdvList($condition, '', 10, 'adv_sort asc,adv_id asc');
  77. if (!empty($adv_list)) {
  78. $result = $adv_list;
  79. }
  80. View::assign('adv_index_2', $result);
  81. //楼层数据
  82. $floor_block = array();
  83. $goodsclass_list = Db::name('goodsclass')->where('gc_parent_id', 0)->where('gc_show', 1)->order('gc_sort asc')->select()->toArray();
  84. foreach ($goodsclass_list as $key => $goodsclass) {
  85. $floor_list = $this->getFloorList($goodsclass['gc_id']);
  86. $floor_block[$key] = $floor_list;
  87. $floor_block[$key]['gc_name'] = $goodsclass['gc_name'];
  88. if (!$floor_block[$key]['goods_list'][0]['gc_list']) {
  89. unset($floor_block[$key]);
  90. continue;
  91. }
  92. $floor_block[$key]['adv_left'] = false;
  93. $floor_block[$key]['adv_bottom'] = false;
  94. if ($key < 5) {
  95. $result = false;
  96. $condition = array();
  97. $condition_1 = array();
  98. $condition_2 = array();
  99. $condition[] = ['adv_enabled', '=', 1];
  100. $condition[] = ['adv_startdate', '<', strtotime(date('Y-m-d H:00:00'))];
  101. $condition[] = ['adv_enddate', '>', strtotime(date('Y-m-d H:00:00'))];
  102. switch ($key) {
  103. case 0:
  104. $condition_1[] = ['ap_id', '=', 8];
  105. $condition_2[] = ['ap_id', '=', 3];
  106. break;
  107. case 1:
  108. $condition_1[] = ['ap_id', '=', 9];
  109. $condition_2[] = ['ap_id', '=', 4];
  110. break;
  111. case 2:
  112. $condition_1[] = ['ap_id', '=', 10];
  113. $condition_2[] = ['ap_id', '=', 5];
  114. break;
  115. case 3:
  116. $condition_1[] = ['ap_id', '=', 11];
  117. $condition_2[] = ['ap_id', '=', 6];
  118. break;
  119. case 4:
  120. $condition_1[] = ['ap_id', '=', 12];
  121. $condition_2[] = ['ap_id', '=', 7];
  122. break;
  123. }
  124. $adv_list = model('adv')->getAdvList(array_merge($condition, $condition_1), '', 1, 'adv_sort asc,adv_id asc');
  125. if (!empty($adv_list)) {
  126. $result = $adv_list[0];
  127. $floor_block[$key]['adv_left'] = $result;
  128. }
  129. $adv_list = model('adv')->getAdvList(array_merge($condition, $condition_2), '', 1, 'adv_sort asc,adv_id asc');
  130. if (!empty($adv_list)) {
  131. $result = $adv_list[0];
  132. $floor_block[$key]['adv_bottom'] = $result;
  133. }
  134. }
  135. }
  136. //楼层数据
  137. View::assign('floor_block', $floor_block);
  138. //显示订单信息
  139. if (session('is_login')) {
  140. //交易提醒 - 显示数量
  141. $order_model = model('order');
  142. $member_order_info['order_nopay_count'] = $order_model->getOrderCountByID('buyer', session('member_id'), 'NewCount');
  143. $member_order_info['order_noreceipt_count'] = $order_model->getOrderCountByID('buyer', session('member_id'), 'SendCount');
  144. $member_order_info['order_noeval_count'] = $order_model->getOrderCountByID('buyer', session('member_id'), 'EvalCount');
  145. View::assign('member_order_info', $member_order_info);
  146. }
  147. }
  148. //SEO 设置
  149. $seo = model('seo')->type('index')->show();
  150. $this->_assign_seo($seo);
  151. return View::fetch($this->template_dir . 'index');
  152. }
  153. private function getIndexData()
  154. {
  155. $index_data = rcache("index_data");
  156. if (empty($index_data)) {
  157. $goods_model = model('goods');
  158. $index_data = array();
  159. $index_data['recommend_list'] = $goods_model->getGoodsUnionList(array(array('goodscommon.mall_goods_commend', '=', 1)), 'goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goodscommon.store_id,goods.goods_promotion_price,goodscommon.goods_price', 'goodscommon.mall_goods_sort asc', 'goodscommon.goods_commonid', 0, 5);
  160. foreach ($index_data['recommend_list'] as $key => $val) {
  161. if (!$val['goods_storage']) {
  162. $goods_info = $goods_model->getGoodsStorageByCommonId($val['goods_commonid']);
  163. if ($goods_info) {
  164. $index_data['recommend_list'][$key]['goods_id'] = $goods_info['goods_id'];
  165. $index_data['recommend_list'][$key]['goods_storage'] = $goods_info['goods_storage'];
  166. $index_data['recommend_list'][$key]['goods_promotion_price'] = $goods_info['goods_promotion_price'];
  167. }
  168. }
  169. }
  170. //秒杀
  171. $index_data['promotion_list'] = model('pxianshigoods')->getXianshigoodsCommendList(5);
  172. $index_data['new_list'] = $goods_model->getGoodsUnionList(array(), 'goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goodscommon.store_id,goods.goods_promotion_price,goodscommon.goods_price', 'goodscommon.goods_addtime desc', 'goodscommon.goods_commonid', 0, 5);
  173. foreach ($index_data['new_list'] as $key => $val) {
  174. if (!$val['goods_storage']) {
  175. $goods_info = $goods_model->getGoodsStorageByCommonId($val['goods_commonid']);
  176. if ($goods_info) {
  177. $index_data['new_list'][$key]['goods_id'] = $goods_info['goods_id'];
  178. $index_data['new_list'][$key]['goods_storage'] = $goods_info['goods_storage'];
  179. $index_data['new_list'][$key]['goods_promotion_price'] = $goods_info['goods_promotion_price'];
  180. }
  181. }
  182. }
  183. $index_data['groupbuy_list'] = model('groupbuy')->getGroupbuyCommendedList(5);
  184. //友情链接
  185. $index_data['link_list'] = model('link')->getLinkList();
  186. //获取第一文章分类的前三篇文章
  187. $index_data['index_articles'] = Db::name('article')->where('ac.ac_code', 'notice')->where('a.article_show', 1)->alias('a')->field('a.article_id,a.article_url,a.article_title')->order('a.article_sort asc,a.article_time desc')->limit(3)->join('articleclass ac', 'a.ac_id=ac.ac_id')->select()->toArray();
  188. wcache('index_data', $index_data);
  189. }
  190. View::assign('recommend_list', $index_data['recommend_list']);
  191. View::assign('promotion_list', $index_data['promotion_list']);
  192. View::assign('new_list', $index_data['new_list']);
  193. View::assign('groupbuy_list', $index_data['groupbuy_list']);
  194. View::assign('link_list', $index_data['link_list']);
  195. View::assign('index_articles', $index_data['index_articles']);
  196. }
  197. private function getFloorList($cate_id)
  198. {
  199. $prefix = 'home-index-floor-';
  200. $result = rcache($cate_id, $prefix);
  201. if (empty($result)) {
  202. $goods_model = model('goods');
  203. //获取此楼层下的所有分类
  204. $goods_class_list = Db::name('goodsclass')->where('gc_parent_id=' . $cate_id)->select()->toArray();
  205. //获取每个分类下的商品
  206. $goods_list = array();
  207. $goods_list[0]['gc_name'] = lang('hot_recommended');
  208. $goods_list[0]['gc_id'] = $cate_id;
  209. $condition = $goods_model->_getRecursiveClass(array(array('goodscommon.mall_goods_commend', '=', 1)), $cate_id, 'goodscommon');
  210. $goods_list[0]['gc_list'] = $goods_model->getGoodsUnionList($condition, 'goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_marketprice,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goodscommon.store_id,goods.goods_promotion_price,goodscommon.goods_price', 'goodscommon.mall_goods_commend desc,goodscommon.mall_goods_sort asc', 'goodscommon.goods_commonid', 0, 10);
  211. foreach ($goods_list[0]['gc_list'] as $key => $val) {
  212. if (!$val['goods_storage']) {
  213. $goods_info = $goods_model->getGoodsStorageByCommonId($val['goods_commonid']);
  214. if ($goods_info) {
  215. $goods_list[0]['gc_list'][$key]['goods_id'] = $goods_info['goods_id'];
  216. $goods_list[0]['gc_list'][$key]['goods_promotion_price'] = $goods_info['goods_promotion_price'];
  217. }
  218. }
  219. }
  220. $hot_goods_class_list = Db::name('goodsclass')->where('gc_parent_id=' . $cate_id)->order('gc_sort asc')->limit(5)->select()->toArray();
  221. foreach ($hot_goods_class_list as $key => $hot_goods_class) {
  222. $data = array();
  223. $data['gc_name'] = $hot_goods_class['gc_name'];
  224. $data['gc_id'] = $hot_goods_class['gc_id'];
  225. $condition = $goods_model->_getRecursiveClass(array(array('goodscommon.mall_goods_commend', '=', 1)), $data['gc_id'], 'goodscommon');
  226. $data['gc_list'] = $goods_model->getGoodsUnionList($condition, 'goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_marketprice,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goodscommon.store_id,goods.goods_promotion_price,goodscommon.goods_price', 'goodscommon.mall_goods_commend desc,goodscommon.mall_goods_sort asc', 'goodscommon.goods_commonid', 0, 10);
  227. foreach ($data['gc_list'] as $k => $v) {
  228. if (!$v['goods_storage']) {
  229. $goods_info = $goods_model->getGoodsStorageByCommonId($v['goods_commonid']);
  230. if ($goods_info) {
  231. $data['gc_list'][$k]['goods_id'] = $goods_info['goods_id'];
  232. $data['gc_list'][$k]['goods_promotion_price'] = $goods_info['goods_promotion_price'];
  233. }
  234. }
  235. }
  236. $goods_list[] = $data;
  237. }
  238. $result['goods_list'] = $goods_list;
  239. $result['goods_class_list'] = $goods_class_list;
  240. wcache($cate_id, $result, $prefix, 3600);
  241. }
  242. return $result;
  243. }
  244. //json输出商品分类
  245. public function josn_class()
  246. {
  247. /**
  248. * 实例化商品分类模型
  249. */
  250. $goodsclass_model = model('goodsclass');
  251. $goods_class = $goodsclass_model->getGoodsclassListByParentId(intval(input('get.gc_id')));
  252. $array = array();
  253. if (is_array($goods_class) and count($goods_class) > 0) {
  254. foreach ($goods_class as $val) {
  255. $array[$val['gc_id']] = array(
  256. 'gc_id' => $val['gc_id'], 'gc_name' => htmlspecialchars($val['gc_name']),
  257. 'gc_parent_id' => $val['gc_parent_id'], 'commis_rate' => $val['commis_rate'],
  258. 'gc_sort' => $val['gc_sort']
  259. );
  260. }
  261. }
  262. echo input('param.callback') . '(' . json_encode($array) . ')';
  263. }
  264. //闲置物品地区json输出
  265. public function flea_area()
  266. {
  267. if (isset($_GET['check']) && intval($_GET['check']) > 0) {
  268. $_GET['area_id'] = $_GET['region_id'];
  269. }
  270. if (intval($_GET['area_id']) == 0) {
  271. return;
  272. }
  273. $fleaarea_model = model('fleaarea');
  274. $area_array = $fleaarea_model->getFleaareaList(array('fleaarea_parent_id' => intval($_GET['area_id'])));
  275. $array = array();
  276. if (is_array($area_array) and count($area_array) > 0) {
  277. foreach ($area_array as $val) {
  278. $array[$val['fleaarea_id']] = array(
  279. 'fleaarea_id' => $val['fleaarea_id'],
  280. 'fleaarea_name' => htmlspecialchars($val['fleaarea_name']),
  281. 'fleaarea_parent_id' => $val['fleaarea_parent_id'], 'fleaarea_sort' => $val['fleaarea_sort']
  282. );
  283. }
  284. }
  285. if (isset($_GET['check']) && intval($_GET['check']) > 0) { //判断当前地区是否为最后一级
  286. if (!empty($array) && is_array($array)) {
  287. echo 'false';
  288. } else {
  289. echo 'true';
  290. }
  291. } else {
  292. echo json_encode($array);
  293. }
  294. }
  295. //json输出闲置物品分类
  296. public function josn_flea_class()
  297. {
  298. /**
  299. * 实例化商品分类模型
  300. */
  301. $fleaclass_model = model('fleaclass');
  302. $goods_class = $fleaclass_model->getFleaclassList(array('fleaclass_parent_id' => intval(input('get.gc_id'))));
  303. $array = array();
  304. if (is_array($goods_class) and count($goods_class) > 0) {
  305. foreach ($goods_class as $val) {
  306. $array[$val['fleaclass_id']] = array(
  307. 'fleaclass_id' => $val['fleaclass_id'], 'fleaclass_name' => htmlspecialchars($val['fleaclass_name']),
  308. 'fleaclass_parent_id' => $val['fleaclass_parent_id'], 'fleaclass_sort' => $val['fleaclass_sort']
  309. );
  310. }
  311. }
  312. /**
  313. * 转码
  314. */
  315. echo json_encode($array);
  316. }
  317. /**
  318. * json输出地址数组 public/static/plugins/area_datas.js
  319. */
  320. public function json_area()
  321. {
  322. echo input('param.callback') . '(' . json_encode(model('area')->getAreaArrayForJson()) . ')';
  323. }
  324. /**
  325. * json输出地址数组
  326. */
  327. public function json_area_show()
  328. {
  329. $area_info['text'] = model('area')->getTopAreaName(intval(input('get.area_id')));
  330. echo input('param.callback') . '(' . json_encode($area_info) . ')';
  331. }
  332. //判断是否登录
  333. public function login()
  334. {
  335. echo (session('is_login') == '1') ? '1' : '0';
  336. }
  337. /**
  338. * 查询每月的周数组
  339. */
  340. public function getweekofmonth()
  341. {
  342. include_once root_path() . 'extend/mall/datehelper.php';
  343. $year = input('get.y');
  344. $month = input('get.m');
  345. $week_arr = getMonthWeekArr($year, $month);
  346. echo json_encode($week_arr);
  347. die;
  348. }
  349. /**
  350. * 头部最近浏览的商品
  351. */
  352. public function viewed_info()
  353. {
  354. $info = array();
  355. if (session('is_login') == '1') {
  356. $member_id = session('member_id');
  357. $info['m_id'] = $member_id;
  358. if (config('ds_config.voucher_allow') == 1) {
  359. $time_to = TIMESTAMP; //当前日期
  360. $info['voucher'] = Db::name('voucher')->where(
  361. array(
  362. array('voucher_owner_id', '=', $member_id), array('voucher_state', '=', 1),
  363. array('voucher_startdate', '<=', $time_to),
  364. array('voucher_enddate', '>=', $time_to)
  365. )
  366. )->count();
  367. }
  368. $time_to = strtotime(date('Y-m-d')); //当前日期
  369. $time_from = date('Y-m-d', ($time_to - 60 * 60 * 24 * 7)); //7天前
  370. $consult_mod = model('consult');
  371. $condition = array();
  372. $condition[] = array('member_id', '=', $member_id);
  373. $condition[] = array('consult_replytime', 'between', array(strtotime($time_from), $time_to + 60 * 60 * 24));
  374. $info['consult'] = $consult_mod->getConsultCount($condition);
  375. }
  376. $goods_list = model('goodsbrowse')->getViewedGoodsList(session('member_id'), 5);
  377. if (is_array($goods_list) && !empty($goods_list)) {
  378. $viewed_goods = array();
  379. foreach ($goods_list as $key => $val) {
  380. $goods_id = $val['goods_id'];
  381. $val['url'] = (string)url('Goods/index', ['goods_id' => $goods_id]);
  382. $val['goods_image'] = goods_thumb($val, 60);
  383. $viewed_goods[$goods_id] = $val;
  384. }
  385. $info['viewed_goods'] = $viewed_goods;
  386. }
  387. echo json_encode($info);
  388. }
  389. }