HotWordRepository.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/12/4
  6. * Time: 10:25
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Hotword;
  10. use Prettus\Repository\Eloquent\BaseRepository;
  11. /**
  12. * Class HelpRepositoryEloquent.
  13. *
  14. * @package namespace App\Repositories;
  15. */
  16. class HotWordRepository extends BaseRepository
  17. {
  18. /**
  19. * Specify Model class name
  20. *
  21. * @return string
  22. */
  23. public function model()
  24. {
  25. return Hotword::class;
  26. }
  27. public function getHotWords($where, $order = 'w_hot desc', $limit = '')
  28. {
  29. if ($limit) {
  30. return $this->model->where($where)->orderByRaw($order)->limit($limit)->get();
  31. } else {
  32. return $this->model->where($where)->orderByRaw($order)->get();
  33. }
  34. //return $this->model->where($where)->orderByRaw($order)->get();
  35. }
  36. /**
  37. * 搜索次数增加1,如果不存在则增加一条数据
  38. */
  39. public function setInc($word, $type)
  40. {
  41. $word = trim($word);
  42. $word = substr($word, 0, 120);
  43. $word_info = $this->model->where(array('w_word'=>$word,'type'=>$type))->first();
  44. $stime = date('Y-m-d H:i:s', time());
  45. if ($word_info) {
  46. $this->model->where(array('id'=>$word_info->id))->increment('w_hot', 1);
  47. } else {
  48. $data = array(
  49. 'w_word' => $word,
  50. 'w_hot' => 1,
  51. 'type' => $type,
  52. 'created_at' => $stime,
  53. 'updated_at' => $stime
  54. );
  55. $this->model->create($data);
  56. }
  57. return true;
  58. }
  59. }