AlihealthService.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace App\Services;
  3. use AlibabaAlihealthSynergyYzwDrugreportOptHistoryAllRequest;
  4. use AlibabaAlihealthSynergyYzwQuerydrugreportRequest;
  5. use AlibabaAlihealthSynergyYzwQuerysealdrugreportRequest;
  6. use Page;
  7. use TopClient;
  8. class AlihealthService
  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. */
  29. public function queryDrugReport(string $beginTime, string $endTime, int $page = 1, int $pageSize = 20): array
  30. {
  31. $req = new AlibabaAlihealthSynergyYzwQuerydrugreportRequest;
  32. $req->setRefEntId($this->config['enterprise_id']);
  33. // $req->setFromRefEntId(""); // 发货企业(可选)
  34. // $req->setBillCode(""); // 单据编号(可选)
  35. $req->setBeginTime($beginTime);
  36. $req->setEndTime($endTime);
  37. // $req->setDrugId(""); // 药品ID(可选)
  38. // $req->setBatchNo(""); // 批号(可选)
  39. $pageObj = new Page;
  40. $pageObj->page = $page;
  41. $pageObj->page_size = $pageSize;
  42. $req->setPage(json_encode($pageObj));
  43. $resp = $this->client->execute($req);
  44. if ('SUCCESS' <> $resp->res_result->msg_code) {
  45. throw new \Exception($resp->result->msg_info);
  46. }
  47. $data = json_decode(json_encode(
  48. $resp->res_result->model->result->onenet_drug_report_top_d_t_o
  49. ), true);
  50. return (array)$resp;
  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. $data = json_decode(json_encode(
  79. $resp->result->model->result_list->ocr_seal_drug_report_d_t_o
  80. ), true);
  81. app(DrugReportInfoService::class)->bulkInsert($data);
  82. return (array)$resp;
  83. }
  84. /**
  85. * 药检报告操作日志
  86. * @link https://open.taobao.com/api.htm?docId=71189&docType=2&scopeId=30361
  87. * @param string $beginDate
  88. * @param string $endDate
  89. * @param int $page
  90. * @param int $pageSize
  91. * @return array
  92. * @throws \Exception
  93. */
  94. public function drugReportOptHistory(string $beginDate, string $endDate, int $page = 1, int $pageSize = 20): array
  95. {
  96. $req = new AlibabaAlihealthSynergyYzwDrugreportOptHistoryAllRequest;
  97. $req->setRefEntId($this->config['enterprise_id']);
  98. $req->setBeginTime($beginDate);
  99. $req->setEndTime($endDate);
  100. // $req->setBatchNo(""); // 批次号(可选)
  101. // $req->setDrugId(""); // 药品ID(可选)
  102. $req->setPage($page);
  103. $req->setPageSize($pageSize);
  104. $resp = $this->client->execute($req);
  105. if ('SUCCESS' <> $resp->result->msg_code) {
  106. throw new \Exception($resp->result->msg_info);
  107. }
  108. $data = json_decode(json_encode(
  109. $resp->result->model->result_list->top_drug_report_opt_log
  110. ), true);
  111. return (array)$resp;
  112. }
  113. }