// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\common\service\goods\source; use app\common\service\BaseService; use app\common\enum\order\OrderSource as OrderSourceEnum; /** * 商品来源工厂类 * Class Factory * @package app\common\service\stock */ class Factory extends BaseService { // 订单来源的结算台服务类 private static array $class = [ OrderSourceEnum::MAIN => Main::class, OrderSourceEnum::BARGAIN => Bargain::class, OrderSourceEnum::SHARP => Sharp::class, OrderSourceEnum::GROUPON => Groupon::class ]; /** * 根据订单来源获取商品库存类 * @param int $orderSource * @return mixed */ public static function getFactory(int $orderSource = OrderSourceEnum::MAIN) { static $classObj = []; if (!isset($classObj[$orderSource])) { $classObj[$orderSource] = new static::$class[$orderSource]; } return $classObj[$orderSource]; } }