| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace app\common\dao\product;
- use app\common\dao\BaseDao;
- use app\common\enum\product\SeckillEnum;
- use app\common\model\product\SeckillModel;
- use app\entity\CommonEntity;
- use app\entity\data\product\SeckillEntity;
- class SeckillDao extends BaseDao
- {
- /**
- * @return string
- */
- protected function getModel(): string
- {
- return SeckillModel::class;
- }
- /**
- * 根据 shareId 获取分享实体
- * @param int $productId
- * @return CommonEntity
- */
- public function getSeckillEntityByProductId(int $productId): CommonEntity
- {
- $data = [];
- try {
- /** @var SeckillModel $model */
- $model = $this->getModel();
- $dataRes = $model::getDB()
- ->where('product_id', '=', $productId)
- ->where("`seckill_date` <= '" . date('Y-m-d H:i:s') . "'")
- ->where("status", '=', SeckillEnum::STATUS['Open']['code'])
- ->find();
- if (!empty($dataRes)) {
- $data = $dataRes->toArray();
- }
- } catch (\Exception $e) {
- }
- return SeckillEntity::newInstance($data);
- }
- }
|