| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace addons\WangDianTong\common\traits;
- use addons\WangDianTong\common\expand\sdk\wangdian\qjb\model\SalesRawTradePushSelfV2Model;
- use addons\WangDianTong\common\expand\sdk\wangdian\qjb\request\SalesRawTradePushSelfV2Request;
- use addons\WangDianTong\common\service\CreateOrderService;
- use common\enums\StatusEnum;
- use yii\helpers\Json;
- trait FlagshipCreateOrderSendTrait
- {
- /**
- * @param array $config
- * @param array $order
- * @return mixed|string|true
- */
- public function flagshipSend(array $config, array $order)
- {
- $req = new SalesRawTradePushSelfV2Request($config);
- $model = new SalesRawTradePushSelfV2Model();
- [$model->rawTradeList, $model->rawTradeOrderList, $model->discountList] = (new CreateOrderService())->flagshipAssembleData($order);
- $model->shop_no = $config['shop_no'];
- if (empty($model->rawTradeList)) {
- return true;
- }
- $resp = $req->send($model);
- if ($resp->getError()) return $resp->getError();
- // 执行其他操作
- try {
- $res = $resp->toArray();
- if (!isset($res['status']) || $res['status'] != StatusEnum::DISABLED) return $res['message'] ?? var_export($res, true);
- } catch (\Exception $e) {
- return $e->getMessage();
- }
- return true;
- }
- /**
- * @param array $config
- * @param array $order
- * @return void
- * @throws \Exception
- */
- protected function flagship(array $config, array $order)
- {
- $flag = $this->retry(function () use ($config, $order) {
- return $this->flagshipSend($config, $order);
- });
- if (is_string($flag)) throw new \Exception($flag);
- }
- }
|