Membergoodsbrowse.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 浏览历史控制器
  10. */
  11. class Membergoodsbrowse extends MobileMember
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/membergoodsbrowse.lang.php');
  17. }
  18. /**
  19. * 我的足迹
  20. */
  21. public function browse_list()
  22. {
  23. $goodsbrowse_model = model('goodsbrowse');
  24. $page = intval(input('param.page'));
  25. $per_page = intval(input('param.per_page'));
  26. //查询浏览记录
  27. $condition = array();
  28. $condition[] = array('member_id', '=', $this->member_info['member_id']);
  29. $timearray = $goodsbrowse_model->getGoodsbrowseList($condition, 'goodsbrowse_time', 0, 'goodsbrowse_time desc');
  30. foreach ($timearray as $key => $val) {
  31. $timearray[$key]['goodsbrowse_time'] = date('Y-m-d', $val['goodsbrowse_time']);
  32. }
  33. $timearray = array_unique(array_column($timearray, 'goodsbrowse_time')); //去除日期数组里面的重复日期
  34. $count = count($timearray); //日期数组长度
  35. $page_total = ceil($count / $per_page); //总页数
  36. if (($count - ($per_page * $page)) > 0) {
  37. $hasmore = true;
  38. } else {
  39. $hasmore = false;
  40. }
  41. $start = $per_page * ($page - 1); //数组起始位置
  42. $pagetimearray = array_slice($timearray, $start, $per_page); //获取页数日期数组
  43. $browsegoodslist = array();
  44. foreach ($pagetimearray as $key => $val) {
  45. $browsegoodslist[$key]['time'] = $val;
  46. $condition = array();
  47. $condition[] = array('member_id', '=', $this->member_info['member_id']);
  48. $condition[] = array('goodsbrowse_time', '>=', strtotime($val));
  49. $condition[] = array('goodsbrowse_time', '<=', strtotime($val) + 86399);
  50. $goodsidarray = $goodsbrowse_model->getGoodsbrowseList($condition, 'goods_id');
  51. $goodsidarray = array_column($goodsidarray, 'goods_id');
  52. $goodsidarray = implode(',', $goodsidarray);
  53. $goods_list = model('goods')->getGoodsList(array(array('goods_id', 'in', $goodsidarray)), 'goods_id, goods_name, goods_advword, goods_promotion_price, goods_promotion_type, goods_marketprice, goods_image, store_id, gc_id, gc_id_1, gc_id_2, gc_id_3');
  54. foreach ($goods_list as $k => $v) {
  55. $goods_list[$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $v['store_id']);
  56. }
  57. $browsegoodslist[$key]['goods_list'] = $goods_list;
  58. }
  59. $result = array_merge(array('goodsbrowse_list' => $browsegoodslist), array('hasmore' => $hasmore), array('page_total' => $page_total));
  60. ds_json_encode(10000, '', $result);
  61. }
  62. /**
  63. * 清空足迹
  64. */
  65. public function browse_clearall()
  66. {
  67. //清除缓存中浏览记录
  68. dcache($this->member_info['member_id'], 'goodsbrowse');
  69. model('goodsbrowse')->delGoodsbrowse(array('member_id' => $this->member_info['member_id']));
  70. ds_json_encode(10000, '', 1);
  71. }
  72. }