Membergoodsbrowse.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Membergoodsbrowse extends BaseMember {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/membergoodsbrowse.lang.php');
  20. }
  21. /**
  22. * 浏览历史列表
  23. */
  24. public function listinfo() {
  25. $goodsbrowse_model = model('goodsbrowse');
  26. //商品分类缓存
  27. $gc_list = model('goodsclass')->getGoodsclassForCacheModel();
  28. //查询浏览记录
  29. $condition = array();
  30. $condition[] = array('member_id','=',session('member_id'));
  31. $gc_id = intval(input('param.gc_id'));
  32. $gc_depth=isset($gc_list[$gc_id]['depth'])?$gc_list[$gc_id]['depth']:1;
  33. if ($gc_id > 0) {
  34. $condition[] = array('gc_id_'.$gc_depth,'=',$gc_id);
  35. }
  36. $browselist_tmp = $goodsbrowse_model->getViewedGoodsList(session('member_id'), 20);
  37. $browselist = array();
  38. foreach ((array) $browselist_tmp as $k => $v) {
  39. $browselist[$v['goods_id']] = $v;
  40. }
  41. //查询商品信息
  42. $browselist_new = array();
  43. if ($browselist) {
  44. $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');
  45. $goods_list = array();
  46. foreach ((array) $goods_list_tmp as $v) {
  47. $goods_list[$v['goods_id']] = $v;
  48. }
  49. foreach ($browselist as $k => $v) {
  50. if ($goods_list[$k]) {
  51. $tmp = array();
  52. $tmp = $goods_list[$k];
  53. $tmp["goodsbrowse_time"] = $v['goodsbrowse_time'];
  54. if (date('Y-m-d', $v['goodsbrowse_time']) == date('Y-m-d', TIMESTAMP)) {
  55. $tmp['browsetime_day'] = lang('today');
  56. } elseif (date('Y-m-d', $v['goodsbrowse_time']) == date('Y-m-d', (TIMESTAMP - 86400))) {
  57. $tmp['browsetime_day'] = lang('yesterday');
  58. } else {
  59. $tmp['browsetime_day'] = date('Y年m月d日', $v['goodsbrowse_time']);
  60. }
  61. $tmp['browsetime_text'] = $tmp['browsetime_day'] . date('H:i', $v['goodsbrowse_time']);
  62. $browselist_new[] = $tmp;
  63. }
  64. }
  65. }
  66. //查询浏览记录商品分类
  67. $browseclass_list = $goodsbrowse_model->getViewedGoodsList(session('member_id'),20);
  68. $browseclass_arr = array();
  69. foreach ((array) $browseclass_list as $k => $v) {
  70. if ($v['gc_id_1'] > 0) {
  71. @$browseclass_arr[$v['gc_id_1']] = array('gc_name' => $gc_list[$v['gc_id_1']]['gc_name'], 'sonclass' => array());
  72. }
  73. if ($v['gc_id_2'] > 0) {
  74. @$browseclass_arr[$v['gc_id_1']]['sonclass'][$v['gc_id_2']] = array('gc_name' => $gc_list[$v['gc_id_2']]['gc_name'], 'sonclass' => array());
  75. }
  76. }
  77. $this->setMemberCurMenu('member_goodsbrowse');
  78. $this->setMemberCurItem('index');
  79. View::assign('browseclass_arr', $browseclass_arr);
  80. View::assign('browselist', $browselist_new);
  81. //View::assign('show_page', $goodsbrowse_model->page_info->render());
  82. return View::fetch($this->template_dir . 'index');
  83. }
  84. /**
  85. * 删除浏览历史
  86. */
  87. public function del() {
  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. $menu_array = array(
  119. array(
  120. 'name' => 'index', 'text' => lang('my_footprint'), 'url' => (string)url('Membergoodsbrowse/listinfo')
  121. )
  122. );
  123. return $menu_array;
  124. }
  125. }