public function update(array $data) { $keyword = Keyword::find($data['keyword_id']); $keyword->keyword = $data['keyword']; $keyword->match_type = $data['match_type']; $keyword->save(); return $keyword; }
public function get_keyword_id($keyword) { if (null !== $keyword) { if ($result = Keyword::where('name', $keyword)->first()) { return $result->id; } else { return 1; } } else { return 1; } }
/** * Run the database seeds. * * @return void */ public function run() { $flags = array('Starbucks' => array('alternatives' => array(array('title' => 'Tim Hortons', 'data' => array('savings_percent' => 40, 'message' => 'Tim Horton\'s costs much less than Starbucks.')), array('title' => 'Make Coffee At Home', 'data' => array('savings_percent' => 60, 'message' => 'Save a ton of money by making your own coffee.'))), 'keywords' => array('starbucks')), 'Loblaws' => array('alternatives' => array(array('title' => 'Metro', 'data' => array('savings_percent' => 30, 'message' => 'Big savings by shopping at Metro vs other stores.'))), 'keywords' => array('sobeys', 'loblaw', 'zehrs')), 'Casino' => array('alternatives' => array(array('title' => 'Don\'t Gamble', 'data' => array('savings_percent' => 100, 'message' => 'Instead of losing money by gambling, we can instantly use that to cover debts.'))), 'keywords' => array('casino'))); foreach ($flags as $key => $flag) { $new_flag = Flag::create(['title' => $key]); foreach ($flag['alternatives'] as $alternative) { $new_alternative = Alternative::create(['title' => $alternative['title']]); $new_flag->alternatives()->attach($new_alternative->id, ['savings_percent' => $alternative['data']['savings_percent'], 'message' => $alternative['data']['message']]); } foreach ($flag['keywords'] as $keyword) { $new_flag->keywords()->attach(Keyword::where('name', $keyword)->first()->id); } } }
/** * * @return type */ public function getUrls() { $keyword = Request::input('keyword'); if ($keyword == '') { return Response::json(array('success' => false, 'error' => 'Please enter a keyword'), 400); } $keyword = Keyword::where('value', '=', $keyword)->first(); if ($keyword == '') { return Response::json(array('success' => false, 'error' => 'No urls found for the keyword'), 400); } $urls = Link::where('keyword_id', '=', $keyword->id)->paginate(10); if (Request::ajax()) { return Response::json(View::make('partials.url-list', array('urls' => $urls))->render()); } }
public function reply($message) { /* * 监听事件类型 * 关注事件回复 * */ //获取公众号信息 $public_number = $message->ToUserName; $wechat = Wechat::where('wechat_account', '=', $public_number)->firstOrFail(); //获取关键词对象 $message->Content; //查询关键字,预载入关键字规则 $keyword = Keyword::with(['keywordRule' => function ($query) use($wechat) { $query->where('wechat_id', '=', $wechat->id); }])->where('keyword', 'like', "{$message->Content}")->first(); //查询对应回复 一对多 $replies = $keyword->keywordRule->reply; //dd($replies); foreach ($replies as $key => $reply) { $contents[$key] = $reply->{$reply->reply_type}; $contents[$key]['reply_type'] = $reply->reply_type; } //取随机数 $num = mt_rand(0, count($replies)); $content = $contents[$num]; switch ($content['reply_type']) { case 'text': case 'image': case 'voice': case 'video': case 'location': return Message::make($content['reply_type'])->content($content->content); break; default: return Message::make($content['reply_type'])->content($content->content); break; case 'news': //查询内容 $news = WechatNews::find($content->content); return Message::make('news')->items(function () use($news) { return array(Message::make('news_item')->title($news->title)->url($news->news_url)->picUrl($news->cover)); }); breadk; } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['file' => 'required', 'city' => 'required', 'year' => 'required']); $city = City::findOrFail($request->city); $tags = Keyword::get(); $parser = new SheetHandler($request->file); if (empty($request->month)) { $investiments = $parser->extractInvestimentsEachMonth(); foreach ($investiments as $investimentIdx => $investiment) { foreach ($investiment as $month => $singleMonth) { if (!empty($singleMonth->domain)) { $flag = 1; $singleMonth->city()->associate($city); $singleMonth->made_at = $request->year . '-' . sprintf("%02s", $month) . '-' . 1; foreach ($tags as $tag) { if (strpos(mb_strtolower($singleMonth, 'UTF-8'), $tag->name) !== FALSE) { $flag = 0; $singleMonth->category()->associate(Category::findOrFail($tag->category_id)); break; } } if ($flag) { $singleMonth->category()->associate(Category::where('name', 'Outros')->firstOrFail()); } } else { unset($investiments[$investimentIdx]); } } } foreach ($investiments as $investiment) { foreach ($investiment as $singleMonth) { $singleMonth->save(); } } } else { $investiments = $parser->extractInvestiments(); foreach ($investiments as $investimentIdx => $investiment) { if (!empty($investiment->domain)) { $flag = 1; $investiment->city()->associate($city); $investiment->made_at = $request->year . '-' . sprintf("%02s", $request->month) . '-' . 1; foreach ($tags as $tag) { if (strpos(mb_strtolower($investiment, 'UTF-8'), $tag->name) !== FALSE) { $flag = 0; $investiment->category()->associate(Category::findOrFail($tag->category_id)); break; } } if ($flag) { $investiment->category()->associate(Category::where('name', 'Outros')->firstOrFail()); } } else { unset($investiments[$investimentIdx]); } } foreach ($investiments as $invesitment) { $investiment->save(); } } return Redirect::route('admin.investimentos.index'); }
private static function processKeywords($company_id, $company_str_id, $name) { $keywords = self::generateCompanyKeywords($name); if (!empty($keywords)) { foreach ($keywords as $k) { Keyword::saveInstance(['keyword' => $k, 'company_id' => $company_id, 'company_str_id' => $company_str_id]); } return true; } return false; }
/** * Bootstrap the application services. * * @return void */ public function boot() { view()->composer('main', function ($view) { $view->with('hotTags', Keyword::orderBy('count', 'desc')->take(10)->get()->toArray()); }); }
private static function processKeywords(Job $jobObj, $record_status, $old_keywords = null) { // remove current keywords from caches if ($record_status == 'existed' && !empty($old_keywords)) { $job_keywords = explode(',', $old_keywords); foreach ($job_keywords as $jkw) { Keyword::removeJobFromKeywordCache($jkw, $jobObj->id); } $jobObj->keywords()->detach(); } if ($record_status == 'new' || !empty($old_keywords)) { $keywords = self::generateJobKeywords($jobObj->title); if (!empty($keywords)) { foreach ($keywords as $kw) { $score = strtotime($jobObj->updated_at); if ($jobObj->is_featured == 1) { $score = $score * 3; } Keyword::saveInstance(['keyword' => $kw, 'job_id' => $jobObj->id, 'score' => $score]); } } } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Keyword::destroy($id); return Redirect::route('admin.tags.index'); }
public function processAdvert($campain_id) { $userName = Auth::user()->name; $campain = Campain::find($campain_id); $advert = $campain->advert; $response = ""; try { $ml = new MonkeyLearn\Client('74312b126c6fcee32bddc68b6b3d4b15fee48868'); $text_list = [$advert]; $module_id = 'ex_eV2dppYE'; $res = $ml->extractors->extract($module_id, $text_list); $results = $res->result; $response = $results[0]; } catch (Exception $e) { echo 'Message: ' . $e->getMessage(); } $colors = ['bg-success', 'bg-primary', 'bg-danger', 'bg-warning']; $keywords = []; foreach ($response as $item) { $text = $item["keyword"]; $relevance = $item["relevance"]; $isRegistered = 'Existente'; $color = $colors[array_rand($colors)]; $relevance = $relevance * 100 . "%"; $keyword = Keyword::where('text', '=', $text)->get(); if (count($keyword) == 0) { $isRegistered = 'Nuevo Registro'; $keyword = new Keyword(); $keyword->text = $text; $keyword->save(); } else { $keyword = $keyword[0]; } $link = new Link(); $link->campain_id = $campain_id; $link->keyword_id = $keyword->id; $link->save(); $keywords[] = ["text" => $text, "relevance" => $relevance, "isRegistered" => $isRegistered, "color" => $color]; } return view('campain.result', ['userName' => $userName, 'textArticle' => $advert, 'keywords' => $keywords]); }
'title' => 'Hot Search Android Apps - AppForAndroidPhone', 'desc' => '', 'keyword' => '' ]); }); Route::get('search/{tag}', function($tag) { if (preg_match('/tag-([a-z0-9\-]+)/', $tag, $matches)) { $css = 'search'; $page = null; $pageSearch = true; $term = $matches[1]; if (strlen($term) > 2) { $term = str_replace('-',' ', $term); $keyword = Keyword::where('name', $term)->first(); if (!$keyword) { $keyword = new Keyword(); $keyword->create(['name' => $term, 'count' => 1]); } else { $keyword->count ++; $keyword->save(); } $games = Game::tagged($term)->latest('update')->paginate(20); } else { $games = Game::latest('update')->paginate(20); } return view('games.search', compact('games', 'term', 'pageSearch', 'css', 'page'))->with([ 'title' => 'Search result for '.$term.' - AppForAndroidPhone', 'desc' => '', 'keyword' => '' ]); }
public function roi() { $userName = Auth::user()->name; $campains = Campain::all(); $resp = array(); foreach ($campains as $campain) { $id = $campain->id; $cost = $campain->cost; $gain = $campain->gain; $roi = ($gain - $cost) / $cost; $resp[$id] = $roi; } arsort($resp); $report = []; foreach ($resp as $key => $value) { $roi = number_format($value, 2); $campain = Campain::find($key); $lists = DB::table('links')->where('campain_id', '=', $key)->get(); $keywords = []; foreach ($lists as $list) { $keyword_id = $list->keyword_id; $keyword = Keyword::find($keyword_id); $keywords[] = $keyword->text; } $report[] = ["campain" => $campain->description, "roi" => $roi, "keywords" => $keywords]; } return view('report.roi', ['userName' => $userName, 'reports' => $report]); }