|
@@ -62,6 +62,8 @@ use App\Model\Idiom;
|
|
|
use App\Model\WhiteRouter;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
+use App\Model\Company;
|
|
|
+use Hyperf\Paginator\Paginator;
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -1458,175 +1460,6 @@ class NewsService implements NewsServiceInterface
|
|
|
* @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) {
|
|
|
- if (isset($item['parent']) && $item['parent'] !== "") {
|
|
|
- $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();
|
|
|
- // return Result::success($pid);
|
|
|
- if (!empty($pid)) {
|
|
|
- $pid = array_values(array_unique($pid));
|
|
|
- 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));
|
|
|
- }
|
|
|
- try {
|
|
|
-
|
|
|
-
|
|
|
- // 提前缓存常用查询结果,减少重复查询
|
|
|
- $categoryCache = [];
|
|
|
- $childCategoryCache = [];
|
|
|
-
|
|
|
- // 使用 array_map 处理每个元素
|
|
|
- $result = array_map(function ($item) use ($website, &$categoryCache, &$childCategoryCache) {
|
|
|
- $resultItem = [
|
|
|
- 'alias' => null,
|
|
|
- 'category_id' => null,
|
|
|
- 'pinyin' => null,
|
|
|
- 'imgnum' => [],
|
|
|
- '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']}";
|
|
|
-
|
|
|
- if (!isset($categoryCache[$cacheKey])) {
|
|
|
- // 查询栏目名称
|
|
|
- $categoryCache[$cacheKey] = WebsiteCategory::where('category_id', $parentCatId)
|
|
|
- ->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']}";
|
|
|
-
|
|
|
- if (!isset($childCategoryCache[$cacheKey])) {
|
|
|
- // 查询子栏目信息
|
|
|
- $childCategoryCache[$cacheKey] = WebsiteCategory::where($website)
|
|
|
- ->where("category_id", $childCatId)
|
|
|
- ->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,
|
|
|
- 'pinyin' => $childCategory->aLIas_pinyin,
|
|
|
- 'all_childcat' => $allChildCategories,
|
|
|
- '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;
|
|
|
- }
|
|
|
- }
|
|
|
- return $resultItem;
|
|
|
- }, $items);
|
|
|
- $cache->set($cacheKey, serialize($result), 86400);
|
|
|
- return Result::success($result);
|
|
|
- } catch (\Exception $e) {
|
|
|
- // 记录错误日志
|
|
|
- return Result::error("获取网站文章失败: " . $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 辅助方法:获取文章列表
|
|
@@ -2034,77 +1867,77 @@ class NewsService implements NewsServiceInterface
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
* */
|
|
|
- public function getWebsiteshopList(array $data): array
|
|
|
- {
|
|
|
- // return Result::success($data);
|
|
|
- $where = [
|
|
|
- 'status' => 2,
|
|
|
- 'website_id' => $data['website_id'],
|
|
|
- ];
|
|
|
- if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
|
|
|
- return Result::error("查询失败", 0);
|
|
|
- }
|
|
|
- if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
|
|
|
- $data['catid'] = $category->category_id ?? 0;
|
|
|
- }
|
|
|
- if (isset($data['keyword']) && !empty($data['keyword'])) {
|
|
|
- array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
|
|
|
- }
|
|
|
- if (isset($data['type_id']) && !empty($data['type_id'])) {
|
|
|
- array_push($where, ['type_id', $data['type_id']]);
|
|
|
- }
|
|
|
- $query = Good::where($where)
|
|
|
- ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
|
|
|
- $query->where(function ($q) use ($data) {
|
|
|
- $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
|
|
|
- ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
|
|
|
- });
|
|
|
- })
|
|
|
- ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
|
|
|
- $query->where(function ($q) use ($data) {
|
|
|
- $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
|
|
|
- ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
|
|
|
- });
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'good.id',
|
|
|
- 'good.name',
|
|
|
- 'good.imgurl',
|
|
|
- 'good.description',
|
|
|
- 'good.updated_at',
|
|
|
- 'good.com',
|
|
|
- 'good.catid',
|
|
|
- 'good.type_id',
|
|
|
- 'good.website_id',
|
|
|
- 'good.cat_arr_id',
|
|
|
- 'good.created_at',
|
|
|
- 'good.city_id'
|
|
|
- )
|
|
|
- ->latest('updated_at');
|
|
|
- $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
|
|
|
- // 获取 type_id 为 1 的数据
|
|
|
- $result['type1'] = $this->processGoods(
|
|
|
- $query->clone()
|
|
|
- ->where('type_id', 1)
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->get(),
|
|
|
- $data
|
|
|
- );
|
|
|
- $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
|
|
|
- // 获取 type_id 为 2 的数据
|
|
|
- $result['type2'] = $this->processGoods(
|
|
|
- $query->clone()
|
|
|
- ->where('type_id', 2)
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->get(),
|
|
|
- $data
|
|
|
- );
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("查询失败", 0);
|
|
|
- }
|
|
|
+ public function getWebsiteshopList(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $where = [
|
|
|
+ 'status' => 2,
|
|
|
+ 'website_id' => $data['website_id'],
|
|
|
+ ];
|
|
|
+ if((empty($data['catid']) ||!isset($data['catid'])) && (empty($data['keyword']) ||!isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['category_id']);
|
|
|
+ $data['catid'] = $category->category_id ?? 0;
|
|
|
+ }
|
|
|
+ if(isset($data['keyword']) &&!empty($data['keyword'])){
|
|
|
+ array_push($where, ['name', 'like', '%'. $data['keyword'].'%']);
|
|
|
+ }
|
|
|
+ if(isset($data['type_id']) && !empty($data['type_id'])){
|
|
|
+ array_push($where, ['type_id', $data['type_id']]);
|
|
|
+ }
|
|
|
+ $query = Good::where($where)
|
|
|
+ ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
|
|
|
+ $query->where(function($q) use ($data) {
|
|
|
+ $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($data['catid']). "') = 1")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"". intval($data['catid']). "\"') = 1");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
|
|
|
+ $query->where(function($q) use ($data) {
|
|
|
+ $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '". intval($data['city_id']). "') = 1")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"". intval($data['city_id']). "\"') = 1");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at', 'good.com',
|
|
|
+ 'good.catid','good.type_id','good.website_id','good.cat_arr_id','good.created_at','good.city_id')
|
|
|
+ ->latest('updated_at');
|
|
|
+ if(isset($data['ismix']) && $data['ismix'] == 1){
|
|
|
+ $result['count'] = $query->clone()->count();
|
|
|
+ $result['goods'] = $this->processGoods(
|
|
|
+ $query->clone()
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ }else{
|
|
|
+ $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
|
|
|
+ // 获取 type_id 为 1 的数据
|
|
|
+ $result['type1'] = $this->processGoods(
|
|
|
+ $query->clone()
|
|
|
+ ->where('type_id', 1)
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
|
|
|
+ // 获取 type_id 为 2 的数据
|
|
|
+ $result['type2'] = $this->processGoods(
|
|
|
+ $query->clone()
|
|
|
+ ->where('type_id', 2)
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
|
|
|
return Result::success($result);
|
|
|
}
|
|
@@ -2795,6 +2628,9 @@ class NewsService implements NewsServiceInterface
|
|
|
if (isset($data['hy_id']) && !empty($data['hy_id'])) {
|
|
|
array_push($recruit_where, ['hy_id', $data['hy_id']]);
|
|
|
}
|
|
|
+ if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
|
+ array_push($recruit_where, ['title','like','%'.$data['keyword'].'%']);
|
|
|
+ }
|
|
|
$query = JobRecruiting::where('job_recruiting.status', 1)
|
|
|
->where('job_recruiting.website_id', $data['website_id'])
|
|
|
->where($recruit_where)
|
|
@@ -2849,6 +2685,9 @@ class NewsService implements NewsServiceInterface
|
|
|
$query = JobHunting::where('status', 2)
|
|
|
->where('job_hunting.website_id', $data['website_id'])
|
|
|
->where($hunt_where)
|
|
|
+ ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
|
|
|
+ $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
|
|
|
+ })
|
|
|
->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
|
|
|
$query->where(function ($q) use ($data) {
|
|
|
$q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
|
|
@@ -3464,10 +3303,38 @@ class NewsService implements NewsServiceInterface
|
|
|
$data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
|
|
|
$data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
|
|
|
$data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
|
|
|
- unset($data['imgUrl']);
|
|
|
+ unset($data['imgUrl']); //大小写
|
|
|
if (isset($data['price']) && $data['price'] == '') {
|
|
|
$data['price'] = 0;
|
|
|
}
|
|
|
+
|
|
|
+ if ($data['imgurl'] == '') {
|
|
|
+ $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
|
|
|
+ preg_match_all($reg, $data['detail'], $matches);
|
|
|
+ if (isset($matches[1][0])) {
|
|
|
+ //截取varchar240
|
|
|
+ $data['imgurl'] = substr($matches[1][0], 0, 240);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($data['keyword'] == '' || $data['keyword'] == array()) {
|
|
|
+ //提取标题+内容中的关键词
|
|
|
+ $data['keyword'] = $data['name'];
|
|
|
+ // . 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['description'] == '') {
|
|
|
+ //提取内容中的描述
|
|
|
+ $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
|
|
|
+ $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
|
|
|
+ // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
$result = Good::insert($data);
|
|
|
if (empty($result)) {
|
|
|
return Result::error("添加失败", 0);
|
|
@@ -3487,6 +3354,33 @@ class NewsService implements NewsServiceInterface
|
|
|
if (isset($data['price']) && $data['price'] == '') {
|
|
|
$data['price'] = 0;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ if ($data['imgurl'] == '') {
|
|
|
+ $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
|
|
|
+ preg_match_all($reg, $data['detail'], $matches);
|
|
|
+ if (isset($matches[1][0])) {
|
|
|
+ //截取varchar240
|
|
|
+ $data['imgurl'] = substr($matches[1][0], 0, 240);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($data['keyword'] == '' || $data['keyword'] == array()) {
|
|
|
+ //提取标题+内容中的关键词
|
|
|
+ $data['keyword'] = $data['name'];
|
|
|
+ // . 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['description'] == '') {
|
|
|
+ //提取内容中的描述
|
|
|
+ $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
|
|
|
+ $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
$result = Good::where('id', $data['id'])->update($data);
|
|
|
if (empty($result)) {
|
|
|
return Result::error("更新失败", 0);
|
|
@@ -5244,7 +5138,8 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
if ($data['description'] == '') {
|
|
|
//提取内容中的描述
|
|
|
- $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
|
|
|
+ $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
|
|
|
+ $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
|
|
|
}
|
|
|
var_dump($data, '--');
|
|
|
|
|
@@ -5335,7 +5230,8 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
if ($data['description'] == '') {
|
|
|
//提取内容中的描述
|
|
|
- $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
|
|
|
+ $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
|
|
|
+ $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
|
|
|
}
|
|
|
$data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
|
|
|
$data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
|
|
@@ -5704,63 +5600,584 @@ class NewsService implements NewsServiceInterface
|
|
|
/**
|
|
|
* 农网导航首页数据
|
|
|
*/
|
|
|
- public function getWebsiteNwHomeList(array $data): array{
|
|
|
- $categoryIds = WebsiteCategory::where(['website_id'=> $data['website_id']])->where("pid","!=",0)
|
|
|
- ->pluck('category_id')
|
|
|
- ->toArray();
|
|
|
- // 使用子查询优化
|
|
|
- $articlesList = DB::table('article')
|
|
|
- ->select([
|
|
|
+ public function getWebsiteNwHomeList(array $data): array
|
|
|
+ {
|
|
|
+ $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
|
|
|
+ ->pluck('category_id')
|
|
|
+ ->toArray();
|
|
|
+ // 使用子查询优化
|
|
|
+ $articlesList = DB::table('article')
|
|
|
+ ->select([
|
|
|
+ 'article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.imgurl',
|
|
|
+ 'article.created_at',
|
|
|
+ 'category.name as category_name',
|
|
|
+ 'category.id as category_id',
|
|
|
+ 'website_category.aLIas_pinyin as pinyin',
|
|
|
+ 'parent_wc.aLIas_pinyin as parent_pinyin',
|
|
|
+ DB::raw('100 as type')
|
|
|
+ ])
|
|
|
+ ->join('category', 'article.catid', '=', 'category.id')
|
|
|
+ ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
|
|
|
+ ->leftJoin('website_category as parent_wc', function ($join) {
|
|
|
+ $join->on('parent_wc.category_id', '=', 'website_category.pid')
|
|
|
+ ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
|
|
|
+ })
|
|
|
+ ->where('website_category.website_id', $data['website_id'])
|
|
|
+ ->where('article.status', 1)
|
|
|
+ ->whereIn('category.id', $categoryIds)
|
|
|
+ ->orderBy('article.created_at', 'desc')
|
|
|
+ ->get()
|
|
|
+ ->groupBy('category_id')
|
|
|
+ ->map(function ($group) {
|
|
|
+ // 确保第一条数据有图片
|
|
|
+ $firstWithImage = $group->first(function ($item) {
|
|
|
+ return !empty($item->imgurl);
|
|
|
+ });
|
|
|
+
|
|
|
+ if ($firstWithImage) {
|
|
|
+ // 如果有带图片的文章,将其放在第一位
|
|
|
+ $group = $group->filter(function ($item) use ($firstWithImage) {
|
|
|
+ return $item->id !== $firstWithImage->id;
|
|
|
+ })->prepend($firstWithImage);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'category_name' => $group->first()->category_name,
|
|
|
+ 'catid' => $group->first()->category_id,
|
|
|
+ 'pinyin' => $group->first()->pinyin,
|
|
|
+ 'parent_pinyin' => $group->first()->parent_pinyin,
|
|
|
+ 'list' => $group->take(4)->map(function ($item) {
|
|
|
+ return [
|
|
|
+ 'id' => $item->id,
|
|
|
+ 'title' => $item->title,
|
|
|
+ ];
|
|
|
+ })->values()
|
|
|
+ ];
|
|
|
+ })
|
|
|
+ ->values()
|
|
|
+ ->toArray();
|
|
|
+ return Result::success($articlesList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模块新闻加强版
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteAllArticle(array $data): array
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 修正传入的字符串,将单引号替换为双引号
|
|
|
+ $input['id'] = $data['id'];
|
|
|
+ $input['website_id'] = $data['website_id'];
|
|
|
+ // 将 JSON 字符串转换为 PHP 数组
|
|
|
+ $data = json_decode($input['id'], true);
|
|
|
+ // 使用 array_map 处理每个元素
|
|
|
+ $result = array_map(function ($item) use ($input) {
|
|
|
+ // 检查parent元素是否存在且不是undefined
|
|
|
+ if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
|
|
|
+ $count = explode(',', $item['parent']);
|
|
|
+ if (count($count) != 3) {
|
|
|
+ return Result::error("参数错误", 0);
|
|
|
+ }
|
|
|
+ list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
|
|
|
+ $website = [
|
|
|
+ 'website_id' => $input['website_id'],
|
|
|
+ ];
|
|
|
+ // 查询栏目名称
|
|
|
+ $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin', 'type']);
|
|
|
+ // 查询图片新闻
|
|
|
+ if (isset($parentImgNum) && $parentImgNum != 0 && !empty($categroy)) {
|
|
|
+ $imgArticles = Article::where('article.status', 1)
|
|
|
+ ->where(function ($query) use ($parentCatId) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($website) {
|
|
|
+ $query->where(function ($subQuery) use ($website) {
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
+ ->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($parentImgNum)
|
|
|
+ ->get();
|
|
|
+ //调取封装路由的方法,处理新闻路由
|
|
|
+ if (!empty($imgArticles)) {
|
|
|
+ $imgArticles = $this->processArticles($imgArticles, $website);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询文字新闻
|
|
|
+ if (isset($parentTextNum) && $parentTextNum != 0 && !empty($categroy)) {
|
|
|
+ $textArticles = [];
|
|
|
+ $textArticles = Article::where('article.status', 1)
|
|
|
+ ->where(function ($query) use ($parentCatId) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($website) {
|
|
|
+ $query->where(function ($subQuery) use ($website) {
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->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.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.cat_arr_id',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.copyfrom',
|
|
|
+ 'article.catid',
|
|
|
+ 'website_category.alias as category_name',
|
|
|
+ )
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($parentTextNum)
|
|
|
+ ->get();
|
|
|
+ if (!empty($textArticles)) {
|
|
|
+ $textArticles = $this->processArticles($textArticles, $website);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $resultItem = [
|
|
|
+ 'alias' => $categroy ? $categroy->alias : null,
|
|
|
+ 'category_id' => $categroy ? $categroy->category_id : null,
|
|
|
+ 'pinyin' => $categroy ? $categroy->aLIas_pinyin : null,
|
|
|
+ 'imgnum' => $imgArticles ?? [],
|
|
|
+ 'textnum' => $textArticles ?? [],
|
|
|
+ ];
|
|
|
+ if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
|
|
|
+ list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
|
|
|
+ $childCategory = WebsiteCategory::where($website)
|
|
|
+ ->where("category_id", $childCatId)
|
|
|
+ ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
|
|
|
+ ->first(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
|
|
|
+ if (!empty($childCategory)) {
|
|
|
+ $childCategory = $this->processArticles($childCategory, $website);
|
|
|
+ // 查询此层级的所有子栏目
|
|
|
+ $all_childcat = WebsiteCategory::where($website)
|
|
|
+ ->where("pid", $childCategory['pid'])
|
|
|
+ ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "') = 1")
|
|
|
+ ->get(['alias', 'category_id', 'aLIas_pinyin', 'pid', 'type', 'category_arr_id as cat_arr_id']);
|
|
|
+ $all_childcat = $this->processArticles($all_childcat, $website);
|
|
|
+ // 查询子栏目图片新闻
|
|
|
+ if (isset($childImgNum) && $childImgNum != 0) {
|
|
|
+ $childImgArticles = Article::where('catid', $childCatId)
|
|
|
+ ->where('status', 1)
|
|
|
+ ->where(function ($query) use ($website) {
|
|
|
+ $query->where(function ($subQuery) use ($website) {
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
|
|
|
+ })->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
'article.id',
|
|
|
'article.title',
|
|
|
'article.imgurl',
|
|
|
- 'article.created_at',
|
|
|
- 'category.name as category_name',
|
|
|
- 'category.id as category_id',
|
|
|
- 'website_category.aLIas_pinyin as pinyin',
|
|
|
- 'parent_wc.aLIas_pinyin as parent_pinyin',
|
|
|
- DB::raw('100 as type')
|
|
|
- ])
|
|
|
- ->join('category', 'article.catid', '=', 'category.id')
|
|
|
- ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
|
|
|
- ->leftJoin('website_category as parent_wc', function($join) {
|
|
|
- $join->on('parent_wc.category_id', '=', 'website_category.pid')
|
|
|
- ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
|
|
|
- })
|
|
|
- ->where('website_category.website_id', $data['website_id'])
|
|
|
- ->where('article.status', 1)
|
|
|
- ->whereIn('category.id', $categoryIds)
|
|
|
- ->orderBy('article.created_at', 'desc')
|
|
|
- ->get()
|
|
|
- ->groupBy('category_id')
|
|
|
- ->map(function ($group) {
|
|
|
- // 确保第一条数据有图片
|
|
|
- $firstWithImage = $group->first(function ($item) {
|
|
|
- return !empty($item->imgurl);
|
|
|
- });
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.catid',
|
|
|
+ 'article.cat_arr_id',
|
|
|
+ 'article.copyfrom',
|
|
|
+ )
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($childImgNum)
|
|
|
+ ->get();
|
|
|
+ $childImgArticles = $this->processArticles($childImgArticles, $website);
|
|
|
+ }
|
|
|
+ // 查询子栏目文字新闻
|
|
|
+ if (isset($childTextNum) && $childTextNum != 0) {
|
|
|
+ $childTextArticles = Article::where('catid', $childCatId)
|
|
|
+ ->where('status', 1)
|
|
|
+ ->where(function ($query) use ($website) {
|
|
|
+ $query->where(function ($subQuery) use ($website) {
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 1");
|
|
|
+ })->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.catid',
|
|
|
+ 'article.cat_arr_id',
|
|
|
+ 'article.copyfrom',
|
|
|
+ )
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($childTextNum)
|
|
|
+ ->get();
|
|
|
+ $childTextArticles = $this->processArticles($childTextArticles, $website);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $resultItem['child'] = [
|
|
|
+ 'alias' => $childCategory ? $childCategory->alias : null,
|
|
|
+ 'category_id' => $childCategory ? $childCategory->category_id : null,
|
|
|
+ 'type' => $childCategory ? $childCategory->type : null,
|
|
|
+ 'pinyin' => $childCategory ? $childCategory->pinyin : null,
|
|
|
+ 'all_childcat' => $all_childcat ?? [],
|
|
|
+ 'imgnum' => $childImgArticles ?? [],
|
|
|
+ 'textnum' => $childTextArticles ?? [],
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $resultItem['child'] = [];
|
|
|
+ }
|
|
|
+ return $resultItem;
|
|
|
+ }, $data);
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 企业管理
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getCompanyList(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $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']) && !empty($data['title'])){
|
|
|
+ array_push($where, ['company.title', 'like', '%'. $data['title']. '%']);
|
|
|
+ }
|
|
|
+ if(isset($data['website_name']) && !empty($data['website_name'])){
|
|
|
+ array_push($where, ['website.website_name', 'like', '%'. $data['website_name']. '%']);
|
|
|
+ }
|
|
|
+ if(isset($data['ischeck']) && !empty($data['ischeck'])){
|
|
|
+ if($data['ischeck'] == 1){
|
|
|
+ if(isset($data['status']) && $data['status'] != ''){
|
|
|
+ array_push($where, ['company.status', $data['status']]);
|
|
|
+ $query = Company::where($where);
|
|
|
+ }else{
|
|
|
+ $query = Company::whereIn('company.status', [0,2]);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $query = Company::where('company.status', 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result = $query->where($where)
|
|
|
+ ->leftJoin('website_category', function ($query) {
|
|
|
+ $query->on('website_category.category_id', '=', 'company.category_id')
|
|
|
+ ->on('website_category.website_id', '=', 'company.website_id');
|
|
|
+ })
|
|
|
+ ->leftJoin('website', 'company.website_id', '=', 'website.id')
|
|
|
+ ->select(
|
|
|
+ 'company.id',
|
|
|
+ 'company.title',
|
|
|
+ 'company.website_id',
|
|
|
+ 'company.category_id',
|
|
|
+ 'website.website_name',
|
|
|
+ 'website_category.alias as category_name',
|
|
|
+ 'company.status',
|
|
|
+ 'company.updated_at',
|
|
|
+ )
|
|
|
+ ->orderBy('company.updated_at', 'desc')
|
|
|
+ ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
|
|
|
|
|
|
- if ($firstWithImage) {
|
|
|
- // 如果有带图片的文章,将其放在第一位
|
|
|
- $group = $group->filter(function ($item) use ($firstWithImage) {
|
|
|
- return $item->id !== $firstWithImage->id;
|
|
|
- })->prepend($firstWithImage);
|
|
|
- }
|
|
|
-
|
|
|
- return [
|
|
|
- 'category_name' => $group->first()->category_name,
|
|
|
- 'catid' => $group->first()->category_id,
|
|
|
- 'pinyin' => $group->first()->pinyin,
|
|
|
- 'parent_pinyin' => $group->first()->parent_pinyin,
|
|
|
- 'list' => $group->take(4)->map(function ($item) {
|
|
|
- return [
|
|
|
- 'id' => $item->id,
|
|
|
- 'title' => $item->title,
|
|
|
- ];
|
|
|
- })->values()
|
|
|
- ];
|
|
|
- })
|
|
|
- ->values()
|
|
|
- ->toArray();
|
|
|
- return Result::success($articlesList);
|
|
|
+ if($result->isEmpty()){
|
|
|
+ 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']) : '';
|
|
|
+ if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
|
|
|
+ $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
|
|
|
+ $data['cat_arr_id'] = json_encode($car_arr_id);
|
|
|
+ }else{
|
|
|
+ $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 ($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'] == '' || empty($data['introduce'])) {
|
|
|
+ //提取内容中的描述
|
|
|
+ $data['introduce'] = mb_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;
|
|
|
+ }
|
|
|
+ if(isset($data['level']) && $data['level'] != null){
|
|
|
+ $data['level'] = intval($data['level']);
|
|
|
+ }else{
|
|
|
+ $data['level'] = null;
|
|
|
+ }
|
|
|
+ $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
|
|
|
+ {
|
|
|
+ if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
|
|
|
+ $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
|
|
|
+ $data['cat_arr_id'] = json_encode($car_arr_id);
|
|
|
+ $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
|
|
|
+ }else{
|
|
|
+ $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])) {
|
|
|
+ //截取varchar
|
|
|
+ $data['imgurl'] = substr($matches[1][0], 0, 240);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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'] == '') {
|
|
|
+ //提取内容中的描述
|
|
|
+ // var_dump(11111);
|
|
|
+ $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
|
|
|
+ }
|
|
|
+ if(isset($data['level']) && $data['level'] != null){
|
|
|
+ $data['level'] = intval($data['level']);
|
|
|
+ }else{
|
|
|
+ $data['level'] = null;
|
|
|
+ }
|
|
|
+ $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('删除失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 审核企业
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function checkCompany(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($data['status'] == 2 || $data['status'] == '2'){
|
|
|
+ $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reason']]);
|
|
|
+ }else{
|
|
|
+ $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
|
|
|
+ }
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('审核失败!');
|
|
|
+ }else{
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取企业信息
|
|
|
+ * @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);
|
|
|
+ }
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteCompany(array $data): array
|
|
|
+ {
|
|
|
+ $where['website_id'] = $data['website_id'];
|
|
|
+ $where['status'] = 1;
|
|
|
+ if(isset($data['category_id']) && !empty($data['category_id'])){
|
|
|
+ $where['category_id'] = $data['category_id'];
|
|
|
+ }
|
|
|
+ if(isset($data['level']) && !empty($data['level'])){
|
|
|
+ $where['level'] = $data['level'];
|
|
|
+ }
|
|
|
+ // return Result::success($where);
|
|
|
+ $query = Company::where($where);
|
|
|
+ $result['img'] = $this->processArticle(
|
|
|
+ $query->clone()
|
|
|
+ ->where('imgurl','!=', '')
|
|
|
+ ->whereNotNull('imgurl')
|
|
|
+ ->select('id','imgurl','title','introduce','description','content','category_id','cat_arr_id')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($data['imgnum'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+
|
|
|
+ $result['text'] = $this->processArticle(
|
|
|
+ $query->clone()
|
|
|
+ ->select('id','title','introduce','description','content','category_id','cat_arr_id')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($data['textnum'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("暂无相关公司信息", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteCompanyList(array $data): array
|
|
|
+ {
|
|
|
+ $where['website_id'] = $data['website_id'];
|
|
|
+ $where['status'] = 1;
|
|
|
+ if(isset($data['category_id']) && !empty($data['category_id'])){
|
|
|
+ $where['category_id'] = $data['category_id'];
|
|
|
+ }
|
|
|
+ if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
|
+ array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
|
|
|
+ }
|
|
|
+ $query = Company::where($where);
|
|
|
+ $company = $this->processArticle(
|
|
|
+ $query->select('id','title','introduce','description','content','category_id','cat_arr_id')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ if(empty($company)){
|
|
|
+ return Result::error("暂无相关公司信息", 0);
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ 'count' => $query->clone()->count(),
|
|
|
+ 'data' => $company,
|
|
|
+ ];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteCompanyInfo(array $data): array
|
|
|
+ {
|
|
|
+ $company = Company::where('id', $data['id'])
|
|
|
+ ->where('status', 1)
|
|
|
+ ->where('website_id', $data['website_id'])
|
|
|
+ ->select('company.*')
|
|
|
+ ->first();
|
|
|
+ if(empty($company)){
|
|
|
+ return Result::error("暂无相关公司信息", 0);
|
|
|
+ }
|
|
|
+ return Result::success($company);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|