QueryDrugReportService.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. return json_decode(json_encode(
  49. $resp->res_result->model->result->onenet_drug_report_top_d_t_o
  50. ), true);
  51. }
  52. /**
  53. * 查询上传报告信息接口
  54. * @link https://open.taobao.com/api.htm?docId=70145&docType=2&scopeId=30361
  55. * @param string $beginTime
  56. * @param string $endTime
  57. * @param int $page
  58. * @param int $pageSize
  59. * @param int $isSeal
  60. * @return array
  61. * @throws \Exception
  62. */
  63. public function querySealDrugReport(string $beginTime, string $endTime, int $page = 1, int $pageSize = 20, int $isSeal = 0): array
  64. {
  65. $req = new AlibabaAlihealthSynergyYzwQuerysealdrugreportRequest;
  66. $req->setRefEntId($this->config['enterprise_id']);
  67. $req->setBeginTime($beginTime);
  68. $req->setEndTime($endTime);
  69. $req->setPage($page);
  70. $req->setPageSize($pageSize);
  71. if ($isSeal) {
  72. $req->setStatus($isSeal);
  73. }
  74. $resp = $this->client->execute($req);
  75. if ('SUCCESS' <> $resp->result->msg_code) {
  76. throw new \Exception($resp->result->msg_info);
  77. }
  78. return json_decode(json_encode(
  79. $resp->result->model->result_list->ocr_seal_drug_report_d_t_o
  80. ), true);
  81. }
  82. /**
  83. * 药检报告操作日志
  84. * @link https://open.taobao.com/api.htm?docId=71189&docType=2&scopeId=30361
  85. * @param string $beginDate
  86. * @param string $endDate
  87. * @param int $page
  88. * @param int $pageSize
  89. * @return array
  90. * @throws \Exception
  91. */
  92. public function drugReportOptHistory(string $beginDate, string $endDate, int $page = 1, int $pageSize = 20): array
  93. {
  94. $req = new AlibabaAlihealthSynergyYzwDrugreportOptHistoryAllRequest;
  95. $req->setRefEntId($this->config['enterprise_id']);
  96. $req->setBeginTime($beginDate);
  97. $req->setEndTime($endDate);
  98. // $req->setBatchNo(""); // 批次号(可选)
  99. // $req->setDrugId(""); // 药品ID(可选)
  100. $req->setPage($page);
  101. $req->setPageSize($pageSize);
  102. $resp = $this->client->execute($req);
  103. if ('SUCCESS' <> $resp->result->msg_code) {
  104. throw new \Exception($resp->result->msg_info);
  105. }
  106. return json_decode(json_encode(
  107. $resp->result->model->result_list->top_drug_report_opt_log
  108. ), true);
  109. }
  110. }