|
@@ -23,6 +23,15 @@ use App\Model\WebsiteRole;
|
|
|
use App\Model\WebsiteRoleUser;
|
|
|
use App\Model\Website;
|
|
|
use App\Model\WebsiteColumn;
|
|
|
+use App\Model\Good;
|
|
|
+use App\Model\Book;
|
|
|
+use App\Model\JobRecruiting;
|
|
|
+use App\Model\JobHunting;
|
|
|
+use App\Model\Notice;
|
|
|
+use App\Model\Complaint;
|
|
|
+use App\Model\Order;
|
|
|
+use App\Model\WebsiteImg;
|
|
|
+use Hyperf\HttpServer\Contract\RequestInterface;
|
|
|
|
|
|
use Hyperf\DbConnection\Db;
|
|
|
use Hyperf\RpcServer\Annotation\RpcService;
|
|
@@ -35,7 +44,7 @@ use App\Model\Sector;
|
|
|
use PhpParser\Node\Stmt\Return_;
|
|
|
use function PHPUnit\Framework\isNull;
|
|
|
use Overtrue\Pinyin\Pinyin;
|
|
|
-
|
|
|
+use App\Tools\buildTree;
|
|
|
#[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class WebsiteService implements WebsiteServiceInterface
|
|
|
{
|
|
@@ -519,27 +528,28 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
$where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
|
|
|
// return Result::success($where);
|
|
|
$result = AdPlace::where($where)
|
|
|
- ->leftJoin("ad", function ($join) use ($now) {
|
|
|
- $join->on("ad.pid", "=", "ad_place.id")
|
|
|
- ->where('ad.status', 1)
|
|
|
- ->where('ad.fromtime', '<=', $now)
|
|
|
- ->where('ad.totime', '>=', $now);
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'ad_place.name as place_name',
|
|
|
- 'ad_place.thumb',
|
|
|
- 'ad_place.ad_tag',
|
|
|
- 'ad_place.introduce',
|
|
|
- 'ad.name as ad_name',
|
|
|
- 'ad.image_src',
|
|
|
- 'ad.image_url',
|
|
|
- 'ad.image_alt')
|
|
|
- ->get()->all();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("此广告位不存在!",0);
|
|
|
- }
|
|
|
- }else{
|
|
|
- return Result::error("请选择广告位!",0);
|
|
|
+ ->leftJoin("ad", function ($join) use ($now) {
|
|
|
+ $join->on("ad.pid", "=", "ad_place.id")
|
|
|
+ ->where('ad.status', 1)
|
|
|
+ ->where('ad.fromtime', '<=', $now)
|
|
|
+ ->where('ad.totime', '>=', $now);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'ad_place.name as place_name',
|
|
|
+ 'ad_place.thumb',
|
|
|
+ 'ad_place.ad_tag',
|
|
|
+ 'ad_place.introduce',
|
|
|
+ 'ad.name as ad_name',
|
|
|
+ 'ad.image_src',
|
|
|
+ 'ad.image_url',
|
|
|
+ 'ad.image_alt'
|
|
|
+ )
|
|
|
+ ->get()->all();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此广告位不存在!", 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return Result::error("请选择广告位!", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
@@ -584,7 +594,11 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
|
|
|
// return Result::success($data);
|
|
|
$pid = $data['pid'] ?? 0;
|
|
|
- $result = District::where('pid', $pid)->where('status', 1)->orderBy('code')->get();
|
|
|
+ $result = District::leftJoin('district as district2', 'district.pid', '=', 'district2.id')
|
|
|
+ ->where('district.pid', $pid)
|
|
|
+ ->where('district.status', 1)
|
|
|
+ ->select('district.*', 'district2.name as pid_name')
|
|
|
+ ->orderBy('district.code')->get();
|
|
|
if (empty($result)) {
|
|
|
return Result::error("未查询到此地区", 0);
|
|
|
} else {
|
|
@@ -592,62 +606,77 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* 获取栏目
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
|
|
|
- public function getWebsiteModelCategory(array $data): array
|
|
|
- {
|
|
|
- // return Result::success($data);
|
|
|
- $website_id = [
|
|
|
- 'website_id' => $data['website_id'],
|
|
|
- ];
|
|
|
- // 初始化 $pid 数组
|
|
|
- // $pid = [];
|
|
|
- // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
|
|
|
- $pidQuery = WebsiteCategory::where($website_id)
|
|
|
- ->where('pid', '!=', 0)
|
|
|
- ->orderBy('sort')
|
|
|
- ->select('pid', 'category_id', 'alias');
|
|
|
- $pid = $pidQuery->pluck('pid');
|
|
|
- $pid = array_values(array_unique($pid->toArray()));
|
|
|
-
|
|
|
- // 构建查询语句
|
|
|
- $query = WebsiteCategory::where($website_id)
|
|
|
- ->where('pid', $data['pid'])
|
|
|
- ->offset($data['placeid'])
|
|
|
- ->limit($data['num'])
|
|
|
- ->orderBy('sort');
|
|
|
- // 如果 $pid 数组不为空,添加 CASE WHEN 条件
|
|
|
- if (!empty($pid)) {
|
|
|
- $placeholders = implode(',', array_fill(0, count($pid), '?'));
|
|
|
- $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
|
|
|
- } else {
|
|
|
- // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
|
|
|
- $query->select('website_category.*', DB::raw('0 as children_count'));
|
|
|
- }
|
|
|
-
|
|
|
- // 执行查询
|
|
|
- $placeid = $data['placeid'] - 1;
|
|
|
- $result = $query->offset($placeid)->limit($data['num'])->get();
|
|
|
-
|
|
|
- if (!empty($result)) {
|
|
|
- $pidResults = $pidQuery->get();
|
|
|
- $pidMap = $pidResults->keyBy('pid');
|
|
|
- $result->each(function ($record) use ($pidMap) {
|
|
|
- if ($pidMap->has($record->category_id)) {
|
|
|
- $pidResult = $pidMap->get($record->category_id);
|
|
|
- $record->chilid_id = $pidResult->category_id;
|
|
|
- $record->chilid_alias = $pidResult->alias;
|
|
|
- }
|
|
|
- });
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error("本网站暂无栏目", 0);
|
|
|
- }
|
|
|
- }
|
|
|
+ public function getWebsiteModelCategory(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $website_id = [
|
|
|
+ 'website_id' => $data['website_id'],
|
|
|
+ ];
|
|
|
+ // 初始化 $pid 数组
|
|
|
+ // $pid = [];
|
|
|
+ // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
|
|
|
+ $pidQuery = WebsiteCategory::where($website_id)
|
|
|
+ ->where('pid', '!=', 0)
|
|
|
+ ->orderBy('sort')
|
|
|
+ ->select('pid', 'category_id', 'alias');
|
|
|
+ $pid = $pidQuery->pluck('pid');
|
|
|
+ $pid = array_values(array_unique($pid->toArray()));
|
|
|
+
|
|
|
+ // 构建查询语句
|
|
|
+ $query = WebsiteCategory::where($website_id)
|
|
|
+ ->where('pid', $data['pid'])
|
|
|
+ ->offset($data['placeid'])
|
|
|
+ ->limit($data['num'])
|
|
|
+ ->orderBy('sort');
|
|
|
+ // 如果 $pid 数组不为空,添加 CASE WHEN 条件
|
|
|
+ if (!empty($pid)) {
|
|
|
+ $placeholders = implode(',', array_fill(0, count($pid), '?'));
|
|
|
+ $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
|
|
|
+ } else {
|
|
|
+ // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
|
|
|
+ $query->select('website_category.*', DB::raw('0 as children_count'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行查询
|
|
|
+ $placeid = $data['placeid'] - 1;
|
|
|
+ $result = $query->offset($placeid)->limit($data['num'])->get();
|
|
|
+
|
|
|
+ if (!empty($result)) {
|
|
|
+ $pidResults = $pidQuery->get();
|
|
|
+ if(isset($data['type']) && $data['type'] == 1){
|
|
|
+ $result = $result->map(function ($item) use ($pidResults) {
|
|
|
+ $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
|
|
|
+ if(!empty($child)){
|
|
|
+ return $child;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 重置索引,使 key 值从 0 开始
|
|
|
+ $item->children = $children->values();
|
|
|
+ return $item;
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ $pidMap = $pidResults->keyBy('pid');
|
|
|
+ $result->each(function ($record) use ($pidMap) {
|
|
|
+ if ($pidMap->has($record->category_id)) {
|
|
|
+ $pidResult = $pidMap->get($record->category_id);
|
|
|
+ $record->chilid_id = $pidResult->category_id;
|
|
|
+ $record->chilid_alias = $pidResult->alias;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error("本网站暂无栏目", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取友情链接
|
|
@@ -681,8 +710,34 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
switch ($data['type_id']) {
|
|
|
case 4:
|
|
|
$result = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM letter_of_complaint WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
|
|
|
- return Result::success($result);
|
|
|
- break;
|
|
|
+ $res = [];
|
|
|
+ //查询已审核文章
|
|
|
+ $user_id = $data['user_id'];
|
|
|
+ $article = Article::where('status', 1)
|
|
|
+ ->where('admin_user_id', $user_id)
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit(10)
|
|
|
+ ->get();
|
|
|
+ $res['letterOfComplaintList'] = $result;
|
|
|
+ $res['article'] = $article;
|
|
|
+ $res['article']['count'] = Article::whereNotIn('status', ['404'])->where('admin_user_id', $user_id)->count();
|
|
|
+ $res['good']['count'] = Good::where([])->where('user_id', $user_id)->count();
|
|
|
+ $res['book']['count'] = Book::where([])->where('user_id', $user_id)->count();
|
|
|
+ $res['jobHunting']['count'] = JobHunting::where([])->where('user_id', $user_id)->count();
|
|
|
+ $res['jobRecruiting']['count'] = JobRecruiting::where([])->where('user_id', $user_id)->count();
|
|
|
+ $res['complaint']['count'] = Complaint::where([])->where('user_id', $user_id)->count();
|
|
|
+ $res['notice']['count'] = Notice::where([])->where('user_id', $user_id)->count();
|
|
|
+
|
|
|
+ //待审核数据
|
|
|
+ $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
|
|
|
+ $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+
|
|
|
+ return Result::success($res);
|
|
|
case 10000:
|
|
|
$res = [];
|
|
|
//网站
|
|
@@ -694,17 +749,56 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
//导航池
|
|
|
$res['category']['count'] = 0;
|
|
|
$res['category']['growth_rate'] = 0;
|
|
|
+ //商品
|
|
|
+ $res['good']['count'] = 0;
|
|
|
+ $res['book']['count'] = 0;
|
|
|
+ $res['jobHunting']['count'] = 0;
|
|
|
+ $res['jobRecruiting']['count'] = 0;
|
|
|
//近一月数据
|
|
|
$res['monthArticle'] = [];
|
|
|
//用户类型
|
|
|
$res['userType'] = [];
|
|
|
$res['website']['count'] = Website::where([])->count();
|
|
|
- $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
|
|
|
+ $res['article']['count'] = Article::whereIn('status', [1])->count();
|
|
|
$res['category']['count'] = Category::where([])->count();
|
|
|
- $res['monthArticle'] = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM article WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
|
|
|
+ $res['good']['count'] = Good::whereIn('status', [2])->count();
|
|
|
+ $res['book']['count'] = Book::whereIn('status', [2])->count();
|
|
|
+ $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])->count();
|
|
|
+ $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])->count();
|
|
|
+ $res['complaint']['count'] = Complaint::whereIn('status', [2])->count();
|
|
|
+ $res['notice']['count'] = Notice::whereIn('status', [2])->count();
|
|
|
+
|
|
|
+ // $res['monthArticle'] = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM article WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
|
|
|
+ $res['monthArticle'] = Db::select(' SELECT DATE(article.created_at) AS date,COUNT(*) AS count ,user.type_id FROM article left JOIN user on article.admin_user_id = user.id WHERE
|
|
|
+ article.status =1 and article.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(article.created_at),`user`.type_id ORDER BY date ASC');
|
|
|
+
|
|
|
+ $res['monthGood'] = Db::select(' SELECT DATE(good.created_at) AS date,COUNT(*) AS count ,user.type_id FROM good left JOIN user on good.user_id = user.id WHERE
|
|
|
+ good.status =2 and good.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(good.created_at),`user`.type_id ORDER BY date ASC');
|
|
|
+
|
|
|
+ $res['monthBook'] = Db::select(' SELECT DATE(book.created_at) AS date,COUNT(*) AS count ,user.type_id FROM book left JOIN user on book.user_id = user.id WHERE book.status =2 and book.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(book.created_at),`user`.type_id ORDER BY date ASC');
|
|
|
+
|
|
|
+ $res['monthJobHunting'] = Db::select(' SELECT DATE(job_hunting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_hunting left JOIN user on job_hunting.user_id = user.id WHERE job_hunting.status =2 and job_hunting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_hunting.created_at),`user`.type_id ORDER BY date ASC');
|
|
|
+
|
|
|
+ $res['monthJobRecruiting'] = Db::select(' SELECT DATE(job_recruiting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_recruiting left JOIN user on job_recruiting.user_id = user.id WHERE job_recruiting.status =1 and job_recruiting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_recruiting.created_at),`user`.type_id ORDER BY date ASC');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
$res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
|
|
|
+
|
|
|
+ //待审核数据
|
|
|
+ $res['apply']['article'] = Article::where(['status' => 0])->count(); //
|
|
|
+ $res['apply']['good'] = Good::where(['status' => 1])->count();
|
|
|
+ $res['apply']['book'] = Book::where(['status' => 1])->count();
|
|
|
+ $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->count();
|
|
|
+ $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->count();
|
|
|
+ $res['apply']['complaint'] = Complaint::where(['status' => 1])->count();
|
|
|
+ $res['apply']['notice'] = Notice::where(['status' => 1])->count(); //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束',
|
|
|
+ $res['apply']['order'] = Order::where(['status' => 6])->count();
|
|
|
+
|
|
|
return Result::success($res);
|
|
|
case 1:
|
|
|
+ case 2:
|
|
|
+ case 3:
|
|
|
$res = [];
|
|
|
//查询已审核文章
|
|
|
$user_id = $data['user_id'];
|
|
@@ -713,7 +807,26 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
->orderBy('updated_at', 'desc')
|
|
|
->limit(10)
|
|
|
->get();
|
|
|
+
|
|
|
$res['article'] = $article;
|
|
|
+ $res['website']['count'] = Website::where([])->count();
|
|
|
+ $res['article']['count'] = Article::whereIn('status', [1])->count();
|
|
|
+ $res['category']['count'] = Category::where([])->count();
|
|
|
+ $res['good']['count'] = Good::whereIn('status', [2])->count();
|
|
|
+ $res['book']['count'] = Book::whereIn('status', [2])->count();
|
|
|
+ $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])->count();
|
|
|
+ $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])->count();
|
|
|
+ $res['complaint']['count'] = Complaint::whereIn('status', [2])->count();
|
|
|
+ $res['notice']['count'] = Notice::whereIn('status', [2])->count();
|
|
|
+
|
|
|
+ //待审核数据
|
|
|
+ $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
|
|
|
+ $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
+ $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
|
|
|
return Result::success($res);
|
|
|
}
|
|
|
|
|
@@ -1003,87 +1116,76 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
*/
|
|
|
public function upWebsiteCategory(array $data): array
|
|
|
{
|
|
|
-
|
|
|
- var_dump("更新数据:", $data);
|
|
|
$pinyin = new Pinyin();
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
- if ($data['category_arr_id']) {
|
|
|
- $oldCategoryList = WebsiteCategory::where(['website_id' => $data['website_id']])->get();
|
|
|
- if ($oldCategoryList) {
|
|
|
- $oldCategoryList = $oldCategoryList->toArray();
|
|
|
- $oldCategoryListIds = [];
|
|
|
- foreach ($oldCategoryList as $val) {
|
|
|
- array_push($oldCategoryListIds, $val['category_id']);
|
|
|
- }
|
|
|
- $newCategoryListIds = [];
|
|
|
- foreach ($data['category_arr_id'] as $v) {
|
|
|
- array_push($newCategoryListIds, end($v));
|
|
|
- }
|
|
|
- $differenceIDS = array_merge(array_diff($oldCategoryListIds, $newCategoryListIds), array_diff($newCategoryListIds, $oldCategoryListIds));
|
|
|
- if ($differenceIDS) {
|
|
|
- foreach ($differenceIDS as $v) {
|
|
|
- WebsiteCategory::where(['website_id' => $data['website_id'], 'category_id' => $v])->delete();
|
|
|
- }
|
|
|
- }
|
|
|
- foreach ($data['category_arr_id'] as $key => $value) {
|
|
|
- $info = Category::where(['id' => end($value)])->first();
|
|
|
- $info = $info->toArray();
|
|
|
- // 假设 $data、$value 和 $info 是已经定义好的变量
|
|
|
- $attributes = [
|
|
|
- 'website_id' => $data['website_id'],
|
|
|
- 'category_id' => end($value),
|
|
|
- ];
|
|
|
- // 先复制一份要更新或创建的数据
|
|
|
- $aLIas_pinyin = $pinyin->permalink($info['name'], '');
|
|
|
- var_dump($aLIas_pinyin, '别名');
|
|
|
- $values = [
|
|
|
- 'website_id' => $data['website_id'],
|
|
|
- 'name' => $info['name'] ?? '',
|
|
|
- 'alias' => $info['name'] ?? '',
|
|
|
- 'aLIas_pinyin' => $aLIas_pinyin ?? '',
|
|
|
- 'sort' => $info['sort'] ?? 0,
|
|
|
- 'pid' => $info['pid'] ?? 0,
|
|
|
- 'pid_arr' => $info['pid_arr'] ?? json_encode([]),
|
|
|
- 'seo_title' => $info['seo_title'] ?? "",
|
|
|
- 'seo_keywords' => $info['seo_keywords'] ?? "",
|
|
|
- 'seo_description' => $info['seo_description'] ?? "",
|
|
|
- 'is_url' => $info['is_url'] ?? 0,
|
|
|
- 'web_url' => $info['web_url'] ?? '',
|
|
|
- 'category_id' => end($value),
|
|
|
- 'category_arr_id' => $value ? json_encode($value) : json_encode([])
|
|
|
- ];
|
|
|
- // 检查数据库中是否已有该记录
|
|
|
- $existingRecord = WebsiteCategory::where($attributes)->first();
|
|
|
- if ($existingRecord && $existingRecord->name) {
|
|
|
- unset($values['name']);
|
|
|
- }
|
|
|
- if ($existingRecord && $existingRecord->sort >= 0) {
|
|
|
- unset($values['sort']);
|
|
|
- }
|
|
|
- if ($existingRecord && $existingRecord->seo_title) {
|
|
|
- unset($values['seo_title']);
|
|
|
- }
|
|
|
- if ($existingRecord && $existingRecord->seo_keywords) {
|
|
|
- unset($values['seo_keywords']);
|
|
|
- }
|
|
|
- if ($existingRecord && $existingRecord->seo_description) {
|
|
|
- unset($values['seo_description']);
|
|
|
- }
|
|
|
- if ($existingRecord && $existingRecord->alias) {
|
|
|
- unset($values['alias']);
|
|
|
- }
|
|
|
- // 执行 updateOrCreate 操作
|
|
|
- var_dump("更新数据:", $values);
|
|
|
- WebsiteCategory::updateOrCreate($attributes, $values);
|
|
|
- }
|
|
|
+ if (!empty($data['category_arr_id'])) {
|
|
|
+ $websiteId = $data['website_id'];
|
|
|
+ // 1. 获取旧的 category_id 列表
|
|
|
+ $oldCategoryListIds = WebsiteCategory::where('website_id', $websiteId)->pluck('category_id')->toArray();
|
|
|
+ // 2. 获取新的 category_id 列表(去重)
|
|
|
+ $newCategoryListIds = [];
|
|
|
+ foreach ($data['category_arr_id'] as $arr) {
|
|
|
+ $lastId = end($arr);
|
|
|
+ $newCategoryListIds[] = $lastId;
|
|
|
+ }
|
|
|
+ $newCategoryListIds = array_unique($newCategoryListIds);
|
|
|
+ // 3. 需要删除的 category_id
|
|
|
+ $toDelete = array_diff($oldCategoryListIds, $newCategoryListIds);
|
|
|
+ if (!empty($toDelete)) {
|
|
|
+ WebsiteCategory::where('website_id', $websiteId)
|
|
|
+ ->whereIn('category_id', $toDelete)
|
|
|
+ ->delete();
|
|
|
+ }
|
|
|
+ // 4. 批量查出所有需要的 category 信息
|
|
|
+ $categories = Category::whereIn('id', $newCategoryListIds)->get()->keyBy('id');
|
|
|
+ // 5. 组装 upsertData,确保 category_id 不重复
|
|
|
+ $upsertData = [];
|
|
|
+ $handledCategoryIds = [];
|
|
|
+ foreach ($data['category_arr_id'] as $arr) {
|
|
|
+ $categoryId = end($arr);
|
|
|
+ if (!isset($categories[$categoryId]) || in_array($categoryId, $handledCategoryIds)) continue;
|
|
|
+ $info = $categories[$categoryId];
|
|
|
+ $aLIas_pinyin = $pinyin->permalink($info->name, '');
|
|
|
+ $upsertData[] = [
|
|
|
+ 'website_id' => $websiteId,
|
|
|
+ 'category_id' => $categoryId,
|
|
|
+ 'name' => $info->name ?? '',
|
|
|
+ 'alias' => $info->name ?? '',
|
|
|
+ 'aLIas_pinyin' => $aLIas_pinyin ?? '',
|
|
|
+ 'sort' => $info->sort ?? 0,
|
|
|
+ 'pid' => $info->pid ?? 0,
|
|
|
+ 'pid_arr' => $info->pid_arr ?? json_encode([]),
|
|
|
+ 'seo_title' => $info->seo_title ?? "",
|
|
|
+ 'seo_keywords' => $info->seo_keywords ?? "",
|
|
|
+ 'seo_description' => $info->seo_description ?? "",
|
|
|
+ 'is_url' => $info->is_url ?? 0,
|
|
|
+ 'web_url' => $info->web_url ?? '',
|
|
|
+ 'type' => $info->type ?? 1,
|
|
|
+ 'category_arr_id' => json_encode($arr)
|
|
|
+ ];
|
|
|
+ $handledCategoryIds[] = $categoryId;
|
|
|
+ }
|
|
|
+ // 6. upsert
|
|
|
+ if (!empty($upsertData)) {
|
|
|
+ WebsiteCategory::upsert(
|
|
|
+ $upsertData,
|
|
|
+ ['website_id', 'category_id'],
|
|
|
+ [
|
|
|
+ 'aLIas_pinyin',
|
|
|
+ 'pid',
|
|
|
+ 'pid_arr',
|
|
|
+ 'is_url',
|
|
|
+ 'web_url',
|
|
|
+ 'category_arr_id'
|
|
|
+ ]
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
Db::commit();
|
|
|
return Result::success();
|
|
|
} catch (\Throwable $ex) {
|
|
|
Db::rollBack();
|
|
|
- // var_dump($ex->getMessage());
|
|
|
return Result::error("修改失败" . $ex->getMessage(), 0);
|
|
|
}
|
|
|
}
|
|
@@ -1353,7 +1455,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
$website_head = Website::where('id', $data['website_id'])
|
|
|
->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
|
|
|
- $website_foot = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
|
|
|
+ $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
if (empty($website_foot)) {
|
|
|
return Result::error("暂无底部基础信息", 0);
|
|
|
}
|
|
@@ -1526,7 +1628,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
return Result::error("参数错误", 0);
|
|
|
}
|
|
|
if (isset($data['catid']) && !empty($data['catid'])) {
|
|
|
- $result = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->first();
|
|
|
+ $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
|
|
|
}
|
|
|
if (empty($result)) {
|
|
|
return Result::error("暂无导航", 0);
|
|
@@ -2157,13 +2259,13 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
return Result::error("暂无该网站", 0);
|
|
|
}
|
|
|
// 1:图片 2:文字 3:底部
|
|
|
- $result['foot_cate'] = FooterCategory::where('website_id',$data['website_id'])->get()->all();
|
|
|
- $result['link_img'] = Link::where('website_id',$data['website_id'])->where('type',1)->where('status',1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
|
|
|
- $result['link_text'] = Link::where('website_id',$data['website_id'])->where('type',2)->where('status',1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
|
|
|
- $result['link_foot'] = Link::where('website_id',$data['website_id'])->where('type',3)->where('status',1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
|
|
|
- $result['foot_info'] = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("暂无此网站信息",0);
|
|
|
+ $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
|
|
|
+ $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
|
|
|
+ $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
|
|
|
+ $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
|
|
|
+ $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无此网站信息", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
@@ -2191,12 +2293,18 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
if (empty($website)) {
|
|
|
return Result::error("暂无该网站", 0);
|
|
|
}
|
|
|
- // return Result::success($data);
|
|
|
- if (isset($data['pinyin']) && !empty($data['pinyin'])) {
|
|
|
- $result = WebsiteCategory::where('website_id', $data['website_id'])->where('aLIas_pinyin', $data['pinyin'])->first(['category_id']);
|
|
|
+ if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
|
|
|
+ $result = WebsiteCategory::where('website_category.website_id', $data['website_id'])
|
|
|
+ ->where('website_category.aLIas_pinyin', $data['pinyin'])
|
|
|
+ ->leftJoin('website_category as pc', function ($join) use ($data) {
|
|
|
+ $join->on('pc.pid', '=', 'website_category.category_id')
|
|
|
+ ->where('pc.website_id', '=', $data['website_id']);
|
|
|
+ })
|
|
|
+ ->select('website_category.category_id', 'website_category.alias', DB::raw('CASE WHEN pc.category_id IS NOT NULL THEN 1 ELSE 0 END as children_count'))
|
|
|
+ ->first();
|
|
|
}
|
|
|
- if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {
|
|
|
- $result = FooterCategory::where('website_id', $data['website_id'])->where('name_pinyin', $data['foot_pinyin'])->first(['id']);
|
|
|
+ if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
|
|
|
+ $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
|
|
|
}
|
|
|
if (!isset($result) || empty($result)) {
|
|
|
return Result::error("暂无该导航", 0);
|
|
@@ -2300,6 +2408,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
public function getWebsiteNavList(array $data): array
|
|
|
{
|
|
|
+ $data['type'] = isset($data['type']) ? $data['type'] : 1;
|
|
|
$where = [];
|
|
|
if (isset($data['website_id']) && !empty($data['website_id'])) {
|
|
|
array_push($where, ['website_id', '=', $data['website_id']]);
|
|
@@ -2307,13 +2416,35 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
if (isset($data['pid'])) {
|
|
|
array_push($where, ['pid', '=', $data['pid']]);
|
|
|
}
|
|
|
- $list = WebsiteCategory::query()->where($where)->get();
|
|
|
+ if (isset($data['type']) && !empty($data['type'])) {
|
|
|
+ array_push($where, ['type', '=', $data['type']]);
|
|
|
+ }
|
|
|
+ // 根据站点和type获取websiteCategory 中的id
|
|
|
+ $websiteCategoryids = WebsiteCategory::query()
|
|
|
+ ->where('website_id', '=', $data['website_id'])
|
|
|
+ ->where('type', '=', $data['type'])
|
|
|
+ ->pluck('category_arr_id')->toArray();
|
|
|
+ var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
|
|
|
+ //合并去重
|
|
|
+ $category_ids = [];
|
|
|
+ foreach ($websiteCategoryids as $key => $value) {
|
|
|
+ $v = json_decode($value, true);
|
|
|
+ $category_ids = array_unique(array_merge($category_ids, $v));
|
|
|
+ }
|
|
|
+ // var_dump($category_ids, '------获取websiteCategory 中的id');
|
|
|
+ //根据pid取出所有的websiteCategory 中的id
|
|
|
+ $list = WebsiteCategory::query()
|
|
|
+ ->where('website_id', '=', $data['website_id'])
|
|
|
+ ->where('pid', '=', $data['pid'])
|
|
|
+ ->whereIn('category_id', $category_ids)
|
|
|
+ ->get();
|
|
|
if (empty($list)) {
|
|
|
return Result::error("获取失败", 0);
|
|
|
} else {
|
|
|
return Result::success($list);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 20250307 根据网站标识获和导航获取站点
|
|
|
|
|
|
public function getWebsiteNavPoolSite(array $data): array
|
|
@@ -2448,4 +2579,118 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
return Result::error("没有数据");
|
|
|
}
|
|
|
}
|
|
|
+ // --自助建站-----------20250522fr----------------------start
|
|
|
+ /**
|
|
|
+ * 获取网站模板下的板块信息
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getStaticResourceList(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $where = [];
|
|
|
+ if(isset($data['keyword']) &&!empty($data['keyword'])){
|
|
|
+ $where = ['img_alias' => $data['keyword'],'name' => ['like', '%'. $data['keyword']. '%']];
|
|
|
+ }
|
|
|
+ if(isset($data['type']) &&!empty($data['type'])){
|
|
|
+ $where = ['type' => $data['type']];
|
|
|
+ }
|
|
|
+ if(isset($data['website_id']) &&!empty($data['website_id'])){
|
|
|
+ $where = ['website_id' => $data['website_id']];
|
|
|
+ }
|
|
|
+ // return Result::success($where);
|
|
|
+ $query = WebsiteImg::when(!empty($where), function ($query) use ($where) {
|
|
|
+ $query->where($where);
|
|
|
+ })
|
|
|
+ ->orderBy('updated_at', 'desc');
|
|
|
+ $count = $query->count();
|
|
|
+ $row = $query->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
|
|
|
+ if (empty($row)) {
|
|
|
+ return Result::error("没有查找到相关数据", 0);
|
|
|
+ } else {
|
|
|
+ $result = [
|
|
|
+ 'row' => $row,
|
|
|
+ 'count' => $count,
|
|
|
+ ];}
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加网站模板下的板块信息
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function addStaticResource(array $data): array
|
|
|
+ {
|
|
|
+ // $file = $data['img_url']->file('image');
|
|
|
+ // $size = $file->getSize();
|
|
|
+ $img_data = [
|
|
|
+ 'website_id' => $data['website_id'],
|
|
|
+ 'img_alias' => $data['img_alias'],
|
|
|
+ 'img_url' => $data['img_url'],
|
|
|
+ 'img_size' => $data['img_size'],
|
|
|
+ ];
|
|
|
+ $img = WebsiteImg::insertGetId($img_data);
|
|
|
+ if (empty($img)) {
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
+ }
|
|
|
+ $img_id['id'] = $img;
|
|
|
+ $url = WebsiteImg::where($img_id)->value('img_url');
|
|
|
+
|
|
|
+ // 1. 分割路径部分(以 / 为分隔符)
|
|
|
+ $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
|
|
|
+
|
|
|
+ // 2. 取最后一个元素作为文件名
|
|
|
+ $fileName = end($pathSegments); // 1743041040714597.jpg
|
|
|
+
|
|
|
+ // 3. 分割文件名获取扩展名
|
|
|
+ $fileParts = explode('.', $fileName);
|
|
|
+ $fileType = end($fileParts); // jpg
|
|
|
+
|
|
|
+
|
|
|
+ $img_datas = [
|
|
|
+ 'img_type' => $fileType,
|
|
|
+ 'name' => $fileName
|
|
|
+ ];
|
|
|
+ $up_img = WebsiteImg::where($img_id)->update($img_datas);
|
|
|
+ if (empty($up_img)) {
|
|
|
+ return Result::error("修改失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($up_img);
|
|
|
+ // 将字节转换为更友好的单位
|
|
|
+ // $friendlySize = $this->formatFileSize($size);
|
|
|
+ // $data['img_size'] = $friendlySize;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 修改网站模板下的板块信息
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function delStaticResource(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'id' => $data['id'],
|
|
|
+ ];
|
|
|
+ $result = WebsiteImg::where($where)->delete();
|
|
|
+ if (empty($result)) {
|
|
|
+
|
|
|
+ return Result::error("修改失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取网站模板下的板块信息
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getStaticResourceInfo(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'id' => $data['id'],
|
|
|
+ ];
|
|
|
+ $result = WebsiteImg::where($where)->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有查找到相关数据", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ // --自助建站-----------20250522fr----------------------end
|
|
|
}
|