dd/app/Http/Controllers/Api/ShipController.php
2025-07-02 17:19:39 +08:00

65 lines
1.7 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
//use App\Models\Article;
use App\Services\TomTool\Http;
//use App\Services\TG\Http as TGHttp;
use App\Models\Ship as ModelShip;
final class ShipController
{
public function getShipByCode($sShipCode, $sClientClass, $sClientCode = false)
{
$sHuodongStr = "";
$aShip = ModelShip::_find($sShipCode)->toArray();
$oHttp = new Http();
$sDateNow = date("Y-m-d");
// $sDateNow = "2025-05-03";
// $sHuodongUrl = $oShip->www.'/'.'api/huodong/findbydate/'.$sDateNow;
$sHuodongUrl = "https://".$aShip['www'].$aShip['api_huodong'].'/'.$sDateNow;
$sHuodong = $oHttp->send($sHuodongUrl);
$aHuodong = json_decode($sHuodong, true);
// huodong永远不为空
// $aShip['huodong'] = $aHuodong ?? false;
$aShip["have_huodong"] = empty($aHuodong) ? false : true;
if ($aShip["have_huodong"]) {
if ($sClientClass == "github") {
$sStartDateStr = date("n月j日", strtotime($aHuodong['start_date']));
$sEndDateStr = date("n月j日", strtotime($aHuodong['end_date']));
$sHuodongStr .= "🎁 ".$aHuodong['title']."".$sStartDateStr."".$sEndDateStr."期间,".$aHuodong['content'];
}
// $aShip["huodong"]["str"] = $sHuodongStr;
}
// 某些键永远有set
$aShip["huodong"]["str"] = $sHuodongStr ?? "";
// tomd($aShip, 1);
$sJson = json_encode($aShip, 1);
echo $sJson;
exit;
}
}