setCode($code); $this->setShop($shopId); $this->auth(); return $this; } public function setShopWithId($shopId) { $this->shop = Shop::query()->find($shopId); return $this; } public function setShop(Shop $shop) { $this->shop = $shop; return $this; } public function getShop() { return $this->shop; } public function setCode($code) { $this->code = $code; return $this; } public function getCode() { return $this->code; } public function setSkuId($skuId) { $this->skuId = $skuId; return $this; } public function getSkuId() { return $this->skuId; } public function formDataPostRequest($url, $params) { $headers = [ 'headers' => ['Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'], 'form_params' => $params ]; $res = (new Client())->request('POST', $url, $headers); $res = json_decode($res->getBody()->getContents(), true); $disableLogType = [ 'pdd.ktt.goods.query.list', 'pdd.ktt.order.list', 'pdd.ktt.increment.order.query' ]; $log = new Log(); $log->module = 'plat'; $log->action = 'POST'; $log->target_type = $this->shop->plat_id; $log->target_id = $this->skuId; $log->target_field = $params['type']; $log->user_id = 1; if (!in_array($params['type'], $disableLogType, true)) { $log->message = json_encode($res, 256); } $log->save(); if (isset($res['error_response'])) { throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']); } return $res; } }