Membergoodsbrowse.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Membergoodsbrowse extends BaseMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/membergoodsbrowse.lang.php');
  18. }
  19. /**
  20. * 浏览历史列表
  21. */
  22. public function listinfo()
  23. {
  24. $goodsbrowse_model = model('goodsbrowse');
  25. //商品分类缓存
  26. $gc_list = model('goodsclass')->getGoodsclassForCacheModel();
  27. //查询浏览记录
  28. $condition = array();
  29. $condition[] = array('member_id', '=', session('member_id'));
  30. $gc_id = intval(input('param.gc_id'));
  31. $gc_depth = isset($gc_list[$gc_id]['depth']) ? $gc_list[$gc_id]['depth'] : 1;
  32. if ($gc_id > 0) {
  33. $condition[] = array('gc_id_' . $gc_depth, '=', $gc_id);
  34. }
  35. $browselist_tmp = $goodsbrowse_model->getViewedGoodsList(session('member_id'), 20);
  36. $browselist = array();
  37. foreach ((array) $browselist_tmp as $k => $v) {
  38. $browselist[$v['goods_id']] = $v;
  39. }
  40. //查询商品信息
  41. $browselist_new = array();
  42. if ($browselist) {
  43. $goods_list_tmp = model('goods')->getGoodsList(array(array('goods_id', 'in', array_keys($browselist))), 'goods_id, goods_name, goods_promotion_price,goods_promotion_type, goods_marketprice, goods_image, store_id, gc_id, gc_id_1, gc_id_2, gc_id_3');
  44. $goods_list = array();
  45. foreach ((array) $goods_list_tmp as $v) {
  46. $goods_list[$v['goods_id']] = $v;
  47. }
  48. foreach ($browselist as $k => $v) {
  49. if ($goods_list[$k]) {
  50. $tmp = array();
  51. $tmp = $goods_list[$k];
  52. $tmp["goodsbrowse_time"] = $v['goodsbrowse_time'];
  53. if (date('Y-m-d', $v['goodsbrowse_time']) == date('Y-m-d', TIMESTAMP)) {
  54. $tmp['browsetime_day'] = lang('today');
  55. } elseif (date('Y-m-d', $v['goodsbrowse_time']) == date('Y-m-d', (TIMESTAMP - 86400))) {
  56. $tmp['browsetime_day'] = lang('yesterday');
  57. } else {
  58. $tmp['browsetime_day'] = date('Y年m月d日', $v['goodsbrowse_time']);
  59. }
  60. $tmp['browsetime_text'] = $tmp['browsetime_day'] . date('H:i', $v['goodsbrowse_time']);
  61. $browselist_new[] = $tmp;
  62. }
  63. }
  64. }
  65. //查询浏览记录商品分类
  66. $browseclass_list = $goodsbrowse_model->getViewedGoodsList(session('member_id'), 20);
  67. $browseclass_arr = array();
  68. foreach ((array) $browseclass_list as $k => $v) {
  69. if ($v['gc_id_1'] > 0) {
  70. @$browseclass_arr[$v['gc_id_1']] = array('gc_name' => $gc_list[$v['gc_id_1']]['gc_name'], 'sonclass' => array());
  71. }
  72. if ($v['gc_id_2'] > 0) {
  73. @$browseclass_arr[$v['gc_id_1']]['sonclass'][$v['gc_id_2']] = array('gc_name' => $gc_list[$v['gc_id_2']]['gc_name'], 'sonclass' => array());
  74. }
  75. }
  76. $this->setMemberCurMenu('member_goodsbrowse');
  77. $this->setMemberCurItem('index');
  78. View::assign('browseclass_arr', $browseclass_arr);
  79. View::assign('browselist', $browselist_new);
  80. //View::assign('show_page', $goodsbrowse_model->page_info->render());
  81. return View::fetch($this->template_dir . 'index');
  82. }
  83. /**
  84. * 删除浏览历史
  85. */
  86. public function del()
  87. {
  88. $return_arr = array();
  89. $goodsbrowse_model = model('goodsbrowse');
  90. if (trim(input('param.goods_id')) == 'all') {
  91. //清除缓存中浏览记录
  92. dcache(session('member_id'), 'goodsbrowse');
  93. $goodsbrowse_model->delGoodsbrowse(array('member_id' => session('member_id')));
  94. $return_arr = array('done' => true);
  95. } elseif (intval(input('param.goods_id')) >= 0) {
  96. $goods_id = intval(input('param.goods_id'));
  97. if (config('ds_config.cache_open')) {
  98. //清除缓存中的浏览记录
  99. $browse_goodsid = rcache(session('member_id'), 'goodsbrowse');
  100. $goodsid_arr = $browse_goodsid['goodsid'] ? unserialize($browse_goodsid['goodsid']) : array();
  101. if (isset($browse_goodsid[$goods_id])) {
  102. unset($browse_goodsid[$goods_id]);
  103. }
  104. if ($goodsid_arr) {
  105. $goodsid_arr = array_diff($goodsid_arr, array($goods_id));
  106. $browse_goodsid['goodsid'] = serialize($goodsid_arr);
  107. }
  108. wcache(session('member_id'), $browse_goodsid, 'goodsbrowse');
  109. }
  110. $goodsbrowse_model->delGoodsbrowse(array('member_id' => session('member_id'), 'goods_id' => $goods_id));
  111. $return_arr = array('done' => true);
  112. } else {
  113. $return_arr = array('done' => false, 'msg' => lang('param_error'));
  114. }
  115. echo json_encode($return_arr);
  116. }
  117. protected function getMemberItemList()
  118. {
  119. $menu_array = array(
  120. array(
  121. 'name' => 'index', 'text' => lang('my_footprint'), 'url' => (string)url('Membergoodsbrowse/listinfo')
  122. )
  123. );
  124. return $menu_array;
  125. }
  126. }