| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\common\service;
- use app\common\enum\FileEnum;
- use app\common\model\export\Export;
- use app\common\model\file\File;
- use app\common\service\storage\Driver as StorageDriver;
- use excel\ExcelWriter;
- use Exception;
- use think\facade\Db;
- use think\facade\Log;
- class ExcelExportService
- {
- private $sheet;
- public function __construct()
- {
- $this->sheet = new ExcelWriter();
- }
- public function download($id)
- {
- try{
- Log::info("download-export:{$id}");
- $infoExport = Export::findOrEmpty($id);
- if(!$infoExport->isEmpty()){
- $download_fun = $infoExport['download_fun'];
- $filename = $infoExport['name'];
- $params = $infoExport['params']?:[];
- // 是否存在该函数
- if(!method_exists($this,$download_fun)){
- throw new Exception('下载函数不存在');
- }
- $this->$download_fun($infoExport,$filename,$params);
- }
- }catch (\Exception $e){
- Log::info("download-error:{$id}:".$e->getMessage());
- throw new Exception($e->getMessage());
- }
- }
- /**
- * @notes 工程师 -上月最后结算余额 导出
- */
- public function EngineerBillDownload($infoExport,$filename,$params)
- {
- try{
- if($params){ }
- $firstDay = date('Y-m-01 00:00:00', strtotime('first day of last month'));
- $lastDay = date('Y-m-t 23:59:59', strtotime('last day of last month'));
- $lists = Db::name('master_worker')->alias('a')->field([
- 'a.id','a.real_name','a.nickname','a.worker_number','e.account_holder','e.bank_name','e.opening_branch','e.account as bank_account',
- Db::raw("IFNULL(c.maxid,0) as maxid"),Db::raw("IFNULL(d.left_amount,0) as left_amount")
- ])
- ->leftJoin([Db::name('master_worker_account_log')
- ->where('create_time','between',[strtotime($firstDay),strtotime($lastDay)])
- ->field('worker_id as master_worker_id, max(id) as maxid')
- ->group('worker_id')
- ->buildSql() => 'c'], 'a.id = c.master_worker_id')
- ->leftJoin('master_worker_account_log d', 'c.maxid = d.id')
- ->leftJoin('bank_account e', 'a.id = e.worker_id')
- //->where('d.left_amount', '>', 0)
- ->select()->toArray();
- $filename = ($filename?:'').('-'.date('YmdHis').'-'.$infoExport->id);
- $this->sheet->generateExcelFile([
- '工程师ID', '工程师编号', '工程师姓名', '工程师银行卡号', '工程师开户行及支行信息','上月最后结算余额'
- ], $lists,$filename, ['id','worker_number','nickname','bank_account','bank_name','left_amount']);
- $infoExport->file_url = $this->sheet->fileUrl();
- $infoExport->generate_status = 1;
- $infoExport->updatetime = time();
- $infoExport->save();
- return $infoExport->file_url;
- }catch (\Exception $e){
- throw new Exception($e->getMessage());
- }
- }
- }
|