Index.php 20 KB

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