Parcourir la source

[智价云] 导出优化更新

tangyuanwang il y a 3 jours
Parent
commit
dc94e6134f

+ 6 - 15
app/Http/Controllers/Manager/Process/LowPriceGoods.php

@@ -218,7 +218,7 @@ class LowPriceGoods extends Controller
      * @version 1.0
      * @date 2025-06-17
      */
-    public function export_excel(Request $request, LowPriceGoodsModel $LowPriceGoodsModel, DownloadTaskModel $DownloadTaskModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel)
+    public function export_excel(Request $request, LowPriceGoodsModel $LowPriceGoodsModel,LowPriceGoodsMemberModel $LowPriceGoodsMemberModel)
     {
         $request->scene('export_excel')->validate();
         $message_data['admin_company_id'] = request('admin_company_id', '0');
@@ -413,20 +413,11 @@ class LowPriceGoods extends Controller
         // 生成唯一文件ID
         $fileId                     = make_snow_flake();
         $message_data['file_id']    = $fileId;
-        $fileName = '低价挂网商品数据' . $fileId. '.xlsx';
-        $downloadLog                 = [
-            'insert_time' => time(),
-            'company_id' => $low_price_goods_where['company_id'],
-            'operator_userid' => $message_data['user_id'],
-            'file_name' => $fileName,
-            'file_id' => $fileId,
-            'url' => '',
-        ];
-        // 写入数据表
-        $result = $DownloadTaskModel->insertGetId($downloadLog);
-        if(!$result) return json_send(['code' => 'fail', 'msg' => '导出任务添加失败', 'data' => '']);
-        ExportLowPriceGoodsJobs::dispatch($message_data);
-        // ExportLowPriceGoodsJobs::dispatchSync($message_data);
+        $fileName = '低价挂网商品数据' . $fileId . '.xlsx';
+        $message_data['company_id']    = $low_price_goods_where['company_id'];
+        $message_data['user_id']    = $message_data['user_id'];
+        // ExportLowPriceGoodsJobs::dispatch($message_data);
+        ExportLowPriceGoodsJobs::dispatchSync($message_data);
         return json_send(['code' => 'success', 'msg' => '导出任务添加成功', 'data' => ['file_id' => $fileId, 'file_name' => $fileName]]);
     }
 

+ 4 - 14
app/Http/Controllers/Manager/Process/ViolationProduct.php

@@ -218,7 +218,7 @@ class ViolationProduct extends Controller
      * @version 1.0
      * @date 2025-06-17
      */
-    public function export_excel(Request $request, DownloadTaskModel $DownloadTaskModel,ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel, ViolationProductMemberModel $ViolationProductMemberModel)
+    public function export_excel(Request $request,ViolationProductModel $ViolationProductModel)
     {
         $request->scene('export_excel')->validate();
         $message_data['admin_company_id'] = request('admin_company_id', '0');
@@ -263,11 +263,10 @@ class ViolationProduct extends Controller
         if ($export_data_info) return json_send(['code' => 'fail', 'msg' => '导出任务正在执行中,请稍后再试', 'data' => '']);
 
 
-         $admin_company_id = $message_data['admin_company_id'] ?? '0';
+        $admin_company_id = $message_data['admin_company_id'] ?? '0';
         $company_id = $message_data['access_token']['company_id'] ?? '0';
         $is_admin = $message_data['access_token']['is_admin'] ?? '0'; //是否管理员操作 0=是1=否
         $user_id = $message_data['access_token']['uid'] ?? 0;
-        $file_id = $message_data['file_id'];
         // 查询条件
         $map  = [];
         $status    = $message_data['status'] ?? '';
@@ -411,17 +410,8 @@ class ViolationProduct extends Controller
         $fileId                     = make_snow_flake();
         $message_data['file_id']    = $fileId;
         $fileName = '禁止挂网商品数据' . $fileId . '.xlsx';
-        $downloadLog                 = [
-            'insert_time' => time(),
-            'company_id' => $violation_product_where['company_id'],
-            'operator_userid' => $message_data['user_id'],
-            'file_name' => $fileName,
-            'file_id' => $fileId,
-            'url' => '',
-        ];
-        // 写入数据表
-        $result = $DownloadTaskModel->insertGetId($downloadLog);
-        if(!$result) return json_send(['code' => 'fail', 'msg' => '导出任务添加失败', 'data' => '']);
+        $message_data['company_id']    = $violation_product_where['company_id'];
+        $message_data['user_id']    = $message_data['user_id'];
         ExportViolationProductJobs::dispatch($message_data);
         // ExportViolationProductJobs::dispatchSync($message_data);
         return json_send(['code' => 'success', 'msg' => '导出任务添加成功', 'data' => ['file_id' => $fileId, 'file_name' => $fileName]]);

+ 19 - 4
app/Jobs/Manager/Other/ExportLowPriceGoodsJobs.php

@@ -49,11 +49,26 @@ class ExportLowPriceGoodsJobs implements ShouldQueue
     public function handle()
     {
         try {
+            $fileId = $this->message_data['file_id'];
+            $company_id = $this->message_data['company_id'];
+            $user_id = $this->message_data['user_id'];
+            $DownloadTaskModel = new DownloadTaskModel();
+            $fileName = '低价挂网商品数据' . $fileId . '.xlsx';
+            $downloadLog                 = [
+                'insert_time' => time(),
+                'company_id' => $company_id,
+                'operator_userid' => $user_id,
+                'file_name' => $fileName,
+                'file_id' => $fileId,
+                'url' => '',
+            ];
+            // 写入数据表
+            $DownloadTaskModel->insertGetId($downloadLog);
             $this->export_excel($this->message_data);
         } catch (\Exception $e) {
             Log::info('job_error', '违规数据-导出低价挂网数据处理队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
             //失败后清除缓存
-            Cache::forget('ExportLowPriceGoodsJobs_'. $this->company_id);
+            Cache::forget('ExportLowPriceGoodsJobs_' . $this->company_id);
         }
     }
 
@@ -338,7 +353,7 @@ class ExportLowPriceGoodsJobs implements ShouldQueue
         $sheet->setCellValue('X2', '记录时间');
         $sheet->setCellValue('Y2', '发货省份');
         $sheet->setCellValue('Z2', '发货城市');
-        
+
         //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
         $platform_data = [
             '0' => '全部',
@@ -428,9 +443,9 @@ class ExportLowPriceGoodsJobs implements ShouldQueue
     public function failed(\Throwable $exception)
     {
         Log::info('job_error', '违规数据-导出低价挂网数据队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
-         if($this->company_id) {
+        if ($this->company_id) {
             //失败后清除缓存
-            Cache::forget('ExportLowPriceGoodsJobs_'. $this->company_id);
+            Cache::forget('ExportLowPriceGoodsJobs_' . $this->company_id);
         }
     }
 }

+ 15 - 0
app/Jobs/Manager/Other/ExportViolationProductJobs.php

@@ -47,6 +47,21 @@ class ExportViolationProductJobs implements ShouldQueue
     public function handle()
     {
         try {
+            $fileId = $this->message_data['file_id'];
+            $company_id = $this->message_data['company_id'];
+            $user_id = $this->message_data['user_id'];
+            $DownloadTaskModel = new DownloadTaskModel();
+            $fileName = '禁止挂网商品数据' . $fileId . '.xlsx';
+            $downloadLog                 = [
+                'insert_time' => time(),
+                'company_id' => $company_id,
+                'operator_userid' => $user_id,
+                'file_name' => $fileName,
+                'file_id' => $fileId,
+                'url' => '',
+            ];
+            // 写入数据表
+            $DownloadTaskModel->insertGetId($downloadLog);
             $this->export_excel($this->message_data);
         } catch (\Exception $e) {
             Log::info('job_error', '违规数据-导出禁止挂网数据处理队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);