SeckillDao.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\common\dao\product;
  3. use app\common\dao\BaseDao;
  4. use app\common\enum\product\SeckillEnum;
  5. use app\common\model\product\SeckillModel;
  6. use app\entity\CommonEntity;
  7. use app\entity\data\product\SeckillEntity;
  8. class SeckillDao extends BaseDao
  9. {
  10. /**
  11. * @return string
  12. */
  13. protected function getModel(): string
  14. {
  15. return SeckillModel::class;
  16. }
  17. /**
  18. * 根据 shareId 获取分享实体
  19. * @param int $productId
  20. * @return CommonEntity
  21. */
  22. public function getSeckillEntityByProductId(int $productId): CommonEntity
  23. {
  24. $data = [];
  25. try {
  26. /** @var SeckillModel $model */
  27. $model = $this->getModel();
  28. $dataRes = $model::getDB()
  29. ->where('product_id', '=', $productId)
  30. ->where("`seckill_date` <= '" . date('Y-m-d H:i:s') . "'")
  31. ->where("status", '=', SeckillEnum::STATUS['Open']['code'])
  32. ->find();
  33. if (!empty($dataRes)) {
  34. $data = $dataRes->toArray();
  35. }
  36. } catch (\Exception $e) {
  37. }
  38. return SeckillEntity::newInstance($data);
  39. }
  40. }