MergePdf.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\event;
  3. use app\model\saas\SaasOrderDetail;
  4. use Webman\RedisQueue\Redis;
  5. use yzh52521\EasyHttp\Http;
  6. class MergePdf
  7. {
  8. public function imgMergePdf(array $data = [])
  9. {
  10. if (empty($data['shop'])) return true;
  11. $detail = (new SaasOrderDetail)->where(["shop_id" => $data['shop'],"openid" => $data['openid'],"order_sn" => $data['order'],'status' => 0])->select();
  12. if ($detail->isEmpty()) return true;
  13. foreach ($detail as $key=>$val) {
  14. if ($val['extension'] !== 'pdf') {
  15. $pathUri = [];
  16. for ($i = $val['start_page']; $i <= $val['end_page']; $i ++) {
  17. // for ($i = 1; $i <= $val['total_page']; $i ++) {
  18. $pathUri[$i] = "https://".sConf("storage.cos_http_domain")."/".$val['path']."?ci-process=doc-preview&dstType=png&imageDpi=300&page={$i}";
  19. }
  20. $resp = Http::asJson()->withHeaders(['x-api-key' => "your-api-key-here"])->post("http://127.0.0.1:3000/api/images-to-pdf",[
  21. "imageUrls" => array_values($pathUri),
  22. "pdfName" => $data['order']."_".$val['id'],
  23. "options" => [
  24. "compression" => false,
  25. "quality" => 100
  26. ]
  27. ])->array();
  28. echo getDateFull()."==={$data['order']}===word转码\n";
  29. print_r($resp);
  30. if ($resp['success']) {
  31. (new SaasOrderDetail)->where("id",$val['id'])->update(['path' => $resp['data']['pdfUrl'],'old_path' => $val['path'], 'status' => 1]);
  32. // 推送打印
  33. Redis::send("push-print",['type' => 'id' , 'order' => $val['id']]);
  34. }
  35. }
  36. }
  37. }
  38. }