HotWordService.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/12/4
  6. * Time: 10:23
  7. */
  8. namespace App\Services\Common;
  9. use App\Repositories\HotWordRepository;
  10. use App\Repositories\MemberHotwordRepository;
  11. //use Illuminate\Support\Facades\Cache;
  12. class HotWordService
  13. {
  14. protected $hotWordRepository;
  15. protected $memberHotwordRepository;
  16. /**
  17. * HotWordService constructor.
  18. * @param $hotWordRepository
  19. */
  20. public function __construct(HotWordRepository $hotWordRepository, MemberHotwordRepository $memberHotwordRepository)
  21. {
  22. $this->hotWordRepository = $hotWordRepository;
  23. $this->memberHotwordRepository = $memberHotwordRepository;
  24. }
  25. public function getHotWord($key, $type = 1)
  26. {
  27. $where[] = array(
  28. 'w_word', 'like', '%'.$key.'%',
  29. );
  30. $where[] = array('type','=',$type);
  31. $order = 'list_order desc,w_hot desc';
  32. $lists = $this->hotWordRepository->getHotWords($where, $order);
  33. //修改热门关键字记录
  34. $word_rst = $this->hotWordRepository->setInc($key, $type);
  35. if ($lists->toArray()) {
  36. return array('key'=>$key,'list'=>$lists);
  37. }
  38. return false;
  39. }
  40. public function setMemberHotword($key, $type = 1)
  41. {
  42. $user = array(
  43. 'utype' => 0,
  44. 'uid' => 0
  45. );
  46. if (auth('web-member')->check()) {
  47. $user = array(
  48. 'utype' => 2,
  49. 'uid' => auth('web-member')->user()->id
  50. );
  51. } elseif (auth('web-company')->check()) {
  52. $user = array(
  53. 'utype' => 1,
  54. 'uid' => auth('web-company')->user()->id
  55. );
  56. }
  57. $where[] = array('w_word', 'like', '%'.$key.'%',);
  58. $where[] = array('type','=',$type);
  59. $where[] = array('utype','=',$user['utype']);
  60. $where[] = array('uid','=',$user['uid']);
  61. $order = 'list_order desc,w_hot desc';
  62. $lists = $this->memberHotwordRepository->getHotWords($where, $order);
  63. //修改热门关键字记录
  64. $word_rst = $this->memberHotwordRepository->setInc($key, $type, $user);
  65. if ($lists->toArray()) {
  66. return array('key'=>$key,'list'=>$lists);
  67. }
  68. }
  69. public function getHotWords($where = array (), $order = 'w_hot desc', $limit = '')
  70. {
  71. return $this->hotWordRepository->getHotWords($where, $order, $limit);
  72. }
  73. }