定制 izopi4a/econt-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

izopi4a/econt-bundle

Composer 安装命令:

composer require izopi4a/econt-bundle

包简介

econt curier bundle for symfony

README 文档

README

api docs by econt here: https://www.econt.com/developers/soap-json-api.html This doesn't cover all the Econt API. I developed what I needed, if you need help or more APIs just open an issue I will add them.

Install

composer require izopi4a/econt-bundle

Post install

add this to your enviorment variables

IZOPI4A_ECONT_USER=
IZOPI4A_ECONT_PASS=
IZOPI4A_ECONT_LOCALE=BG
IZOPI4A_ECONT_DEV=true

Usage

It is a service, so you can autowire it. Example:

#[Route('/{_locale<%app.supported_locales%>}', name: 'app_home')]
public function index(EcontService $econtService): Response
{

    $offices_in_sofia = $econtService->getOfficesInCity(41);
    
    dd($offices_in_sofia)
}

Calculating delivery

$sender = new \Izopi4a\EcontBundle\Service\Http\Payload\Party();
$sender->setTypeSender();
$sender->setOffice(1000);


$receiver = new \Izopi4a\EcontBundle\Service\Http\Payload\Party();
$receiver->setTypeReciever();
// to specify office use
//$receiver->setOffice(1100);
//to specify home address use
$receiver->setAddress(41, "Незабравка", 31, "");

$package = new \Izopi4a\EcontBundle\Service\Http\Payload\Package();
$package->setWeight(1);
$package->setDescription("обувки");
$package->setCount(2);
//to add cash on delivery uncomment
//$package->addCashOnDelivery(200);

$sender_contact = new \Izopi4a\EcontBundle\Service\Http\Payload\Contact();
$sender_contact->setName("Иван Иванов");
$sender_contact->addPhone("0888888888");
$sender_contact->setTypeSender();

$receiver_contact = new \Izopi4a\EcontBundle\Service\Http\Payload\Contact();
$receiver_contact->setName("Иван Иванов");
$receiver_contact->addPhone("0888888888");
$receiver_contact->setTypeReciever();

$shipment = $econtService->calculateDelivery($sender, $receiver, $package, $sender_contact, $receiver_contact);

//you can check for errors with $shipment->getErrors() or $shipment->hasErrors()

dd($shipment->getTotalPrice(), $shipment);

Getting all the cities

I didn't find an option to filter the cities, so Econt are returning ~6k cities, in my case I store them in my database so I can use them faster. Example entity / php bin/console make:entity City

<?php

namespace App\Entity;

use App\Repository\CityRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: CityRepository::class)]
class City
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    private ?string $name_bg = null;

    #[ORM\Column(length: 255)]
    private ?string $name_en = null;

    #[ORM\Column(nullable: true)]
    private ?int $econt_id = null;

    #[ORM\Column(nullable: true)]
    private ?int $speedy_id = null;

    #[ORM\Column(length: 255)]
    private ?string $post_code = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getNameBg(): ?string
    {
        return $this->name_bg;
    }

    public function setNameBg(string $name_bg): static
    {
        $this->name_bg = $name_bg;

        return $this;
    }

    public function getNameEn(): ?string
    {
        return $this->name_en;
    }

    public function setNameEn(string $name_en): static
    {
        $this->name_en = $name_en;

        return $this;
    }

    public function getEcontId(): ?int
    {
        return $this->econt_id;
    }

    public function setEcontId(?int $econt_id): static
    {
        $this->econt_id = $econt_id;

        return $this;
    }

    public function getSpeedyId(): ?int
    {
        return $this->speedy_id;
    }

    public function setSpeedyId(?int $speedy_id): static
    {
        $this->speedy_id = $speedy_id;

        return $this;
    }

    public function getPostCode(): ?string
    {
        return $this->post_code;
    }

    public function setPostCode(string $post_code): static
    {
        $this->post_code = $post_code;

        return $this;
    }
}

and example command. Just use php bin/console to start the command. And then replace execute method

protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $repo = $this->entityManager->getRepository(City::class);
        $inserted = 0;

        $items = $this->econtService->getAllCitiesInCountry();

        foreach ($items as $econtCity) {
            $exists = $repo->findOneBy(['econt_id' => $econtCity->getId()]);

            if (!$exists) {
                $city = new City();
                $city->setNameBg($econtCity->getName());
                $city->setNameEn($econtCity->getNameEn());
                $city->setEcontId($econtCity->getId());
                $city->setPostCode($econtCity->getPostCode());
                $this->entityManager->persist($city);
                $inserted++;
            }
        }

        $this->entityManager->flush();

        $io->success('Done. Inserted '.$inserted.' cities.');

        return Command::SUCCESS;
    }

izopi4a/econt-bundle 适用场景与选型建议

izopi4a/econt-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 izopi4a/econt-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 izopi4a/econt-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 izopi4a/econt-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-03