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

feat: EK-3320: 订单增加 Invoice 下载

zhangl 1 месяц назад
Родитель
Сommit
bbdb820e40
3 измененных файлов с 38 добавлено и 7 удалено
  1. 26 0
      common/helpers/Tool.php
  2. 11 7
      common/libs/export/BaseExport.php
  3. 1 0
      common/models/Order.php

+ 26 - 0
common/helpers/Tool.php

@@ -11,6 +11,8 @@ namespace common\helpers;
 
 use common\models\AlarmCall;
 use common\models\ApproachOrderCall;
+use common\models\Countries;
+use common\models\Order;
 use Faker\Provider\Uuid;
 use Yii;
 use yii\helpers\Url;
@@ -627,4 +629,28 @@ class Tool {
 
         return ($amount / $beforeRate) * $afterRate;
     }
+
+    /**
+     * 生成发票号
+     * @param $countryId
+     * @return string
+     */
+    public static function generateInvoiceNo()
+    {
+        $prefix = 'Inv';
+
+        $order = Order::find()
+            ->where(['STATUS' => 1, 'IS_DELETE' => 0, 'INVOICE_NO' => ['$ne' => '']])
+            ->orderBy(['PAY_AT' => SORT_DESC])
+            ->asArray()
+            ->one();
+        if ($order) {
+            // 截取后 5 位, 转为数字+1
+            $no = sprintf('%05d', intval(substr($order->INVOICE_NO, -5)) + 1);
+        } else {
+            $no = '00001';
+        }
+
+        return $prefix . date('dmY') . $no;
+    }
 }

+ 11 - 7
common/libs/export/BaseExport.php

@@ -1582,7 +1582,13 @@ ORDER;
             $invoiceRemark = '';
             $paymentMethod = ''; // 支付方式
             $currency = '';
-            $invoiceNo = '';
+            $invoiceNo = $oderList[0]['INVOICE_NO'] ?: Tool::generateInvoiceNo();
+            if (!$oderList[0]['INVOICE_NO']) {
+                // 写入发票号
+                $orderModel = Order::find()->where(['SN' => $oderList[0]['ORDER_SN']])->one();
+                $orderModel->INVOICE_NO = $invoiceNo;
+                $orderModel->save();
+            }
 
             $orderTotalBv = 0;
             $orderTotalTaxAmount = 0;
@@ -1590,10 +1596,9 @@ ORDER;
             $orderTotal = 0;
             $orderTotalQuantity = count($oderList);
 
-            LoggerTool::debug($oderList);
-
             foreach ($oderList as $key => $value) {
                 $no = $key + 1;
+                $invoiceNo = $value['INVOICE_NO'] ?: Tool::generateInvoiceNo();
                 $invoiceRemark = $value['INVOICE_REMARK'] ?: '';
                 $provinceName = $value['PROVINCE'] ? Region::getCnName($value['PROVINCE']) : '';
                 $cityName = $value['CITY'] ? Region::getCnName($value['CITY']) : '';
@@ -1621,7 +1626,6 @@ ORDER;
                 $orderTotalTaxAmount += $taxAmount;
                 $orderTotalAmount += $totalAmount - $taxAmount;
                 $orderTotal += $totalAmount;
-                $invoiceNo = '123213123123';
 
                 $totalBvFormat = Tool::formatAmount($totalBv);
                 $taxableAmountFormat =Tool::formatAmount($taxAmount);
@@ -1633,8 +1637,8 @@ ORDER;
 
                 // 订单详情
                 $orderDetails .= <<<EOT
-                <tr style="text-align: left; padding: 10px 5px; font-weight: normal; font-size: 13px;">
-                    <td>{$no}</td>
+                <tr style="text-align: left; padding: 10px 5px; font-weight: normal; font-size: 12px;">
+                    <td style="width: 20px;">{$no}</td>
                     <td>{$value['SKU_CODE']}</td>
                     <td>{$value['GOODS_TITLE']}</td>
                     <td>{$value['BUY_NUMS']}</td>
@@ -1769,7 +1773,7 @@ EOT;
                             <br />
                             <table border="1" width="100%">
                                 <tr style="text-align: left; font-weight: normal; font-size: 12px;">
-                                    <th>No.</th>
+                                    <th style="width: 20px;">No.</th>
                                     <th>Product Code</th>
                                     <th>Product Name</th>
                                     <th>Quantity</th>

+ 1 - 0
common/models/Order.php

@@ -58,6 +58,7 @@ use Yii;
  * @property int CURRENCY_ID 币种ID
  * @property int AUTO_MAINTENANCE AMP订单
  * @property string INVOICE_REMARK 发票备注
+ * @property string INVOICE_NO 发票号
  */
 class Order extends \common\components\ActiveRecord
 {