From c6b986f06f7070a4c5f7abd2b5f9ff8c4fe86de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Wed, 7 May 2025 20:13:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9A=90=E8=97=8F=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 19 +++++++++++++++++++ application/common/model/Order.php | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/application/common.php b/application/common.php index 088dccd..bdabd39 100755 --- a/application/common.php +++ b/application/common.php @@ -525,3 +525,22 @@ if (!function_exists('dd')) { } } +if (!function_exists('maskExceptFirstChar')) { + /** + * 将字符串的首个字符保留,其余字符全部替换为 * + */ + function maskExceptFirstChar(string $str): string + { + $length = mb_strlen($str, 'UTF-8'); + + if ($length <= 1) { + return $str; + } + + $firstChar = mb_substr($str, 0, 1, 'UTF-8'); + $masked = str_repeat('*', $length - 1); + + return $firstChar . $masked; + } +} + diff --git a/application/common/model/Order.php b/application/common/model/Order.php index 2c60e3b..58c144c 100644 --- a/application/common/model/Order.php +++ b/application/common/model/Order.php @@ -18,4 +18,9 @@ class Order extends Model { return $this->belongsTo(\app\admin\model\Area::class,'area_id', 'area_code'); } + + public function getCustomerAttr(string $val) + { + return maskExceptFirstChar($val); + } }