WxSearchRepositores.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Controllers\Api\Repositories;
  3. use App\Jobs\AttachIpAddressJob;
  4. use App\Wen\Utils\Settings;
  5. use App\Models\WxSearch;
  6. class WxSearchRepositores
  7. {
  8. public static function record($uid,$search_content)
  9. {
  10. $first_model = WxSearch::where('user_id', $uid)->latest()->first();
  11. if($first_model){
  12. if($first_model->search_content == $search_content){
  13. return true;
  14. }
  15. }
  16. $SearchModel = new WxSearch();
  17. $SearchModel->user_id = $uid;
  18. $SearchModel->search_content = $search_content;
  19. global $__MINI_GLOBAL_IP__;
  20. if($__MINI_GLOBAL_IP__){
  21. $SearchModel->ip = $__MINI_GLOBAL_IP__;
  22. }
  23. $r = $SearchModel->save();
  24. if($r){
  25. if($__MINI_GLOBAL_IP__){
  26. AttachIpAddressJob::dispatch(4, $SearchModel->id)->delay(2);
  27. }
  28. }
  29. return $r;
  30. }
  31. public static function hot_search($num = 10, $field = ['search_content', 'is_hot']){
  32. if(Settings::get('app_hot_search', '')){
  33. return WxSearch::whereIn('id', explode(',', Settings::get('app_hot_search', '')))->limit($num)->get($field);
  34. }else{
  35. return WxSearch::where('is_hot', 1)->orderby('updated_at', 'desc')->limit($num)->get($field);
  36. }
  37. }
  38. }