"; } $result = $result . $orderNameEmpty; } $result = $result . $quantityStr . str_repeat(" ", self::MAX_QUANTITY_CHAR_LEN - $quantityLen); $result = $result . $priceStr . str_repeat(" ", self::MAX_PRICE_CHAR_LEN - $priceLen); // $result = ''.$result . "
"; return $result; } /** * 大趋智能格式化菜品列表(用于58mm打印机) * @param $foodName * @param $quantity * @param $price * @return string */ public static function trenditFormatOrderItem($foodName, $quantity, $price) { $orderNameEmpty = str_repeat(" ", self::MAX_NAME_CHAR_LEN); $foodNameLen = self::CalcGbkLenForPrint($foodName); // print("foodNameLen=".$foodNameLen."\n"); $quantityStr = '*' . $quantity; $quantityLen = self::CalcAsciiLenForPrint($quantityStr); // print("quantityLen=".$quantityLen."\n"); $priceStr = '' . round($price, 2); $priceLen = self::CalcAsciiLenForPrint($priceStr); // print("priceLen=".$priceLen); $result = $foodName; $mod = $foodNameLen % self::ROW_MAX_CHAR_LEN; // print("mod=".$mod."\n"); if ($mod <= self::LAST_ROW_MAX_NAME_CHAR_LEN) { // 保证各个列的宽度固定,不足部分,利用空格填充 //make sure all the column length fixed, fill with space if not enough $result = $result . str_repeat(" ", self::MAX_NAME_CHAR_LEN - $mod); } else { // 另起新行 // new line // $result = $result . '
'; $result = $result . $orderNameEmpty; } $result = $result . $quantityStr . str_repeat(" ", self::MAX_QUANTITY_CHAR_LEN - $quantityLen); $result = $result . $priceStr . str_repeat(" ", self::MAX_PRICE_CHAR_LEN - $priceLen); $result = ''.$result . '
'; return $result; } public static function CalcGbkLenForPrint($data) { return (strlen($data) + mb_strlen($data, "UTF8")) / 2; } public static function CalcAsciiLenForPrint($data) { return strlen($data); } /** * @return string */ public function getErrorMsg(): string { return $this->errorMsg; } }