ShuoboController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers\Web\Talent;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use App\Models\MemberShuobo;
  5. use App\Services\Common\SmsService;
  6. use App\Models\Member;
  7. use Illuminate\Http\Request;
  8. use App\Services\Common\SearchService;
  9. class ShuoboController extends WebBaseController
  10. {
  11. private $smsService;
  12. protected $searchService;
  13. public function __construct(SmsService $smsService,SearchService $searchService)
  14. {
  15. $this->smsService = $smsService;
  16. $this->searchService = $searchService;
  17. }
  18. public function talent()
  19. {
  20. dd(MemberShuobo::search("郑明炜")->get());
  21. return view('app.shuobo.talent');
  22. }
  23. public function getTalentData(Request $request)
  24. {
  25. $keyword = $request->input('keyword');
  26. $page = $request->input('page');
  27. $list = $this->searchService->search('Shuobo', [], [], $keyword,10,$page);
  28. $list_data =[];
  29. foreach ($list->items() as $k => $v){
  30. $item = [
  31. 'name' => $this->splitName($v->realname)[0] . ($v->sex == '男' ? '先生' : '女士'),
  32. 'sex' => $v->sex,
  33. 'birthday' => date('Y-m-d H:i:s',$v->birthday),
  34. 'education' => $v->education,
  35. 'school' => $v->school,
  36. 'pro' => $v->pro,
  37. 'trade_type' => $v->trade_type,
  38. 'speciality' => $v->speciality
  39. ];
  40. array_push($list_data,$item);
  41. }
  42. $data = array(
  43. 'total' => $list->total(),
  44. 'list' => $list_data
  45. );
  46. return json_encode($data);
  47. }
  48. function splitName($fullname){
  49. $hyphenated = array('欧阳','太史','端木','上官','司马','东方','独孤','南宫','万俟','闻人','夏侯','诸葛','尉迟','公羊','赫连','澹台','皇甫',
  50. '宗政','濮阳','公冶','太叔','申屠','公孙','慕容','仲孙','钟离','长孙','宇文','城池','司徒','鲜于','司空','汝嫣','闾丘','子车','亓官',
  51. '司寇','巫马','公西','颛孙','壤驷','公良','漆雕','乐正','宰父','谷梁','拓跋','夹谷','轩辕','令狐','段干','百里','呼延','东郭','南门',
  52. '羊舌','微生','公户','公玉','公仪','梁丘','公仲','公上','公门','公山','公坚','左丘','公伯','西门','公祖','第五','公乘','贯丘','公皙',
  53. '南荣','东里','东宫','仲长','子书','子桑','即墨','达奚','褚师');
  54. $vLength = mb_strlen($fullname, 'utf-8');
  55. $lastname = '';
  56. $firstname = '';//前为姓,后为名
  57. if($vLength > 2){
  58. $preTwoWords = mb_substr($fullname, 0, 2, 'utf-8');//取命名的前两个字,看是否在复姓库中
  59. if(in_array($preTwoWords, $hyphenated)){
  60. $lastname = $preTwoWords;
  61. $firstname = mb_substr($fullname, 2, 10, 'utf-8');
  62. }else{
  63. $lastname = mb_substr($fullname, 0, 1, 'utf-8');
  64. $firstname = mb_substr($fullname, 1, 10, 'utf-8');
  65. }
  66. }else if($vLength == 2){//全名只有两个字时,以前一个为姓,后一下为名
  67. $lastname = mb_substr($fullname ,0, 1, 'utf-8');
  68. $firstname = mb_substr($fullname, 1, 10, 'utf-8');
  69. }else{
  70. $lastname = $fullname;
  71. }
  72. return array($lastname, $firstname);
  73. }
  74. }