🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
use think\Db; // 公共助手函数 if (!function_exists('search')) { /** * 获取语言变量值 * @param string $name 语言变量名 * @param array $vars 动态变量值 * @param string $lang 语言 * @return mixed */ function search() { $getKeywords= getKeywords("你好神经病"); $user_id=1; $GetFinallyKeywords= explode(",",$getKeywords['GetFinallyKeywords']); $where=[]; foreach ($GetFinallyKeywords as $key => $value) { $Pinyin= Pinyin($value); $where[] =$Pinyin; $my_search= Db::name("my_search")->where("key_word","LIKE",$value)->where("user_id",$user_id)->find(); if(isset($my_search["id"])){ Db::name("my_search")->where("id", $my_search["id"]) ->setInc('commission', 1); }else{ $data=[]; $data["user_id"]=$user_id; $data["creationtime"]=time(); $data["updatetime"]=time(); $data["key_word"]=$value; $data["pinyin"]=$Pinyin["py"]; $data["full_pinyin"]=$Pinyin["pinyin"]; $data["commission"]=1; Db::name("my_search")->insert($data); } $search= Db::name("search")->where("key_word","LIKE",$value)->find(); if(isset($search["id"])){ Db::name("search")->where("id", $search["id"]) ->setInc('commission', 1); }else{ $data=[]; $data["creationtime"]=time(); $data["updatetime"]=time(); $data["key_word"]=$value; $data["pinyin"]=$Pinyin["py"]; $data["full_pinyin"]=$Pinyin["pinyin"]; $data["commission"]=1; Db::name("search")->insert($data); } // code... } return $where; } } if (!function_exists('getKeywords')) { /** * 关键字提取方法 * @param $content string * @return array 得到的关键词数组 */ function getKeywords($content) { Vendor('phpanalysis.PhpAnalysis'); debug('run'); $str = $content; $pa = new \PhpAnalysis('utf-8','utf-8',true); $pa::$loadInit = false; $pa->LoadDict(); $pa->SetSource($str); $pa->StartAnalysis( false ); $tags["GetFinallyResult"] = $pa->GetFinallyResult(); $tags["GetFinallyKeywords"] = $pa->GetFinallyKeywords(); return $tags; } } if (!function_exists('Pinyin')) { /** fastadmin自带类库 文字转拼音 */ function Pinyin($content) { $pinyin = new \Overtrue\Pinyin\Pinyin('Overtrue\Pinyin\MemoryFileDictLoader'); $v['Pinyin'] = $content; $v['py'] = $pinyin->abbr($content, ''); $v['pinyin'] = $pinyin->permalink($content, ''); return $v; } }