QueryDrugReportService.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Services;
  3. use AlibabaAlihealthSynergyYzwDrugreportOptHistoryAllRequest;
  4. use AlibabaAlihealthSynergyYzwQuerydrugreportRequest;
  5. use AlibabaAlihealthSynergyYzwQuerysealdrugreportRequest;
  6. use Page;
  7. use TopClient;
  8. class QueryDrugReportService
  9. {
  10. private $client;
  11. private $config;
  12. public function __construct()
  13. {
  14. $this->config = config('taobao');
  15. $this->client = new TopClient;
  16. $this->client->appkey = $this->config['app_key'];
  17. $this->client->secretKey = $this->config['secret_key'];
  18. $this->client->format = "json";
  19. }
  20. /**
  21. * 查询上游企业的待签收药检报告信息
  22. * @link https://open.taobao.com/api.htm?docId=70169&docType=2&scopeId=30361
  23. * @param string $beginTime
  24. * @param string $endTime
  25. * @param int $page
  26. * @param int $pageSize
  27. * @return array
  28. * @throws \Exception
  29. */
  30. public function queryDrugReport(string $beginTime, string $endTime, int $page = 1, int $pageSize = 20): array
  31. {
  32. $req = new AlibabaAlihealthSynergyYzwQuerydrugreportRequest;
  33. $req->setRefEntId($this->config['enterprise_id']);
  34. // $req->setFromRefEntId(""); // 发货企业(可选)
  35. // $req->setBillCode(""); // 单据编号(可选)
  36. $req->setBeginTime($beginTime);
  37. $req->setEndTime($endTime);
  38. // $req->setDrugId(""); // 药品ID(可选)
  39. // $req->setBatchNo(""); // 批号(可选)
  40. $pageObj = new Page;
  41. $pageObj->page = $page;
  42. $pageObj->page_size = $pageSize;
  43. $req->setPage(json_encode($pageObj));
  44. $resp = $this->client->execute($req);
  45. if ('SUCCESS' <> $resp->res_result->msg_code) {
  46. throw new \Exception($resp->res_result->msg_info);
  47. }
  48. if (!isset($resp->res_result->model->result->onenet_drug_report_top_d_t_o)) {
  49. return [];
  50. }
  51. return json_decode(json_encode(
  52. $resp->res_result->model->result->onenet_drug_report_top_d_t_o
  53. ), true);
  54. }
  55. /**
  56. * 查询上传报告信息接口
  57. * @link https://open.taobao.com/api.htm?docId=70145&docType=2&scopeId=30361
  58. * @param string $beginTime
  59. * @param string $endTime
  60. * @param int $page
  61. * @param int $pageSize
  62. * @param int $isSeal
  63. * @return array
  64. * @throws \Exception
  65. */
  66. public function querySealDrugReport(string $beginTime, string $endTime, int $page = 1, int $pageSize = 20, int $isSeal = 0): array
  67. {
  68. $req = new AlibabaAlihealthSynergyYzwQuerysealdrugreportRequest;
  69. $req->setRefEntId($this->config['enterprise_id']);
  70. $req->setBeginTime($beginTime);
  71. $req->setEndTime($endTime);
  72. $req->setPage($page);
  73. $req->setPageSize($pageSize);
  74. if ($isSeal) {
  75. $req->setStatus($isSeal);
  76. }
  77. $resp = $this->client->execute($req);
  78. if ('SUCCESS' <> $resp->result->msg_code) {
  79. throw new \Exception($resp->result->msg_info);
  80. }
  81. if (!isset($resp->result->model->result_list->ocr_seal_drug_report_d_t_o)) {
  82. return [];
  83. }
  84. return json_decode(json_encode(
  85. $resp->result->model->result_list->ocr_seal_drug_report_d_t_o
  86. ), true);
  87. }
  88. /**
  89. * 药检报告操作日志
  90. * @link https://open.taobao.com/api.htm?docId=71189&docType=2&scopeId=30361
  91. * @param string $beginDate
  92. * @param string $endDate
  93. * @param int $page
  94. * @param int $pageSize
  95. * @return array
  96. * @throws \Exception
  97. */
  98. public function drugReportOptHistory(string $beginDate, string $endDate, int $page = 1, int $pageSize = 20): array
  99. {
  100. $req = new AlibabaAlihealthSynergyYzwDrugreportOptHistoryAllRequest;
  101. $req->setRefEntId($this->config['enterprise_id']);
  102. $req->setBeginTime($beginDate);
  103. $req->setEndTime($endDate);
  104. // $req->setBatchNo(""); // 批次号(可选)
  105. // $req->setDrugId(""); // 药品ID(可选)
  106. $req->setPage($page);
  107. $req->setPageSize($pageSize);
  108. $resp = $this->client->execute($req);
  109. if ('SUCCESS' <> $resp->result->msg_code) {
  110. throw new \Exception($resp->result->msg_info);
  111. }
  112. if (!isset($resp->result->model->result_list->top_drug_report_opt_log)) {
  113. return [];
  114. }
  115. return json_decode(json_encode(
  116. $resp->result->model->result_list->top_drug_report_opt_log
  117. ), true);
  118. }
  119. }