|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\JsonRpc;
|
|
|
|
|
|
+use _PHPStan_62c6a0a8b\OndraM\CiDetector\Env;
|
|
|
use App\Model\BlackWord;
|
|
|
use App\Model\Department;
|
|
|
use App\Model\District;
|
|
@@ -26,13 +27,21 @@ use App\Model\Component;
|
|
|
use App\Model\Link;
|
|
|
use App\Model\FooterCategory;
|
|
|
use App\Model\Size;
|
|
|
+
|
|
|
+use function Hyperf\Support\retry;
|
|
|
+use Hyperf\Paginator\Paginator;
|
|
|
+use App\Model\User;
|
|
|
use App\Model\Website;
|
|
|
+use App\Constants\ErrorCode;
|
|
|
+use GuzzleHttp\Client;
|
|
|
+use GuzzleHttp\Exception\GuzzleException;
|
|
|
use App\Model\SectorPlace;
|
|
|
#[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
#[Inject]
|
|
|
protected Redis $redis;
|
|
|
+
|
|
|
/**
|
|
|
* @param array $data
|
|
|
* @return array
|
|
@@ -468,7 +477,9 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
public function getZhinengbumen(array $data): array
|
|
|
{
|
|
|
- $result = Department::where('id', $data['id'])->first();
|
|
|
+ $result = Department::where('id', $data['id'])
|
|
|
+ ->orderBy('department', 'desc')
|
|
|
+ ->first();
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
public function getPidZhinengbumen(array $data): array
|
|
@@ -660,12 +671,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (isset($data['name']) && $data['name']) {
|
|
|
array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
|
|
|
}
|
|
|
- if(isset($data['keyword']) && $data['keyword']){
|
|
|
- array_push($where, ['template_class.keyword', 'like', '%'. $data['keyword']. '%']);
|
|
|
+ if (isset($data['keyword']) && $data['keyword']) {
|
|
|
+ array_push($where, ['template_class.keyword', 'like', '%' . $data['keyword'] . '%']);
|
|
|
}
|
|
|
$template = TemplateClass::when($where, function ($query) use ($where) {
|
|
|
- $query->where($where);
|
|
|
- });
|
|
|
+ $query->where($where);
|
|
|
+ });
|
|
|
$count = $template->count();
|
|
|
// $countQuery = clone $template;
|
|
|
$row = $template
|
|
@@ -727,10 +738,10 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (empty($template_class)) {
|
|
|
return Result::error("未查询到风格", 0);
|
|
|
}
|
|
|
- if($template_class->type == 1){
|
|
|
+ if ($template_class->type == 1) {
|
|
|
return Result::error("默认风格不能修改", 0);
|
|
|
}
|
|
|
- $template = TemplateClass::where('id','!=',$data['id'])
|
|
|
+ $template = TemplateClass::where('id', '!=', $data['id'])
|
|
|
// ->where(['name' => $data['name']])
|
|
|
// ->orWhere(['class_id' => $data['class_id']])
|
|
|
->where(function ($query) use ($data) {
|
|
@@ -768,28 +779,28 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (empty($template_class)) {
|
|
|
return Result::error("未查询到风格", 0);
|
|
|
}
|
|
|
- if($template_class->type == 1){
|
|
|
+ if ($template_class->type == 1) {
|
|
|
return Result::error("默认风格不能删除", 0);
|
|
|
}
|
|
|
- $template = Template::where('template_class_id',$template_class['class_id'])->get();
|
|
|
- if(!empty($template->all())){
|
|
|
- try{
|
|
|
+ $template = Template::where('template_class_id', $template_class['class_id'])->get();
|
|
|
+ if (!empty($template->all())) {
|
|
|
+ try {
|
|
|
// 默认风格 1
|
|
|
Db::beginTransaction();
|
|
|
- $template = Template::where('template_class_id',$template['class_id'])->update(['template_class_id'=>1]);
|
|
|
-
|
|
|
- if(empty($template)){
|
|
|
+ $template = Template::where('template_class_id', $template['class_id'])->update(['template_class_id' => 1]);
|
|
|
+
|
|
|
+ if (empty($template)) {
|
|
|
Db::rollBack();
|
|
|
return Result::error("删除失败", 0);
|
|
|
}
|
|
|
$result = TemplateClass::where($where)->delete();
|
|
|
- }catch (\Exception $e){
|
|
|
- return Result::error("删除失败".$e->getMessage(), 0);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return Result::error("删除失败" . $e->getMessage(), 0);
|
|
|
}
|
|
|
- }else{
|
|
|
- $result = TemplateClass::where('id',$data['id'])->delete();
|
|
|
+ } else {
|
|
|
+ $result = TemplateClass::where('id', $data['id'])->delete();
|
|
|
}
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error("删除失败", 0);
|
|
|
}
|
|
|
|
|
@@ -807,7 +818,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$where['name'] = $data['template_name'];
|
|
|
}
|
|
|
$result = TemplateClass::where($where)->get();
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error("暂无风格", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -824,17 +835,17 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$where['template_class_id'] = $data['template_class_id'];
|
|
|
}
|
|
|
if (!empty($data['template_name'])) {
|
|
|
- array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']);
|
|
|
+ array_push($where, ['template_name', 'like', '%' . $data['template_name'] . '%']);
|
|
|
}
|
|
|
if (!empty($data['template_keyword'])) {
|
|
|
- array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']);
|
|
|
+ array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
|
|
|
}
|
|
|
$result = Template::where($where)
|
|
|
->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
|
|
|
->select('template.*', 'template_class.name as template_class_name')
|
|
|
->orderBy('template.id', 'desc')
|
|
|
->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error("暂无皮肤", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -845,7 +856,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
|
|
|
->select('template.*', 'template_class.name as template_class_name')
|
|
|
->first();
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error("暂无皮肤", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -869,9 +880,9 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$page_type = json_decode($data['page_type'], true);
|
|
|
$data['page_type'] = json_encode(array_values(array_unique($page_type)));
|
|
|
$result = Template::insertGetId($data);
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error("创建失败", 0);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
}
|
|
@@ -880,17 +891,17 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function delTemplate(array $data): array
|
|
|
+ public function delTemplate(array $data): array
|
|
|
{
|
|
|
$rector = Sector::where('template_id', $data['id'])->first();
|
|
|
if (!empty($rector)) {
|
|
|
return Result::error("此皮肤已被绑定通栏,不可删除", 0);
|
|
|
}
|
|
|
$template = WebsiteTemplateInfo::where('template_id', $data['id'])->first();
|
|
|
- if(empty($template)){
|
|
|
+ if (empty($template)) {
|
|
|
return Result::error("此皮肤已被绑定网站,不可删除", 0);
|
|
|
}
|
|
|
- if($template->type == 1){
|
|
|
+ if ($template->type == 1) {
|
|
|
return Result::error("默认皮肤不能删除", 0);
|
|
|
}
|
|
|
$result = Template::where('id', $data['id'])->delete();
|
|
@@ -959,14 +970,14 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function getAllTemplate(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
|
|
|
+ if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
|
|
|
$where[] = ['template_class_id', $data['template_class_id']];
|
|
|
}
|
|
|
- if(isset($data['template_name']) && !empty($data['template_name'])){
|
|
|
- $where[] = ['template_name', 'like', '%'.$data['template_name'].'%'];
|
|
|
+ if (isset($data['template_name']) && !empty($data['template_name'])) {
|
|
|
+ $where[] = ['template_name', 'like', '%' . $data['template_name'] . '%'];
|
|
|
}
|
|
|
$result = Template::where($where)->get()->all();
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error("暂无皮肤", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -988,13 +999,13 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (isset($data['sector_name']) && !empty($data['sector_name'])) {
|
|
|
array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
|
|
|
}
|
|
|
- if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
|
|
|
- $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
|
|
|
- } else if( isset($data['width']) && !empty($data['width'])){
|
|
|
- $size_id = Size::where('width','like','%' .$data['width'].'%')->pluck('id');
|
|
|
- }else if( isset($data['height']) && !empty($data['height'])){
|
|
|
- $size_id = Size::where('height','like','%' .$data['height'].'%')->pluck('id');
|
|
|
- }else{
|
|
|
+ if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
|
|
|
+ $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
|
|
|
+ } else if (isset($data['width']) && !empty($data['width'])) {
|
|
|
+ $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->pluck('id');
|
|
|
+ } else if (isset($data['height']) && !empty($data['height'])) {
|
|
|
+ $size_id = Size::where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
|
|
|
+ } else {
|
|
|
$size_id = [];
|
|
|
}
|
|
|
$result = Sector::when(!empty($size_id), function ($query) use ($size_id) {
|
|
@@ -1025,40 +1036,59 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$where[] = ['sector.id', '=', $data['id']];
|
|
|
$result = Sector::where($where)
|
|
|
->leftJoin('size', 'size.id', '=', 'sector.size_id')
|
|
|
- ->select('sector.*', 'size.width','size.height')
|
|
|
+ ->select('sector.*', 'size.width', 'size.height')
|
|
|
->orderBy('sector.id', 'desc')
|
|
|
->first();
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error('此通栏不存在!');
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 获取经纬度信息
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function getIpInfo(array $data) :array
|
|
|
+ public function getIpInfo(array $data): array
|
|
|
{
|
|
|
- $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
|
|
|
- // 使用 IPinfo 服务获取 IP 信息
|
|
|
- $api_url = "https://ipinfo.io/{$client_ip}/json";
|
|
|
- $ch = curl_init($api_url);
|
|
|
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
- $response = curl_exec($ch);
|
|
|
- curl_close($ch);
|
|
|
- // 解析 JSON 响应
|
|
|
- $ip_info = json_decode($response, true);
|
|
|
- // 提取地址和经纬度
|
|
|
- if ($ip_info && !isset($ip_info['bogon'])) {
|
|
|
- $latitude = explode(',', $ip_info['loc'])[0];
|
|
|
- $longitude = explode(',', $ip_info['loc'])[1];
|
|
|
- $ip_info['latitude'] = $latitude;
|
|
|
- $ip_info['longitude'] = $longitude;
|
|
|
- return Result::success($ip_info);
|
|
|
- } else {
|
|
|
- $data['ip'] = '101.254.114.212';
|
|
|
- $this->getIpinfo(["ip"=>$data['ip']]);
|
|
|
+ if (empty($data['ip'])) {
|
|
|
+ // 在RPC服务中,依赖$_SERVER是不可靠的,强制要求调用方传入IP
|
|
|
+ return Result::error('IP地址不能为空!');
|
|
|
+ }
|
|
|
+ $client_ip = $data['ip'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 直接从容器获取 Guzzle 客户端实例
|
|
|
+ /** @var \GuzzleHttp\Client $client */
|
|
|
+ $client = \Hyperf\Context\ApplicationContext::getContainer()->get(Client::class);
|
|
|
+
|
|
|
+ // 使用新的 GeoJS API 地址
|
|
|
+ $api_url = "https://get.geojs.io/v1/ip/geo/{$client_ip}.json";
|
|
|
+ // 将 timeout 作为请求选项传递
|
|
|
+ $response = $client->get($api_url, ['timeout' => 5]);
|
|
|
+
|
|
|
+ if ($response->getStatusCode() !== 200) {
|
|
|
+ return Result::error('IP查询接口请求失败,状态码:' . $response->getStatusCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ $ip_info = json_decode($response->getBody()->getContents(), true);
|
|
|
+
|
|
|
+ // GeoJS 的成功响应不包含 'status' 字段,直接检查关键数据是否存在
|
|
|
+ if ($ip_info && isset($ip_info['latitude']) && isset($ip_info['longitude'])) {
|
|
|
+ // GeoJS 返回的经纬度是字符串,转换为浮点数
|
|
|
+ $ip_info['latitude'] = floatval($ip_info['latitude']);
|
|
|
+ $ip_info['longitude'] = floatval($ip_info['longitude']);
|
|
|
+ return Result::success($ip_info);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果返回的数据不符合预期,提供一个通用错误
|
|
|
+ $errorMessage = $ip_info['message'] ?? '获取IP地理位置信息失败';
|
|
|
+ return Result::error($errorMessage);
|
|
|
+ } catch (GuzzleException $e) {
|
|
|
+ // 这个异常会给出详细的网络错误信息,如超时、无法解析域名等
|
|
|
+ return Result::error('请求IP查询接口异常: ' . $e->getMessage());
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ return Result::error('获取IP信息时发生未知错误: ' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1067,7 +1097,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getWeatherInfo(array $data) :array
|
|
|
+ public function getWeatherInfo(array $data): array
|
|
|
{
|
|
|
$month = $data['month'] ?? date('m');
|
|
|
$day = $data['day'] ?? date('d');
|
|
@@ -1080,8 +1110,8 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if ($cachedData = $cache->get($cacheKey)) {
|
|
|
return Result::success(unserialize($cachedData));
|
|
|
}
|
|
|
- $location = $data['latitude'].":".$data['longitude'];
|
|
|
- $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
|
|
|
+ $location = $data['latitude'] . ":" . $data['longitude'];
|
|
|
+ $api_url = "https://api.seniverse.com/v3/weather/now.json?key=" . \Hyperf\Support\env('WEATHER_KEY') . "&location=" . $location . "&language=zh-Hans&unit=c";
|
|
|
$ch = curl_init($api_url);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
$response = curl_exec($ch);
|
|
@@ -1090,9 +1120,9 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$WeatherInfo = json_decode($response, true);
|
|
|
// 缓存结果,设置1小时过期
|
|
|
$cache->set($cacheKey, serialize($WeatherInfo), 3600);
|
|
|
- if($WeatherInfo){
|
|
|
+ if ($WeatherInfo) {
|
|
|
return Result::success($WeatherInfo);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return Result::error("获取天气失败", 0);
|
|
|
}
|
|
|
}
|
|
@@ -1101,7 +1131,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
* 获取农历信息
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function getCalendar(array $data) :array
|
|
|
+ public function getCalendar(array $data): array
|
|
|
{
|
|
|
$calendar = new Calendar();
|
|
|
$result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
|
|
@@ -1163,9 +1193,8 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
// return Result::success($sector_code);
|
|
|
$data['sector_code'] = json_encode($sector_code);
|
|
|
$template = Template::where('template_id', $data['template_id'])
|
|
|
- ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
|
|
|
->first();
|
|
|
- if(empty($template)){
|
|
|
+ if (empty($template)) {
|
|
|
return Result::error('皮肤不存在!');
|
|
|
}
|
|
|
$sector_id = Sector::where('sector_id',$data['sector_id'])->first();
|
|
@@ -1173,7 +1202,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::error('通栏编号已存在!');
|
|
|
}
|
|
|
$result = Sector::insertGetId($data);
|
|
|
- if(empty($result)){
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error('添加失败');
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -1186,7 +1215,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function delSector(array $data): array
|
|
|
{
|
|
|
$component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
|
|
|
- if(!empty($component_id)){
|
|
|
+ if (!empty($component_id)) {
|
|
|
return Result::error('请先删除相关组件!');
|
|
|
}
|
|
|
$result = Sector::where('id', $data['id'])->delete();
|
|
@@ -1205,7 +1234,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
unset($data['user_id']);
|
|
|
$sector = Sector::where('id', $data['id'])->first();
|
|
|
- if(empty($sector)){
|
|
|
+ if (empty($sector)) {
|
|
|
return Result::error('通栏不存在!');
|
|
|
}
|
|
|
if($sector['sector_id'] != $data['sector_id']){
|
|
@@ -1265,7 +1294,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$template = Template::where('template_id', $data['template_id'])
|
|
|
->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
|
|
|
->first();
|
|
|
- if(empty($template)){
|
|
|
+ if (empty($template)) {
|
|
|
return Result::error('皮肤不存在!');
|
|
|
}
|
|
|
$result = Sector::where('id', $data['id'])->update($data);
|
|
@@ -1331,7 +1360,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$result = Component::where('id', $data['id'])->update($data);
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function getWebsiteTemplateInfo(array $data)
|
|
|
{
|
|
|
$where = [];
|
|
@@ -1357,24 +1386,24 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function getWebPageType(array $data): array
|
|
|
{
|
|
|
// 1:图片 2:文字 3:底部
|
|
|
- $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
|
|
|
- if(empty($friend_link->toArray())){
|
|
|
+ $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
|
|
|
+ if (empty($friend_link->toArray())) {
|
|
|
return Result::error('暂无友情链接数据!');
|
|
|
}
|
|
|
$footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
|
|
|
- if(empty($footer_category->toArray())){
|
|
|
+ if (empty($footer_category->toArray())) {
|
|
|
return Result::error('暂无底部导航数据!');
|
|
|
}
|
|
|
$page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
|
|
|
- if(empty($page_type)){
|
|
|
+ if (empty($page_type)) {
|
|
|
$page_type = [];
|
|
|
- }else{
|
|
|
- $page_type = json_decode($page_type,true);
|
|
|
+ } else {
|
|
|
+ $page_type = json_decode($page_type, true);
|
|
|
}
|
|
|
// '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
|
|
|
- if(isset($page_type) && in_array(5,$page_type)){
|
|
|
+ if (isset($page_type) && in_array(5, $page_type)) {
|
|
|
$page_type = 1;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$page_type = 0;
|
|
|
}
|
|
|
$result = [
|
|
@@ -1393,24 +1422,23 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
// return Result::success($data);
|
|
|
// 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
|
|
|
- if($data['is_search'] == 1){
|
|
|
- $page_type = json_encode([1,2,3,4,5,6,7]);
|
|
|
- }else{
|
|
|
- $page_type = json_encode([1,2,3,4,6,7]);
|
|
|
+ if ($data['is_search'] == 1) {
|
|
|
+ $page_type = json_encode([1, 2, 3, 4, 5, 6, 7]);
|
|
|
+ } else {
|
|
|
+ $page_type = json_encode([1, 2, 3, 4, 6, 7]);
|
|
|
}
|
|
|
// 0:未构建;1:已填写基础信息;2:已选择模板; action_id
|
|
|
$website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
// return Result::success($website_template_info);
|
|
|
-
|
|
|
+
|
|
|
// return Result::success(empty($website_template_info));
|
|
|
- if(empty($website_template_info)){
|
|
|
+ if (empty($website_template_info)) {
|
|
|
$result = WebsiteTemplateInfo::insertGetId(['website_id' => $data['website_id'], 'page_type' => $page_type, 'user_id' => $data['user_id']]);
|
|
|
-
|
|
|
- }else{
|
|
|
- if($website_template_info['status'] == 2){
|
|
|
+ } else {
|
|
|
+ if ($website_template_info['status'] == 2) {
|
|
|
return Result::error('网站已应用,不可再次修改!');
|
|
|
}
|
|
|
- $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1,'user_id' => $data['user_id']]);
|
|
|
+ $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type], ['action_id' => 1, 'user_id' => $data['user_id']]);
|
|
|
}
|
|
|
if ($result) {
|
|
|
return Result::success($result);
|
|
@@ -1426,19 +1454,19 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function getWebsiteTemplateList(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if(isset($data['template_class_id']) && $data['template_class_id']){
|
|
|
+ if (isset($data['template_class_id']) && $data['template_class_id']) {
|
|
|
$where[] = ['template_class_id', '=', $data['template_class_id']];
|
|
|
}
|
|
|
// 0:未构建 1:未应用 2:已应用 status
|
|
|
$templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
- if(empty($templste_info)){
|
|
|
+ if (empty($templste_info)) {
|
|
|
return Result::error('请先填写网站基础信息!');
|
|
|
}
|
|
|
- if($templste_info['status'] == 2){
|
|
|
+ if ($templste_info['status'] == 2) {
|
|
|
return Result::error('网站已应用,不可再次修改!');
|
|
|
}
|
|
|
-
|
|
|
- if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
|
+
|
|
|
+ if (isset($data['keyword']) && !empty($data['keyword'])) {
|
|
|
if (is_array($data['keyword'])) {
|
|
|
// 拼接多个模糊查询条件
|
|
|
$query = Template::query();
|
|
@@ -1450,33 +1478,33 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
|
|
|
$where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$query = Template::where($where);
|
|
|
}
|
|
|
$template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
|
|
|
// return Result::success($template_id);
|
|
|
- if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
|
|
|
+ if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
|
|
|
$template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$template_page = [];
|
|
|
}
|
|
|
- if(!empty($template_id['template_id'])){
|
|
|
+ if (!empty($template_id['template_id'])) {
|
|
|
$result['template_id'] = $templste_info['template_id'];
|
|
|
}
|
|
|
// 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
|
|
|
$template_page_str = json_encode($template_page);
|
|
|
$result['template'] = $query->where($where)
|
|
|
->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
|
|
|
- ->orderBy('updated_at','desc')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
if (empty($result['template'])) {
|
|
|
- $result['template'] = Template::orderBy('updated_at','desc')
|
|
|
+ $result['template'] = Template::orderBy('updated_at', 'desc')
|
|
|
->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
}
|
|
|
$template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
|
|
|
- if($template){
|
|
|
+ if ($template) {
|
|
|
$result['template_id'] = $template;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$result['template_id'] = 0;
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -1489,19 +1517,19 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function chooseWebsiteTemplate(array $data): array
|
|
|
{
|
|
|
$website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
- if(empty($website_template_info)){
|
|
|
+ if (empty($website_template_info)) {
|
|
|
return Result::error('请先填写网站基础信息!');
|
|
|
}
|
|
|
// 0:未构建 1:未应用 2:已应用 status
|
|
|
- if($website_template_info['status'] == 2){
|
|
|
+ if ($website_template_info['status'] == 2) {
|
|
|
return Result::error('网站已应用,不可再次修改!');
|
|
|
}
|
|
|
$template = Template::where('template_id', $data['template_id'])->first();
|
|
|
- if(empty($template)){
|
|
|
+ if (empty($template)) {
|
|
|
return Result::error('未查询到皮肤!');
|
|
|
}
|
|
|
// 0:未构建;1:已填写基础信息;2:已选择模板; action_id
|
|
|
- $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
|
|
|
+ $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
|
|
|
if ($web_template) {
|
|
|
return Result::success($web_template);
|
|
|
} else {
|
|
@@ -1517,21 +1545,21 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
// return Result::success($data);
|
|
|
$website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
- if(empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)){
|
|
|
+ if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
|
|
|
return Result::error('请先填写网站基础信息!');
|
|
|
}
|
|
|
// 0:未构建 1:未应用 2:已应用 status
|
|
|
- if($website_template_info['status'] == 2){
|
|
|
+ if ($website_template_info['status'] == 2) {
|
|
|
return Result::error('网站已应用,不可再次保存!');
|
|
|
}
|
|
|
- if($website_template_info['action_id'] != 2){
|
|
|
+ if ($website_template_info['action_id'] != 2) {
|
|
|
return Result::error('请完成之前的步骤!');
|
|
|
}
|
|
|
$template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
|
|
|
// var_dump($data['template_data']);
|
|
|
- try{
|
|
|
+ try {
|
|
|
Db::beginTransaction();
|
|
|
- if(empty($template_info)){
|
|
|
+ if (empty($template_info)) {
|
|
|
$template = WebsiteTemplate::insertGetId([
|
|
|
'website_id' => $data['website_id'],
|
|
|
'template_data' => $data['template_data'],
|
|
@@ -1540,25 +1568,29 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
'page_type' => $website_template_info['page_type'],
|
|
|
'template_id' => $website_template_info['template_id'],
|
|
|
]);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
|
|
|
- ['template_data' => $data['template_data'],'user_id' => $data['user_id'],'canvas_data' => $data['canvas_data'],
|
|
|
- 'page_type' => $website_template_info['page_type'],
|
|
|
- 'template_id' => $website_template_info['template_id'],
|
|
|
- ]);
|
|
|
+ [
|
|
|
+ 'template_data' => $data['template_data'],
|
|
|
+ 'user_id' => $data['user_id'],
|
|
|
+ 'canvas_data' => $data['canvas_data'],
|
|
|
+ 'page_type' => $website_template_info['page_type'],
|
|
|
+ 'template_id' => $website_template_info['template_id'],
|
|
|
+ ]
|
|
|
+ );
|
|
|
}
|
|
|
- if(empty($template)){
|
|
|
+ if (empty($template)) {
|
|
|
Db::rollback();
|
|
|
return Result::error('保存失败!');
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
|
|
|
- if(empty($tempalte_info)){
|
|
|
+ if (empty($tempalte_info)) {
|
|
|
Db::rollback();
|
|
|
return Result::error('保存失败!');
|
|
|
}
|
|
|
Db::commit();
|
|
|
}
|
|
|
- }catch (\Exception $e){
|
|
|
+ } catch (\Exception $e) {
|
|
|
return Result::error('模版数据格式错误!');
|
|
|
}
|
|
|
return Result::success($template);
|
|
@@ -1571,12 +1603,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function getWebsiteTemplate(array $data): array
|
|
|
{
|
|
|
$web = Website::where('id', $data['website_id'])->first();
|
|
|
- if(empty($web)){
|
|
|
+ if (empty($web)) {
|
|
|
return Result::error('未查询到网站信息!');
|
|
|
}
|
|
|
$template = WebsiteTemplate::where('website_id', $data['website_id'])
|
|
|
- ->first(['website_id','template_id','page_type','template_data','canvas_data']);
|
|
|
- if(empty($template)){
|
|
|
+ ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
|
|
|
+ if (empty($template)) {
|
|
|
return Result::error('未查询到模版!');
|
|
|
}
|
|
|
return Result::success($template);
|
|
@@ -1612,12 +1644,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if(isset($data['sector_type']) && !empty($data['sector_type'])){
|
|
|
$where['sector_place.sector_type'] = $data['sector_type'];
|
|
|
}
|
|
|
- if(isset($data['component_type']) && !empty($data['component_type'])){
|
|
|
- $where['sector_place.component_type'] = $data['component_type'];
|
|
|
- }
|
|
|
+ // if(isset($data['component_type']) && !empty($data['component_type'])){
|
|
|
+ // $where['sector_place.component_type'] = $data['component_type'];
|
|
|
+ // }
|
|
|
if(isset($data['name']) && !empty($data['name'])){
|
|
|
array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
|
|
|
- }
|
|
|
+ }
|
|
|
if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
|
|
|
$size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
|
|
|
} else if( isset($data['width']) && !empty($data['width'])){
|
|
@@ -1661,12 +1693,15 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
'type_id' => $data['type_id'],
|
|
|
];
|
|
|
}else{
|
|
|
- $sector_type = SectorPlace::where('sector_type', $data['type'])->where('type_id',1)->first();
|
|
|
+ $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
|
|
|
if(empty($sector_type)){
|
|
|
return Result::error('通栏版式类别不存在!');
|
|
|
}
|
|
|
- $component_type = SectorPlace::where('component_type', $data['type'])->where('type_id',2)->first();
|
|
|
- if(!empty($component_type)){
|
|
|
+ $component = SectorPlace::where('sector_type', $data['sector_type'])
|
|
|
+ ->where('component_type', $data['type'])
|
|
|
+ ->where('type_id',2)
|
|
|
+ ->first();
|
|
|
+ if(!empty($component)){
|
|
|
return Result::error('组件版式类别编号已存在!');
|
|
|
}
|
|
|
$data = [
|
|
@@ -1677,6 +1712,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
'sector_img' => $data['sector_img'],
|
|
|
'component_type' => $data['type'],
|
|
|
'type_id' => $data['type_id'],
|
|
|
+ 'sector_type' => $data['sector_type'],
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -1691,6 +1727,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
*/
|
|
|
public function upSectorPlace(array $data): array
|
|
|
{
|
|
|
+ $id = $data['id'];
|
|
|
// 1:通栏;2:组件;
|
|
|
if($data['type_id'] == 1){
|
|
|
$sector_place = SectorPlace::where('sector_type', $data['type'])->first();
|
|
@@ -1698,7 +1735,6 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::error('通栏版式类别编号已存在!');
|
|
|
}
|
|
|
$data = [
|
|
|
- 'id' => $data['id'],
|
|
|
'name' => $data['name'],
|
|
|
'component_num' => $data['component_num'],
|
|
|
'size_id' => $data['size_id'],
|
|
@@ -1708,16 +1744,18 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
'type_id' => $data['type_id'],
|
|
|
];
|
|
|
}else{
|
|
|
- $sector_type = SectorPlace::where('sector_type', $data['type'])->where('type_id',1)->first();
|
|
|
+ $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
|
|
|
if(empty($sector_type)){
|
|
|
return Result::error('通栏版式类别不存在!');
|
|
|
}
|
|
|
- $component_type = SectorPlace::where('component_type', $data['type'])->where('type_id',2)->first();
|
|
|
- if(!empty($component_type)){
|
|
|
+ $component = SectorPlace::where('sector_type', $data['sector_type'])
|
|
|
+ ->where('component_type', $data['type'])
|
|
|
+ ->where('type_id',2)
|
|
|
+ ->first();
|
|
|
+ if(!empty($component)){
|
|
|
return Result::error('组件版式类别编号已存在!');
|
|
|
}
|
|
|
$data = [
|
|
|
- 'id' => $data['id'],
|
|
|
'name' => $data['name'],
|
|
|
'component_num' => 0,
|
|
|
'size_id' => $data['size_id'],
|
|
@@ -1725,9 +1763,11 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
'sector_img' => $data['sector_img'],
|
|
|
'component_type' => $data['type'],
|
|
|
'type_id' => $data['type_id'],
|
|
|
+ 'sector_type' => $data['sector_type'],
|
|
|
];
|
|
|
}
|
|
|
- $result = SectorPlace::where('id',$data['id'])->update($data);
|
|
|
+
|
|
|
+ $result = SectorPlace::where('id',$id)->update($data);
|
|
|
if(empty($result)){
|
|
|
return Result::error('修改失败!');
|
|
|
}
|
|
@@ -1773,4 +1813,37 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 自助建站-通栏版式管理-获取通栏版式列表
|
|
|
+ */
|
|
|
+ public function getSectorPlaceSort(array $data): array
|
|
|
+ {
|
|
|
+ $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
|
|
|
+ if(empty($sector)){
|
|
|
+ return Result::error('通栏版式不存在!');
|
|
|
+ }
|
|
|
+ $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
|
|
|
+ if(count($component) < $sector['component_num']){
|
|
|
+ // 根据 $sector['component_num'] 的值生成对应元素数量的数组
|
|
|
+ if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
|
|
|
+ $num = intval($sector['component_num']);
|
|
|
+ if ($num > 0 && $num <= 10) {
|
|
|
+ $sector_arr = range(1, $num);
|
|
|
+ } else {
|
|
|
+ $sector_arr = [];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $sector_arr = [];
|
|
|
+ }
|
|
|
+ // 获取 $sector_arr 中不在 $component 里的元素
|
|
|
+ $sort = array_diff($sector_arr, $component);
|
|
|
+ // return Result::success($sort);
|
|
|
+ }
|
|
|
+ if(!empty($sort)){
|
|
|
+ $sort = array_values($sort);
|
|
|
+ }else{
|
|
|
+ return Result::error("组件版式数量已达上限!");
|
|
|
+ }
|
|
|
+ return Result::success($sort);
|
|
|
+ }
|
|
|
}
|