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