Order.Class.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * 配送订单管理
  4. * Created by PhpStorm.
  5. * User: phperstar
  6. * Date: 2020/11/12
  7. * Time: 3:56 PM
  8. */
  9. namespace Util\DaDa;
  10. use Mall\Framework\Core\ResultWrapper;
  11. use Mall\Framework\Core\ErrorCode;
  12. class Order
  13. {
  14. private $objCommon;
  15. // 基础域名
  16. private $baseUrl = 'http://newopen.qa.imdada.cn';
  17. //公共header头
  18. private $commonHeader = [
  19. CURLOPT_HTTPHEADER => [
  20. 'Content-Type: application/json'
  21. ],
  22. ];
  23. public function __construct($appKey='', $appSecret = '', $sourceId)
  24. {
  25. $this->objCommon = new Common($appKey, $appSecret, $sourceId);
  26. }
  27. /**
  28. * 官网文档地址: http://newopen.imdada.cn/#/development/file/add?_k=yytpqx
  29. * 新增配送单接口
  30. */
  31. public function addOrder($params)
  32. {
  33. $postData = $this->objCommon->CommonRequestParams();
  34. // 业务请求参数
  35. $postData['body'] = json_encode([
  36. 'shop_no' => $params['shop_no'],
  37. 'origin_id' => $params['origin_id'],
  38. 'city_code' => $params['city_code'],
  39. 'cargo_price' => $params['cargo_price'],
  40. 'cargo_weight' => $params['cargo_weight'],
  41. 'is_prepay' => $params['is_prepay'],
  42. 'receiver_name' => $params['receiver_name'],
  43. 'receiver_address' => $params['receiver_address'],
  44. 'receiver_lat' => $params['receiver_lat'],
  45. 'receiver_lng' => $params['receiver_lng'],
  46. 'callback' => $params['callback'],
  47. ]);
  48. $postData['signature'] = $this->objCommon->getSignature($postData);
  49. $url = $this->baseUrl . '/api/order/addOrder';
  50. $response = request($url, json_encode($postData, JSON_UNESCAPED_UNICODE), 5, true, $this->commonHeader);
  51. $result = $this->objCommon->commonResponse($response);
  52. if (!$result->isSuccess()) {
  53. return ResultWrapper::fail($result->getData(), $result->getErrorCode());
  54. }
  55. return ResultWrapper::success($result->getData());
  56. }
  57. }