Membergoodsbrowse.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 浏览历史控制器
  14. */
  15. class Membergoodsbrowse extends MobileMember {
  16. public function initialize() {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/membergoodsbrowse.lang.php');
  19. }
  20. /**
  21. * 我的足迹
  22. */
  23. public function browse_list() {
  24. $goodsbrowse_model = model('goodsbrowse');
  25. $page = intval(input('param.page'));
  26. $per_page = intval(input('param.per_page'));
  27. //查询浏览记录
  28. $condition = array();
  29. $condition[] = array('member_id','=',$this->member_info['member_id']);
  30. $timearray = $goodsbrowse_model->getGoodsbrowseList($condition,'goodsbrowse_time',0,'goodsbrowse_time desc');
  31. foreach($timearray as $key => $val){
  32. $timearray[$key]['goodsbrowse_time'] = date('Y-m-d',$val['goodsbrowse_time']);
  33. }
  34. $timearray = array_unique(array_column($timearray,'goodsbrowse_time'));//去除日期数组里面的重复日期
  35. $count = count($timearray);//日期数组长度
  36. $page_total = ceil($count/$per_page);//总页数
  37. if(($count - ($per_page * $page)) > 0){
  38. $hasmore = true;
  39. }else{
  40. $hasmore = false;
  41. }
  42. $start = $per_page * ($page - 1);//数组起始位置
  43. $pagetimearray = array_slice($timearray,$start,$per_page);//获取页数日期数组
  44. $browsegoodslist = array();
  45. foreach($pagetimearray as $key => $val){
  46. $browsegoodslist[$key]['time'] =$val;
  47. $condition = array();
  48. $condition[] = array('member_id' ,'=', $this->member_info['member_id']);
  49. $condition[] = array('goodsbrowse_time' ,'>=', strtotime($val));
  50. $condition[] = array('goodsbrowse_time' ,'<=', strtotime($val)+86399);
  51. $goodsidarray = $goodsbrowse_model->getGoodsbrowseList($condition,'goods_id');
  52. $goodsidarray = array_column($goodsidarray,'goods_id');
  53. $goodsidarray = implode(',',$goodsidarray);
  54. $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');
  55. foreach($goods_list as $k => $v){
  56. $goods_list[$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $v['store_id']);
  57. }
  58. $browsegoodslist[$key]['goods_list'] =$goods_list;
  59. }
  60. $result = array_merge(array('goodsbrowse_list' => $browsegoodslist),array('hasmore' => $hasmore),array('page_total' => $page_total));
  61. ds_json_encode(10000, '', $result);
  62. }
  63. /**
  64. * 清空足迹
  65. */
  66. public function browse_clearall() {
  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. }