common.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. /**
  12. * 设置浏览信息
  13. * @param $uid
  14. * @param int $product_id
  15. * @param int $cate
  16. * @param string $type
  17. * @param string $content
  18. * @param int $min
  19. */
  20. function setView($uid,$product_id=0,$cate=0,$type='',$content='',$min=20){
  21. $Db=think\Db::name('store_visit');
  22. $view=$Db->where(['uid'=>$uid,'product_id'=>$product_id])->field('count,add_time,id')->find();
  23. if($view && $type!='search'){
  24. $time=time();
  25. if(($view['add_time']+$min)<$time){
  26. $Db->where(['id'=>$view['id']])->update(['count'=>$view['count']+1,'add_time'=>time()]);
  27. }
  28. }else{
  29. $cate = explode(',',$cate)[0];
  30. $Db->insert([
  31. 'add_time'=>time(),
  32. 'count'=>1,
  33. 'product_id'=>$product_id,
  34. 'cate_id'=>$cate,
  35. 'type'=>$type,
  36. 'uid'=>$uid,
  37. 'content'=>$content
  38. ]);
  39. }
  40. }