Index.php 20 KB

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