2024-07-10 17:16:48 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\command;
|
|
|
|
|
|
|
|
|
|
use app\common\Error;
|
|
|
|
|
use app\model\Orders as OrdersModel;
|
|
|
|
|
use app\server\Orders;
|
2024-08-02 10:14:31 +08:00
|
|
|
|
use app\server\Orders as ServerOrders;
|
2024-07-10 17:16:48 +08:00
|
|
|
|
use support\Redis;
|
|
|
|
|
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 NotUsedOrderSms extends Command
|
|
|
|
|
{
|
|
|
|
|
protected static $defaultName = 'sms:notusedorder';
|
|
|
|
|
protected static $defaultDescription = '给带使用订单发送短信。';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
{
|
2024-08-02 10:14:31 +08:00
|
|
|
|
$this->output($output, self::$defaultName . " started, " . date('Y-m-d H:i:s'));
|
2024-07-10 17:16:48 +08:00
|
|
|
|
|
|
|
|
|
$orders = $this->orders();
|
|
|
|
|
$total = count($orders);
|
|
|
|
|
|
|
|
|
|
$this->output($output, "got {$total} orders");
|
|
|
|
|
|
|
|
|
|
if (1 > $total) {
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach($orders as $order) {
|
|
|
|
|
if (empty($order->mobile)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 10:14:31 +08:00
|
|
|
|
if (ServerOrders::isDaishiyong($order)) {
|
|
|
|
|
$order = ServerOrders::syncFromThirdV2($order);
|
|
|
|
|
}
|
2024-07-10 17:16:48 +08:00
|
|
|
|
|
2024-08-02 10:14:31 +08:00
|
|
|
|
if ( $order &&
|
|
|
|
|
($order->os == 1 && $order->order_status != 3)
|
|
|
|
|
|| ($order->os == 2 && $order->order_status != 4)
|
|
|
|
|
|| ($order->os == 3 && $order->order_status != 1)
|
|
|
|
|
) {
|
|
|
|
|
$this->output($output, "单号 {$order->sn} : 状态已修改");
|
|
|
|
|
continue;
|
2024-07-10 17:16:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 10:22:50 +08:00
|
|
|
|
$result = Orders::reminderOrders($order);
|
2024-08-02 10:14:31 +08:00
|
|
|
|
$text = '已发送提醒。';
|
|
|
|
|
|
2024-08-02 10:22:50 +08:00
|
|
|
|
if (Error::is($result)) {
|
|
|
|
|
$text = '发送短信失败,' . $result['message'] ?? '';
|
|
|
|
|
}
|
2024-08-02 10:14:31 +08:00
|
|
|
|
|
2024-07-10 17:16:48 +08:00
|
|
|
|
$this->output($output, "单号 {$order->sn} : {$text}");
|
2024-08-02 10:14:31 +08:00
|
|
|
|
|
2024-08-02 10:22:50 +08:00
|
|
|
|
$order->next_remind_time = $order->next_remind_time + 10 * 24 * 60 * 60;
|
|
|
|
|
$order->save();
|
2024-07-10 17:16:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 10:14:31 +08:00
|
|
|
|
private function output(OutputInterface $output, string $message)
|
2024-07-10 17:16:48 +08:00
|
|
|
|
{
|
|
|
|
|
$output->writeln(sprintf('{"time":"%s", "message":"%s"}', date('Y-m-d H:i:s'), $message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return OrdersModel[]
|
|
|
|
|
*/
|
|
|
|
|
private function orders(): array
|
|
|
|
|
{
|
2024-08-02 10:14:31 +08:00
|
|
|
|
$startTime = strtotime(date('Y-m-d H:i:00'));
|
|
|
|
|
$endTime = strtotime(date('Y-m-d H:i:59'));
|
|
|
|
|
|
|
|
|
|
$list = OrdersModel::where('admin_id', '>', 0)->whereRaw(OrdersModel::AllOssStatusSql[1])
|
|
|
|
|
->whereBetween('next_remind_time', [$startTime, $endTime])
|
|
|
|
|
->select()->all();
|
2024-07-10 17:16:48 +08:00
|
|
|
|
return $list;
|
|
|
|
|
}
|
|
|
|
|
}
|