Order.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\library\wechat\wow;
  10. use app\common\library\wechat\WxBase;
  11. /**
  12. * 微信好物圈-订单接口
  13. * Class Order
  14. * @url https://wsad.weixin.qq.com/wsad/zh_CN/htmledition/order/html/document/orderlist/import.part.html
  15. * @package app\common\library\wechat\wow
  16. */
  17. class Order extends WxBase
  18. {
  19. /**
  20. * 接口方法描述
  21. * @var array
  22. */
  23. private $describe = [
  24. 'import' => '导入订单',
  25. 'update' => '更新订单信息',
  26. 'delete' => '删除订单',
  27. ];
  28. /**
  29. * 导入订单
  30. * @param $orderList
  31. * @param int $isHistory
  32. * @return bool
  33. * @throws \app\common\exception\BaseException
  34. */
  35. public function import($orderList, $isHistory = 0)
  36. {
  37. // 微信接口url
  38. $accessToken = $this->getAccessToken();
  39. $url = "https://api.weixin.qq.com/mall/importorder?action=add-order&is_history={$isHistory}&access_token={$accessToken}";
  40. // 请求参数
  41. $params = $this->jsonEncode(['order_list' => $orderList]);
  42. // 执行请求
  43. $result = $this->post($url, $params);
  44. // 记录日志
  45. $this->doLogs(['describe' => $this->describe['import'], 'url' => $url, 'params' => $params, 'result' => $result]);
  46. // 返回结果
  47. $response = $this->jsonDecode($result);
  48. if (!isset($response['errcode'])) {
  49. $this->error = 'not found errcode';
  50. return false;
  51. }
  52. if ($response['errcode'] != 0) {
  53. $this->error = $response['errmsg'];
  54. return false;
  55. }
  56. return true;
  57. }
  58. /**
  59. * 更新订单
  60. * @param $orderList
  61. * @param int $isHistory
  62. * @return bool
  63. * @throws \app\common\exception\BaseException
  64. */
  65. public function update($orderList, $isHistory = 0)
  66. {
  67. // 微信接口url
  68. $accessToken = $this->getAccessToken();
  69. $url = "https://api.weixin.qq.com/mall/importorder?action=update-order&is_history={$isHistory}&access_token={$accessToken}";
  70. // 请求参数
  71. $params = $this->jsonEncode(['order_list' => $orderList]);
  72. // 执行请求
  73. $result = $this->post($url, $params);
  74. // 记录日志
  75. $this->doLogs(['describe' => $this->describe['update'], 'url' => $url, 'params' => $params, 'result' => $result]);
  76. // 返回结果
  77. $response = $this->jsonDecode($result);
  78. if (!isset($response['errcode'])) {
  79. $this->error = 'not found errcode';
  80. return false;
  81. }
  82. if ($response['errcode'] != 0) {
  83. $this->error = $response['errmsg'];
  84. return false;
  85. }
  86. return true;
  87. }
  88. /**
  89. * 删除商品收藏
  90. * @param string $openId
  91. * @param string $orderId
  92. * @return bool
  93. * @throws \app\common\exception\BaseException
  94. */
  95. public function delete($openId, $orderId)
  96. {
  97. // 微信接口url
  98. $accessToken = $this->getAccessToken();
  99. $url = "https://api.weixin.qq.com/mall/deleteorder?access_token={$accessToken}";
  100. // 请求参数
  101. $params = [
  102. 'user_open_id' => $openId,
  103. 'order_id' => $orderId
  104. ];
  105. // 执行请求
  106. $result = $this->post($url, $this->jsonEncode($params));
  107. // 记录日志
  108. $this->doLogs(['describe' => $this->describe['delete'], 'url' => $url, 'params' => $params, 'result' => $result]);
  109. // 返回结果
  110. $response = $this->jsonDecode($result);
  111. if (!isset($response['errcode'])) {
  112. $this->error = 'not found errcode';
  113. return false;
  114. }
  115. if ($response['errcode'] != 0) {
  116. $this->error = $response['errmsg'];
  117. return false;
  118. }
  119. return true;
  120. }
  121. }