Country.php
1.3 KB
<?php
namespace App\Models\Project;
use App\Models\Base;
use App\Models\WebSetting\WebLanguage;
use App\Models\WebSetting\WebSetting;
use Illuminate\Support\Facades\Redis;
class Country extends Base
{
protected $table = 'gl_project_country';
public static function getProjectCountry($projectId)
{
if (Redis::get("project_" . $projectId . "_country") == null) {
$country = Country::where("project_id", $projectId)->first();
if (!empty($country)) {
// $webCountry = WebLanguage::with("countryCustom")->whereIn("id", explode(",", $country->country_lists))->get();
$webCountry = WebLanguage::with(["countryCustom" => function($query) use ($projectId) {
$query->where('project_id', $projectId);
}])->whereIn("id", explode(",", $country->country_lists))->orderByRaw(DB::raw("FIND_IN_SET(id,'" . $country->country_lists. "'" . ')'))->get();
} else {
$webCountry = null;
}
Redis::set("project_" . $projectId . "_country", json_encode($webCountry));
Redis::expire("project_" . $projectId . "_country", WebSetting::$redisExpireTime);
}
return json_decode(Redis::get("project_".$projectId."_country"));
}
}