<?php

namespace App\Services\Business\KuaiTuanTuan;

class FaceSheet extends KuaiTuanTuan
{
    protected $clientId = '24f25877aca447c5830a6aa896301d5e';
    protected $clientSecret = '59b6f4bd402c6423878a8f4ef1bde28359c1f05a';
    protected $redirectUri = 'http://erp.chutang66.com/pdd/ship';

    public function __construct()
    {
    }

    public function getAuthUrl($shopId, $platId)
    {
        $state = $shopId . '_' . $platId;

        return "https://wb.pinduoduo.com/logistics/auth?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}";
    }

    /**
     * 快递公司查看接口
     *
     * @return mixed
     */
    public function getCompanies()
    {
        $type = 'pdd.logistics.companies.get';
        $appendParams = [];

        return $this->doRequest($type, $appendParams);
    }

    public function getWayBill($sender, $orderInfo, $wpCode)
    {
        $type = 'pdd.waybill.get';
        $appendParams = [
            'param_waybill_cloud_print_apply_new_request' => [
                'sender' => $sender,
                'trade_order_info_dtos' => [$orderInfo],
                'wp_code' => $wpCode,
            ]
        ];
        $appendParams['param_waybill_cloud_print_apply_new_request'] = json_encode($appendParams['param_waybill_cloud_print_apply_new_request'], 256);

        return $this->doRequest($type, $appendParams);
    }

    /**
     * searchWayBill
     *
     * @return mixed
     */
    public function searchWayBill()
    {
        $type = 'pdd.waybill.search';
        $appendParams = [];

        return $this->doRequest($type, $appendParams);
    }

    public function getLogisticsOrderTrance()
    {
        $type = 'pdd.logistics.ordertrace.get';
        $appendParams = [];

        return $this->doRequest($type, $appendParams);
    }

    public function getStdTemplates()
    {
        $type = 'pdd.cloudprint.stdtemplates.get';
        $appendParams = [
            'wp_code' => 'SF'
        ];

        return $this->doRequest($type, $appendParams);
    }

    public function getCustomares()
    {
        $type = 'pdd.cloudprint.customares.get';
        $appendParams = [];

        return $this->doRequest($type, $appendParams);
    }

    public function cancel($waybillCode, $wpCode)
    {
        $type = 'pdd.cloudprint.customares.get';
        $appendParams = [
            'waybill_code' => $waybillCode,
            'wp_code' => $wpCode,
        ];

        return $this->doRequest($type, $appendParams);
    }
}

