BaseExport.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <?php
  2. namespace common\libs\export;
  3. use common\helpers\Cache as CacheHelper;
  4. use common\helpers\Date;
  5. use common\helpers\Form;
  6. use common\helpers\http\RemoteUploadApi;
  7. use common\helpers\Tool;
  8. use common\libs\dataList\DataList;
  9. use common\models\Export;
  10. use common\models\Region;
  11. use Yii;
  12. use yii\base\Exception;
  13. use yii\base\StaticInstanceTrait;
  14. use yii\base\Component;
  15. class BaseExport extends Component {
  16. use StaticInstanceTrait;
  17. public $moduleId;
  18. /**
  19. * @var string the model class name. This property must be set.
  20. */
  21. public $modelClass;
  22. /**
  23. * @var
  24. */
  25. public $listModelClass;
  26. /**
  27. * @var int
  28. */
  29. public $pageSize = 100;
  30. /**
  31. * @var int
  32. */
  33. public $totalCount = 0;
  34. /**
  35. * @var int
  36. */
  37. public $offset = 0;
  38. /**
  39. * @var int
  40. */
  41. public $limit = 100;
  42. /**
  43. * csv文件名称
  44. * @var null
  45. */
  46. public $fileName = null;
  47. /**
  48. * 保存的基本路径
  49. * @var null
  50. */
  51. public $saveBasePath = null;
  52. /**
  53. * 保存路径
  54. * @var null
  55. */
  56. public $savePath = null;
  57. /**
  58. * 正在导出的id
  59. * 来源于exporting_file表
  60. * @var null
  61. */
  62. public $exportId = null;
  63. /**
  64. * 操作人的id
  65. * @var null
  66. */
  67. public $userId = null;
  68. /**
  69. * 任务id
  70. * @var null
  71. */
  72. public $taskId = null;
  73. /**
  74. * 是否完成
  75. * @var bool
  76. */
  77. public $completed = false;
  78. /**
  79. * @var array
  80. */
  81. public $params = [];
  82. /**
  83. * 文件句柄
  84. * @var null
  85. */
  86. private $_fp = null;
  87. /**
  88. * 是否上传远程
  89. * @var bool
  90. */
  91. public $isRemote = true;
  92. /**
  93. * @var DataList
  94. */
  95. private $_listModel;
  96. public static function factory($taskId) {
  97. return new self([
  98. 'taskId' => $taskId
  99. ]
  100. );
  101. }
  102. /**
  103. *
  104. */
  105. public function init() {
  106. parent::init();
  107. $this->isRemote = \Yii::$app->params['isRemoteUpload'];
  108. }
  109. /**
  110. * 生成复杂的路径
  111. * @return string
  112. */
  113. public function pathCreator(...$params) {
  114. $hash = md5(implode('_', $params));
  115. $first = substr($hash, 0, 3);
  116. $second = substr($hash, 3, 2);
  117. $dir = $first . __DS__ . $second . __DS__;
  118. return $dir;
  119. }
  120. /**
  121. * 获取文件名
  122. * @return string|null
  123. * @throws \Exception
  124. */
  125. public function getFileName($ext = '.csv') {
  126. $this->fileName = date('YmdHis', Date::nowTime()) . random_int(1000, 9999) . $ext;
  127. return $this->fileName;
  128. }
  129. /**
  130. * 获取保存的路径
  131. * @return array|null
  132. */
  133. public function getSavePath() {
  134. $this->savePath = $this->pathCreator(date('Ymd', Date::nowTime()));
  135. return trim($this->savePath, __DS__);
  136. }
  137. /**
  138. * @return bool|string|null
  139. */
  140. public function getSaveBasePath() {
  141. $this->saveBasePath = Yii::getAlias('@backendApi') . __DS__ . 'web' . __DS__ . 'upload' . __DS__ . \Yii::$app->params['excelLocalDir'];
  142. return trim($this->saveBasePath, __DS__);
  143. }
  144. /**
  145. * 创建目录(递归创建)
  146. *
  147. * @param $dir
  148. * @return string|false
  149. */
  150. public function mkdir($dir) {
  151. if (!is_dir($dir)) {
  152. $this->mkdir(dirname($dir));
  153. if (!mkdir($dir, 0777))
  154. return false;
  155. @exec('chown -R www:www /'.$dir);
  156. @exec('chmod -R 777 /'.$dir);
  157. }
  158. return $dir;
  159. }
  160. /**
  161. * @return array|mixed
  162. */
  163. public function getParams() {
  164. $this->params = CacheHelper::getAsyncParams($this->taskId);
  165. return $this->params;
  166. }
  167. /**
  168. * @return mixed|null
  169. */
  170. public function getUserId() {
  171. $this->userId = isset($this->params['userId']) ? $this->params['userId'] : null;
  172. return $this->userId;
  173. }
  174. /**
  175. * @return |null
  176. */
  177. public function getExportId() {
  178. $this->exportId = isset($this->params['exportId']) ? $this->params['exportId'] : null;
  179. return $this->userId;
  180. }
  181. /**
  182. * 生成
  183. * @return bool
  184. * @throws Exception
  185. * @throws \yii\base\InvalidConfigException
  186. * @throws \yii\httpclient\Exception
  187. */
  188. public function generate() {
  189. //Logger::info(date('Y-m-d H:i:s'), 'export');
  190. $this->getParams();
  191. if (!$this->params) {
  192. throw new Exception('无法获取需要的参数');
  193. }
  194. $path = $this->getSaveBasePath() . __DS__ . $this->getSavePath();
  195. $path = __DS__ . $path;
  196. $realFile = $this->mkdir($path) . __DS__ . $this->getFileName();
  197. $this->completed = false;
  198. $this->getExportId();
  199. $this->getUserId();
  200. $fileNameUpdated = false;
  201. $this->_fp = fopen($realFile, 'w');
  202. @exec('chown -R www:www /'.$realFile);
  203. @exec('chmod -R 777 /'.$realFile);
  204. // 获取列表数据及表头
  205. $this->_listModel = new $this->listModelClass();
  206. $this->_listModel->isExport = true;
  207. if(method_exists($this->_listModel, 'getExportHeaders')){
  208. if(method_exists($this->_listModel, 'exportPrepare')) {//导出数据提前设置参数
  209. $this->_listModel->exportPrepare(['condition' => $this->params['condition'], 'params' => $this->params['params'], 'others' => isset($this->params['others']) ? $this->params['others'] : [], 'page' => 0, 'pageSize' => $this->pageSize, 'userId' => $this->userId]);
  210. }
  211. $headers = $this->_listModel->getExportHeaders($this->userId);
  212. fputcsv($this->_fp, $headers);
  213. unset($headers);
  214. $this->_updateFirst($realFile, 1);
  215. } else {
  216. throw new Exception($this->listModelClass.'的getExportHeaders方法不存在');
  217. }
  218. $this->_loopWriteData($realFile, $fileNameUpdated);
  219. $this->complete();
  220. return true;
  221. }
  222. /**
  223. * 循环写入数据
  224. * @param $realFile
  225. * @param $fileNameUpdated
  226. * @param int $page
  227. * @param int $counter
  228. * @return string
  229. * @throws Exception
  230. */
  231. private function _loopWriteData($realFile, &$fileNameUpdated, $page = 0, $counter = 0){
  232. if(method_exists($this->_listModel, 'getList')){
  233. $list = $this->_listModel->getList(['condition'=>$this->params['condition'], 'params'=>isset($this->params['params']) ? $this->params['params'] : [], 'others'=>isset($this->params['others']) ? $this->params['others'] : [], 'page'=>$page, 'pageSize'=>$this->pageSize, 'userId'=>$this->userId]);
  234. } else {
  235. throw new Exception($this->listModelClass.'的getList方法不存在');
  236. }
  237. if($page >= $list['totalPages']){
  238. return 'finish';
  239. }
  240. if(!empty($list['list'])){
  241. foreach($list['list'] as $columnData){
  242. fputcsv($this->_fp, Tool::arrTextConvert($columnData));
  243. $counter++;
  244. if ($list['totalCount'] < $counter) {
  245. // $counter = $list['totalCount'];
  246. return 'finish';
  247. }
  248. $percent = intval(($counter / $list['totalCount']) * 100);
  249. $this->_updatePercent($percent);
  250. // if (!$fileNameUpdated) {
  251. // $this->_updateFirst($realFile, $percent);
  252. // } else {
  253. // $this->_updatePercent($percent);
  254. // }
  255. // $fileNameUpdated = true;
  256. unset($percent, $columnData);
  257. }
  258. $page++;
  259. unset($list);
  260. return $this->_loopWriteData($realFile, $fileNameUpdated, $page, $counter);
  261. }
  262. unset($list);
  263. return 'finish';
  264. }
  265. /**
  266. * 完成
  267. * @return bool
  268. * @throws Exception
  269. * @throws \yii\base\InvalidConfigException
  270. * @throws \yii\httpclient\Exception
  271. */
  272. public function complete() {
  273. $this->_updatePercent(100);
  274. if ($this->completed) {
  275. return true;
  276. }
  277. if ($this->_fp) {
  278. fclose($this->_fp);
  279. }
  280. // 把导出的文件上传至静态文件服务器
  281. if ($this->isRemote) {
  282. $realFile = $this->getSaveBasePath() . __DS__ . $this->getSavePath() . __DS__ . $this->getFileName();
  283. $remoteUploadApi = RemoteUploadApi::instance();
  284. if ($uploadResult = $remoteUploadApi->upload($realFile)) {
  285. Export::updateAll(['REMOTE_URL' => $uploadResult['url'], 'IS_EXPORTING' => 0, 'EXPORT_PERCENT' => 100, 'ENDED_AT' => Date::nowTime()], 'ID=:ID', [':ID' => $this->exportId]);
  286. } else {
  287. $this->_errorHandle();
  288. throw new Exception('文件远程上传失败');
  289. }
  290. // 删除本地临时文件
  291. unlink($realFile);
  292. } else {
  293. Export::updateAll(['IS_EXPORTING' => 0, 'EXPORT_PERCENT' => 100, 'ENDED_AT' => Date::nowTime()], 'ID=:ID', [':ID' => $this->exportId]);
  294. }
  295. \Yii::$app->swooleAsyncTimer->pushAsyncPercentToAdmin(100, ['MODEL' => 'EXPORT', 'ID' => $this->exportId, 'FIELD' => 'EXPORT_PERCENT']);
  296. CacheHelper::deleteAsyncParams($this->taskId);
  297. $this->completed = true;
  298. }
  299. /**
  300. * @param $message
  301. */
  302. private function _errorNotice($message) {
  303. Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($this->userId, $message, false);
  304. }
  305. /**
  306. * 首次更新
  307. * @param $exportId
  308. * @param $realName
  309. */
  310. private function _updateFirst($realName, $percent) {
  311. $fileName = str_replace($this->getSaveBasePath() . __DS__, '', $realName);
  312. Export::updateAll([
  313. 'FILE_NAME' => str_replace(__DS__, '/', $fileName),
  314. 'UPDATED_AT' => Date::nowTime(),
  315. 'EXPORT_PERCENT' => $percent,
  316. ], 'ID=:ID', [':ID' => $this->exportId]);
  317. }
  318. /**
  319. * 更新百分比
  320. * @param $exportId
  321. * @param $percent
  322. */
  323. private function _updatePercent($percent) {
  324. // 把数据写入数据库中
  325. Export::updateAll(['EXPORT_PERCENT' => $percent], 'ID=:ID', [':ID' => $this->exportId]);
  326. \Yii::$app->swooleAsyncTimer->pushAsyncPercentToAdmin($percent, ['MODEL' => 'EXPORT', 'ID' => $this->exportId, 'FIELD' => 'EXPORT_PERCENT']);
  327. }
  328. /**
  329. * 发生错误处理
  330. * @param $exportId
  331. */
  332. private function _errorHandle() {
  333. Export::updateAll(['IS_EXPORTING' => 0], 'ID=:ID', [':ID' => $this->exportId]);
  334. }
  335. /**
  336. * 导出逻辑
  337. * @param $filter
  338. * @param $listName
  339. * @param null $consoleRouter
  340. * @throws Exception
  341. */
  342. public function exportHandle($filter, $listName, $consoleRouter = null){
  343. $params = [
  344. 'moduleId' => $this->moduleId,
  345. 'listName' => $listName,
  346. 'action' => $consoleRouter ? $consoleRouter : Yii::$app->controller->id.'/'.Yii::$app->controller->action->id, // 这里这么写,是因为调用的异步路由和同步的控制器和方法是一样的,所以,只要不传默认调和同步一样的异步方法
  347. 'userId' => Yii::$app->user->id,
  348. ];
  349. $this->webToAsync($params,$filter);
  350. }
  351. /**
  352. * 页面到异步的请求
  353. * @param $params
  354. * @param array $extend
  355. * @return bool
  356. * @throws Exception
  357. */
  358. public function webToAsync($params, $extend = []) {
  359. $default = [
  360. 'moduleId' => null,
  361. 'listName' => null,
  362. 'remark' => null,
  363. 'action' => null,
  364. 'userId' => null,
  365. ];
  366. $params = Tool::deepParse($params, $default);
  367. if (!$params['moduleId'] || !$params['listName'] || !$params['action']) {
  368. throw new Exception('请设置moduleId,listName和action');
  369. }
  370. // 把文件对应的相关资料存入数据库中
  371. $export = new Export();
  372. $export->EXPORT_NAME = $params['listName'] . '_' . date('y年m月d日H时i分s秒导出', Date::nowTime());
  373. $export->MODULE_NAME = $params['moduleId'];
  374. $export->REMARK = $params['remark'];
  375. $export->IS_EXPORTING = 1;
  376. $export->ADMIN_ID = \Yii::$app->user->id;
  377. $export->STARTED_AT = Date::nowTime();
  378. $export->CREATED_AT = Date::nowTime();
  379. $export->EXPORT_PERCENT = 0;
  380. $export->ENDED_AT = 0;
  381. $export->UPDATED_AT = 0;
  382. if (!$export->save()) {
  383. throw new Exception(Form::formatErrorsForApi($export->getErrors()));
  384. }
  385. $extend = array_merge($extend, [
  386. 'exportId' => $export->ID,
  387. 'userId' => $params['userId'],
  388. ]);
  389. // 异步处理添加任务
  390. $taskKey = \Yii::$app->swooleAsyncTimer->asyncHandle($params['action'], $extend);
  391. if($taskKey === false){
  392. // 删除刚刚添加的导出数据
  393. Export::deleteAll(['ID'=>$export->ID]);
  394. throw new Exception('导出失败,请求异步处理服务器失败');
  395. }
  396. return $taskKey;
  397. }
  398. /**
  399. * 生成
  400. * @return bool
  401. * @throws Exception
  402. * @throws \yii\base\InvalidConfigException
  403. * @throws \yii\httpclient\Exception
  404. */
  405. public function generatePDF() {
  406. $this->getParams();
  407. if (!$this->params) {
  408. throw new Exception('无法获取需要的参数');
  409. }
  410. $path = __DS__ . $this->getSaveBasePath() . __DS__ . $this->getSavePath();
  411. $realFile = $path . __DS__ . $this->getFileName('.pdf');
  412. $this->completed = false;
  413. $this->getExportId();
  414. $this->getUserId();
  415. $fileNameUpdated = false;
  416. // 获取列表数据及表头
  417. $this->_listModel = new $this->listModelClass();
  418. $this->_listModel->isExport = true;
  419. // 查询订单数据
  420. $oderList = $this->_loopWriteDataPDF($realFile, $fileNameUpdated);
  421. if ($oderList) {
  422. $userId = '';
  423. $userName = '';
  424. $address = '';
  425. $mobile = '';
  426. $orderAt = '';
  427. $orderDetails = '';
  428. $orderSn = '';
  429. $orderAmount = 0; // 合计总额
  430. $orderNums = 0; // 合计总数
  431. foreach ($oderList as $key => $value) {
  432. $provinceName = $value['PROVINCE'] ? Region::getCnName($value['PROVINCE']) : '';
  433. $cityName = $value['CITY'] ? Region::getCnName($value['CITY']) : '';
  434. $countyName = $value['COUNTY'] ? Region::getCnName($value['COUNTY']) : '';
  435. $userId = $value['USER_NAME'];
  436. $userName = $value['CREATE_USER_NAME'];
  437. $address = $provinceName . $cityName . $countyName . $value['ADDRESS'];
  438. $mobile = $value['MOBILE'];
  439. $orderAt = $value['PAY_AT'];
  440. $orderSn = $value['SN'];
  441. // 总价
  442. $totalAmount = $value['BUY_NUMS'] * $value['REAL_PRICE'];
  443. $orderAmount += $totalAmount;
  444. $orderNums += $value['BUY_NUMS'];
  445. // 订单详情
  446. $orderDetails .= <<<EOT
  447. <tr>
  448. <td>{$value['SKU_CODE']}</td>
  449. <td>{$value['GOODS_TITLE']}</td>
  450. <td>{$value['BUY_NUMS']}</td>
  451. <td>{$value['REAL_PRICE']}</td>
  452. <td>{$totalAmount}</td>
  453. </tr>
  454. EOT;
  455. }
  456. // 订单基本信息
  457. $orderBase = <<<ORDER
  458. <table border="1" style="table-layout: fixed; padding: 10px 20px;" width="100%">
  459. <tr>
  460. <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员编号</td>
  461. <td width="70%">{$userId}</td>
  462. </tr>
  463. <tr>
  464. <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员名字</td>
  465. <td width="70%">{$userName}</td>
  466. </tr>
  467. <tr>
  468. <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员地址</td>
  469. <td width="70%">{$address}</td>
  470. </tr>
  471. <tr>
  472. <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">会员电话</td>
  473. <td width="70%">{$mobile}</td>
  474. </tr>
  475. <tr>
  476. <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">订单编号</td>
  477. <td width="70%">{$orderSn}</td>
  478. </tr>
  479. <tr>
  480. <td width="30%" style="font-weight: bold; text-align: center; font-size: 14px;">订单日期</td>
  481. <td width="70%">{$orderAt}</td>
  482. </tr>
  483. <tr>
  484. <td class="bg" style="font-weight: bold; font-size: 14px; text-align: center;">订单明细</td>
  485. <td class="bg"></td>
  486. </tr>
  487. </table>
  488. ORDER;
  489. $l['a_meta_charset'] = 'UTF-8';
  490. $l['a_meta_dir'] = 'ltr';
  491. $l['a_meta_language'] = 'zh';
  492. $l['w_page'] = '页面';
  493. $context = <<<ORDER
  494. <!doctype html>
  495. <html lang="en">
  496. <head>
  497. <meta charset="UTF-8" />
  498. <title>订单详情</title>
  499. <style>
  500. table {
  501. border-collapse: collapse;
  502. }
  503. table td, table th {
  504. border: 1px solid #ccc;
  505. padding: 10px 30px;
  506. border-collapse: collapse;
  507. }
  508. td {
  509. padding: 120px;
  510. }
  511. .bg {
  512. background-color: #ccc;
  513. }
  514. </style>
  515. </head>
  516. <body>
  517. <div class="content">
  518. <p style="text-align: center; font-weight: bold; font-size: 22px;"><b>订单详情</b><br></p>
  519. <div>
  520. <div style="display: block; width: 100%;">
  521. {$orderBase}
  522. <table border="1" width="100%" style="padding: 10px 20px; text-align: center;">
  523. <tr>
  524. <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">商品编号</th>
  525. <th width="30%" style="font-size: 14px; font-weight: bold; text-align: center;">商品名称</th>
  526. <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">数量</th>
  527. <th width="15%" style="font-size: 14px; font-weight: bold; text-align: center;">单价</th>
  528. <th width="20%" style="font-size: 14px; font-weight: bold; text-align: center;">总价</th>
  529. </tr>
  530. {$orderDetails}
  531. <tr>
  532. <td colspan="2">合计</td>
  533. <td>{$orderNums}</td>
  534. <td></td>
  535. <td>{$orderAmount}</td>
  536. </tr>
  537. </table>
  538. </div>
  539. <div style="width: 100%; margin-top: 50px; height: 30px;">
  540. <table width="100%" style="border: none; padding: 10px 20px; text-align: center;">
  541. <tr style="border: none;">
  542. <td width="70%" style="border: none;"></td>
  543. <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">签名:</td>
  544. </tr>
  545. <tr style="border: none;">
  546. <td width="70%" style="border: none;"></td>
  547. <td width="30%" style="font-weight: bold; text-align: left; font-size: 14px; border: none;">日期:</td>
  548. </tr>
  549. </table>
  550. </div>
  551. </div>
  552. </div>
  553. </body>
  554. </html>
  555. ORDER;
  556. require_once (\Yii::$app->vendorPath . '/tecnickcom/tcpdf/tcpdf.php');
  557. $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  558. // 设置打印模式
  559. $pdf->SetCreator(PDF_CREATOR);
  560. $pdf->SetAuthor('DaZe');
  561. $pdf->SetTitle($orderSn);
  562. $pdf->SetSubject('TCPDF Tutorial');
  563. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  564. // 是否显示页眉
  565. $pdf->setPrintHeader(false);
  566. // 设置页眉字体
  567. $pdf->setHeaderFont(Array('dejavusans', '', '12'));
  568. // 页眉距离顶部的距离
  569. $pdf->SetHeaderMargin('5');
  570. // 是否显示页脚
  571. $pdf->setPrintFooter(false);
  572. // 设置默认等宽字体
  573. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  574. // 设置行高
  575. $pdf->setCellHeightRatio(1);
  576. // 设置左、上、右的间距
  577. $pdf->SetMargins('10', '10', '10');
  578. // 设置是否自动分页 距离底部多少距离时分页
  579. $pdf->SetAutoPageBreak(TRUE, '15');
  580. // 设置图像比例因子
  581. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  582. if (@file_exists(\Yii::$app->vendorPath . 'tecnickcom/tcpdf/examples/lang/eng.php')) {
  583. require_once(\Yii::$app->vendorPath . '/tecnickcom/tcpdf/examples/lang/eng.php');
  584. $pdf->setLanguageArray($l);
  585. }
  586. $pdf->setFontSubsetting(true);
  587. $pdf->AddPage();
  588. // 设置字体
  589. $pdf->SetFont('stsongstdlight', '', 10, '', true);
  590. $pdf->writeHTML($context);
  591. $pdf->Output($realFile, 'F');
  592. $this->_updateFirst($realFile, 1);
  593. }
  594. $this->complete();
  595. return true;
  596. }
  597. /**
  598. * 循环写入数据
  599. * @param $realFile
  600. * @param $fileNameUpdated
  601. * @param int $page
  602. * @param int $counter
  603. * @return array
  604. * @throws Exception
  605. */
  606. private function _loopWriteDataPDF($realFile, &$fileNameUpdated, $page = 0, $counter = 0){
  607. if(method_exists($this->_listModel, 'getList')){
  608. $list = $this->_listModel->getList(['condition'=>$this->params['condition'], 'params'=>isset($this->params['params']) ? $this->params['params'] : [], 'others'=>isset($this->params['others']) ? $this->params['others'] : [], 'page'=>$page, 'pageSize'=>$this->pageSize, 'userId'=>$this->userId]);
  609. } else {
  610. throw new Exception($this->listModelClass.'的getList方法不存在');
  611. }
  612. return $list['list'];
  613. }
  614. }