liugc 11 месяцев назад
Родитель
Сommit
045be58346

+ 2 - 1
app/adminapi/controller/export/ExportController.php

@@ -113,6 +113,7 @@ class ExportController extends BaseAdminController
     {
     {
         $params = $this->request->get();
         $params = $this->request->get();
         if(empty($params['download_type'])) return $this->fail('参数错误');
         if(empty($params['download_type'])) return $this->fail('参数错误');
+        $params['admin_id'] = $this->adminId??0;
         $result = ExportLogic::add([
         $result = ExportLogic::add([
             'download_type' => $params['download_type']??0,
             'download_type' => $params['download_type']??0,
             'params' => $params,
             'params' => $params,
@@ -123,7 +124,7 @@ class ExportController extends BaseAdminController
             return $this->fail(ExportLogic::getError());
             return $this->fail(ExportLogic::getError());
         }
         }
         // 暂时 - 立即生成导出文件
         // 暂时 - 立即生成导出文件
-        (new ExcelExportService)->download($result);
+        if(!isset($params['cmd'])) (new ExcelExportService)->download($result);
         return $this->success('添加成功-'.$result, [], 1, 1);
         return $this->success('添加成功-'.$result, [], 1, 1);
     }
     }
 
 

+ 57 - 1
app/adminapi/lists/master_worker_register/MasterWorkerRegisterLists.php

@@ -16,6 +16,8 @@ namespace app\adminapi\lists\master_worker_register;
 
 
 
 
 use app\adminapi\lists\BaseAdminDataLists;
 use app\adminapi\lists\BaseAdminDataLists;
+use app\adminapi\logic\auth\AdminLogic;
+use app\adminapi\logic\ConfigLogic;
 use app\common\model\master_worker_register\MasterWorkerRegister;
 use app\common\model\master_worker_register\MasterWorkerRegister;
 use app\common\lists\ListsSearchInterface;
 use app\common\lists\ListsSearchInterface;
 
 
@@ -50,7 +52,11 @@ class MasterWorkerRegisterLists extends BaseAdminDataLists implements ListsSearc
      */
      */
     public function queryDataWhere(){
     public function queryDataWhere(){
         $where = [];
         $where = [];
-        $data_rules = $this->adminInfo['data_rules'];
+        if(isset($this->params['admin_id']) && $this->params['admin_id']){
+            $data_rules = AdminLogic::getDataPermissions($this->params['admin_id']);
+        }else{
+            $data_rules = $this->adminInfo['data_rules'];
+        }
         if (isset($data_rules['province']) && !empty($data_rules['province'])) {
         if (isset($data_rules['province']) && !empty($data_rules['province'])) {
             $where[] = ['province','in' ,$data_rules['province']];
             $where[] = ['province','in' ,$data_rules['province']];
         }
         }
@@ -99,4 +105,54 @@ class MasterWorkerRegisterLists extends BaseAdminDataLists implements ListsSearc
         return MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())->where($this->queryDataWhere())->count();
         return MasterWorkerRegister::where($this->searchWhere)->where($this->queryWhere())->where($this->queryDataWhere())->count();
     }
     }
 
 
+    public function setExcelComplexFields(): array
+    {
+        $zh_cn_fields = [
+            '工作经验','是否有证件', '特种证名称','证件照片','地区',
+            '销售名称','销售手机号'
+        ];
+        $data_fields = [
+            function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('worker_exp_type')['worker_exp_type'],'name','value');
+                return $dictType[$row['maintain_exp_type']]??'';
+            },function($row){ return $row['is_credential']? '有特种证' : '无特种证'; },function($row){ return $row['credential_name']? implode('、',$row['credential_name']) : ''; }
+            ,function($row){
+                if(empty($row['credential_images'])) return '';
+                $images = '';
+                if(is_array($row['credential_images'])){
+                    $images = implode("\r\n",$row['credential_images']);
+                }
+                return $images;
+            },'area_name',
+            function($row){ return empty($row['sale'])? '' :$row['sale']['sale_name']??''; },
+            function($row){ return empty($row['sale'])? '' :$row['sale']['mobile']??''; }
+        ];
+        /*$data_fields = [
+            function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('worker_exp_type')['worker_exp_type'],'name','value');
+                return $dictType[$row['maintain_exp_type']]??'';
+            },function($row){ return $row['is_credential']? '有特种证' : '无特种证'; },'credential_name'
+            ,function($row){
+                    if(empty($row['credential_images'])) return '';
+                    $images = '';
+                    if(is_array($row['credential_images'])){
+                        $images = implode(',',$row['credential_images']);
+                    }
+                    return $images;
+            },'area_name',function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('worker_vehicle_type')['worker_vehicle_type'],'name','value');
+                return $dictType[$row['vehicle_type']]??'';
+            },
+            function($row){ return $row['sale']['sale_name']??''; },
+            function($row){ return $row['sale']['mobile']??''; },
+            'name','age','mobile','address','create_time',function($row){
+                $dictType = array_column(\app\adminapi\logic\ConfigLogic::getDictByType('audit_state')['audit_state'],'name','value');
+                return $dictType[$row['status']]??'';
+            },'update_time'
+        ];*/
+        return [
+            'zh_cn_fields' => $zh_cn_fields,
+            'data_fields' => $data_fields
+        ];
+    }
 }
 }

+ 42 - 0
app/common/command/ExcelExport.php

@@ -0,0 +1,42 @@
+<?php
+namespace app\common\command;
+
+use app\common\model\bank_account\BankAccount;
+use app\common\model\export\Export;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker\MasterWorkerInfo;
+use app\common\service\ExcelExportService;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\facade\Log;
+
+/**
+ *  表格导出
+ * Class OpenObtainOrder
+ * @package app\command
+ */
+class ExcelExport extends Command
+{
+    protected function configure()
+    {
+        $this->setName('excel_export')->setDescription('表格导出');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        set_time_limit(180);
+        ini_set('memory_limit', '1024M');
+        try {
+            Export::where('generate_status',0)->where('createtime','<',(time()-86400*2))->delete();
+            $result = Export::where('generate_status',0)->findOrEmpty();
+            if(!$result->isEmpty()){
+                (new ExcelExportService)->download($result->id,true);
+            }
+            return true;
+        } catch (\Exception $e) {
+            Log::write('ExcelExport:'.$e->getMessage());
+            return $e->getMessage();
+        }
+    }
+}

+ 6 - 2
app/common/service/ExcelExportService.php

@@ -46,7 +46,7 @@ class ExcelExportService
         $this->download_type = config('export.download_type');
         $this->download_type = config('export.download_type');
         $this->sheet = new ExcelWriter();
         $this->sheet = new ExcelWriter();
     }
     }
-    public function download($id)
+    public function download($id,$isCmd = false)
     {
     {
         try{
         try{
             $infoExport = Export::findOrEmpty($id);
             $infoExport = Export::findOrEmpty($id);
@@ -64,12 +64,16 @@ class ExcelExportService
                         break;
                         break;
                     default:
                     default:
                         $use_file = explode('.',$download_fun);
                         $use_file = explode('.',$download_fun);
-                        $this->getDownloadFileUrl(invoke(str_replace('.', '\\', App::getNamespace() . '\\lists\\' . $use_file[0] . '\\'. ucwords($use_file[1]))));
+                        $this->sheet->savePath = ($isCmd?'./public/exports/':'');
+                        $this->getDownloadFileUrl(invoke(str_replace('.', '\\', App::getNamespace() . ($isCmd?'\\adminapi':'') . '\\lists\\' . $use_file[0] . '\\'. ucwords($use_file[1]))));
                        break;
                        break;
                 }
                 }
             }
             }
         }catch (\Exception $e){
         }catch (\Exception $e){
             Log::info("download-error:{$id}:".$e->getMessage());
             Log::info("download-error:{$id}:".$e->getMessage());
+            $this->infoExport->generate_status = 2;
+            $this->infoExport->updatetime = time();
+            $this->infoExport->save();
             throw new Exception($e->getMessage());
             throw new Exception($e->getMessage());
         }
         }
     }
     }

+ 2 - 0
config/console.php

@@ -23,5 +23,7 @@ return [
         'update_worker_score' => 'app\common\command\UpdateWorkerScore',
         'update_worker_score' => 'app\common\command\UpdateWorkerScore',
         //拼团订单结束
         //拼团订单结束
         'group_order' => 'app\common\command\GroupOrder',
         'group_order' => 'app\common\command\GroupOrder',
+        // 导出表格
+        'excel_export' => 'app\common\command\ExcelExport',
     ],
     ],
 ];
 ];

+ 1 - 0
config/export.php

@@ -21,5 +21,6 @@ return [
         '11' =>  'group_activity.GroupUserOrderLists',
         '11' =>  'group_activity.GroupUserOrderLists',
         '12' =>  'sale.SaleMasterWorkerLists',
         '12' =>  'sale.SaleMasterWorkerLists',
         '13' =>  'sale.SaleCommissionLists',
         '13' =>  'sale.SaleCommissionLists',
+        '14' =>  'master_worker_register.MasterWorkerRegisterLists',
     ],
     ],
 ];
 ];

+ 1 - 1
extend/excel/ExcelWriter.php

@@ -42,7 +42,7 @@ class ExcelWriter
         $filePath = $savePath . $filename;
         $filePath = $savePath . $filename;
         $writer = new Xlsx($this->spreadsheet);
         $writer = new Xlsx($this->spreadsheet);
         $writer->save($filePath);
         $writer->save($filePath);
-        $this->fileUrl = ($this->savePath?:"/exports/"). $filename;
+        $this->fileUrl = "/exports/". $filename;
     }
     }
     public function fileUrl()
     public function fileUrl()
     {
     {