REAPI/app/queue/command/kami91order/KamiOrderErrorRefund.php

142 lines
4.2 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\queue\command\kami91order;
//require_once(__DIR__ . "/../../../../extend/sdk/taobao/UpdateOrders.php");
use app\merchant\service\MerchantService;
use app\merchant\service\OrderService;
use app\openapi\controller\Coretb;
use app\order\service\Kami91OrderService;
use dever\Log;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
use think\Collection;
//use extend\sdk\taobao\UpdateOrders;
/**
* 错误订单退款
* Class KamiOrderStatusSync
* @package app\data\command
*/
class KamiOrderErrorRefund extends Command
{
protected function configure()
{
$this->setName('xQueue:KamiOrderErrorRefund')->setDescription('[ 卡密列表 - 自动同步 ] 错误订单退款');
}
/**
* @param Input $input
* @param Output $output
* @throws \think\admin\Exception
*/
protected function execute(Input $input, Output $output)
{
ini_set('memory_limit', '1024M');
$kami91server = Kami91OrderService::instance();
$cur = time();
$time = 300;
$whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time;
list($count, $total) = [0, $kami91server->db()->whereRaw('status = 1 and ' . $whereRaw)->count()];
// $taobao = new \app\openapi\controller\Taobao($this->app);
$kami91server->db()->whereRaw('status = 1 and ' . $whereRaw)->chunk(100, function (Collection $data) use (&$count, $total, $kami91server) {
// var_dump($orderlist);die;
foreach ($data->toArray() as $vo) {
$merchant_order_id = $vo['merchant_order_id'];
2024-09-29 15:43:18 +08:00
// $orderService = OrderService::instance();
if(str_ends_with($merchant_order_id, '-00')){
$merchant_order_id = substr($merchant_order_id, 0, -3);
}
// $orderService = OrderService::instance();
$order = OrderService::instance()->get('',$merchant_order_id, $vo['mid']);
2024-09-29 15:43:18 +08:00
if (!$order) {
$upData = [];
$upData['order_id'] = 'E' . $vo['merchant_order_id'];
$upData['status'] = '3';
$upData['callback_msg'] = '{-错误订单-}';
$upData['callback_at'] = date('Y-m-d H:i:s');
$kami91server->db()->where(array('merchant_order_id' => $vo['merchant_order_id']))->update($upData);
# 失败...
$apiParams['coop_order_status'] = 'FAILED';
$apiParams['failed_code'] = '1067';
$apiParams['failed_reason'] = '淘宝订单不存在';
$merchant = MerchantService::instance()->getInfo($vo['mid']);
$msg = $this->notify($merchant, $merchant_order_id, $apiParams);
2024-09-29 15:43:18 +08:00
if ($msg == 'success') {
$count++;
$this->setQueueProgress("错误订单退款 {$vo['merchant_order_id']} ", $count / $total * 100);
}
}
}
});
$this->setQueueSuccess("总计 {$total} 个, 处理成功 {$count} 个错误订单退款!");
}
public function notify($merchant, $merchant_order_id, $apiParams)
{
2024-09-29 15:43:18 +08:00
$requestParam = [
'coopId' => '2217166441303',
'tbOrderSnap' => ' '
];
if(isset($merchant['other_param'])){
$other_param = json_decode($merchant['other_param'],true);
if(is_array($other_param) && isset($other_param['tbCoopId'])){
$requestParam['coopId'] = $other_param['tbCoopId'];
}
}
2024-09-29 15:43:18 +08:00
$request = [
'order_id' => 'E' . $merchant_order_id,
'merchant_order_id' => $merchant_order_id
];
try {
2024-09-29 15:43:18 +08:00
$senddata = Coretb::doaction($merchant, $request, $requestParam, $apiParams);
} catch (\Exception $e) {
Log::write('errorTip', 'taobao_notify', $e->getMessage());
return 'error';
}
$data = (array)$senddata;
if (isset($data['update_result']) == 'T') {
return 'success';
} else {
return json_encode($data);
}
}
}