| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace App\Module\Shop\Dtos;
- use App\Module\Shop\Models\ShopPromotion;
- use UCore\Dto\BaseDto;
- /**
- * 商店促销活动数据传输对象
- *
- * 用于在服务层和控制器层之间传递促销活动数据,避免直接暴露模型
- */
- class ShopPromotionDto extends BaseDto
- {
- /**
- * 促销活动ID
- *
- * @var int
- */
- public int $id;
- /**
- * 促销活动名称
- *
- * @var string
- */
- public string $name;
- /**
- * 促销活动描述
- *
- * @var string|null
- */
- public ?string $description;
- /**
- * 折扣类型(1:百分比折扣, 2:固定金额折扣)
- *
- * @var int
- */
- public int $discountType;
- /**
- * 折扣值
- *
- * @var int
- */
- public int $discountValue;
- /**
- * 是否激活
- *
- * @var bool
- */
- public bool $isActive;
- /**
- * 开始时间(时间戳)
- *
- * @var int|null
- */
- public ?int $startTime;
- /**
- * 结束时间(时间戳)
- *
- * @var int|null
- */
- public ?int $endTime;
- /**
- * 排序权重
- *
- * @var int
- */
- public int $sortOrder;
- /**
- * 创建时间
- *
- * @var string
- */
- public string $createdAt;
- /**
- * 更新时间
- *
- * @var string
- */
- public string $updatedAt;
- /**
- * 自定义折扣值(可选,来自促销商品关联表)
- *
- * @var int|null
- */
- public ?int $customDiscountValue = null;
- /**
- * 从模型创建DTO
- *
- * @param ShopPromotion $promotion 促销活动模型
- * @param int|null $customDiscountValue 自定义折扣值(可选)
- * @return self
- */
- public static function fromModel(ShopPromotion $promotion, ?int $customDiscountValue = null): self
- {
- $dto = new self();
- $dto->id = $promotion->id;
- $dto->name = $promotion->name;
- $dto->description = $promotion->description;
- $dto->discountType = $promotion->discount_type;
- $dto->discountValue = $promotion->discount_value;
- $dto->isActive = $promotion->is_active;
- $dto->startTime = $promotion->start_time ? $promotion->start_time->timestamp : null;
- $dto->endTime = $promotion->end_time ? $promotion->end_time->timestamp : null;
- $dto->sortOrder = $promotion->sort_order;
- $dto->createdAt = $promotion->created_at->toDateTimeString();
- $dto->updatedAt = $promotion->updated_at->toDateTimeString();
- $dto->customDiscountValue = $customDiscountValue;
- return $dto;
- }
- }
|