命令行
This commit is contained in:
89
app/command/TempCashOutTask.php
Normal file
89
app/command/TempCashOutTask.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\admin\model\Order;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\utils\WuYouPayUtils;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use support\Log;
|
||||
|
||||
|
||||
class TempCashOutTask extends Command
|
||||
{
|
||||
protected static $defaultName = 'TempCashOutTask';
|
||||
protected static $defaultDescription = 'TempCashOutTask';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
try {
|
||||
$time = date('Y-m-d H:i:s', strtotime('-15 minutes'));
|
||||
|
||||
// 查询待处理的提现订单(你需要根据你的业务逻辑调整 where 条件)
|
||||
$cashOuts = DatabaseRoute::getAllDbData('cash_out', function ($query) use ($time) {
|
||||
return $query->where([
|
||||
['state', 'in', [0, 4]],
|
||||
['user_type', '=', 1],
|
||||
['create_at', '<', $time],
|
||||
['order_number', '!=', ''],
|
||||
])->whereNotNull('order_number');
|
||||
})->select()->toArray();
|
||||
|
||||
Log::info('定时查询提现订单 待处理订单: ' . count($cashOuts));
|
||||
|
||||
$sucOrderList = [];
|
||||
$failOrderList = [];
|
||||
|
||||
foreach ($cashOuts as $cashOut) {
|
||||
try {
|
||||
// 调用支付平台接口(需你自定义服务类)
|
||||
$baseResp = WuYouPayUtils::queryExtractOrder(
|
||||
$cashOut['order_number'],
|
||||
$cashOut['user_id'],
|
||||
$cashOut['user_type'] != 2,
|
||||
$cashOut['money']
|
||||
);
|
||||
|
||||
// 执行回调(需你自定义服务类)
|
||||
$result = Order::executeExtractCallback($cashOut, $baseResp);
|
||||
|
||||
if ($result === 1) {
|
||||
$sucOrderList[] = $cashOut['order_number'];
|
||||
} else {
|
||||
$failOrderList[] = $cashOut['order_number'];
|
||||
}
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('提现定时任务查询出错: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('定时查询提现订单 提现结束, 成功:' . count($sucOrderList) . '条, 失败:' . count($failOrderList) . '条');
|
||||
Log::info('定时查询提现订单 成功:' . json_encode($sucOrderList) . ', 失败:' . json_encode($failOrderList));
|
||||
} catch (\Exception $e) {
|
||||
Log::error("定时查询提现订单失败: " . $e->getMessage());
|
||||
Log::info($e->getTraceAsString());
|
||||
$output->writeln("<error>定时查询提现订单失败: " . $e->getMessage() . "</error>");
|
||||
return 1; // 返回错误码
|
||||
}
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user