| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | <?phpnamespace App\Http\Controllers\Web\Talent;use App\Http\Controllers\Web\WebBaseController;use App\Models\MemberShuobo;use App\Services\Common\SmsService;use App\Models\Member;use Illuminate\Http\Request;use App\Services\Common\SearchService;class ShuoboController extends WebBaseController{    private $smsService;    protected $searchService;    public function __construct(SmsService $smsService,SearchService $searchService)    {        $this->smsService = $smsService;        $this->searchService = $searchService;    }    public function talent()    {        dd(MemberShuobo::search("郑明炜")->get());        return view('app.shuobo.talent');    }    public function getTalentData(Request $request)    {        $keyword = $request->input('keyword');        $page = $request->input('page');        $list = $this->searchService->search('Shuobo', [], [], $keyword,10,$page);        $list_data =[];        foreach ($list->items() as $k => $v){            $item = [                'name' => $this->splitName($v->realname)[0] . ($v->sex == '男' ? '先生' : '女士'),                'sex' => $v->sex,                'birthday' => date('Y-m-d H:i:s',$v->birthday),                'education' => $v->education,                'school' => $v->school,                'pro' => $v->pro,                'trade_type' => $v->trade_type,                'speciality' => $v->speciality            ];            array_push($list_data,$item);        }        $data = array(            'total' => $list->total(),            'list' => $list_data        );        return json_encode($data);    }    function splitName($fullname){        $hyphenated = array('欧阳','太史','端木','上官','司马','东方','独孤','南宫','万俟','闻人','夏侯','诸葛','尉迟','公羊','赫连','澹台','皇甫',            '宗政','濮阳','公冶','太叔','申屠','公孙','慕容','仲孙','钟离','长孙','宇文','城池','司徒','鲜于','司空','汝嫣','闾丘','子车','亓官',            '司寇','巫马','公西','颛孙','壤驷','公良','漆雕','乐正','宰父','谷梁','拓跋','夹谷','轩辕','令狐','段干','百里','呼延','东郭','南门',            '羊舌','微生','公户','公玉','公仪','梁丘','公仲','公上','公门','公山','公坚','左丘','公伯','西门','公祖','第五','公乘','贯丘','公皙',            '南荣','东里','东宫','仲长','子书','子桑','即墨','达奚','褚师');        $vLength = mb_strlen($fullname, 'utf-8');        $lastname = '';        $firstname = '';//前为姓,后为名        if($vLength > 2){            $preTwoWords = mb_substr($fullname, 0, 2, 'utf-8');//取命名的前两个字,看是否在复姓库中            if(in_array($preTwoWords, $hyphenated)){                $lastname = $preTwoWords;                $firstname = mb_substr($fullname, 2, 10, 'utf-8');            }else{                $lastname = mb_substr($fullname, 0, 1, 'utf-8');                $firstname = mb_substr($fullname, 1, 10, 'utf-8');            }        }else if($vLength == 2){//全名只有两个字时,以前一个为姓,后一下为名            $lastname = mb_substr($fullname ,0, 1, 'utf-8');            $firstname = mb_substr($fullname, 1, 10, 'utf-8');        }else{            $lastname = $fullname;        }        return array($lastname, $firstname);    }}
 |