diff --git a/application/admin/command/AreaPinyinCommand.php b/application/admin/command/AreaPinyinCommand.php new file mode 100644 index 0000000..d49b6ee --- /dev/null +++ b/application/admin/command/AreaPinyinCommand.php @@ -0,0 +1,40 @@ +setName('area:pinyin') + ->setDescription('批量生成区域名称的拼音'); + } + + protected function execute(Input $input, Output $output) + { + $pinyin = new Pinyin(); + + // 读取 `area` 表所有数据 + $areas = Db::name('areas')->where('id','>',1738)->select(); + + foreach ($areas as $area) { + $fullPinyin = strtolower(str_replace(' ','',$pinyin->name($area['short_name'],Converter::TONE_STYLE_NONE))); // 全拼 + $abbrPinyin = strtolower(str_replace(' ','',$pinyin->abbr($area['short_name']))); // 首字母 + // 更新数据库 + Db::name('areas') + ->where('id', $area['id']) + ->update(['pinyin' => $fullPinyin, 'abbr' => $abbrPinyin]); + + $output->writeln("更新: {$area['merge_name']} -> {$fullPinyin} ({$abbrPinyin})"); + } + + $output->writeln("拼音转换完成!"); + } +} diff --git a/application/admin/controller/Area.php b/application/admin/controller/Area.php index 89edbe1..be5df7e 100644 --- a/application/admin/controller/Area.php +++ b/application/admin/controller/Area.php @@ -19,9 +19,22 @@ class Area extends Backend $this->success(data:[]); }else{ $data = model('area') - ->where('merge_name','like','%'.$keyword.'%') ->where('level','=',3) + ->where(function ($query)use ($keyword){ + $query->where('merge_name','like','%'.$keyword.'%') + ->whereOr('pinyin', 'like', "%{$keyword}%") + ->whereOr('abbr', 'like', "%{$keyword}%"); + }) + ->field('area_code, merge_name') + ->orderRaw( + "CASE + WHEN name LIKE '{$keyword}%' THEN 1 + WHEN pinyin LIKE '{$keyword}%' THEN 2 + WHEN abbr LIKE '{$keyword}%' THEN 3 + ELSE 4 + END" + ) ->limit(0,10) ->select(); $this->success(data:$data); diff --git a/application/command.php b/application/command.php index ab4178a..ba52d02 100755 --- a/application/command.php +++ b/application/command.php @@ -17,4 +17,5 @@ return [ 'app\admin\command\Min', 'app\admin\command\Addon', 'app\admin\command\Api', + 'app\admin\command\AreaPinyinCommand', ]; diff --git a/composer.json b/composer.json index 68fca10..64a383d 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "topthink/think-queue": "1.1.6", "topthink/think-helper": "^1.0.7", "karsonzhang/fastadmin-addons": "~1.4.0", - "overtrue/pinyin": "^3.0", + "overtrue/pinyin": "^5.3", "phpoffice/phpspreadsheet": "^1.29.1", "overtrue/wechat": "^4.6", "ext-json": "*", diff --git a/composer.lock b/composer.lock index cae54f9..2d00e40 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "da8316e5b18922be071cdeaf00c4d962", + "content-hash": "fe3829381cb87e4cad3751a2d797da6e", "packages": [ { "name": "composer/pcre", @@ -790,31 +790,63 @@ }, { "name": "overtrue/pinyin", - "version": "3.0.6", + "version": "5.3.3", + "source": { + "type": "git", + "url": "https://github.com/overtrue/pinyin.git", + "reference": "bff15b27cf3e1cc416464b678576f4da9899692e" + }, "dist": { "type": "zip", - "url": "https://mirrors.cloud.tencent.com/repository/composer/overtrue/pinyin/3.0.6/overtrue-pinyin-3.0.6.zip", - "reference": "3b781d267197b74752daa32814d3a2cf5d140779", - "shasum": "" + "url": "https://api.github.com/repos/overtrue/pinyin/zipball/bff15b27cf3e1cc416464b678576f4da9899692e", + "reference": "bff15b27cf3e1cc416464b678576f4da9899692e", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] }, "require": { - "php": ">=5.3" + "php": ">=8.0.2" }, "require-dev": { - "phpunit/phpunit": "~4.8" + "brainmaestro/composer-git-hooks": "^3.0", + "friendsofphp/php-cs-fixer": "^3.2", + "laravel/pint": "^1.10", + "nunomaduro/termwind": "^1.0|^2.0", + "phpunit/phpunit": "^10.0|^11.2" }, + "bin": [ + "bin/pinyin" + ], "type": "library", + "extra": { + "hooks": { + "pre-push": [ + "composer pint", + "composer test" + ], + "pre-commit": [ + "composer pint", + "composer test" + ] + } + }, "autoload": { "psr-4": { "Overtrue\\Pinyin\\": "src/" } }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { - "name": "Carlos", + "name": "overtrue", + "email": "anzhengchao@gmail.com", "homepage": "http://github.com/overtrue" } ], @@ -827,9 +859,15 @@ ], "support": { "issues": "https://github.com/overtrue/pinyin/issues", - "source": "https://github.com/overtrue/pinyin/tree/master" + "source": "https://github.com/overtrue/pinyin/tree/5.3.3" }, - "time": "2017-07-10T07:20:01+00:00" + "funding": [ + { + "url": "https://github.com/overtrue", + "type": "github" + } + ], + "time": "2024-08-01T08:19:06+00:00" }, { "name": "overtrue/socialite", @@ -2592,6 +2630,6 @@ "ext-pdo": "*", "ext-bcmath": "*" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/public/assets/js/backend/order.js b/public/assets/js/backend/order.js index 1e577a9..b662eed 100644 --- a/public/assets/js/backend/order.js +++ b/public/assets/js/backend/order.js @@ -187,7 +187,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin console.error("请求失败"); } }); - }, 200); // 500 毫秒防抖 + }, 400); // 500 毫秒防抖 }); // 渲染城市下拉选项 @@ -246,7 +246,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin console.error("请求失败"); } }); - }, 200); // 500 毫秒防抖 + }, 400); // 500 毫秒防抖 }); // 渲染城市下拉选项