|
@@ -26,19 +26,22 @@ use App\Model\Sector;
|
|
|
use App\Model\Component;
|
|
|
use App\Model\Link;
|
|
|
use App\Model\FooterCategory;
|
|
|
+use App\Model\Size;
|
|
|
|
|
|
use function Hyperf\Support\retry;
|
|
|
-use App\Model\Company;
|
|
|
use Hyperf\Paginator\Paginator;
|
|
|
use App\Model\User;
|
|
|
-use Fukuball\Jieba\Jieba;
|
|
|
-use Fukuball\Jieba\Finalseg;
|
|
|
+use App\Model\Website;
|
|
|
+use App\Constants\ErrorCode;
|
|
|
+use GuzzleHttp\Client;
|
|
|
+use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
|
|
#[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
#[Inject]
|
|
|
protected Redis $redis;
|
|
|
+
|
|
|
/**
|
|
|
* @param array $data
|
|
|
* @return array
|
|
@@ -677,8 +680,10 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$count = $template->count();
|
|
|
// $countQuery = clone $template;
|
|
|
$row = $template
|
|
|
- ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
|
|
|
- ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
|
|
|
+ ->leftJoin('template', function ($join) {
|
|
|
+ $join->on('template_class.class_id', '=', 'template.template_class_id');
|
|
|
+ })
|
|
|
+ ->select('template_class.*', DB::raw('COUNT(template.template_class_id) as template_count'))
|
|
|
->groupBy('template_class.id')
|
|
|
->orderBy('template_class.id', 'desc')
|
|
|
->offset(($data['page'] - 1) * $data['pageSize'])
|
|
@@ -770,28 +775,52 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$where = [
|
|
|
'id' => $data['id'],
|
|
|
];
|
|
|
- $template = TemplateClass::where($where)->first();
|
|
|
- if (empty($template)) {
|
|
|
+ $template_class = TemplateClass::where($where)->first();
|
|
|
+ if (empty($template_class)) {
|
|
|
return Result::error("未查询到风格", 0);
|
|
|
}
|
|
|
- if ($template->type == 1) {
|
|
|
+ if ($template_class->type == 1) {
|
|
|
return Result::error("默认风格不能删除", 0);
|
|
|
}
|
|
|
- $result = TemplateClass::where($where)->delete();
|
|
|
+ $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)) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error("删除失败", 0);
|
|
|
+ }
|
|
|
+ $result = TemplateClass::where($where)->delete();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return Result::error("删除失败" . $e->getMessage(), 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $result = TemplateClass::where('id', $data['id'])->delete();
|
|
|
+ }
|
|
|
if (empty($result)) {
|
|
|
return Result::error("删除失败", 0);
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
}
|
|
|
+
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
/**
|
|
|
- * 获取getTemplateClass
|
|
|
+ * 根据风格名称-获取获取所有风格
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
public function getTemplateClass(array $data): array
|
|
|
{
|
|
|
- $result = TemplateClass::get();
|
|
|
+ $where = [];
|
|
|
+ if (!empty($data['template_name'])) {
|
|
|
+ $where['name'] = $data['template_name'];
|
|
|
+ }
|
|
|
+ $result = TemplateClass::where($where)->get();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无风格", 0);
|
|
|
+ }
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
/**
|
|
@@ -812,7 +841,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
|
|
|
}
|
|
|
$result = Template::where($where)
|
|
|
- ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
|
|
|
+ ->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']);
|
|
@@ -824,7 +853,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function getTemplateInfo(array $data): array
|
|
|
{
|
|
|
$result = Template::where('template.id', $data['id'])
|
|
|
- ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
|
|
|
+ ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
|
|
|
->select('template.*', 'template_class.name as template_class_name')
|
|
|
->first();
|
|
|
if (empty($result)) {
|
|
@@ -864,6 +893,17 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
*/
|
|
|
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)) {
|
|
|
+ return Result::error("此皮肤已被绑定网站,不可删除", 0);
|
|
|
+ }
|
|
|
+ if ($template->type == 1) {
|
|
|
+ return Result::error("默认皮肤不能删除", 0);
|
|
|
+ }
|
|
|
$result = Template::where('id', $data['id'])->delete();
|
|
|
var_dump($result, '-------------------delete');
|
|
|
if ($result) {
|
|
@@ -905,42 +945,83 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::success('更新成功');
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 根据皮肤名称-获取所有皮肤
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getAllTemplate(array $data): array
|
|
|
+ {
|
|
|
+ $where = [];
|
|
|
+ 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'] . '%'];
|
|
|
+ }
|
|
|
+ $result = Template::where($where)->get()->all();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无皮肤", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取通栏列表
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function getSectorList(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if (!empty($data['template_class_id'])) {
|
|
|
- $where['template_class.id'] = $data['template_class_id'];
|
|
|
+ if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
|
|
|
+ $where['template_class.class_id'] = $data['template_class_id'];
|
|
|
}
|
|
|
- if (!empty($data['template_class_name'])) {
|
|
|
- $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
|
|
|
+ if (isset($data['template_id']) && !empty($data['template_id'])) {
|
|
|
+ array_push($where, ['template.template_id', $data['template_id']]);
|
|
|
}
|
|
|
-
|
|
|
- if (!empty($data['sector_name'])) {
|
|
|
- if (!empty($data['sector_name'])) {
|
|
|
- // $where['sector_name'] = $data['sector_name'];
|
|
|
- $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
|
|
|
- }
|
|
|
+ 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 {
|
|
|
+ $size_id = [];
|
|
|
+ }
|
|
|
+ // $size_id = $size_id->toArray();
|
|
|
$result = Sector::where($where)
|
|
|
- ->leftJoin('template', 'template.id', '=', 'sector.template_id')
|
|
|
- ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
|
|
|
- ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
|
|
|
+ ->when(!empty($size_id), function ($query) use ($size_id) {
|
|
|
+ $query->whereIn('size_id', $size_id);
|
|
|
+ })
|
|
|
+ ->leftJoin('size', 'size.id', '=', 'sector.size_id')
|
|
|
+ ->leftJoin('template_class', 'template_class.class_id', '=', 'sector.template_class_id')
|
|
|
+ ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
|
|
|
+ ->select('sector.*', 'size.width', 'size.height', 'template_class.name as class_name', 'template.template_name')
|
|
|
->orderBy('sector.id', 'desc')
|
|
|
- ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
|
|
|
-
|
|
|
+ ->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取通栏详情
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+
|
|
|
public function getSectorInfo(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
$where[] = ['sector.id', '=', $data['id']];
|
|
|
$result = Sector::where($where)
|
|
|
- ->leftJoin('template', 'template.id', '=', 'sector.template_id')
|
|
|
- ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
|
|
|
- ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
|
|
|
+ ->leftJoin('size', 'size.id', '=', 'sector.size_id')
|
|
|
+ ->select('sector.*', 'size.width', 'size.height')
|
|
|
->orderBy('sector.id', 'desc')
|
|
|
- ->get();
|
|
|
+ ->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error('此通栏不存在!');
|
|
|
+ }
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
|
|
@@ -950,27 +1031,44 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
*/
|
|
|
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";
|
|
|
- //http://ip-api.com/json/117.136.12.79?lang=zh-cn
|
|
|
- $api_url = "http://ip-api.com/json/{$client_ip}/?lang=zh-cn";
|
|
|
- $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) {
|
|
|
- // $latitude = explode(',', $ip_info['loc'])[0];
|
|
|
- // $longitude = explode(',', $ip_info['loc'])[1];
|
|
|
- $ip_info['latitude'] = $ip_info['lat'];
|
|
|
- $ip_info['longitude'] = $ip_info['lon'];
|
|
|
- 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());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1019,16 +1117,52 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 添加通栏
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function addSector(array $data): array
|
|
|
{
|
|
|
unset($data['user_id']);
|
|
|
- // $data['page_type'] = json_encode($data['page_type']);
|
|
|
+ // 对传入的 page_type 数组进行去重、转换为整数并重新索引
|
|
|
+ $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
|
|
|
+ $data['page_type'] = json_encode($data['page_type']);
|
|
|
+ $template = Template::where('template_id', $data['template_id'])
|
|
|
+ ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
|
|
|
+ ->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error('皮肤不存在!');
|
|
|
+ }
|
|
|
+ // 皮肤相关信息
|
|
|
+ $data['template_name'] = $template['template_name'];
|
|
|
+ $data['template_id'] = $template['template_id'];
|
|
|
+ // 风格相关信息
|
|
|
+ $template_class = TemplateClass::where('class_id', $template['template_class_id'])->first();
|
|
|
+ if (empty($template_class)) {
|
|
|
+ return Result::error('所属风格不存在!');
|
|
|
+ }
|
|
|
+ // $data['sector_keyword'] = json_encode($data['sector_keyword']);
|
|
|
+ $data['template_class_id'] = $template_class['class_id'];
|
|
|
+ $data['template_class_name'] = $template_class['name'];
|
|
|
+
|
|
|
$result = Sector::insertGetId($data);
|
|
|
- return Result::success();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error('添加失败');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 删除通栏
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function delSector(array $data): array
|
|
|
{
|
|
|
+ $component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
|
|
|
+ if (!empty($component_id)) {
|
|
|
+ return Result::error('请先删除相关组件!');
|
|
|
+ }
|
|
|
$result = Sector::where('id', $data['id'])->delete();
|
|
|
if ($result == 1) {
|
|
|
return Result::success('删除成功');
|
|
@@ -1036,9 +1170,38 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::error('删除失败');
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 修改通栏
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function updateSector(array $data): array
|
|
|
{
|
|
|
unset($data['user_id']);
|
|
|
+ $sector = Sector::where('id', $data['id'])->first();
|
|
|
+ if (empty($sector)) {
|
|
|
+ return Result::error('通栏不存在!');
|
|
|
+ }
|
|
|
+ // 对传入的 page_type 数组进行去重、转换为整数并重新索引
|
|
|
+ $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
|
|
|
+ $data['page_type'] = json_encode($data['page_type']);
|
|
|
+ $template = Template::where('template_id', $data['template_id'])
|
|
|
+ ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
|
|
|
+ ->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error('皮肤不存在!');
|
|
|
+ }
|
|
|
+ // 皮肤相关信息
|
|
|
+ $data['template_name'] = $template['template_name'];
|
|
|
+ $data['template_id'] = $template['template_id'];
|
|
|
+ // 风格相关信息
|
|
|
+ $template_class = TemplateClass::where('class_id', $template['template_class_id'])->first();
|
|
|
+ if (empty($template_class)) {
|
|
|
+ return Result::error('所属风格不存在!');
|
|
|
+ }
|
|
|
+ // $data['sector_keyword'] = json_encode($data['sector_keyword']);
|
|
|
+ $data['template_class_id'] = $template_class['class_id'];
|
|
|
+ $data['template_class_name'] = $template_class['name'];
|
|
|
$result = Sector::where('id', $data['id'])->update($data);
|
|
|
if ($result == 1) {
|
|
|
return Result::success('修改成功');
|
|
@@ -1136,9 +1299,22 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (empty($footer_category->toArray())) {
|
|
|
return Result::error('暂无底部导航数据!');
|
|
|
}
|
|
|
+ $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
|
|
|
+ if (empty($page_type)) {
|
|
|
+ $page_type = [];
|
|
|
+ } else {
|
|
|
+ $page_type = json_decode($page_type, true);
|
|
|
+ }
|
|
|
+ // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
|
|
|
+ if (isset($page_type) && in_array(5, $page_type)) {
|
|
|
+ $page_type = 1;
|
|
|
+ } else {
|
|
|
+ $page_type = 0;
|
|
|
+ }
|
|
|
$result = [
|
|
|
'friend_link' => $friend_link,
|
|
|
'footer_category' => $footer_category,
|
|
|
+ 'page_type' => $page_type,
|
|
|
];
|
|
|
return Result::success($result);
|
|
|
}
|
|
@@ -1149,6 +1325,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
*/
|
|
|
public function addWebPageType(array $data): array
|
|
|
{
|
|
|
+ // 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]);
|
|
@@ -1156,7 +1333,18 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$page_type = json_encode([1, 2, 3, 4, 6, 7]);
|
|
|
}
|
|
|
// 0:未构建;1:已填写基础信息;2:已选择模板; action_id
|
|
|
- $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type], ['action_id' => 1]);
|
|
|
+ $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)) {
|
|
|
+ $result = WebsiteTemplateInfo::insertGetId(['website_id' => $data['website_id'], 'page_type' => $page_type, 'user_id' => $data['user_id']]);
|
|
|
+ } 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']]);
|
|
|
+ }
|
|
|
if ($result) {
|
|
|
return Result::success($result);
|
|
|
} else {
|
|
@@ -1195,6 +1383,8 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
|
|
|
$where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
|
|
|
}
|
|
|
+ } else {
|
|
|
+ $query = Template::where($where);
|
|
|
}
|
|
|
$template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
|
|
|
// return Result::success($template_id);
|
|
@@ -1208,19 +1398,20 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
// 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
|
|
|
$template_page_str = json_encode($template_page);
|
|
|
- if (isset($query)) {
|
|
|
- $result['template'] = $query->where($where)
|
|
|
- ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
|
|
|
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
- } else {
|
|
|
- $result['template'] = Template::where($where)
|
|
|
- ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
|
|
|
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
- }
|
|
|
- if (empty($result['template']['data'])) {
|
|
|
+ $result['template'] = $query->where($where)
|
|
|
+ ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
+ if (empty($result['template'])) {
|
|
|
$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) {
|
|
|
+ $result['template_id'] = $template;
|
|
|
+ } else {
|
|
|
+ $result['template_id'] = 0;
|
|
|
+ }
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
/**
|
|
@@ -1238,7 +1429,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if ($website_template_info['status'] == 2) {
|
|
|
return Result::error('网站已应用,不可再次修改!');
|
|
|
}
|
|
|
- $template = Template::where('id', $data['template_id'])->first();
|
|
|
+ $template = Template::where('template_id', $data['template_id'])->first();
|
|
|
if (empty($template)) {
|
|
|
return Result::error('未查询到皮肤!');
|
|
|
}
|
|
@@ -1251,14 +1442,15 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
- * 自助建站---流程---5.选择组件
|
|
|
+ * 自助建站---流程---5.保存模版
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
public function saveWebsiteTemplate(array $data): array
|
|
|
{
|
|
|
+ // return Result::success($data);
|
|
|
$website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
- if (empty($website_template_info)) {
|
|
|
+ if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
|
|
|
return Result::error('请先填写网站基础信息!');
|
|
|
}
|
|
|
// 0:未构建 1:未应用 2:已应用 status
|
|
@@ -1268,202 +1460,62 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if ($website_template_info['action_id'] != 2) {
|
|
|
return Result::error('请完成之前的步骤!');
|
|
|
}
|
|
|
- $template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
- if (empty($template_info)) {
|
|
|
- $template = WebsiteTemplate::insertGetId(['website_id' => $data['website_id'], 'template_data' => $data['template_data']]);
|
|
|
- } else {
|
|
|
- $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]);
|
|
|
- }
|
|
|
- if (empty($template)) {
|
|
|
- return Result::error('保存失败!');
|
|
|
- } else {
|
|
|
- return Result::success($template);
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 企业管理
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getCompanyList(array $data): array
|
|
|
- {
|
|
|
- $where = [];
|
|
|
- $user = User::where('id', $data['user_id'])->first();
|
|
|
- if (empty($user)) {
|
|
|
- return Result::error('用户不存在!');
|
|
|
- }
|
|
|
- if ($user['type_id'] != 10000) {
|
|
|
- $where['user_id'] = $data['user_id'];
|
|
|
- }
|
|
|
- if (isset($data['title']) && $data['title']) {
|
|
|
- array_push($where, ['title', 'like', '%' . $data['title'] . '%']);
|
|
|
- }
|
|
|
- if (isset($data['website_id']) && $data['website_id']) {
|
|
|
- $where['website_id'] = $data['website_id'];
|
|
|
- }
|
|
|
- // 状态:0:未审核 1:已审核 2:已拒绝
|
|
|
- $pageSize = isset($data['pageSize']) ? (int)$data['pageSize'] : 10; // 默认每页 10 条记录
|
|
|
- $page = isset($data['page']) ? (int)$data['page'] : 1; // 默认第 1 页
|
|
|
- if (isset($data['ischeck']) && !empty($data['ischeck'])) {
|
|
|
- if ($data['ischeck'] == 1) {
|
|
|
- $query = Company::whereIn('status', [0, 2]);
|
|
|
+ $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
|
|
|
+ // var_dump($data['template_data']);
|
|
|
+ try {
|
|
|
+ Db::beginTransaction();
|
|
|
+ if (empty($template_info)) {
|
|
|
+ $template = WebsiteTemplate::insertGetId([
|
|
|
+ 'website_id' => $data['website_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'],
|
|
|
+ ]);
|
|
|
} else {
|
|
|
- $query = Company::where('status', 1);
|
|
|
- }
|
|
|
- }
|
|
|
- $result = $query->where($where)->paginate($pageSize, ['*'], 'page', $page);
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("暂无企业", 0);
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- /**
|
|
|
- * 添加企业
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function addCompany(array $data): array
|
|
|
- {
|
|
|
- $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
|
|
|
- $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
|
|
|
- if ($data['imgurl'] == '') {
|
|
|
- //content中提取图片第一个图,正则提取
|
|
|
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
|
|
|
- preg_match_all($reg, $data['content'], $matches);
|
|
|
- if (isset($matches[1][0])) {
|
|
|
- //截取varchar240
|
|
|
- $data['imgurl'] = substr($matches[1][0], 0, 240);
|
|
|
+ $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'],
|
|
|
+ ]
|
|
|
+ );
|
|
|
}
|
|
|
- }
|
|
|
- if ($data['keyword'] == '') {
|
|
|
- //提取标题+内容中的关键词
|
|
|
- $data['keyword'] = $data['title'];
|
|
|
- // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
|
|
|
- Jieba::init(); // 初始化 jieba-php
|
|
|
- Finalseg::init();
|
|
|
- $segList = Jieba::cut($data['keyword']);
|
|
|
- $segList1 = array_slice($segList, 0, 8);
|
|
|
- $data['keyword'] = implode(',', $segList1);
|
|
|
- }
|
|
|
- if ($data['introduce'] == '') {
|
|
|
- //提取内容中的描述
|
|
|
- $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
|
|
|
- }
|
|
|
- $user = User::where('id', $data['user_id'])->first();
|
|
|
- if (empty($user)) {
|
|
|
- return Result::error('用户不存在!');
|
|
|
- }
|
|
|
- if ($user['type_id'] == 10000) {
|
|
|
- $data['status'] = 1;
|
|
|
- }
|
|
|
- $result = Company::insertGetId($data);
|
|
|
- if ($result) {
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error('添加失败');
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 更新企业
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function upCompany(array $data): array
|
|
|
- {
|
|
|
- $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
|
|
|
- $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
|
|
|
- if ($data['imgurl'] == '') {
|
|
|
- //content中提取图片第一个图,正则提取
|
|
|
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
|
|
|
- preg_match_all($reg, $data['content'], $matches);
|
|
|
- if (isset($matches[1][0])) {
|
|
|
- //截取varchar240
|
|
|
- $data['imgurl'] = substr($matches[1][0], 0, 240);
|
|
|
+ if (empty($template)) {
|
|
|
+ Db::rollback();
|
|
|
+ return Result::error('保存失败!');
|
|
|
+ } else {
|
|
|
+ $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
|
|
|
+ if (empty($tempalte_info)) {
|
|
|
+ Db::rollback();
|
|
|
+ return Result::error('保存失败!');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
}
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return Result::error('模版数据格式错误!');
|
|
|
}
|
|
|
- if ($data['keyword'] == '') {
|
|
|
- //提取标题+内容中的关键词
|
|
|
- $data['keyword'] = $data['title'];
|
|
|
- // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
|
|
|
- Jieba::init(); // 初始化 jieba-php
|
|
|
- Finalseg::init();
|
|
|
- $segList = Jieba::cut($data['keyword']);
|
|
|
- $segList1 = array_slice($segList, 0, 8);
|
|
|
- $data['keyword'] = implode(',', $segList1);
|
|
|
- }
|
|
|
- if ($data['introduce'] == '') {
|
|
|
- //提取内容中的描述
|
|
|
- $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
|
|
|
- }
|
|
|
- $user = User::where('id', $data['user_id'])->first();
|
|
|
- if (empty($user)) {
|
|
|
- return Result::error('用户不存在!');
|
|
|
- }
|
|
|
- if ($user['type_id'] == 10000) {
|
|
|
- $data['status'] = 1;
|
|
|
- } else {
|
|
|
- $data['status'] = 0;
|
|
|
- }
|
|
|
- $result = Company::where('id', $data['id'])->update($data);
|
|
|
- if ($result) {
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error('修改失败');
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 删除企业
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function delCompany(array $data): array
|
|
|
- {
|
|
|
- $result = Company::where('id', $data['id'])->delete();
|
|
|
- if ($result) {
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error('删除失败');
|
|
|
- }
|
|
|
+ return Result::success($template);
|
|
|
}
|
|
|
/**
|
|
|
- * 审核企业
|
|
|
+ * 自助建站---流程---6.返显保存的模版
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function checkCompany(array $data): array
|
|
|
+ public function getWebsiteTemplate(array $data): array
|
|
|
{
|
|
|
- $user = User::where('id', $data['user_id'])->first();
|
|
|
- if (empty($user)) {
|
|
|
- return Result::error('用户不存在!');
|
|
|
- }
|
|
|
- $company = Company::where('id', $data['id'])->first();
|
|
|
- if (empty($company)) {
|
|
|
- return Result::error('企业不存在!');
|
|
|
- }
|
|
|
- // 状态:0:未审核 1:已审核 2:已拒绝
|
|
|
- if ($company['status'] == 0 || $company['status'] == 1) {
|
|
|
- $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
|
|
|
- } else {
|
|
|
- $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reject_reason']]);
|
|
|
- }
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error('审核失败!');
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
+ $web = Website::where('id', $data['website_id'])->first();
|
|
|
+ if (empty($web)) {
|
|
|
+ return Result::error('未查询到网站信息!');
|
|
|
}
|
|
|
- }
|
|
|
- /**
|
|
|
- * 获取企业信息
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getCompanyInfo(array $data): array
|
|
|
- {
|
|
|
- $result = Company::where('id', $data['id'])->first();
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error('企业不存在!');
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
+ $template = WebsiteTemplate::where('website_id', $data['website_id'])
|
|
|
+ ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error('未查询到模版!');
|
|
|
}
|
|
|
+ return Result::success($template);
|
|
|
}
|
|
|
}
|