UserVisitRepository.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\user;
  12. use app\common\dao\user\UserVisitDao;
  13. use app\common\repositories\BaseRepository;
  14. /**
  15. * Class UserVisitRepository
  16. * @package app\common\repositories\user
  17. * @author xaboy
  18. * @day 2020/5/27
  19. * @mixin UserVisitDao
  20. */
  21. class UserVisitRepository extends BaseRepository
  22. {
  23. /**
  24. * @var UserVisitDao
  25. */
  26. protected $dao;
  27. /**
  28. * UserVisitRepository constructor.
  29. * @param UserVisitDao $dao
  30. */
  31. public function __construct(UserVisitDao $dao)
  32. {
  33. $this->dao = $dao;
  34. }
  35. public function getRecommend(?int $uid)
  36. {
  37. $data = $this->dao->search($uid,'product')->with(['product'=>function($query){
  38. $query->field('product_id,cate_id');
  39. }])->limit(7)->select();
  40. $i = [];
  41. if(is_array($data)){
  42. foreach ($data as $item){
  43. $i[] = $item['product']['cate_id'];
  44. }
  45. }
  46. return $i;
  47. }
  48. public function getHistory($uid,$page, $limit)
  49. {
  50. $query = $this->dao->search($uid,'product');
  51. $query->with(['product'=>function($query){
  52. $query->field('product_id,image,store_name,slider_image,price,is_show,status,sales');
  53. }]);
  54. $count = $query->count();
  55. $list = $query->page($page,$limit)->select();
  56. return compact('count','list');
  57. }
  58. }