HotWordService.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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[] = [
  28. 'w_word', 'like', '%' . $key . '%',
  29. ];
  30. $where[] = ['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 ['key' => $key, 'list' => $lists];
  37. }
  38. return false;
  39. }
  40. public function setMemberHotword($key, $type = 1)
  41. {
  42. $user = [
  43. 'utype' => 0,
  44. 'uid' => 0,
  45. ];
  46. if (auth('web-member')->check()) {
  47. $user = [
  48. 'utype' => 2,
  49. 'uid' => auth('web-member')->user()->id,
  50. ];
  51. } elseif (auth('web-company')->check()) {
  52. $user = [
  53. 'utype' => 1,
  54. 'uid' => auth('web-company')->user()->id,
  55. ];
  56. }
  57. $where[] = ['w_word', 'like', '%' . $key . '%',];
  58. $where[] = ['type', '=', $type];
  59. $where[] = ['utype', '=', $user['utype']];
  60. $where[] = ['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 ['key' => $key, 'list' => $lists];
  67. }
  68. }
  69. public function getHotWords($where = [], $order = 'w_hot desc', $limit = '')
  70. {
  71. return $this->hotWordRepository->getHotWords($where, $order, $limit);
  72. }
  73. public function searchHostWords($key, $type = 1)
  74. {
  75. $this->hotWordRepository->setInc($key, $type);
  76. }
  77. }