
- 添加 endsWithDoubleZero 函数,用于处理数值字符串末尾的两个零 - 修改 Core.php 中的 queue 方法,增加对卡库提单的特殊处理逻辑 -调整 Feedov.php 中的订单查询和充值逻辑,提高系统稳定性 - 优化数据库配置,连接测试数据库以确保数据安全
142 lines
4.2 KiB
PHP
142 lines
4.2 KiB
PHP
<?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'];
|
|
|
|
// $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']);
|
|
|
|
|
|
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);
|
|
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)
|
|
{
|
|
|
|
$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'];
|
|
}
|
|
}
|
|
|
|
$request = [
|
|
'order_id' => 'E' . $merchant_order_id,
|
|
'merchant_order_id' => $merchant_order_id
|
|
];
|
|
|
|
|
|
|
|
try {
|
|
|
|
$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);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|