ArticleMetaLike.php 720 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2017-03-15 21:16
  7. */
  8. namespace common\models\meta;
  9. use Yii;
  10. class ArticleMetaLike extends \common\models\ArticleMeta
  11. {
  12. public $keyName = "like";
  13. /**
  14. * @param $aid
  15. * @return bool
  16. */
  17. public function setLike($aid)
  18. {
  19. $this->aid = $aid;
  20. $this->key = $this->keyName;
  21. $this->value = Yii::$app->getRequest()->getUserIP();
  22. return $this->save(false);
  23. }
  24. /**
  25. * @param $aid
  26. * @return int|string
  27. */
  28. public function getLikeCount($aid)
  29. {
  30. return $this->find()->where(['aid' => $aid, 'key' => $this->keyName])->count("aid");
  31. }
  32. }