ShareDao.php 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\common\dao\product;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\product\ShareModel;
  5. use app\entity\CommonEntity;
  6. use app\entity\data\product\ShareEntity;
  7. class ShareDao extends BaseDao
  8. {
  9. /**
  10. * @return string
  11. */
  12. protected function getModel(): string
  13. {
  14. return ShareModel::class;
  15. }
  16. /**
  17. * 根据 shareId 获取分享实体
  18. * @param int $shareId
  19. * @return CommonEntity
  20. */
  21. public function getShareEntityByShareId(int $shareId): CommonEntity
  22. {
  23. $shareData = [];
  24. try {
  25. /** @var ShareModel $model */
  26. $model = $this->getModel();
  27. $shareDataRes = $model::getDB()
  28. ->where('id', '=', $shareId)
  29. ->find();
  30. if (!empty($shareDataRes)) {
  31. $shareData = $shareDataRes->toArray();
  32. }
  33. } catch (\Exception $e) {
  34. }
  35. return ShareEntity::newInstance($shareData);
  36. }
  37. }