Browse Source

refactor(wechat): 移除 Column 依赖并优化代码风格

runphp 1 tháng trước cách đây
mục cha
commit
27e4273f72

+ 2 - 1
config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return json_decode(<<<'JSON'
@@ -159,4 +160,4 @@ return json_decode(<<<'JSON'
     "_fc_drag_tag": "group"
   }
 ]
-JSON, true);
+JSON, true);

+ 6 - 7
database/migrations/20250709013140_extension_wechat_user.php

@@ -1,7 +1,6 @@
 <?php
 
 use Phinx\Migration\AbstractMigration;
-use think\migration\db\Column;
 
 class ExtensionWechatUser extends AbstractMigration
 {
@@ -30,13 +29,13 @@ class ExtensionWechatUser extends AbstractMigration
     {
         $table = $this->table('extension_wechat_user', ['engine' => 'InnoDB', 'comment' => '微信用户表']);
         $table
-            ->addColumn(Column::integer('user_id')->setSigned(false)->setComment('用户ID'))
-            ->addColumn(Column::string('openid')->setComment('微信openid'))
-            ->addColumn(Column::string('appid')->setComment('微信appid'))
-            ->addColumn(Column::string('nickname')->setComment('昵称'))
-            ->addColumn(Column::string('avatar')->setComment('头像'))
+            ->addColumn('user_id', 'integer', ['signed' => false, 'comment' => '用户ID'])
+            ->addColumn('openid', 'string', ['comment' => '微信openid'])
+            ->addColumn('appid', 'string', ['comment' => '微信appid'])
+            ->addColumn('nickname', 'string', ['comment' => '昵称'])
+            ->addColumn('avatar', 'string', ['comment' => '头像'])
             ->addTimestamps('create_time', 'update_time')
-            ->addSoftDelete()
+            ->addColumn('delete_time', 'timestamp', ['null' => true, 'default' => null])
             ->create();
     }
 }

+ 0 - 1
database/migrations/20250709024603_extension_wechat_user_add_session_key.php

@@ -1,7 +1,6 @@
 <?php
 
 use Phinx\Migration\AbstractMigration;
-use think\migration\db\Column;
 
 class ExtensionWechatUserAddSessionKey extends AbstractMigration
 {

+ 1 - 2
database/migrations/20251121023409_wechat_delivery.php

@@ -6,7 +6,6 @@ use Phinx\Migration\AbstractMigration;
 
 final class WechatDelivery extends AbstractMigration
 {
-
     /**
      * Change Method.
      *
@@ -21,7 +20,7 @@ final class WechatDelivery extends AbstractMigration
     public function change(): void
     {
         $this->table('wechat_delivery', ['signed' => false, 'comment' => '微信快递公司列表'])
-            ->addColumn('delivery_id', 'string', ['limit' =>32, 'comment' => '快递公司 ID'])
+            ->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表示支持'])

+ 1 - 0
info.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return [

+ 2 - 1
route/admin.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 // API路由
@@ -7,4 +8,4 @@ declare(strict_types=1);
 use SixShop\Wechat\Controller\DeliveryController;
 use think\facade\Route;
 
-Route::resource('delivery', DeliveryController::class)->only(['index']);
+Route::resource('delivery', DeliveryController::class)->only(['index']);

+ 2 - 1
route/api.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 // API路由
@@ -11,4 +12,4 @@ Route::group('user', function () {
     Route::get('phone_number', [UserController::class, 'phoneNumber']);
     Route::get('session', [UserController::class, 'session']);
     Route::delete('', [UserController::class, 'delete']);
-})->middleware(['auth']);
+})->middleware(['auth']);

+ 1 - 0
src/ChineseUtil.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat;

+ 5 - 2
src/Controller/DeliveryController.php

@@ -1,15 +1,18 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Controller;
 
 use SixShop\Wechat\Entity\WechatDeliveryEntity;
 use think\Response;
+
 use function SixShop\Core\page_response;
 
 class DeliveryController
 {
-    public function index(WechatDeliveryEntity $wechatDeliveryEntity):Response
+    public function index(WechatDeliveryEntity $wechatDeliveryEntity): Response
     {
         return page_response($wechatDeliveryEntity->paginate(100));
     }
-}
+}

+ 4 - 1
src/Controller/UserController.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Controller;
 
 use app\model\User;
@@ -7,6 +9,7 @@ use SixShop\Core\Request;
 use SixShop\Wechat\Entity\ExtensionWechatUserEntity;
 use SixShop\Wechat\Service\MiniApp;
 use think\Response;
+
 use function SixShop\Core\success_response;
 use function SixShop\Core\throw_logic_exception;
 
@@ -55,4 +58,4 @@ class UserController
         }
         return success_response($wechatUser->delete());
     }
-}
+}

+ 2 - 1
src/Cron/AccessTokenCron.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Cron;
@@ -66,4 +67,4 @@ class AccessTokenCron extends BaseJob
         }
         return $expireIn;
     }
-}
+}

+ 2 - 2
src/Entity/ExtensionWechatUserEntity.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Entity;
@@ -14,7 +15,6 @@ use think\facade\Event;
  */
 class ExtensionWechatUserEntity extends BaseEntity
 {
-
     public function getUserID(string $code, ?string $appID = null): int
     {
         $miniApp = app()->make(MiniApp::class, [$appID]);
@@ -58,4 +58,4 @@ class ExtensionWechatUserEntity extends BaseEntity
         $data = json_decode($content, true);
         return $data['phone_info'];
     }
-}
+}

+ 3 - 1
src/Entity/WechatDeliveryEntity.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Entity;
 
 use SixShop\Core\Entity\BaseEntity;
@@ -10,4 +12,4 @@ use SixShop\Wechat\Model\WechatDeliveryModel;
  */
 class WechatDeliveryEntity extends BaseEntity
 {
-}
+}

+ 4 - 2
src/Enum/WechatOrderStateEnum.php

@@ -1,8 +1,10 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Enum;
 
-enum WechatOrderStateEnum:int
+enum WechatOrderStateEnum: int
 {
     /**
      * 待发货
@@ -46,4 +48,4 @@ enum WechatOrderStateEnum:int
             default => '未知状态',
         };
     }
-}
+}

+ 2 - 1
src/Extension.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat;
@@ -32,4 +33,4 @@ class Extension extends ExtensionAbstract
             AccessTokenCron::class,
         ];
     }
-}
+}

+ 3 - 1
src/Facade/WechatUser.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Facade;
 
 use think\Facade;
@@ -13,4 +15,4 @@ class WechatUser extends Facade
     {
         return \SixShop\Wechat\WechatUser::class;
     }
-}
+}

+ 2 - 2
src/Hook/WechatUserHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Hook;
@@ -10,7 +11,6 @@ use SixShop\Wechat\Model\ExtensionWechatUserModel;
 
 class WechatUserHook
 {
-
     #[Hook(UserDeletedEvent::class)]
     public function deleteWechatUser(UserDeletedEvent $event): void
     {
@@ -30,4 +30,4 @@ class WechatUserHook
         }
         $event->userInfo['wechat_openid'] = $user->openid;
     }
-}
+}

+ 2 - 1
src/Model/ExtensionWechatUserModel.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Model;
@@ -28,4 +29,4 @@ class ExtensionWechatUserModel extends Model
             'name' => 'extension_wechat_user'
         ];
     }
-}
+}

+ 2 - 1
src/Model/WechatDeliveryModel.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Model;
@@ -19,4 +20,4 @@ class WechatDeliveryModel extends Model
         ];
     }
 
-}
+}

+ 4 - 3
src/Service/ExpressService.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Service;
@@ -6,6 +7,7 @@ namespace SixShop\Wechat\Service;
 use SixShop\Wechat\Entity\WechatDeliveryEntity;
 use think\Collection;
 use think\facade\Log;
+
 use function SixShop\Core\throw_logic_exception;
 
 class ExpressService
@@ -70,8 +72,7 @@ class ExpressService
         int    $logisticsType = 1,
         int    $deliveryMode = 1,
         bool   $isAllDelivered = false,
-    ): void
-    {
+    ): void {
         $data = [
             'order_key' => [
                 'order_number_type' => 2, // 使用微信支付单号
@@ -97,4 +98,4 @@ class ExpressService
             throw_logic_exception(msg: '发货信息录入失败', code: $responseData['errcode']);
         }
     }
-}
+}

+ 2 - 1
src/Service/MiniApp.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Service;
@@ -37,4 +38,4 @@ class MiniApp extends Application
         parent::__construct($config);
         $this->setCache(Cache::instance());
     }
-}
+}

+ 2 - 2
src/WechatUser.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat;
@@ -7,7 +8,6 @@ use SixShop\Wechat\Model\ExtensionWechatUserModel;
 
 readonly class WechatUser
 {
-
     /**
      * 获取用户openid
      */
@@ -15,4 +15,4 @@ readonly class WechatUser
     {
         return ExtensionWechatUserModel::where(['user_id' => $userID])->value('openid');
     }
-}
+}

+ 2 - 2
tests/ChineseUtilTest.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat;
@@ -7,11 +8,10 @@ use PHPUnit\Framework\TestCase;
 
 class ChineseUtilTest extends TestCase
 {
-
     public function testRandomCreateChinese()
     {
         $chinese = ChineseUtil::randomCreateChinese();
         $this->assertSame(1, mb_strlen($chinese, 'UTF-8'));
         ChineseUtil::randomChineseName();
     }
-}
+}

+ 3 - 1
tests/Cron/AccessTokenCronTest.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Cron;
 
 use PHPUnit\Framework\Attributes\Test;
@@ -17,4 +19,4 @@ class AccessTokenCronTest extends TestCase
     {
         $this->accessTokenCron->refreshMiniAppAccessToken();
     }
-}
+}

+ 2 - 1
tests/Entity/ExtensionWechatUserEntityTest.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Entity;
@@ -11,4 +12,4 @@ class ExtensionWechatUserEntityTest extends TestCase
     {
         app(ExtensionWechatUserEntity::class)->getUserID('code');
     }
-}
+}

+ 3 - 1
tests/Service/ExpressServiceTest.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\Wechat\Service;
 
 use PHPUnit\Framework\Attributes\Test;
@@ -26,4 +28,4 @@ class ExpressServiceTest extends TestCase
         $res = $this->expressService->queryOrder('4200002925202511205107137676');
         dump($res);
     }
-}
+}

+ 2 - 1
tests/Service/MiniAppTest.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\Wechat\Service;
@@ -24,4 +25,4 @@ class MiniAppTest extends TestCase
             'env_version' => 'develop'
         ]);
     }
-}
+}