Order.php 3.7 KB

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