Explorar o código

feat(wechat): 新增微信快递公司管理功能

- 添加快递公司数据表迁移文件,包含快递公司ID、名称、散单支持等字段
- 创建快递公司模型和实体类,定义数据结构和类型转换
- 实现快递服务类,提供获取所有快递公司的方法
- 集成微信小程序客户端,支持从微信接口同步快递公司数据
- 添加快递服务单元测试,验证数据获取和同步逻辑
- 移除IDEA编辑器相关的忽略文件配置
runphp hai 4 meses
pai
achega
add8d58268

+ 0 - 8
.idea/.gitignore

@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml

+ 34 - 0
database/migrations/20251121023409_wechat_delivery.php

@@ -0,0 +1,34 @@
+<?php
+
+declare(strict_types=1);
+
+use Phinx\Migration\AbstractMigration;
+
+final class WechatDelivery extends AbstractMigration
+{
+
+    /**
+     * Change Method.
+     *
+     * Write your reversible migrations using this method.
+     *
+     * More information on writing migrations is available here:
+     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
+     *
+     * Remember to call "create()" or "update()" and NOT "save()" when working
+     * with the Table class.
+     */
+    public function change(): void
+    {
+        $this->table('wechat_delivery', ['signed' => false, 'comment' => '微信快递公司列表'])
+            ->addColumn('delivery_id', 'string', ['limit' =>32, 'comment' => '快递公司 ID'])
+            ->addColumn('delivery_name', 'string', ['comment' => '快递公司名称'])
+            ->addColumn('can_use_cash', 'tinyinteger', ['signed' => false, 'comment' => '是否支持散单, 1表示支持'])
+            ->addColumn('can_get_quota', 'tinyinteger', ['signed' => false, 'comment' => '是否支持查询面单余额, 1表示支持'])
+            ->addColumn('service_type', 'json', ['comment' => '支持的服务类型'])
+            ->addColumn('cash_biz_id', 'string', ['limit' => 32, 'comment' => '散单对应的bizid,当can_use_cash=1时有效'])
+            ->addTimestamps('create_time', 'update_time')
+            ->addIndex(['delivery_id'], ['unique' => true])
+            ->create();
+    }
+}

+ 13 - 0
src/Entity/WechatDeliveryEntity.php

@@ -0,0 +1,13 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Wechat\Entity;
+
+use SixShop\Core\Entity\BaseEntity;
+use SixShop\Wechat\Model\WechatDeliveryModel;
+
+/**
+ * @mixin WechatDeliveryModel
+ */
+class WechatDeliveryEntity extends BaseEntity
+{
+}

+ 22 - 0
src/Model/WechatDeliveryModel.php

@@ -0,0 +1,22 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Wechat\Model;
+
+use think\Model;
+
+class WechatDeliveryModel extends Model
+{
+    protected function getOptions(): array
+    {
+        return [
+            'name' => 'wechat_delivery',
+            'type' => [
+                'can_use_cash' => 'boolean',
+                'can_get_quota' => 'boolean',
+                'service_type' => 'array'
+            ]
+        ];
+    }
+
+}

+ 27 - 0
src/Service/ExpressService.php

@@ -0,0 +1,27 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Wechat\Service;
+
+use SixShop\Wechat\Entity\WechatDeliveryEntity;
+use think\Collection;
+
+class ExpressService
+{
+    public function __construct(private MiniApp $miniApp, private WechatDeliveryEntity $wechatDeliveryEntity)
+    {
+    }
+
+    /**
+     * 获取所有快递公司
+     */
+    public function getAllDelivery(): Collection
+    {
+        $result = $this->wechatDeliveryEntity->select();
+        if ($result->isEmpty()) {
+            $response = $this->miniApp->getClient()->get('/cgi-bin/express/business/delivery/getall');
+            $result = $response->toArray();
+            $result = $this->wechatDeliveryEntity->saveAll($result['data']);
+        }
+        return $result;
+    }
+}

+ 22 - 0
test/Service/ExpressServiceTest.php

@@ -0,0 +1,22 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Wechat\Service;
+
+use PHPUnit\Framework\Attributes\Test;
+use PHPUnit\Framework\TestCase;
+
+class ExpressServiceTest extends TestCase
+{
+    private ExpressService $expressService;
+    protected function setUp(): void
+    {
+        $this->expressService = app(ExpressService::class);
+    }
+
+    #[Test]
+    public function getAllDelivery()
+    {
+        $res = $this->expressService->getAllDelivery();
+        dump($res);
+    }
+}