Order.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services\erp\storage\jushuitan;
  12. use crmeb\exceptions\AdminException;
  13. use crmeb\services\erp\AccessToken;
  14. use crmeb\services\erp\storage\Jushuitan;
  15. use Exception;
  16. class Order
  17. {
  18. /**
  19. * token句柄
  20. * @var AccessToken
  21. */
  22. protected $accessToken;
  23. /*** @var Jushuitan */
  24. protected $jushuitan;
  25. /**
  26. * @param Jushuitan $jushuitan
  27. */
  28. public function __construct(AccessToken $accessToken, Jushuitan $jushuitan)
  29. {
  30. $this->accessToken = $accessToken;
  31. $this->jushuitan = $jushuitan;
  32. }
  33. /**
  34. * 订单上传(推荐)
  35. * @param array $data
  36. * @return array
  37. * @throws Exception
  38. */
  39. public function ordersUpload(array $data): array
  40. {
  41. $url = $this->accessToken->getApiUrl("/open/jushuitan/orders/upload");
  42. //拼装请求参数
  43. $params = $this->jushuitan->getParams($data);
  44. //请求平台接口
  45. $request = $this->jushuitan->postRequest($url, $params);
  46. return $request["data"];
  47. }
  48. /**
  49. * 订单查询
  50. * @param array $data
  51. * @return array
  52. * @throws Exception
  53. */
  54. public function ordersSingleQuery(array $data): array
  55. {
  56. $url = $this->accessToken->getApiUrl("/open/orders/single/query");
  57. //业务参数
  58. $biz = [];
  59. if (isset($data["page_index"])) {
  60. //int 第几页,从第一页开始,默认1
  61. $biz["page_index"] = intval($data["page_index"]);
  62. }
  63. if (isset($data["page_size"])) {
  64. //int 每页多少条;默认30条,最大50条
  65. $biz["page_size"] = intval($data["page_size"]);
  66. }
  67. if (isset($data["modified_begin"])) {
  68. if (empty($data["modified_end"])) {
  69. throw new AdminException("起始和结束时间必须同时存在");
  70. }
  71. //string日志起始时间,起始时间和 结束时间必须同时存在,时间间隔不能超过七天
  72. $biz["modified_begin"] = strval($data["modified_begin"]);
  73. $biz["modified_end"] = strval($data["modified_end"]);
  74. }
  75. ///list 线上单号号,最大限制20条
  76. if (isset($data["so_ids"])) {
  77. $biz["so_ids"] = $data["so_ids"];
  78. } elseif (empty($biz["modified_begin"]) || empty($biz["modified_end"])) {
  79. //线上单号与修改时间不能同时为空
  80. throw new AdminException("线上单号,与修改时间不能同时为空");
  81. }
  82. //店铺编号
  83. if (!empty($data["shop_id"])) {
  84. $biz["shop_id"] = $data["shop_id"];
  85. }
  86. //shop_id为0且is_offline_shop为true查询线下店铺单据 非必填 bool
  87. if (isset($data["is_offline_shop"]) && !is_null($data["is_offline_shop"])) {
  88. $biz["is_offline_shop"] = $data["is_offline_shop"];
  89. }
  90. if (!empty($data["status"])) {
  91. $biz["status"] = $data["status"];
  92. }
  93. //拼装请求参数
  94. $params = $this->jushuitan->getParams($biz);
  95. //请求平台接口
  96. $request = $this->jushuitan->postRequest($url, $params);
  97. return $request["data"];
  98. }
  99. /**
  100. * 订单取消-按内部单号取消
  101. * @param array $data
  102. * @return bool
  103. * @throws Exception
  104. */
  105. public function orderByOIdCancel(array $data): bool
  106. {
  107. $url = $this->accessToken->getApiUrl("/open/jushuitan/orderbyoid/cancel");
  108. //拼装请求参数
  109. $params = $this->jushuitan->getParams($data);
  110. //请求平台接口
  111. $this->jushuitan->postRequest($url, $params);
  112. return true;
  113. }
  114. /**
  115. * 实际收货上传
  116. * @param array $list
  117. * @return array
  118. * @throws Exception
  119. */
  120. public function afterSaleUpload(array $list): array
  121. {
  122. $url = $this->accessToken->getApiUrl("/open/aftersale/upload");
  123. //拼装请求参数
  124. $params = $this->jushuitan->getParams($list);
  125. //请求平台接口
  126. $request = $this->jushuitan->postRequest($url, $params);
  127. return $request["data"];
  128. }
  129. }