BaseHome.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use app\BaseController;
  5. /*
  6. * 基类
  7. */
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class BaseHome extends BaseController
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. //自动加入配置
  25. $config_list = rkcache('config', true);
  26. config($config_list,'ds_config');
  27. $controller=request()->controller();
  28. $action=request()->action();
  29. if(!config('ds_config.site_state') &&
  30. (!($controller=='Index' && $action=='josn_class') &&
  31. !($controller=='Index' && $action=='flea_area') &&
  32. !($controller=='Index' && $action=='josn_flea_class') &&
  33. !($controller=='Index' && $action=='json_area') &&
  34. !($controller=='Index' && $action=='json_area_show') &&
  35. !($controller=='Index' && $action=='getweekofmonth') &&
  36. !($controller=='Payment' && $action=='allinpay_notify') &&
  37. !($controller=='Payment' && $action=='unionpay_notify') &&
  38. !($controller=='Payment' && $action=='wxpay_minipro_notify') &&
  39. !($controller=='Payment' && $action=='wxpay_jsapi_notify') &&
  40. !($controller=='Payment' && $action=='wxpay_h5_notify') &&
  41. !($controller=='Payment' && $action=='wxpay_app_notify') &&
  42. !($controller=='Payment' && $action=='alipay_notify') &&
  43. !($controller=='Payment' && $action=='alipay_app_notify') &&
  44. !($controller=='Payment' && $action=='alipay_h5_notify'))) {
  45. echo '<div style="height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center">';
  46. echo '<img src="'.ds_get_pic(ATTACH_COMMON,config('ds_config.site_logo')).'"/>';
  47. echo '<div style="font-size:30px;font-weight:bold;padding-top:40px;color:#999;max-width:1200px;text-align:center;">'.(config('ds_config.closed_reason')?config('ds_config.closed_reason'):'站点已关闭').'</div>';
  48. echo '</div>';
  49. exit;
  50. }
  51. $this->checkMessage(); //短消息检查
  52. $this->showArticle();
  53. $this->showCartCount();
  54. //顶部广告
  55. $prefix = 'home-adv';
  56. $result = rcache(21, $prefix);
  57. if (empty($result)) {
  58. $condition=array();
  59. $condition[]=['ap_id','=',21];
  60. $condition[]=['adv_enabled','=',1];
  61. $condition[]=['adv_startdate','<',strtotime(date('Y-m-d H:00:00'))];
  62. $condition[]=['adv_enddate','>',strtotime(date('Y-m-d H:00:00'))];
  63. $adv_list=model('adv')->getAdvList($condition,'',1,'adv_sort asc,adv_id asc');
  64. if(!empty($adv_list)){
  65. $result=$adv_list[0];
  66. }
  67. wcache(21, $result, $prefix, 3600);
  68. }
  69. View::assign('adv_top', $result);
  70. View::assign('hot_search', @explode(',', config('ds_config.hot_search'))); //热门搜索
  71. // 自定义导航
  72. View::assign('navs', $this->_get_navs());
  73. //获取所有分类
  74. View::assign('header_categories', $this->_get_header_categories());
  75. }
  76. //SEO 赋值
  77. function _assign_seo($seo)
  78. {
  79. View::assign('html_title', $seo['html_title']);
  80. View::assign('seo_keywords', $seo['seo_keywords']);
  81. View::assign('seo_description', $seo['seo_description']);
  82. }
  83. /**
  84. * 检查短消息数量
  85. *
  86. */
  87. protected function checkMessage()
  88. {
  89. if (session('member_id') == '')
  90. return;
  91. //判断cookie是否存在
  92. $cookie_name = 'msgnewnum' . session('member_id');
  93. if (cookie($cookie_name) != null) {
  94. $countnum = intval(cookie($cookie_name));
  95. }
  96. else {
  97. $message_model = model('message');
  98. $countnum = $message_model->getNewMessageCount(session('member_id'));
  99. cookie($cookie_name, $countnum, 2 * 3600); //保存2小时
  100. }
  101. View::assign('message_num', $countnum);
  102. }
  103. public function _get_navs()
  104. {
  105. $data = array(
  106. 'header' => array(), 'middle' => array(), 'footer' => array(),
  107. );
  108. $rows = rkcache('nav', true);
  109. foreach ($rows as $row) {
  110. $data[$row['nav_location']][] = $row;
  111. }
  112. return $data;
  113. }
  114. public function _get_header_categories()
  115. {
  116. $goodsclass_model = model('goodsclass');
  117. $goods_class = $goodsclass_model->get_all_category();
  118. return $goods_class;
  119. }
  120. /**
  121. * 显示购物车数量
  122. */
  123. protected function showCartCount()
  124. {
  125. if (cookie('cart_goods_num') != null) {
  126. $cart_num = intval(cookie('cart_goods_num'));
  127. }
  128. else {
  129. //已登录状态,存入数据库,未登录时,优先存入缓存,否则存入COOKIE
  130. if (session('member_id')) {
  131. $save_type = 'db';
  132. }
  133. else {
  134. $save_type = 'cookie';
  135. }
  136. $cart_num = model('cart')->getCartNum($save_type, array('buyer_id' => session('member_id'))); //查询购物车商品种类
  137. }
  138. View::assign('cart_goods_num', $cart_num);
  139. }
  140. /**
  141. * 输出会员等级
  142. * @param bool $is_return 是否返回会员信息,返回为true,输出会员信息为false
  143. */
  144. protected function getMemberAndGradeInfo($is_return = false)
  145. {
  146. $member_info = array();
  147. //会员详情及会员级别处理
  148. if (session('member_id')) {
  149. $member_model = model('member');
  150. $member_info = $member_model->getMemberInfoByID(session('member_id'));
  151. if ($member_info) {
  152. $member_gradeinfo = $member_model->getOneMemberGrade(intval($member_info['member_exppoints']));
  153. $member_info = array_merge($member_info, $member_gradeinfo);
  154. }
  155. }
  156. if ($is_return == true) {//返回会员信息
  157. return $member_info;
  158. }
  159. else {//输出会员信息
  160. View::assign('member_info', $member_info);
  161. }
  162. }
  163. /**
  164. * 验证会员是否登录
  165. *
  166. */
  167. protected function checkLogin()
  168. {
  169. if (session('is_login') !== '1') {
  170. if (trim(request()->action()) == 'favoritesgoods' || trim(request()->action()) == 'favoritesstore') {
  171. echo json_encode(array('done' => false, 'msg' => lang('no_login')));
  172. die;
  173. }
  174. $ref_url = request_uri();
  175. session('ref_url',$ref_url);
  176. if (input('get.inajax')) {
  177. ds_show_dialog('', '', 'js', "login_dialog();", 200);
  178. }
  179. else {
  180. @header("location: " . HOME_SITE_URL . "/Login/logon.html");
  181. }
  182. exit;
  183. }
  184. }
  185. /**
  186. * 添加到任务队列
  187. *
  188. * @param array $goods_array
  189. * @param boolean $ifdel 是否删除以原记录
  190. */
  191. protected function addcron($data = array(), $ifdel = false)
  192. {
  193. $cron_model = model('cron');
  194. if (isset($data[0])) { // 批量插入
  195. $where = array();
  196. foreach ($data as $k => $v) {
  197. // 删除原纪录条件
  198. if ($ifdel) {
  199. $where[] = '(cron_type = "' . $data['cron_type'] . '" and cron_value = "' . $data['cron_value'] . '")';
  200. }
  201. }
  202. // 删除原纪录
  203. if ($ifdel) {
  204. $cron_model->delCron(implode(',', $where));
  205. }
  206. $cron_model->addCronAll($data);
  207. }
  208. else { // 单条插入
  209. // 删除原纪录
  210. if ($ifdel) {
  211. $cron_model->delCron(array('cron_type' => $data['cron_type'], 'cron_value' => $data['cron_value']));
  212. }
  213. $cron_model->addCron($data);
  214. }
  215. }
  216. //文章输出
  217. public function showArticle()
  218. {
  219. $article = rcache("index_article");
  220. if (!empty($article)) {
  221. View::assign('show_article', $article['show_article']);
  222. View::assign('article_list', $article['article_list']);
  223. }
  224. else {
  225. $articleclass_model = model('articleclass');
  226. $article_model = model('article');
  227. $show_article = array(); //商城公告
  228. $article_list = array(); //下方文章
  229. $notice_class = array('notice');
  230. $code_array = array('member', 'store', 'payment', 'sold', 'service', 'about');
  231. $notice_limit = 5;
  232. $faq_limit = 5;
  233. $class_condition = array();
  234. $class_condition[]=array('ac_id','<=',7);
  235. $class_order = 'ac_sort asc';
  236. $article_class = $articleclass_model->getArticleclassList($class_condition,$class_order);
  237. $class_list = array();
  238. if (!empty($article_class) && is_array($article_class)) {
  239. foreach ($article_class as $key => $val) {
  240. $ac_code = $val['ac_code'];
  241. $ac_id = $val['ac_id'];
  242. $val['list'] = array(); //文章
  243. $class_list[$ac_id] = $val;
  244. }
  245. }
  246. //首页系统文章
  247. $article_where = "article.article_show = '1' and (article_class.ac_id <= 7 or (article_class.ac_parent_id > 0 and article_class.ac_parent_id <= 7))";
  248. $article_field = 'article.article_id,article.ac_id,article.article_url,article.article_title,article.article_time,article_class.ac_name,article_class.ac_parent_id';
  249. $article_order = 'article_sort asc,article_time desc';
  250. $article_array = $article_model->getJoinArticleList($article_where,300,$article_field,$article_order);
  251. if (!empty($article_array) && is_array($article_array)) {
  252. foreach ($article_array as $key => $val) {
  253. $ac_id = $val['ac_id'];
  254. $ac_parent_id = $val['ac_parent_id'];
  255. if ($ac_parent_id == 0) {//顶级分类
  256. $class_list[$ac_id]['list'][] = $val;
  257. }
  258. else {
  259. $class_list[$ac_parent_id]['list'][] = $val;
  260. }
  261. }
  262. }
  263. if (!empty($class_list) && is_array($class_list)) {
  264. foreach ($class_list as $key => $val) {
  265. $ac_code = @$val['ac_code'];
  266. if (in_array($ac_code, $notice_class)) {
  267. $list = $val['list'];
  268. array_splice($list, $notice_limit);
  269. $val['list'] = $list;
  270. $show_article[$ac_code] = $val;
  271. }
  272. if (in_array($ac_code, $code_array)) {
  273. $list = $val['list'];
  274. $val['class']['ac_name'] = $val['ac_name'];
  275. array_splice($list, $faq_limit);
  276. $val['list'] = $list;
  277. $article_list[] = $val;
  278. }
  279. }
  280. }
  281. wcache('index_article', array('show_article' => $show_article, 'article_list' => $article_list,));
  282. View::assign('show_article', $show_article);
  283. View::assign('article_list', $article_list);
  284. }
  285. }
  286. /**
  287. * 自动登录
  288. */
  289. protected function auto_login()
  290. {
  291. $data = cookie('auto_login');
  292. if (empty($data)) {
  293. return false;
  294. }
  295. $member_model = model('member');
  296. if (session('is_login')) {
  297. $member_model->auto_login();
  298. }
  299. $member_id = intval(ds_decrypt($data, MD5_KEY));
  300. if ($member_id <= 0) {
  301. return false;
  302. }
  303. $member_info = $member_model->getMemberInfoByID($member_id);
  304. if (!$member_info['member_state']) {
  305. return false;
  306. }
  307. $member_model->createSession($member_info);
  308. }
  309. }
  310. ?>