154 lines
5.5 KiB
PHP
154 lines
5.5 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\queue\command\taobao;
|
||
|
|
||
|
|
||
|
use app\merchant\service\MerchantService;
|
||
|
use app\openapi\controller\Coretb;
|
||
|
use app\order\service\AfterSalesOrderService;
|
||
|
use think\admin\Command;
|
||
|
use think\console\Input;
|
||
|
use think\console\Output;
|
||
|
use think\Collection;
|
||
|
|
||
|
/**
|
||
|
* 主动更新退款订单详情
|
||
|
* Class KamiOrderStatusSync
|
||
|
* @package app\data\command
|
||
|
*/
|
||
|
class TaobaoAfterSalesOrderInfo extends Command
|
||
|
{
|
||
|
protected function configure()
|
||
|
{
|
||
|
|
||
|
$this->setName('xQueue:TaobaoAfterSalesOrderInfo')->setDescription('[ 淘宝直充 - 自动同步 ] 主动更新售后订单信息');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param Input $input
|
||
|
* @param Output $output
|
||
|
* @throws \think\admin\Exception
|
||
|
*/
|
||
|
protected function execute(Input $input, Output $output)
|
||
|
{
|
||
|
ini_set('memory_limit', '1024M');
|
||
|
// $request = [];
|
||
|
// $request['agentId'] = '34615444';
|
||
|
// $request['agentkey'] = '2e59a0c00b4fafd9ae46bedced6eccc3';
|
||
|
// $mid = '1';
|
||
|
// $merchant = MerchantService::instance()->get($mid);
|
||
|
// $request['access_token'] = $merchant['access_token'];
|
||
|
$merchants=MerchantService::instance()->db()->where(['merchant_type'=>8,['access_token_time','>=',time()]])->whereNotNull('access_token')->select()->toArray();
|
||
|
if(!$merchants) $this->setQueueSuccess("未找到需要处理的天猫商家");
|
||
|
$merchant_num = count($merchants);
|
||
|
$count_sum = 0;
|
||
|
$total_sum=0;
|
||
|
|
||
|
|
||
|
foreach($merchants as $merchant){
|
||
|
$request = [];
|
||
|
$other_param = json_decode($merchant['other_param'],true);
|
||
|
$request['agentId'] = $other_param['reapi_appkey'];
|
||
|
$request['agentkey'] = $other_param['reapi_appsecret'];
|
||
|
$mid =$merchant['id'];
|
||
|
$request['access_token'] = $merchant['access_token'];
|
||
|
|
||
|
|
||
|
$aftersalesservice = AfterSalesOrderService::instance();
|
||
|
// $where1[] = [
|
||
|
// 'status' ,'not in', [2, 3]
|
||
|
// ];
|
||
|
$where1 = [
|
||
|
'status' =>1,
|
||
|
'mid' =>$mid
|
||
|
];
|
||
|
|
||
|
list($count, $total) = [0, $aftersalesservice->db()->where($where1)->count()];
|
||
|
$total_sum+=$total;
|
||
|
|
||
|
|
||
|
$aftersalesservice->db()->where($where1)->chunk(100, function (Collection $data) use (&$count, $total,$aftersalesservice,$request,&$count_sum) {
|
||
|
// var_dump($orderlist);die;
|
||
|
foreach ($data->toArray() as $vo) {
|
||
|
$request['refundId'] = $vo['refund_id'];
|
||
|
$response = Coretb::taobaosdk('refundInfo', $request);
|
||
|
$json = json_encode($response);
|
||
|
$array = json_decode($json,true);
|
||
|
if (!isset($array['refund'])){
|
||
|
$this->setQueueError("没有获取到售后退款订单!");
|
||
|
|
||
|
}
|
||
|
if(isset($array['refund'])) {
|
||
|
$array = $array['refund'];
|
||
|
|
||
|
|
||
|
$update = [];
|
||
|
$up = false;
|
||
|
switch ($array['status']) {
|
||
|
case "WAIT_SELLER_AGREE" :
|
||
|
if (empty($vo['s_nubmer'])) {
|
||
|
$update['reason'] = $array['reason'];
|
||
|
$update['infodata'] = json_encode($array);
|
||
|
$update['s_nubmer'] = $array['alipay_no'];
|
||
|
|
||
|
if (isset($array['refund_remind_timeout']['exist_timeout']) && $array['refund_remind_timeout']['exist_timeout'] == 'true') {
|
||
|
$update['expire_time'] = $array['refund_remind_timeout']['timeout'];
|
||
|
}
|
||
|
$up = true;
|
||
|
}
|
||
|
break;
|
||
|
case "SUCCESS" :
|
||
|
$update['status'] = '2';
|
||
|
if (isset($array['end_time'])) {
|
||
|
$update['end_time'] = $array['end_time'];
|
||
|
}
|
||
|
|
||
|
$up = true;
|
||
|
break;
|
||
|
case "CLOSED" :
|
||
|
$update['status'] = '3';
|
||
|
if (isset($array['end_time'])) {
|
||
|
$update['end_time'] = $array['end_time'];
|
||
|
}
|
||
|
$up = true;
|
||
|
break;
|
||
|
case "SELLER_REFUSE_BUYER" :
|
||
|
$update['infodata'] = json_encode($array);
|
||
|
$update['status'] = '5';
|
||
|
$up = true;
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
if ($up) {
|
||
|
$count++;
|
||
|
$count_sum++;
|
||
|
$this->setQueueProgress("更新售后订单 {$vo['refund_id']} 状态", $count / $total * 100);
|
||
|
$upRefund = $aftersalesservice->up(['refund_id' => $vo['refund_id']], $update);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
$this->setQueueProgress("处理完订单状态 {$vo['order_id']} ", $count / $total * 100);
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
$this->setQueueSuccess("共处理 {$merchant_num} 个商家,共获取到个 {$total_sum} 售后退款订单,更新了 {$count_sum} 个售后订单信息!");
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|