123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace app\common\library\wechat\wow;
- use app\common\library\wechat\WxBase;
- /**
- * 微信好物圈-订单接口
- * Class Order
- * @url https://wsad.weixin.qq.com/wsad/zh_CN/htmledition/order/html/document/orderlist/import.part.html
- * @package app\common\library\wechat\wow
- */
- class Order extends WxBase
- {
- /**
- * 接口方法描述
- * @var array
- */
- private $describe = [
- 'import' => '导入订单',
- 'update' => '更新订单信息',
- 'delete' => '删除订单',
- ];
- /**
- * 导入订单
- * @param $orderList
- * @param int $isHistory
- * @return bool
- * @throws \app\common\exception\BaseException
- */
- public function import($orderList, $isHistory = 0)
- {
- // 微信接口url
- $accessToken = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/mall/importorder?action=add-order&is_history={$isHistory}&access_token={$accessToken}";
- // 请求参数
- $params = $this->jsonEncode(['order_list' => $orderList]);
- // 执行请求
- $result = $this->post($url, $params);
- // 记录日志
- $this->doLogs(['describe' => $this->describe['import'], 'url' => $url, 'params' => $params, 'result' => $result]);
- // 返回结果
- $response = $this->jsonDecode($result);
- if (!isset($response['errcode'])) {
- $this->error = 'not found errcode';
- return false;
- }
- if ($response['errcode'] != 0) {
- $this->error = $response['errmsg'];
- return false;
- }
- return true;
- }
- /**
- * 更新订单
- * @param $orderList
- * @param int $isHistory
- * @return bool
- * @throws \app\common\exception\BaseException
- */
- public function update($orderList, $isHistory = 0)
- {
- // 微信接口url
- $accessToken = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/mall/importorder?action=update-order&is_history={$isHistory}&access_token={$accessToken}";
- // 请求参数
- $params = $this->jsonEncode(['order_list' => $orderList]);
- // 执行请求
- $result = $this->post($url, $params);
- // 记录日志
- $this->doLogs(['describe' => $this->describe['update'], 'url' => $url, 'params' => $params, 'result' => $result]);
- // 返回结果
- $response = $this->jsonDecode($result);
- if (!isset($response['errcode'])) {
- $this->error = 'not found errcode';
- return false;
- }
- if ($response['errcode'] != 0) {
- $this->error = $response['errmsg'];
- return false;
- }
- return true;
- }
- /**
- * 删除商品收藏
- * @param string $openId
- * @param string $orderId
- * @return bool
- * @throws \app\common\exception\BaseException
- */
- public function delete($openId, $orderId)
- {
- // 微信接口url
- $accessToken = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/mall/deleteorder?access_token={$accessToken}";
- // 请求参数
- $params = [
- 'user_open_id' => $openId,
- 'order_id' => $orderId
- ];
- // 执行请求
- $result = $this->post($url, $this->jsonEncode($params));
- // 记录日志
- $this->doLogs(['describe' => $this->describe['delete'], 'url' => $url, 'params' => $params, 'result' => $result]);
- // 返回结果
- $response = $this->jsonDecode($result);
- if (!isset($response['errcode'])) {
- $this->error = 'not found errcode';
- return false;
- }
- if ($response['errcode'] != 0) {
- $this->error = $response['errmsg'];
- return false;
- }
- return true;
- }
- }
|