|
@@ -52,6 +52,7 @@ use App\Model\JobHunting;
|
|
|
use App\Model\JobRemuse;
|
|
|
use Hyperf\Redis\Redis;
|
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
+
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -1440,65 +1441,64 @@ class NewsService implements NewsServiceInterface
|
|
|
return Result::error("查询失败", 0);
|
|
|
}
|
|
|
return Result::success($category);
|
|
|
- }
|
|
|
+ }
|
|
|
/**
|
|
|
- * 模块新闻加强版
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
+ * 模块新闻加强版
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function getWebsiteAllArticle(array $data): array
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
// $redisKey = 'website_cache';
|
|
|
// $this->redis->hSet($redisKey, $data['website_id'], json_encode($data));
|
|
|
// $result = $this->redis->sadd($redisKey);
|
|
|
- // 使用缓存键
|
|
|
+ // 使用缓存键
|
|
|
// $cacheKey = $data['website_id'];
|
|
|
-
|
|
|
+
|
|
|
// // 尝试从缓存获取数据
|
|
|
- $container = \Hyperf\Context\ApplicationContext::getContainer();
|
|
|
- $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
|
|
|
- // 修正传入的字符串,将单引号替换为双引号
|
|
|
- $input['id'] = $data['id'];
|
|
|
- $input['website_id'] = $data['website_id'];
|
|
|
-
|
|
|
- // 将 JSON 字符串转换为 PHP 数组
|
|
|
- $items = json_decode($input['id'], true);
|
|
|
-
|
|
|
- if (!is_array($items)) {
|
|
|
- return Result::error("无效的JSON格式", 0);
|
|
|
- }
|
|
|
-
|
|
|
- $website = [
|
|
|
- 'website_id' => $input['website_id'],
|
|
|
- ];
|
|
|
- foreach ($items as $key=>$item) {
|
|
|
+ $container = \Hyperf\Context\ApplicationContext::getContainer();
|
|
|
+ $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
|
|
|
+ // 修正传入的字符串,将单引号替换为双引号
|
|
|
+ $input['id'] = $data['id'];
|
|
|
+ $input['website_id'] = $data['website_id'];
|
|
|
+
|
|
|
+ // 将 JSON 字符串转换为 PHP 数组
|
|
|
+ $items = json_decode($input['id'], true);
|
|
|
+
|
|
|
+ if (!is_array($items)) {
|
|
|
+ return Result::error("无效的JSON格式", 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ $website = [
|
|
|
+ 'website_id' => $input['website_id'],
|
|
|
+ ];
|
|
|
+ foreach ($items as $key => $item) {
|
|
|
if (isset($item['parent']) && $item['parent'] !== "") {
|
|
|
- $parentParams = explode(',', $item['parent']);
|
|
|
- if(isset($parentParams) && $parentParams[0]!== ""){
|
|
|
- $parentCatId[$key] = $parentParams[0];
|
|
|
- }
|
|
|
- }else{
|
|
|
+ $parentParams = explode(',', $item['parent']);
|
|
|
+ if (isset($parentParams) && $parentParams[0] !== "") {
|
|
|
+ $parentCatId[$key] = $parentParams[0];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
return Result::error("缺少必需参数错误", 0);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- $pid = WebsiteCategory::whereIn('category_id',$parentCatId)->where($website)->pluck('pid')->toArray();
|
|
|
+ $pid = WebsiteCategory::whereIn('category_id', $parentCatId)->where($website)->pluck('pid')->toArray();
|
|
|
// return Result::success($pid);
|
|
|
- if(!empty($pid)){
|
|
|
+ if (!empty($pid)) {
|
|
|
$pid = array_values(array_unique($pid));
|
|
|
- if(count($pid)==1){
|
|
|
- $cacheKey = $data['website_id'].','.$pid[0];
|
|
|
- }else{
|
|
|
+ if (count($pid) == 1) {
|
|
|
+ $cacheKey = $data['website_id'] . ',' . $pid[0];
|
|
|
+ } else {
|
|
|
return Result::error("参数传递错误", 0);
|
|
|
}
|
|
|
}
|
|
|
// return Result::success($cacheKey);
|
|
|
- if ($cachedData = $cache->get($cacheKey)) {
|
|
|
- return Result::success(unserialize($cachedData));
|
|
|
- }
|
|
|
+ if ($cachedData = $cache->get($cacheKey)) {
|
|
|
+ return Result::success(unserialize($cachedData));
|
|
|
+ }
|
|
|
try {
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// 提前缓存常用查询结果,减少重复查询
|
|
|
$categoryCache = [];
|
|
@@ -1514,15 +1514,15 @@ class NewsService implements NewsServiceInterface
|
|
|
'textnum' => [],
|
|
|
'child' => []
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
// 处理父级栏目
|
|
|
if (isset($item['parent']) && $item['parent'] !== 'undefined' && $item['parent'] !== "") {
|
|
|
$parentParams = explode(',', $item['parent']);
|
|
|
-
|
|
|
+
|
|
|
if (count($parentParams) !== 3) {
|
|
|
return Result::error("父级栏目:缺少必需参数错误", 0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
list($parentCatId, $parentImgNum, $parentTextNum) = $parentParams;
|
|
|
$cacheKey = "parent_{$parentCatId}_{$website['website_id']}";
|
|
|
|
|
@@ -1532,34 +1532,34 @@ class NewsService implements NewsServiceInterface
|
|
|
->where($website)
|
|
|
->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$category = $categoryCache[$cacheKey];
|
|
|
|
|
|
if (!empty($category)) {
|
|
|
$resultItem['alias'] = $category->alias;
|
|
|
$resultItem['category_id'] = $category->category_id;
|
|
|
$resultItem['pinyin'] = $category->aLIas_pinyin;
|
|
|
-
|
|
|
+
|
|
|
// 查询图片新闻
|
|
|
if (!empty($parentImgNum)) {
|
|
|
$resultItem['imgnum'] = $this->fetchArticles($parentCatId, $website, (int)$parentImgNum, true);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 查询文字新闻
|
|
|
if (!empty($parentTextNum)) {
|
|
|
$resultItem['textnum'] = $this->fetchArticles($parentCatId, $website, (int)$parentTextNum, false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 处理子级栏目
|
|
|
if (isset($item['child']) && $item['child'] !== 'undefined' && $item['child'] !== "") {
|
|
|
$childParams = explode(',', $item['child']);
|
|
|
-
|
|
|
+
|
|
|
if (count($childParams) !== 3) {
|
|
|
return Result::error("子级栏目:缺少必需参数错误", 0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
list($childCatId, $childImgNum, $childTextNum) = $childParams;
|
|
|
$cacheKey = "child_{$childCatId}_{$website['website_id']}";
|
|
|
|
|
@@ -1567,22 +1567,22 @@ class NewsService implements NewsServiceInterface
|
|
|
// 查询子栏目信息
|
|
|
$childCategoryCache[$cacheKey] = WebsiteCategory::where($website)
|
|
|
->where("category_id", $childCatId)
|
|
|
- ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($childCatId)."') = 1")
|
|
|
+ ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($childCatId) . "') = 1")
|
|
|
->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$childCategory = $childCategoryCache[$cacheKey];
|
|
|
|
|
|
if (!empty($childCategory)) {
|
|
|
$childCategory = $this->processArticles($childCategory, $website);
|
|
|
-
|
|
|
+
|
|
|
// 查询此层级的所有子栏目
|
|
|
$allChildCategories = WebsiteCategory::where($website)
|
|
|
->where("pid", $childCategory['pid'])
|
|
|
->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'category_arr_id as cat_arr_id']);
|
|
|
-
|
|
|
+
|
|
|
$allChildCategories = $this->processArticles($allChildCategories, $website);
|
|
|
-
|
|
|
+
|
|
|
$childResult = [
|
|
|
'alias' => $childCategory->alias,
|
|
|
'category_id' => $childCategory->category_id,
|
|
@@ -1591,17 +1591,17 @@ class NewsService implements NewsServiceInterface
|
|
|
'imgnum' => [],
|
|
|
'textnum' => []
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
// 查询子栏目图片新闻
|
|
|
if (!empty($childImgNum)) {
|
|
|
$childResult['imgnum'] = $this->fetchArticles($childCatId, $website, (int)$childImgNum, true);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 查询子栏目文字新闻
|
|
|
if (!empty($childTextNum)) {
|
|
|
$childResult['textnum'] = $this->fetchArticles($childCatId, $website, (int)$childTextNum, false);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$resultItem['child'] = $childResult;
|
|
|
}
|
|
|
}
|
|
@@ -1615,41 +1615,50 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * 辅助方法:获取文章列表
|
|
|
- */
|
|
|
-private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
|
|
|
-{
|
|
|
- $query = Article::where('article.status', 1)
|
|
|
- // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
|
|
|
- ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
|
|
|
- ->where(function ($query) use ($website) {
|
|
|
- $query->whereRaw("(JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0 OR ignore_ids IS NULL)");
|
|
|
- })
|
|
|
- ->leftJoin('website_category', function($join) use ($website) {
|
|
|
- $join->on('article.catid', '=', 'website_category.category_id')
|
|
|
- ->where('website_category.website_id', '=', $website['website_id']);
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at',
|
|
|
- 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id',
|
|
|
- 'article.catid', 'website_category.alias as category_name'
|
|
|
- )
|
|
|
- ->orderBy('updated_at', 'desc')
|
|
|
- ->limit($limit);
|
|
|
-
|
|
|
- // 如果是图片文章,添加图片URL条件
|
|
|
- if ($isImageArticle) {
|
|
|
- $query->where('imgurl', '!=', '');
|
|
|
- } else {
|
|
|
- // 文字文章不需要imgurl字段
|
|
|
- $query->addSelect('article.introduce');
|
|
|
+ /**
|
|
|
+ * 辅助方法:获取文章列表
|
|
|
+ */
|
|
|
+ private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
|
|
|
+ {
|
|
|
+ $query = Article::where('article.status', 1)
|
|
|
+ // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
|
|
|
+ ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
|
|
|
+ ->where(function ($query) use ($website) {
|
|
|
+ $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
|
|
|
+ })
|
|
|
+ ->leftJoin('website_category', function ($join) use ($website) {
|
|
|
+ $join->on('article.catid', '=', 'website_category.category_id')
|
|
|
+ ->where('website_category.website_id', '=', $website['website_id']);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.imgurl',
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.copyfrom',
|
|
|
+ 'article.cat_arr_id',
|
|
|
+ 'article.catid',
|
|
|
+ 'website_category.alias as category_name'
|
|
|
+ )
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($limit);
|
|
|
+
|
|
|
+ // 如果是图片文章,添加图片URL条件
|
|
|
+ if ($isImageArticle) {
|
|
|
+ $query->where('imgurl', '!=', '');
|
|
|
+ } else {
|
|
|
+ // 文字文章不需要imgurl字段
|
|
|
+ $query->addSelect('article.introduce');
|
|
|
+ }
|
|
|
+
|
|
|
+ $articles = $query->get();
|
|
|
+
|
|
|
+ return !empty($articles) ? $this->processArticles($articles, $website) : [];
|
|
|
}
|
|
|
-
|
|
|
- $articles = $query->get();
|
|
|
-
|
|
|
- return !empty($articles) ? $this->processArticles($articles, $website) : [];
|
|
|
-}
|
|
|
/**
|
|
|
* 乡村网-获取特殊新闻模块
|
|
|
* @param array $data
|
|
@@ -1954,43 +1963,43 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
* */
|
|
|
public function getWebsiteshopCat(array $data): array
|
|
|
{
|
|
|
- $website = $data['website_id'];
|
|
|
- $category = WebsiteCategory::where('website_id', $website)
|
|
|
- ->whereRaw("JSON_CONTAINS(category_arr_id, '". intval($data['id']). "') = 1")
|
|
|
- ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"". intval($data['id']). "\"') = 1")
|
|
|
- ->select('category_id', 'alias','aLIas_pinyin','pid','category_arr_id' ,'sort')
|
|
|
- ->orderBy('sort')
|
|
|
- ->get();
|
|
|
- $cat = $category->map(function ($item) use ($website) {
|
|
|
- $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
|
|
|
- $pid = $item->pid?? 0;
|
|
|
- if(!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0){
|
|
|
- $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
|
|
|
- ->where('website_id', $website)
|
|
|
- ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr_id). ')')
|
|
|
- ->get(['aLIas_pinyin'])
|
|
|
- ->pluck('aLIas_pinyin')
|
|
|
- ->implode('/');
|
|
|
- }else{
|
|
|
- $pinyin = $item->aLIas_pinyin ?? '';
|
|
|
- }
|
|
|
- $item->pinyin = $pinyin;
|
|
|
- });
|
|
|
- if(empty($category)){
|
|
|
- return Result::error("栏目查询失败", 0);
|
|
|
- }
|
|
|
- $cat_tree = Result::buildMenuTree($category);
|
|
|
- $web['website_id'] = $website;
|
|
|
- $goods = Good::where('website_id', $website)
|
|
|
- ->where('status', 2)
|
|
|
- ->select('good.id as good_id', 'name','imgurl','description','updated_at','catid','type_id','website_id')
|
|
|
- ->latest('updated_at')
|
|
|
- ->offset(($data['page']-1)*$data['pageSize'])
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->get();
|
|
|
- if(!empty($goods)){
|
|
|
- if($goods->count() > 1 && !empty($goods)){
|
|
|
- $goods = $this->processGoods($goods, $web);
|
|
|
+ $website = $data['website_id'];
|
|
|
+ $category = WebsiteCategory::where('website_id', $website)
|
|
|
+ ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
|
|
|
+ ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
|
|
|
+ ->orderBy('sort')
|
|
|
+ ->get();
|
|
|
+ $cat = $category->map(function ($item) use ($website) {
|
|
|
+ $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
|
|
|
+ $pid = $item->pid ?? 0;
|
|
|
+ if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
|
|
|
+ $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
|
|
|
+ ->where('website_id', $website)
|
|
|
+ ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
|
|
|
+ ->get(['aLIas_pinyin'])
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ } else {
|
|
|
+ $pinyin = $item->aLIas_pinyin ?? '';
|
|
|
+ }
|
|
|
+ $item->pinyin = $pinyin;
|
|
|
+ });
|
|
|
+ if (empty($category)) {
|
|
|
+ return Result::error("栏目查询失败", 0);
|
|
|
+ }
|
|
|
+ $cat_tree = Result::buildMenuTree($category);
|
|
|
+ $web['website_id'] = $website;
|
|
|
+ $goods = Good::where('website_id', $website)
|
|
|
+ ->where('status', 2)
|
|
|
+ ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
|
|
|
+ ->latest('updated_at')
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get();
|
|
|
+ if (!empty($goods)) {
|
|
|
+ if ($goods->count() > 1 && !empty($goods)) {
|
|
|
+ $goods = $this->processGoods($goods, $web);
|
|
|
}
|
|
|
} else {
|
|
|
$goods = [];
|
|
@@ -2116,11 +2125,11 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
// 检查 $articles 是否为数组或可迭代对象
|
|
|
if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
|
|
|
return $articles->map(function ($article) use ($data) {
|
|
|
- if(isset($article->cat_arr_id) &&!empty($article->cat_arr_id)){
|
|
|
- $catid = $article->cat_arr_id?? '';
|
|
|
+ if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
|
|
|
+ $catid = $article->cat_arr_id ?? '';
|
|
|
}
|
|
|
- if(isset($article->category_arr_id) &&!empty($article->category_arr_id)){
|
|
|
- $catid = $article->category_arr_id?? '';
|
|
|
+ if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
|
|
|
+ $catid = $article->category_arr_id ?? '';
|
|
|
}
|
|
|
// $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
|
|
|
$level = json_decode($catid, true);
|
|
@@ -3569,7 +3578,12 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
unset($data['job_typename']); //不知道这是啥,
|
|
|
$data['created_at'] = date('Y-m-d H:i:s');
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
|
- var_dump($data, '-----------------test---------');
|
|
|
+ //根据用户 user_id 只能添加一次
|
|
|
+ $result = JobHunting::where('user_id', $data['user_id'])->first();
|
|
|
+ if (!empty($result)) {
|
|
|
+ return Result::error("您已添加过求职信息", 0);
|
|
|
+ }
|
|
|
+ var_dump($result, '-----------------test---------');
|
|
|
$result = JobHunting::create($data);
|
|
|
if (empty($result)) {
|
|
|
return Result::error("添加失败", 0);
|
|
@@ -4411,12 +4425,12 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
// 先添加职位相关信息
|
|
|
- if($user['type_id'] == 10000){
|
|
|
- $job['status'] = 1;
|
|
|
+ if ($user['type_id'] == 10000) {
|
|
|
+ $job['status'] = 1;
|
|
|
}
|
|
|
- if(empty($data['experience']) || $data['experience'] == ''){
|
|
|
+ if (empty($data['experience']) || $data['experience'] == '') {
|
|
|
$job['experience'] = null;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$job['experience'] = $data['experience'];
|
|
|
}
|
|
|
$jobId = JobRecruiting::insertGetId($job);
|
|
@@ -4586,9 +4600,9 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
} else {
|
|
|
$data['status'] = 0;
|
|
|
}
|
|
|
- if(empty($data['experience']) || $data['experience'] == ''){
|
|
|
+ if (empty($data['experience']) || $data['experience'] == '') {
|
|
|
$job['experience'] = null;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$job['experience'] = $data['experience'];
|
|
|
}
|
|
|
// Db::rollBack();
|