| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- declare(strict_types=1);
- namespace app\miniapi\service;
- use app\miniapi\support\PhoneNumber;
- use plugin\saiadmin\app\model\water\WaterEnterprise;
- use plugin\saiadmin\app\model\water\WaterEnterpriseAddress;
- final class EnterpriseAddressPresenter
- {
- public static function summary(WaterEnterpriseAddress $address, WaterEnterprise $enterprise): array
- {
- return [
- 'id' => (int) $address->id,
- 'enterprise_id' => (int) $enterprise->id,
- 'name' => $enterprise->name,
- 'employee_count' => $enterprise->employee_count === null ? null : (int) $enterprise->employee_count,
- 'label' => $address->label,
- 'contact' => $address->contact,
- 'phone' => PhoneNumber::mask($address->phone),
- 'address' => $address->address,
- 'region' => $address->region,
- 'longitude' => $address->longitude === null ? null : (float) $address->longitude,
- 'latitude' => $address->latitude === null ? null : (float) $address->latitude,
- 'is_default' => (int) $address->is_default === 1,
- 'status' => (int) $address->status,
- 'revision' => self::revision($address),
- ];
- }
- public static function detail(WaterEnterpriseAddress $address, WaterEnterprise $enterprise): array
- {
- return array_replace(self::summary($address, $enterprise), ['phone' => $address->phone]);
- }
- public static function revision(WaterEnterpriseAddress $address): string
- {
- return hash('sha256', json_encode($address->only([
- 'id',
- 'enterprise_id',
- 'label',
- 'contact',
- 'phone',
- 'region',
- 'address',
- 'longitude',
- 'latitude',
- 'is_default',
- 'status',
- 'updated_at',
- ]), JSON_THROW_ON_ERROR));
- }
- public static function legacy(WaterEnterprise $enterprise): array
- {
- return [
- 'id' => 0,
- 'enterprise_id' => (int) $enterprise->id,
- 'name' => $enterprise->name,
- 'employee_count' => $enterprise->employee_count === null ? null : (int) $enterprise->employee_count,
- 'label' => '主配送地址',
- 'contact' => $enterprise->contact,
- 'phone' => PhoneNumber::mask($enterprise->phone),
- 'address' => $enterprise->address,
- 'region' => $enterprise->region,
- 'longitude' => $enterprise->longitude === null ? null : (float) $enterprise->longitude,
- 'latitude' => $enterprise->latitude === null ? null : (float) $enterprise->latitude,
- 'is_default' => true,
- 'status' => (int) $enterprise->status,
- 'revision' => WaterPresenter::revision($enterprise),
- ];
- }
- }
|