Browse Source

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

zhangl 1 month ago
parent
commit
afdc825fd0

+ 11 - 0
backendApi/modules/v1/controllers/ShopController.php

@@ -50,6 +50,7 @@ use common\models\ShopGoods;
 use common\models\ShopGoodsNature;
 use common\models\User;
 use common\models\UserInfo;
+use common\helpers\Tool;
 use Yii;
 use yii\web\HttpException;
 use yii\web\UploadedFile;
@@ -833,6 +834,16 @@ class ShopController extends BaseController {
         $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
         $filter['params'] = [':SN' => $orderSn];
 
+        // 生成发票编号
+        $order = Order::find()->where(['SN' => $orderSn])->asArray()->one();
+        if (!$order) {
+            return static::notice('订单不存在', 400);
+        }
+        if (!$order['INVOICE_NO']) {
+            $invoiceNo = Tool::generateInvoiceNo();
+            Order::updateAll(['INVOICE_NO' => $invoiceNo], 'SN = :SN', [':SN' => $orderSn]);
+        }
+
         $form = new ShopExportForm();
         $result = $form->run($filter, \Yii::t('ctx', 'actionOrderInvoiceExport'));
         if (!$result) {

+ 1 - 5
common/libs/export/BaseExport.php

@@ -1590,11 +1590,7 @@ ORDER;
             $invoiceRemark = '';
             $paymentMethod = ''; // 支付方式
             $currency = '';
-            $invoiceNo = $oderList[0]['INVOICE_NO'] ?: Tool::generateInvoiceNo();
-            if (!$oderList[0]['INVOICE_NO']) {
-                // 写入发票号
-                Order::updateAll(['INVOICE_NO' => $invoiceNo], 'SN = :SN', [':SN' => $orderSn]);
-            }
+            $invoiceNo = $oderList[0]['INVOICE_NO'];
 
             LoggerTool::debug($oderList);