Ejemplo n.º 1
0
 public static function setRecommend($blog_id, $relate_blog_id, $params = [])
 {
     $date_now = date("Y-m-d H:i:s");
     $info = PostsRecommend::findOne(['blog_id' => $blog_id, "relation_blog_id" => $relate_blog_id]);
     $title_rate = isset($params['title_rate']) ? $params['title_rate'] : 0;
     $content_rate = isset($params['content_rate']) ? $params['content_rate'] : 0;
     $tags_rate = isset($params['tags_rate']) ? $params['tags_rate'] : 0;
     $score = $title_rate * 0.25 + $content_rate * 0.15 + $tags_rate * 0.6;
     if ($info) {
         $model_posts_recommend = $info;
     } else {
         $model_posts_recommend = new PostsRecommend();
         $model_posts_recommend->blog_id = $blog_id;
         $model_posts_recommend->relation_blog_id = $relate_blog_id;
         $model_posts_recommend->created_time = $date_now;
     }
     $model_posts_recommend->title_rate = $title_rate;
     $model_posts_recommend->content_rate = $content_rate;
     $model_posts_recommend->tags_rate = $content_rate;
     $model_posts_recommend->score = round($score);
     $model_posts_recommend->updated_time = $date_now;
     $model_posts_recommend->save(0);
 }
Ejemplo n.º 2
0
 private function afterDel($blog_id)
 {
     PostsTags::deleteAll(["posts_id" => $blog_id]);
     PostsRecommend::deleteAll(['OR', ['blog_id' => $blog_id], ["relation_blog_id" => $blog_id]]);
 }