NotifyAnnounceService.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace addons\TinyShop\services\common;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use addons\TinyShop\common\models\common\NotifyAnnounce;
  6. /**
  7. * Class NotifyAnnounceService
  8. * @package addons\TinyShop\services\common
  9. */
  10. class NotifyAnnounceService
  11. {
  12. /**
  13. * 获取公告
  14. *
  15. * @return array|\yii\db\ActiveRecord[]
  16. */
  17. public function findByCustom()
  18. {
  19. return NotifyAnnounce::find()
  20. ->select(['id', 'title', 'cover', 'view', 'synopsis', 'created_at'])
  21. ->where(['status' => StatusEnum::ENABLED])
  22. ->andWhere(['merchant_id' => Yii::$app->services->merchant->getNotNullId()])
  23. ->orderBy('id desc')
  24. ->cache(30)
  25. ->limit(20)
  26. ->asArray()
  27. ->all();
  28. }
  29. /**
  30. * @return array|\yii\db\ActiveRecord|null
  31. */
  32. public function findById($id)
  33. {
  34. return NotifyAnnounce::find()
  35. ->where(['id' => $id])
  36. ->andWhere(['status' => StatusEnum::ENABLED])
  37. ->one();
  38. }
  39. }
粤ICP备19079148号