Membergoodsbrowse.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Membergoodsbrowse extends BaseMember {
  18. public function initialize() {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/membergoodsbrowse.lang.php');
  21. }
  22. /**
  23. * 浏览历史列表
  24. */
  25. public function listinfo() {
  26. $goodsbrowse_model = model('goodsbrowse');
  27. //商品分类缓存
  28. $gc_list = model('goodsclass')->getGoodsclassForCacheModel();
  29. //查询浏览记录
  30. $condition = array();
  31. $condition[] = array('member_id','=',session('member_id'));
  32. $gc_id = intval(input('param.gc_id'));
  33. $gc_depth=isset($gc_list[$gc_id]['depth'])?$gc_list[$gc_id]['depth']:1;
  34. if ($gc_id > 0) {
  35. $condition[] = array('gc_id_'.$gc_depth,'=',$gc_id);
  36. }
  37. $browselist_tmp = $goodsbrowse_model->getViewedGoodsList(session('member_id'), 20);
  38. $browselist = array();
  39. foreach ((array) $browselist_tmp as $k => $v) {
  40. $browselist[$v['goods_id']] = $v;
  41. }
  42. //查询商品信息
  43. $browselist_new = array();
  44. if ($browselist) {
  45. $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');
  46. $goods_list = array();
  47. foreach ((array) $goods_list_tmp as $v) {
  48. $goods_list[$v['goods_id']] = $v;
  49. }
  50. foreach ($browselist as $k => $v) {
  51. if ($goods_list[$k]) {
  52. $tmp = array();
  53. $tmp = $goods_list[$k];
  54. $tmp["goodsbrowse_time"] = $v['goodsbrowse_time'];
  55. if (date('Y-m-d', $v['goodsbrowse_time']) == date('Y-m-d', TIMESTAMP)) {
  56. $tmp['browsetime_day'] = lang('today');
  57. } elseif (date('Y-m-d', $v['goodsbrowse_time']) == date('Y-m-d', (TIMESTAMP - 86400))) {
  58. $tmp['browsetime_day'] = lang('yesterday');
  59. } else {
  60. $tmp['browsetime_day'] = date('Y年m月d日', $v['goodsbrowse_time']);
  61. }
  62. $tmp['browsetime_text'] = $tmp['browsetime_day'] . date('H:i', $v['goodsbrowse_time']);
  63. $browselist_new[] = $tmp;
  64. }
  65. }
  66. }
  67. //查询浏览记录商品分类
  68. $browseclass_list = $goodsbrowse_model->getViewedGoodsList(session('member_id'),20);
  69. $browseclass_arr = array();
  70. foreach ((array) $browseclass_list as $k => $v) {
  71. if ($v['gc_id_1'] > 0) {
  72. @$browseclass_arr[$v['gc_id_1']] = array('gc_name' => $gc_list[$v['gc_id_1']]['gc_name'], 'sonclass' => array());
  73. }
  74. if ($v['gc_id_2'] > 0) {
  75. @$browseclass_arr[$v['gc_id_1']]['sonclass'][$v['gc_id_2']] = array('gc_name' => $gc_list[$v['gc_id_2']]['gc_name'], 'sonclass' => array());
  76. }
  77. }
  78. $this->setMemberCurMenu('member_goodsbrowse');
  79. $this->setMemberCurItem('index');
  80. View::assign('browseclass_arr', $browseclass_arr);
  81. View::assign('browselist', $browselist_new);
  82. //View::assign('show_page', $goodsbrowse_model->page_info->render());
  83. return View::fetch($this->template_dir . 'index');
  84. }
  85. /**
  86. * 删除浏览历史
  87. */
  88. public function del() {
  89. $return_arr = array();
  90. $goodsbrowse_model = model('goodsbrowse');
  91. if (trim(input('param.goods_id')) == 'all') {
  92. //清除缓存中浏览记录
  93. dcache(session('member_id'), 'goodsbrowse');
  94. $goodsbrowse_model->delGoodsbrowse(array('member_id' => session('member_id')));
  95. $return_arr = array('done' => true);
  96. } elseif (intval(input('param.goods_id')) >= 0) {
  97. $goods_id = intval(input('param.goods_id'));
  98. if (config('ds_config.cache_open')) {
  99. //清除缓存中的浏览记录
  100. $browse_goodsid = rcache(session('member_id'), 'goodsbrowse');
  101. $goodsid_arr = $browse_goodsid['goodsid'] ? unserialize($browse_goodsid['goodsid']) : array();
  102. if (isset($browse_goodsid[$goods_id])) {
  103. unset($browse_goodsid[$goods_id]);
  104. }
  105. if ($goodsid_arr) {
  106. $goodsid_arr = array_diff($goodsid_arr, array($goods_id));
  107. $browse_goodsid['goodsid'] = serialize($goodsid_arr);
  108. }
  109. wcache(session('member_id'), $browse_goodsid, 'goodsbrowse');
  110. }
  111. $goodsbrowse_model->delGoodsbrowse(array('member_id' => session('member_id'), 'goods_id' => $goods_id));
  112. $return_arr = array('done' => true);
  113. } else {
  114. $return_arr = array('done' => false, 'msg' => lang('param_error'));
  115. }
  116. echo json_encode($return_arr);
  117. }
  118. protected function getMemberItemList() {
  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. }