diff --git a/service/app/command/NotUsedOrderSms.php b/service/app/command/NotUsedOrderSms.php index b76909a6..179ee365 100644 --- a/service/app/command/NotUsedOrderSms.php +++ b/service/app/command/NotUsedOrderSms.php @@ -5,6 +5,7 @@ namespace app\command; use app\common\Error; use app\model\Orders as OrdersModel; use app\server\Orders; +use app\server\Orders as ServerOrders; use support\Redis; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -33,7 +34,7 @@ class NotUsedOrderSms extends Command */ protected function execute(InputInterface $input, OutputInterface $output): int { - $this->output($output, self::$defaultName . " started"); + $this->output($output, self::$defaultName . " started, " . date('Y-m-d H:i:s')); $orders = $this->orders(); $total = count($orders); @@ -49,20 +50,36 @@ class NotUsedOrderSms extends Command continue; } - $result = Orders::reminderOrders($order); - $text = '已发送提醒。'; - - if (Error::is($result)) { - $text = '发送短信失败,' . $result['message'] ?? ''; + if (ServerOrders::isDaishiyong($order)) { + $order = ServerOrders::syncFromThirdV2($order); } + 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; + } + +// $result = Orders::reminderOrders($order); + $text = '已发送提醒。'; + +// if (Error::is($result)) { +// $text = '发送短信失败,' . $result['message'] ?? ''; +// } + $this->output($output, "单号 {$order->sn} : {$text}"); + +// $order->next_remind_time = $order->next_remind_time + 10 * 24 * 60 * 60; +// $order->save(); } return self::SUCCESS; } - private function output(OutputInterface $output, string $message) + private function output(OutputInterface $output, string $message) { $output->writeln(sprintf('{"time":"%s", "message":"%s"}', date('Y-m-d H:i:s'), $message)); } @@ -72,7 +89,12 @@ class NotUsedOrderSms extends Command */ private function orders(): array { - $list = OrdersModel::where('admin_id', '>', 0)->whereRaw(OrdersModel::AllOssStatusSql[1])->select()->all(); + $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(); return $list; } } diff --git a/service/app/command/OrderNextRemindTime.php b/service/app/command/OrderNextRemindTime.php new file mode 100644 index 00000000..b947ce35 --- /dev/null +++ b/service/app/command/OrderNextRemindTime.php @@ -0,0 +1,100 @@ +addArgument('name', InputArgument::OPTIONAL, 'Name description'); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $this->output($output, self::$defaultName . " started, " . date('Y-m-d H:i:s')); + + $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; + } + + $orderTime = (int)($order->create_at / 1000); + + $orderTime = date('Y-m-d H:i:s', $orderTime); + + $next_remind_time = $this->getNextPeriodDateTime($orderTime); + + $this->output($output, "单号 {$order->sn} : 下单时间:{$orderTime}, 下次提醒时间:{$next_remind_time}"); + + $order->next_remind_time = strtotime($next_remind_time); + $order->save(); + } + + return self::SUCCESS; + } + + private function getNextPeriodDateTime($startDateTime, $periodDays = 10) { + $startDate = new \DateTime($startDateTime); + $currentDate = new \DateTime(); + $periodSeconds = $periodDays * 24 * 60 * 60; + + $secondsSinceStart = $currentDate->getTimestamp() - $startDate->getTimestamp(); + + $completedPeriods = floor($secondsSinceStart / $periodSeconds); + + if ($completedPeriods < 0) { + $completedPeriods = 0; + } + + $nextPeriodTimestamp = $startDate->getTimestamp() + (($completedPeriods + 1) * $periodSeconds); + + $nextPeriodDate = (new \DateTime())->setTimestamp($nextPeriodTimestamp); + + return $nextPeriodDate->format('Y-m-d H:i:s'); + } + + private function output(OutputInterface $output, string $message) + { + $output->writeln(sprintf('{"time":"%s", "message":"%s"}', date('Y-m-d H:i:s'), $message)); + } + + /** + * @return OrdersModel[] + */ + private function orders(): array + { + $list = OrdersModel::where('admin_id', '>', 0)->where('next_remind_time', 0)->whereRaw(OrdersModel::AllOssStatusSql[1])->select()->all(); + return $list; + } +} diff --git a/service/app/server/Orders.php b/service/app/server/Orders.php index f911ad4a..19412464 100644 --- a/service/app/server/Orders.php +++ b/service/app/server/Orders.php @@ -143,4 +143,49 @@ class Orders { return; } + + /** + * 同步第三方返回 + * @param OrdersModel $order + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function syncFromThirdV2(OrdersModel $order) + { + $got = null; + switch ($order->os) { + case 1: + $mt = new Meituan(); + $it = $mt->get(1, null, null, $order->sn); + + if ($it) { + $got = $it[0]; + } + + break; + case 3: + $dy = new Douyin(); + $it = $dy->get(1, null, null, $order->sn); + if ($it) { + $got = $it[0]; + } + + break; + } + + if (is_null($got)) { + Log::info(__METHOD__ . ": get from os is null", [$order]); + return $order; + } + + $back = $order->save($got); + + if ($back) { + self::finance(0, $order->id, $order->asset_price); + } + + return $order; + } }