惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
aimingoo的专栏
aimingoo的专栏
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
IT之家
IT之家
V
Visual Studio Blog
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
A
About on SuperTechFans
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
N
News and Events Feed by Topic
A
Arctic Wolf
WordPress大学
WordPress大学
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Y
Y Combinator Blog
T
Threat Research - Cisco Blogs
Latest news
Latest news
Simon Willison's Weblog
Simon Willison's Weblog
Cyberwarzone
Cyberwarzone
S
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
Lohrmann on Cybersecurity
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
J
Java Code Geeks
Spread Privacy
Spread Privacy
宝玉的分享
宝玉的分享
I
Intezer
L
LangChain Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
G
GRAHAM CLULEY
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
News and Events Feed by Topic
AWS News Blog
AWS News Blog
Attack and Defense Labs
Attack and Defense Labs
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 天心PHP

去除文件夹下面所有xlsx的样式脚本 php 上传视频到阿里云OSS (不用SDK) 升级版本 断点续传 php 上传视频到阿里云OSS (不用SDK) SHEIN 开放平台授权 mercadolibre 美卡多 拉取listing Amazon SP API批量更新价格 JSON_LISTINGS_FEED Allegro API接口 Wildberries API接口 沃尔玛拉取listing和库存 沃尔玛修改促销价格 Amazon SP API 拉取产品详情和修改产品属性 Amazon SP API拉取分类,五点,描述和关键字 Amazon SP API拉取日期范围报告和分类树 PHP 提取PDF文件内容 常用sql(1.分组取最新的 N 条数据; 2.删除重复数据 ) kaufland平台api mercadolibre 美卡多 本土授权(PKCE) go mod Amazon SP API拉取listing 和 批量调价
Ozon API接口
天心PHP · 2025-04-23 · via 博客园 - 天心PHP

2025-04-23 15:07  天心PHP  阅读(1040)  评论()    收藏  举报

退货申请列表

https://docs.ozon.ru/api/seller/zh/?__rr=1#operation/RFBSReturnsAPI_ReturnsRfbsListV2

OzonController

<?php
class OzonController extends YbController
{
    /**
     * @Notes : 获取Ozon退货报告
     * /services/ozon/ozon/getgoodsreturn
     * @author: xsh
     * @Time  : 2025/4/22 0020   14:40
     */
    public function actionGetgoodsreturn()
    {
        set_time_limit('3600');
        $account_id = Yii::app()->request->getParam('account_id');
        $type = Yii::app()->request->getParam('type');
        $gstart_date = Yii::app()->request->getParam('start_date');
        $gend_date = Yii::app()->request->getParam('end_date');
        $model = new Ozonreturns();
        $accmodel = new OzonAccount();
        $keys = "ozon_returns_line";
        if($type=='see'){
            $accountss = Yii::app()->memcache->get($keys);
            $lines = json_decode($accountss,true);
            VHelper::dump($lines);exit();
        }
        if($type=='del'){
            Yii::app()->memcache->delete($keys);
            die('删除换成成功');
        }
        if($account_id){
            if($gstart_date){
                $start_date = date('Y-m-d\TH:i:s', strtotime(date('Y-m-d', strtotime($gstart_date)))); // 转换为日期时间格式,但不包括毫秒和时区
            }else{
                $start_date = date('Y-m-d\TH:i:s', strtotime(date('Y-m-d', strtotime('-31 day')))); // 转换为日期时间格式,但不包括毫秒和时区
            }
            $start_utcDate = $start_date . 'Z'; // 添加'Z'表示UTC
            if($gend_date){
                $end_date = date('Y-m-d\TH:i:s', strtotime(date('Y-m-d', strtotime($gend_date)))); // 转换为日期时间格式,但不包括毫秒和时区
            }else{
                $end_date = date('Y-m-d\TH:i:s', strtotime(date('Y-m-d', strtotime('-1 day')))); // 转换为日期时间格式,但不包括毫秒和时区
            }
            $end_utcDate = $end_date . 'Z'; // 添加'Z'表示UTC
            $oaccmodel=new OzonAccount();
            $accountinfo = $oaccmodel->findByPk($account_id);
            $wmodel = new Ozon($accountinfo);
            $datetimes = date('Y-m-d H:i:s');
            $paramdata['filter'] = ['created_at'=>['from'=>$start_utcDate,'to'=>$end_utcDate]];
            $paramdata['limit'] = 1000;
            $res = $wmodel->get_goods_return($paramdata);
            if($res[0]==200 && isset($res[1]['returns'])){
                $list = $data = [];
                foreach ($res[1]['returns'] as $key => $value) {
                    $dateTime = new DateTime($value['created_at']);
                    $created_date = $dateTime->format('Y-m-d H:i:s');
                    $data['account_name'] = $accountinfo->account_name;
                    $data['account_id'] = $account_id;
                    $data['batchnumber'] = date('Ym',strtotime($created_date));
                    $data['client_name'] = $value['client_name'];
                    $data['created_at'] = $value['created_at'];
                    $data['created_date'] = $created_date;
                    $data['order_number'] = $value['order_number'];
                    $data['posting_number'] = $value['posting_number'];
                    $data['product_name'] = $value['product']['name'];
                    $data['product_offer_id'] = $value['product']['offer_id'];
                    $data['product_currency_code'] = $value['product']['currency_code'];
                    $data['product_price'] = $value['product']['price'];
                    $data['product_sku'] = $value['product']['sku'];
                    $data['return_id'] = $value['return_id'];
                    $data['return_number'] = $value['return_number'];
                    $data['group_state'] = $value['state']['group_state'];
                    $data['money_return_state_name'] = $value['state']['money_return_state_name'];
                    $data['state'] = $value['state']['state'];
                    $data['state_name'] = $value['state']['state_name'];
                    $infoid = $model->getDbConnection()->createCommand()->select('id')->from("yibai_ozon_returns")
                        ->where("order_number='{$value['order_number']}' and return_id={$value['return_id']}")->queryScalar();
                    if($infoid){
                        $data['update_date'] = $datetimes;
                        $model->updateAll($data,"id=".$infoid);
                    }else{
                        $data['create_date'] = $datetimes;
                        $list[] = $data;
                        if(count($list)>=2000){
                            $fart = $model->batchReplaceAll("{{ozon_returns}}", array_keys($list[0]), $list);
                            if($fart){
                                $list = [];
                            }
                        }
                    }
                }
                if($list){
                    $fart = $model->batchReplaceAll("{{ozon_returns}}", array_keys($list[0]), $list);
                    if($fart){
                        $list = [];
                    }
                }
            }
            $accountss = Yii::app()->memcache->get($keys);
            $accountss = json_decode($accountss,true);
            $line = $account_id%10;
            if(!empty($accountss[$line])){
                $account_id = array_shift($accountss[$line]);
                Yii::app()->memcache->set($keys,json_encode($accountss),12*3600);
                if($gstart_date || $gend_date){
                    $url = sprintf('%s/services/ozon/ozon/getgoodsreturn/account_id/%s/start_date/%s/end_date/%s', $_SERVER['HTTP_HOST'], $account_id,$start_date,$end_date);
                }else{
                    $url = sprintf('%s/services/ozon/ozon/getgoodsreturn/account_id/%s', $_SERVER['HTTP_HOST'], $account_id);
                }
                echo $url;echo '<br/>';
                MHelper::curl_post_async($url);
            }else{
                $line = $line+1;
                if($line>9){
                    die('处理完成');
                }
                $account_id = array_shift($accountss[$line]);
                Yii::app()->memcache->set($keys,json_encode($accountss),12*3600);
                if($gstart_date || $gend_date){
                    $url = sprintf('%s/services/ozon/ozon/getgoodsreturn/account_id/%s/start_date/%s/end_date/%s', $_SERVER['HTTP_HOST'], $account_id,$start_date,$end_date);
                }else{
                    $url = sprintf('%s/services/ozon/ozon/getgoodsreturn/account_id/%s', $_SERVER['HTTP_HOST'], $account_id);
                }
                echo $url;echo '<br/>';
                MHelper::curl_post_async($url);
            }
        }else{
            $accountss = Yii::app()->memcache->get($keys);
            $lines = json_decode($accountss,true);
            if(count(array_filter($lines))==0){
                Yii::app()->memcache->delete($keys);
            }
            if(empty($lines)){
                $accounts = $accmodel->getDbConnection()->createCommand()
                    ->select('id,MOD(id,10)as line')
                    ->from($accmodel->tableName())
                    ->where('status=1')
                    ->order('id asc')
                    ->queryAll();
                if(!$accounts){
                    die('数据已经处理完成');
                }
                $accounts_line=array_column($accounts,null,'id');
                foreach($accounts_line as $val){
                    $lines[$val['line']][] = $val['id'];
                }
            }
            if(count(array_filter($lines))==0){
                die('处理完成');
            }
            for($i=0;$i<10;$i++){
                if(!empty($lines[$i])){
                    $account_id = array_shift($lines[$i]);
                    Yii::app()->memcache->set($keys,json_encode($lines),12*3600);
                    if($gstart_date || $gend_date){
                        $url = sprintf('%s/services/ozon/ozon/getgoodsreturn/account_id/%s/start_date/%s/end_date/%s', $_SERVER['HTTP_HOST'], $account_id,$gstart_date,$gend_date);
                    }else{
                        $url = sprintf('%s/services/ozon/ozon/getgoodsreturn/account_id/%s', $_SERVER['HTTP_HOST'], $account_id);
                    }
                    echo $url;echo '<br/>';
                    MHelper::curl_post_async($url);
                    break;
                }else{
                    continue;
                }
            }
        }
    }

}
class Ozon
<?php
class Ozon
{
    private $Client_Id;
    private $Api_Key;
    private $host_url;
    function __construct($account){
        //获取配置信息
        $this->Client_Id = $account->client_id;
        $this->Api_Key = $account->api_key;
        $this->host_url = 'https://api-seller.ozon.ru';
    }

    public function get_goods_return($paramdata)
    {
        $url = '/v2/returns/rfbs/list';
        $url = $this->host_url.$url."";
        $headers[] = 'Client-Id:' . $this->Client_Id;
        $headers[] = 'Api-Key:' . $this->Api_Key;
        $headers[] = 'Content-Type: application/json';
        $res = $this->cur_request($url, 'POST', json_encode($paramdata), $headers);
        return $res;
    }

    public function cur_request($URL, $type, $params, $headers)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $URL);
        if ($headers != "") {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        } else {
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
        }
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        switch ($type) {
            case "GET" :
                curl_setopt($ch, CURLOPT_HTTPGET, true);
                break;
            case "POST":
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                break;
            case "PUT" :
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                break;
            case "PATCH":
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                break;
            case "DELETE":
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                break;
        }
        $file_contents = curl_exec($ch);//获得返回值
        $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return [$responseCode, json_decode($file_contents, true)];
    }
}