命令行
This commit is contained in:
76
app/command/Logzip.php
Normal file
76
app/command/Logzip.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
class Logzip extends Command
|
||||
{
|
||||
protected static $defaultName = 'logzip';
|
||||
protected static $defaultDescription = 'logzip';
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$dir_arr = [
|
||||
'runtime/admin/log/',
|
||||
'runtime/api/log/',
|
||||
'runtime/czg/log/',
|
||||
'runtime/log/',
|
||||
];
|
||||
$yestermonth = date("Ym");
|
||||
// 如果今天是1号
|
||||
if(date('d') == 01 || date('d') == 1) {
|
||||
$yestermonth = date("Ym", strtotime('-1 month'));
|
||||
}
|
||||
foreach ($dir_arr as $dir_a) {
|
||||
$file_arr = getYesterdayFiles($dir_a . $yestermonth . '/');
|
||||
if(!empty($file_arr['files'])) {
|
||||
foreach ($file_arr['files'] as $k => $file_p) {
|
||||
$file = $dir_a . $yestermonth . '/' . $file_p;
|
||||
$zip_filename = str_replace('.log', '.zip', $file_p);
|
||||
$file_zip = $dir_a . $yestermonth . '/' . $zip_filename;
|
||||
$is_close = false;
|
||||
if(!file_exists($file_zip)) {
|
||||
$zip = new ZipArchive();
|
||||
if($zip->open($file_zip, ZipArchive::CREATE) === TRUE) {
|
||||
if(file_exists($file)) {
|
||||
if($zip->addFile($file, $file_p)) {
|
||||
$is_close = true;
|
||||
print_r($file . "\r\n");
|
||||
}
|
||||
}
|
||||
if ($is_close) {
|
||||
if($zip->close()) {
|
||||
if($is_close) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$output->writeln('ok');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
62
app/command/OrderTask.php
Normal file
62
app/command/OrderTask.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
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 OrderTask extends Command
|
||||
{
|
||||
protected static $defaultName = 'OrderTask';
|
||||
protected static $defaultDescription = 'OrderTask';
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
Log::info("未支付订单删除开始");
|
||||
// 获取3小时前的时间
|
||||
$threeHoursAgo = date('Y-m-d H:i:s', strtotime('-3 hours'));
|
||||
// 开启事务确保数据一致性
|
||||
DatabaseRoute::transactionXa(function () use ($threeHoursAgo, $output) {
|
||||
$deletedOrders = DatabaseRoute::deleteAllDbDirect('orders', function ($query) use ($threeHoursAgo) {
|
||||
return $query->where('create_time', '<=', $threeHoursAgo)
|
||||
->where('status', '<>', 1);
|
||||
});
|
||||
Log::info("删除了 {$deletedOrders} 条未支付订单");
|
||||
$deletedPayments = DatabaseRoute::deleteAllDbDirect('pay_details', function ($query) use ($threeHoursAgo) {
|
||||
return $query->where('create_time', '<=', $threeHoursAgo)
|
||||
->where('state', '<>', 1);
|
||||
});
|
||||
Log::info("删除了 {$deletedPayments} 条未支付支付记录");
|
||||
$output->writeln("<info>清理完成: 删除 {$deletedOrders} 个订单, {$deletedPayments} 个支付记录</info>");
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
Log::error("未支付订单清理失败: " . $e->getMessage());
|
||||
$output->writeln("<error>清理失败: " . $e->getMessage() . "</error>");
|
||||
return 1; // 返回错误码
|
||||
}
|
||||
// 返回成功码
|
||||
$output->writeln(0);
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
71
app/command/SpinningTask3.php
Normal file
71
app/command/SpinningTask3.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\queue\DiscCompensateJob;
|
||||
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 SpinningTask3 extends Command
|
||||
{
|
||||
protected static $defaultName = 'SpinningTask3';
|
||||
protected static $defaultDescription = 'SpinningTask3';
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$params = 1;
|
||||
if($input->hasOption('params')) {
|
||||
$params = $input->getOption('params');
|
||||
}
|
||||
// 计算时间范围(当前时间 - N*5分钟 到 当前时间 - (N*5+15)分钟)
|
||||
$now = time();
|
||||
$offsetMinutes = (int)$params * -5; // N*5分钟前
|
||||
$fiveMinutesAgo = date('Y-m-d H:i:s', strtotime("{$offsetMinutes} minutes", $now));
|
||||
$tenMinutesAgo = date('Y-m-d H:i:s', strtotime("-15 minutes", strtotime($fiveMinutesAgo)));
|
||||
Log::info("大转盘到账补偿时间范围:{$tenMinutesAgo}-----{$fiveMinutesAgo}");
|
||||
$list = DatabaseRoute::getAllDbData('disc_spinning_record', function ($query) use($fiveMinutesAgo, $tenMinutesAgo) {
|
||||
return $query->whereNull('target')
|
||||
->whereNull('target_id')
|
||||
->where('type', 2)
|
||||
->where('create_time', '>=', $tenMinutesAgo) // 大于等于(N*5+15)分钟前
|
||||
->where('create_time', '<=', $fiveMinutesAgo);
|
||||
})->select();
|
||||
if($list) {
|
||||
$list = $list->toArray();
|
||||
Log::info('需要补偿的总条数' . count($list));
|
||||
if(count($list) > 0) {
|
||||
// 推进队列
|
||||
$this->execAsync($list);
|
||||
}
|
||||
}
|
||||
$output->writeln("大转盘到账补偿机制结束");
|
||||
Log::write("大转盘到账补偿机制结束");
|
||||
$output->writeln('Hello SpinningTask3');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
public function execAsync($list)
|
||||
{
|
||||
foreach ($list as $k => $value) {
|
||||
pushQueue(DiscCompensateJob::class, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
106
app/command/TempOrderTask.php
Normal file
106
app/command/TempOrderTask.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\api\model\Orders;
|
||||
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 TempOrderTask extends Command
|
||||
{
|
||||
protected static $defaultName = 'TempOrderTask';
|
||||
protected static $defaultDescription = 'TempOrderTask';
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
Log::info('订单表数据处理开始');
|
||||
|
||||
// 查询待处理的支付明细(state=0,create_time 早于 15 分钟前)
|
||||
$payDetailsList = DatabaseRoute::getAllDbData('pay_details', function ($query) {
|
||||
return $query
|
||||
->where('state', 0)
|
||||
->where('create_time', '<', date('Y-m-d H:i:s', strtotime('-15 minutes')))
|
||||
->order('create_time', 'asc')
|
||||
->limit(1800);
|
||||
})->select()->toArray();
|
||||
|
||||
if (empty($payDetailsList)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Log::info('待处理数据' . count($payDetailsList) . '条');
|
||||
|
||||
foreach ($payDetailsList as $details) {
|
||||
try {
|
||||
usleep(100 * 1000); // sleep 100ms
|
||||
|
||||
// 根据 orderId 查询 Orders 表
|
||||
$order = DatabaseRoute::getAllDbData('orders', function ($query) use ($details) {
|
||||
return $query->where('orders_no', $details['order_id'])
|
||||
->where('user_id', $details['user_id']);
|
||||
})->find();
|
||||
|
||||
// 调用支付平台查询订单状态
|
||||
$baseResp = WuYouPayUtils::queryOrder(
|
||||
$details['trade_no'],
|
||||
$details['user_id'],
|
||||
(string)$details['money'],
|
||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X)...'
|
||||
);
|
||||
|
||||
Log::info('baseResp: ' . json_encode($baseResp));
|
||||
|
||||
if (empty($baseResp['code']) || $baseResp['code'] != 200) {
|
||||
Log::info('code 错误跳过');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($baseResp['payStatus'] ?? '') === 'SUCCESS' || ($baseResp['payStatus2'] ?? '') === 'SUCCESS') {
|
||||
Log::info('payDetails: ' . json_encode($details));
|
||||
Log::info('order: ' . json_encode($order));
|
||||
Orders::updateOrderStatus($details, $order, $order['user_id']);
|
||||
} else {
|
||||
Log::info('订单未支付,修改状态: ' . $details['trade_no']);
|
||||
DatabaseRoute::getDb('orders', $order['user_id'], true, true)->where([
|
||||
'orders_id' => $order['orders_id']
|
||||
])->update([
|
||||
'status' => $order ? 3 : 2
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('订单数据处理异常:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('订单表数据处理完毕');
|
||||
} 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