FlagshipCreateOrderSendTrait.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace addons\WangDianTong\common\traits;
  3. use addons\WangDianTong\common\expand\sdk\wangdian\qjb\model\SalesRawTradePushSelfV2Model;
  4. use addons\WangDianTong\common\expand\sdk\wangdian\qjb\request\SalesRawTradePushSelfV2Request;
  5. use addons\WangDianTong\common\service\CreateOrderService;
  6. use common\enums\StatusEnum;
  7. use yii\helpers\Json;
  8. trait FlagshipCreateOrderSendTrait
  9. {
  10. /**
  11. * @param array $config
  12. * @param array $order
  13. * @return mixed|string|true
  14. */
  15. public function flagshipSend(array $config, array $order)
  16. {
  17. $req = new SalesRawTradePushSelfV2Request($config);
  18. $model = new SalesRawTradePushSelfV2Model();
  19. [$model->rawTradeList, $model->rawTradeOrderList, $model->discountList] = (new CreateOrderService())->flagshipAssembleData($order);
  20. $model->shop_no = $config['shop_no'];
  21. if (empty($model->rawTradeList)) {
  22. return true;
  23. }
  24. $resp = $req->send($model);
  25. if ($resp->getError()) return $resp->getError();
  26. // 执行其他操作
  27. try {
  28. $res = $resp->toArray();
  29. if (!isset($res['status']) || $res['status'] != StatusEnum::DISABLED) return $res['message'] ?? var_export($res, true);
  30. } catch (\Exception $e) {
  31. return $e->getMessage();
  32. }
  33. return true;
  34. }
  35. /**
  36. * @param array $config
  37. * @param array $order
  38. * @return void
  39. * @throws \Exception
  40. */
  41. protected function flagship(array $config, array $order)
  42. {
  43. $flag = $this->retry(function () use ($config, $order) {
  44. return $this->flagshipSend($config, $order);
  45. });
  46. if (is_string($flag)) throw new \Exception($flag);
  47. }
  48. }