MemberHotwordRepository.php 1.7 KB

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