CollectService.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace addons\TinyShop\services\common;
  3. use common\components\Service;
  4. use addons\TinyShop\common\models\common\Collect;
  5. use common\enums\StatusEnum;
  6. /**
  7. * Class CollectService
  8. * @package addons\TinyShop\services\common
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class CollectService extends Service
  12. {
  13. /**
  14. * @param $topic_id
  15. * @param $topic_type
  16. * @param $member_id
  17. * @return Collect|array|\yii\db\ActiveRecord|null
  18. */
  19. public function findByTopicId($topic_id, $topic_type, $member_id)
  20. {
  21. $model = Collect::find()
  22. ->where([
  23. 'topic_id' => $topic_id,
  24. 'topic_type' => $topic_type,
  25. 'member_id' => $member_id,
  26. 'status' => StatusEnum::ENABLED,
  27. ])
  28. ->one();
  29. return empty($model) ? new Collect() : $model;
  30. }
  31. /**
  32. * @param $id
  33. * @return array|\yii\db\ActiveRecord|null
  34. */
  35. public function findById($id, $member_id)
  36. {
  37. return Collect::find()
  38. ->where(['id' => $id, 'member_id' => $member_id])
  39. ->one();
  40. }
  41. }
粤ICP备19079148号