diff --git a/app/common/lib/pinyin/PinyinNumber.php b/app/common/lib/pinyin/PinyinNumber.php new file mode 100644 index 0000000..583f5b3 --- /dev/null +++ b/app/common/lib/pinyin/PinyinNumber.php @@ -0,0 +1,50 @@ + 'ling', 1 => 'yi', 2 => 'er', 3 => 'san', 4 => 'si', 5 => 'wu', 6 => 'liu', 7 => 'qi', 8 => 'ba', 9 => 'jiu']; + + protected static $unit = ['', 'shi', 'bai', 'qian', 'wan', 'shiwan', 'baiwan', 'qianwan', 'yi']; + + /** + * 获取数字的拼音 + * @param $number + * @param $strtoupper // 返回大写 + * @return string + */ + public static function getPinyin($number,$strtoupper = false) + { + $number = strval($number); // 将数字转换为字符串 + $length = strlen($number); + $pinyinStr = ''; + + for ($i = 0; $i < $length; $i++) { + $digit = intval($number[$i]); + + if ($digit != 0) { + // 处理万以上的位数 + if ($length - $i > 4) { + $pinyinStr .= self::$pinyin[$digit] . self::$unit[$length - $i - 1]; + // 处理万位之间的零 + if ($digit == 0 && $number[$i + 1] != 0) { + $pinyinStr .= 'ling'; + } + } else { + $pinyinStr .= self::$pinyin[$digit] . self::$unit[$length - $i - 1]; + } + } else { + // 处理连续的0 + if ($i == 0 || $number[$i] != 0) { + $pinyinStr .= self::$pinyin[$digit]; + } + } + } + if ($strtoupper) $pinyinStr = strtoupper($pinyinStr); + return $pinyinStr; + } +} diff --git a/app/logic/Zone.php b/app/logic/Zone.php index ecb388f..976a03d 100644 --- a/app/logic/Zone.php +++ b/app/logic/Zone.php @@ -1,6 +1,7 @@ $v) { + $data[$key][$k]['amount'] = rtrim($v['amount'],'.00'); unset($data[$key][$k]['id']); } } @@ -232,14 +234,17 @@ class Zone break; } } - + $amount = rtrim($selectedPattern['amount'],'.00'); + $pinyin = PinyinNumber::getPinyin(100000,true); $data[$i][] = [ - 'amount' => $selectedPattern['amount'], + 'amount' => $amount, + 'pinyin' => $pinyin, 'image' => get_image_url($selectedPattern['image']) ]; $save_data[$i][] = [ 'id' => $selectedPattern['id'], - 'amount' => $selectedPattern['amount'], + 'amount' => $amount, + 'pinyin' => $pinyin, 'image' => get_image_url($selectedPattern['image']) ]; }