|
@@ -27,6 +27,7 @@ use app\common\model\user\User;
|
|
|
use app\common\service\storage\Driver as StorageDriver;
|
|
use app\common\service\storage\Driver as StorageDriver;
|
|
|
use excel\ExcelWriter;
|
|
use excel\ExcelWriter;
|
|
|
use Exception;
|
|
use Exception;
|
|
|
|
|
+use think\facade\App;
|
|
|
use think\facade\Db;
|
|
use think\facade\Db;
|
|
|
use think\facade\Log;
|
|
use think\facade\Log;
|
|
|
|
|
|
|
@@ -34,14 +35,13 @@ use think\facade\Log;
|
|
|
class ExcelExportService
|
|
class ExcelExportService
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- private $sheet;
|
|
|
|
|
- public $download_type = [
|
|
|
|
|
- '1' => 'EngineerBillDownload',
|
|
|
|
|
- '2' => 'MasterWorkerServiceOrderDownload',
|
|
|
|
|
- '3' => 'UserEquityDownload',
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ private ExcelWriter $sheet;
|
|
|
|
|
+ protected array $params = [];
|
|
|
|
|
+ protected Export $infoExport;
|
|
|
|
|
+ public array $download_type = [];
|
|
|
public function __construct()
|
|
public function __construct()
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->download_type = config('export.download_type');
|
|
|
$this->sheet = new ExcelWriter();
|
|
$this->sheet = new ExcelWriter();
|
|
|
}
|
|
}
|
|
|
public function download($id)
|
|
public function download($id)
|
|
@@ -50,16 +50,43 @@ class ExcelExportService
|
|
|
$infoExport = Export::findOrEmpty($id);
|
|
$infoExport = Export::findOrEmpty($id);
|
|
|
if(!$infoExport->isEmpty()){
|
|
if(!$infoExport->isEmpty()){
|
|
|
$download_fun = $infoExport['download_fun'];
|
|
$download_fun = $infoExport['download_fun'];
|
|
|
- if(!method_exists($this,$download_fun)){
|
|
|
|
|
- throw new Exception('下载不存在-1001');
|
|
|
|
|
|
|
+ $this->infoExport = $infoExport;
|
|
|
|
|
+ switch ($infoExport['download_type']){
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ if(!method_exists($this,$download_fun)){
|
|
|
|
|
+ throw new Exception('下载不存在-1001');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->$download_fun($infoExport);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ $use_file = explode('.',$download_fun);
|
|
|
|
|
+ $this->getDownloadFileUrl(invoke(str_replace('.', '\\', App::getNamespace() . '\\lists\\' . $use_file[0] . '\\'. ucwords($use_file[1]))));
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- $this->$download_fun($infoExport);
|
|
|
|
|
}
|
|
}
|
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
|
Log::info("download-error:{$id}:".$e->getMessage());
|
|
Log::info("download-error:{$id}:".$e->getMessage());
|
|
|
throw new Exception($e->getMessage());
|
|
throw new Exception($e->getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 获取下载文件路径
|
|
|
|
|
+ public function getDownloadFileUrl($downloadObj){
|
|
|
|
|
+ $lists = $downloadObj->excelExportList($this->infoExport['params']?:[]);
|
|
|
|
|
+ $filename = $downloadObj->setFileName()?:($this->infoExport['name']?:'');
|
|
|
|
|
+ $fields = $downloadObj->setExcelComplexFields();
|
|
|
|
|
+ if(!$lists || !$fields){
|
|
|
|
|
+ throw new Exception('lists或fields不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->sheet->generateExcelFile($fields['zh_cn_fields'], $lists,$filename.'-'.$this->infoExport->id, $fields['data_fields']);
|
|
|
|
|
+ $this->infoExport->file_url = $this->sheet->fileUrl();
|
|
|
|
|
+ $this->infoExport->generate_status = 1;
|
|
|
|
|
+ $this->infoExport->updatetime = time();
|
|
|
|
|
+ $this->infoExport->save();
|
|
|
|
|
+ return $this->infoExport->file_url;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @notes 工程师 -截止某日最后结算余额 导出
|
|
* @notes 工程师 -截止某日最后结算余额 导出
|
|
@@ -90,12 +117,12 @@ class ExcelExportService
|
|
|
]);
|
|
]);
|
|
|
//生成数据表格 & 更新表 -- 批次编号、状态-待算
|
|
//生成数据表格 & 更新表 -- 批次编号、状态-待算
|
|
|
$lists = MasterSettlementDetailsLogic::upBatchStatus($params,$batch_number);
|
|
$lists = MasterSettlementDetailsLogic::upBatchStatus($params,$batch_number);
|
|
|
- $filename = ($filename?($filename.'-批号'.$batch_number):'').('-'.date('YmdHis').'-'.$infoExport->id);
|
|
|
|
|
|
|
+ $filename = ($filename?($filename.'-批号'.$batch_number):'');
|
|
|
$this->sheet->generateExcelFile([
|
|
$this->sheet->generateExcelFile([
|
|
|
'工程师ID', '工程师编号', '工程师姓名', '工程师银行卡号', '所属银行', '工程师开户行及支行信息','导出时账号余额',
|
|
'工程师ID', '工程师编号', '工程师姓名', '工程师银行卡号', '所属银行', '工程师开户行及支行信息','导出时账号余额',
|
|
|
'批次编号',
|
|
'批次编号',
|
|
|
'应发金额', '扣款金额', '扣款说明', '实发金额', '打款时间','备注'
|
|
'应发金额', '扣款金额', '扣款说明', '实发金额', '打款时间','备注'
|
|
|
- ], $lists,$filename, [
|
|
|
|
|
|
|
+ ], $lists,$filename.'-'.$infoExport->id, [
|
|
|
'master_worker_id','worker_number','engineer_name','bank_account','bank_name','opening_branch','original_balance',
|
|
'master_worker_id','worker_number','engineer_name','bank_account','bank_name','opening_branch','original_balance',
|
|
|
'batch_number',
|
|
'batch_number',
|
|
|
'total_settlement_amount','','','','',''
|
|
'total_settlement_amount','','','','',''
|
|
@@ -169,10 +196,10 @@ class ExcelExportService
|
|
|
foreach ($lists as &$item) {
|
|
foreach ($lists as &$item) {
|
|
|
$item['category_name'] = $item['category_ids']?implode('、',array_column(get_parent_info($categoryData,explode(',',$item['category_ids'])),'name')):'';
|
|
$item['category_name'] = $item['category_ids']?implode('、',array_column(get_parent_info($categoryData,explode(',',$item['category_ids'])),'name')):'';
|
|
|
}
|
|
}
|
|
|
- $filename = ($filename?:'').('-'.date('YmdHis').'-'.$infoExport->id);
|
|
|
|
|
|
|
+
|
|
|
$this->sheet->generateExcelFile([
|
|
$this->sheet->generateExcelFile([
|
|
|
'服务类别', '工程师编号', '工程师姓名', '工程师手机', '代招人姓名', '工程师接单数', '工程师成功单','工程师失败单','工程师成交金额','工程师提成金额'
|
|
'服务类别', '工程师编号', '工程师姓名', '工程师手机', '代招人姓名', '工程师接单数', '工程师成功单','工程师失败单','工程师成交金额','工程师提成金额'
|
|
|
- ], $lists,$filename, ['category_name','worker_number','real_name','mobile','recruiting_behalf','all_count','success_count','fail_count','work_total','worker_price']);
|
|
|
|
|
|
|
+ ], $lists,$filename.'-'.$infoExport->id, ['category_name','worker_number','real_name','mobile','recruiting_behalf','all_count','success_count','fail_count','work_total','worker_price']);
|
|
|
$infoExport->file_url = $this->sheet->fileUrl();
|
|
$infoExport->file_url = $this->sheet->fileUrl();
|
|
|
$infoExport->generate_status = 1;
|
|
$infoExport->generate_status = 1;
|
|
|
$infoExport->updatetime = time();
|
|
$infoExport->updatetime = time();
|
|
@@ -213,10 +240,10 @@ class ExcelExportService
|
|
|
->field(['id', 'user_id', 'equity_id', 'goods_id', 'number', "IF(end_time=0,'',FROM_UNIXTIME(end_time, '%Y-%m-%d %H:%i:%s')) AS end_time",'code','IF(user_id=0,2,1) as is_binding'])
|
|
->field(['id', 'user_id', 'equity_id', 'goods_id', 'number', "IF(end_time=0,'',FROM_UNIXTIME(end_time, '%Y-%m-%d %H:%i:%s')) AS end_time",'code','IF(user_id=0,2,1) as is_binding'])
|
|
|
->select()
|
|
->select()
|
|
|
->toArray();
|
|
->toArray();
|
|
|
- $filename = ($filename?:'').('-'.date('YmdHis').'-'.$infoExport->id);
|
|
|
|
|
|
|
+
|
|
|
$this->sheet->generateExcelFile([
|
|
$this->sheet->generateExcelFile([
|
|
|
'用户','编码', '权益卡名称','商品','预售价','权益总次数','剩余次数','权益截止时间'
|
|
'用户','编码', '权益卡名称','商品','预售价','权益总次数','剩余次数','权益截止时间'
|
|
|
- ], $lists,$filename, ['user.nickname','code','equityConfig.equity_name','goods.goods_name','equityConfig.price','equityConfig.number','number','end_time']);
|
|
|
|
|
|
|
+ ], $lists,$filename.'-'.$infoExport->id, ['user.nickname','code','equityConfig.equity_name','goods.goods_name','equityConfig.price','equityConfig.number','number','end_time']);
|
|
|
$infoExport->file_url = $this->sheet->fileUrl();
|
|
$infoExport->file_url = $this->sheet->fileUrl();
|
|
|
$infoExport->generate_status = 1;
|
|
$infoExport->generate_status = 1;
|
|
|
$infoExport->updatetime = time();
|
|
$infoExport->updatetime = time();
|