common.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 set_view($uid, $product_id = 0, $cate = 0, $type = '', $content = '', $min = 20)
  21. {
  22. $Db = new \app\models\store\StoreVisit;
  23. $view = $Db->where('uid', $uid)->where('product_id', $product_id)->field('count,add_time,id')->find();
  24. if ($view && $type != 'search') {
  25. $time = time();
  26. if (($view['add_time'] + $min) < $time) {
  27. $Db->where(['id' => $view['id']])->update(['count' => $view['count'] + 1, 'add_time' => time()]);
  28. }
  29. } else {
  30. $cate = explode(',', $cate)[0];
  31. $Db->insert([
  32. 'add_time' => time(),
  33. 'count' => 1,
  34. 'product_id' => $product_id,
  35. 'cate_id' => $cate,
  36. 'type' => $type,
  37. 'uid' => $uid,
  38. 'content' => $content
  39. ]);
  40. }
  41. }