Просмотр исходного кода

导出文件国际化;导出订单PDF国际化

kevin_zhangl 2 лет назад
Родитель
Сommit
f77f58de0f

+ 86 - 44
common/libs/export/BaseExport.php

@@ -190,6 +190,11 @@ class BaseExport extends Component {
      */
     public function getParams() {
         $this->params = CacheHelper::getAsyncParams($this->taskId);
+        
+        // 设置语言
+        Yii::$app->language = $this->params['language'] ?? 'en-US';
+        Yii::$app->sourceLanguage = Yii::$app->language == 'zh-CN' ? 'en-US' : 'zh-CN';
+
         return $this->params;
     }
 
@@ -512,6 +517,7 @@ class BaseExport extends Component {
         $extend = array_merge($extend, [
             'exportId' => $export->ID,
             'userId' => $params['userId'],
+            'language' => Yii::$app->language,
         ]);
         // 异步处理添加任务
         $taskKey = \Yii::$app->swooleAsyncTimer->asyncHandle($params['action'], $extend);
@@ -661,35 +667,53 @@ class BaseExport extends Component {
 EOT;
             }
 
+            $memberCode = Yii::t('ctx', 'memberCode');
+            $memberName = Yii::t('ctx', 'memberName');
+            $memberAddress = Yii::t('ctx', 'memberAddress');
+            $memberPhone = Yii::t('ctx', 'memberPhone');
+            $orderCode = Yii::t('ctx', 'orderCode');
+            $orderDetail = Yii::t('ctx', 'orderDetail');
+            $productCode = Yii::t('ctx', 'productCode');
+            $productName = Yii::t('ctx', 'productName');
+            $productPrice = Yii::t('ctx', 'productPrice');
+            $quantity = Yii::t('ctx', 'qty');
+            $taxRate = Yii::t('ctx', 'taxRate');
+            $totalTax = Yii::t('ctx', 'totalTax');
+            $totalAmount = Yii::t('ctx', 'totalAmount');
+            $total = Yii::t('ctx', 'total');
+            $signature = Yii::t('ctx', 'signature');
+            $date = Yii::t('ctx', 'date');
+            $createAt = Yii::t('ctx', 'createAt');
+
             // 订单基本信息
             $orderBase = <<<ORDER
             <table border="1" style="table-layout: fixed; padding: 10px 20px;" width="100%">
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Code</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberCode}</td>
                     <td width="70%">{$userId}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Name</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberName}</td>
                     <td width="70%">{$userName}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Address</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberAddress}</td>
                     <td width="70%">{$address}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Phone</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberPhone}</td>
                     <td width="70%">{$mobile}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Order Code</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$orderCode}</td>
                     <td width="70%">{$orderSn}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Creation Time</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$createAt}</td>
                     <td width="70%">{$orderAt}</td>
                 </tr>
                 <tr>
-                    <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">Order Detail</td>
+                    <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">{$orderDetail}</td>
                     <td class="bg"></td>
                 </tr>
             </table>
@@ -708,14 +732,14 @@ ORDER;
             <html lang="en">
             <head>
                 <meta charset="UTF-8" />
-                <title>Order detail</title>
+                <title>{$orderDetail}</title>
                 <style>
                     table {
                         border-collapse: collapse;
                     }
                     table td, table th {
                         border: 1px solid #ccc;
-                        padding: 5px 5px;
+                        /*padding: 5px 5px;*/
                         border-collapse: collapse;
                     }
                     /*td {*/
@@ -728,25 +752,25 @@ ORDER;
             </head>
             <body>
                 <div class="content">
-                    <p style="text-align: center; font-weight: bold; font-size: 22px;"><b>Order detail</b><br></p>
+                    <p style="text-align: center; font-weight: bold; font-size: 22px;"><b>{$orderDetail}</b><br></p>
                     <div>
                         <div style="display: block; width: 100%;">
                             {$orderBase}
                             
                             <table border="1" width="100%" style="padding: 10px 5px; text-align: center;">
                                 <tr>
-                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">Product Code</th>
-                                    <th width="25%" style="font-size: 14px; font-weight: bold; text-align: center;">Product Name</th>
-                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">Product Price</th>
-                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">Qty</th>
-                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">Tax Rate</th>
-                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">Tax</th>
-                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">Total Amount</th>
+                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productCode}</th>
+                                    <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productName}</th>
+                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productPrice}</th>
+                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">{$quantity}</th>
+                                    <th width="12%" style="font-size: 14px; font-weight: bold; text-align: center;">{$taxRate}</th>
+                                    <th width="13%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalTax}</th>
+                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalAmount}</th>
                                 </tr>
                                 {$orderDetails}
                                 <tr>
-                                    <td colspan="3">Total</td>
-                                    <td>{$orderNums}</td>
+                                    <td colspan="3">{$total}</td>
+                                    <td style="text-align: right;">{$orderNums}</td>
                                     <td></td>
                                     <td style="text-align: right;">{$totalTaxAmount}</td>
                                     <td style="text-align: right;">{$orderAmount}</td>
@@ -758,11 +782,11 @@ ORDER;
                             <table width="100%" style="border: none; padding: 10px 20px; text-align: center;">
                                 <tr style="border: none;">
                                     <td width="70%" style="border: none;"></td>
-                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">Signature:</td>
+                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">{$signature}:</td>
                                 </tr>
                                 <tr style="border: none;">
                                     <td width="70%" style="border: none;"></td>
-                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">Date:</td>
+                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">{$date}:</td>
                                 </tr>
                             </table>
                         </div>
@@ -916,35 +940,53 @@ ORDER;
 EOT;
             }
 
+            $memberCode = Yii::t('app', 'memberCode');
+            $memberName = Yii::t('app', 'memberName');
+            $memberAddress = Yii::t('app', 'memberAddress');
+            $memberPhone = Yii::t('app', 'memberPhone');
+            $orderCode = Yii::t('app', 'orderCode');
+            $orderDetail = Yii::t('app', 'orderDetail');
+            $productCode = Yii::t('app', 'productCode');
+            $productName = Yii::t('app', 'productName');
+            $productPrice = Yii::t('app', 'productPrice');
+            $quantity = Yii::t('app', 'qty');
+            $taxRate = Yii::t('app', 'taxRate');
+            $totalTax = Yii::t('app', 'totalTax');
+            $totalAmount = Yii::t('app', 'totalAmount');
+            $total = Yii::t('app', 'total');
+            $signature = Yii::t('app', 'signature');
+            $date = Yii::t('app', 'date');
+            $createAt = Yii::t('app', 'createAt');
+
             // 订单基本信息
             $orderBase = <<<ORDER
             <table border="1" style="table-layout: fixed; padding: 10px 20px;" width="100%">
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Code</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberCode}</td>
                     <td width="70%">{$userId}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Name</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberName}</td>
                     <td width="70%">{$userName}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Address</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberAddress}</td>
                     <td width="70%">{$address}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Member Phone</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$memberPhone}</td>
                     <td width="70%">{$mobile}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Order Code</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$orderCode}</td>
                     <td width="70%">{$orderSn}</td>
                 </tr>
                 <tr>
-                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">Creation Time</td>
+                    <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">{$createAt}</td>
                     <td width="70%">{$orderAt}</td>
                 </tr>
                 <tr>
-                    <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">Order Detail</td>
+                    <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">{$orderDetail}</td>
                     <td class="bg"></td>
                 </tr>
             </table>
@@ -955,22 +997,22 @@ ORDER;
             $l['a_meta_language'] = 'zh';
             $l['w_page'] = '页面';
 
-            $orderAmount = Tool::formatAmount($orderAmount);
-            $totalTaxAmount = Tool::formatAmount($totalTaxAmount);
+            $orderAmount = sprintf('%.2f', $orderAmount);
+            $totalTaxAmount = sprintf('%.2f', $totalTaxAmount);
 
             $context = <<<ORDER
             <!doctype html>
             <html lang="en">
             <head>
                 <meta charset="UTF-8" />
-                <title>Order detail</title>
+                <title>{$orderDetail}</title>
                 <style>
                     table {
                         border-collapse: collapse;
                     }
                     table td, table th {
                         border: 1px solid #ccc;
-                        padding: 5px 5px;
+                        /*padding: 5px 5px;*/
                         border-collapse: collapse;
                     }
                     /*td {*/
@@ -983,25 +1025,25 @@ ORDER;
             </head>
             <body>
                 <div class="content">
-                    <p style="text-align: center; font-weight: bold; font-size: 22px;"><b>Order detail</b><br></p>
+                    <p style="text-align: center; font-weight: bold; font-size: 22px;"><b>{$orderDetail}</b><br></p>
                     <div>
                         <div style="display: block; width: 100%;">
                             {$orderBase}
                             
                             <table border="1" width="100%" style="padding: 10px 5px; text-align: center;">
                                 <tr>
-                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">Product Code</th>
-                                    <th width="25%" style="font-size: 14px; font-weight: bold; text-align: center;">Product Name</th>
-                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">Product Price</th>
-                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">Qty</th>
-                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">Tax Rate</th>
-                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">Tax</th>
-                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">Total Amount</th>
+                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productCode}</th>
+                                    <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productName}</th>
+                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$productPrice}</th>
+                                    <th width="10%" style="font-size: 14px; font-weight: bold; text-align: center;">{$quantity}</th>
+                                    <th width="12%" style="font-size: 14px; font-weight: bold; text-align: center;">{$taxRate}</th>
+                                    <th width="13%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalTax}</th>
+                                    <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">{$totalAmount}</th>
                                 </tr>
                                 {$orderDetails}
                                 <tr>
-                                    <td colspan="3">Total</td>
-                                    <td>{$orderNums}</td>
+                                    <td colspan="3">{$total}</td>
+                                    <td style="text-align: right;">{$orderNums}</td>
                                     <td></td>
                                     <td style="text-align: right;">{$totalTaxAmount}</td>
                                     <td style="text-align: right;">{$orderAmount}</td>
@@ -1013,11 +1055,11 @@ ORDER;
                             <table width="100%" style="border: none; padding: 10px 20px; text-align: center;">
                                 <tr style="border: none;">
                                     <td width="70%" style="border: none;"></td>
-                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">Signature:</td>
+                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">{$signature}:</td>
                                 </tr>
                                 <tr style="border: none;">
                                     <td width="70%" style="border: none;"></td>
-                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">Date:</td>
+                                    <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">{$date}:</td>
                                 </tr>
                             </table>
                         </div>

+ 11 - 1
common/messages/en-US/ctx.php

@@ -302,7 +302,17 @@ return [
     'shopOrderPayBV' => 'Pay BV',
     'total' => 'Total',
     'date' => 'Date',
-    
+    'orderCode' => 'Order Code',
+    'orderDetail' => 'Order Detail',
+    'productCode' => 'Product Code',
+    'productName' => 'Product Name',
+    'productPrice' => 'Product Price',
+    'qty' => 'Qty',
+    'taxRate' => 'Tax Rate',
+    'totalTax' => 'Total Tax',
+    'totalAmount' => 'Total Amount',
+    'signature' => 'Signature',
+
     #Log
     'adminUserDoesNotExist'  => 'Administrator does not exist',
     'adminUserGroupDoesNotExist'  => 'Management group does not exist',

+ 11 - 0
common/messages/zh-CN/ctx.php

@@ -302,6 +302,16 @@ return [
     'shopOrderPayBV' => '支付BV',
     'total' => '总计',
     'date' => '日期',
+    'orderCode' => '订单号',
+    'orderDetail' => '订单详情',
+    'productCode' => '商品编号',
+    'productName' => '商品名字',
+    'productPrice' => '商品价格',
+    'qty' => '数量',
+    'taxRate' => '税率',
+    'totalTax' => '数额总计',
+    'totalAmount' => '总金额',
+    'signature' => '签名',
 
     #Log
     'adminUserDoesNotExist'  => '管理员不存在',
@@ -420,6 +430,7 @@ return [
     'memberCode' => '会员编号',
     'memberName' => '会员姓名',
     'memberAddress' => '收货地址',
+    'memberPhone' => '手机号',
     'loginStatus' => '登录状态',
     'allowLogin' => '允许登录',
     'prohibitLogin' => '禁止登录',

+ 22 - 0
console/config/main.php

@@ -8,6 +8,7 @@ $params = array_merge(
 
 return [
     'language' => 'zh-CN',
+    'sourceLanguage' => 'en-US',
     'timeZone' => 'PRC',
     'id' => 'app-console',
     'basePath' => dirname(__DIR__),
@@ -52,6 +53,27 @@ return [
                 ],*/
             ],
         ],
+        // 多语言
+        'i18n' => [
+            'translations' => [
+                'app*' => [
+                    'class' => 'yii\i18n\PhpMessageSource',
+                    'basePath' => '@common/messages',
+                    'fileMap' => [
+                        'app' => 'app.php',
+                        'app/error' => 'error.php',
+                    ],
+                ],
+                'ctx*' => [
+                    'class' => 'yii\i18n\PhpMessageSource',
+                    'basePath' => '@common/messages',
+                    'fileMap' => [
+                        'ctx' => 'ctx.php',
+                        'ctx/error' => 'error.php',
+                    ],
+                ],
+            ],
+        ],
     ],
     'params' => $params,
 ];