BaseHome.php 13 KB

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