|
@@ -4,12 +4,16 @@ namespace App\JsonRpc;
|
|
|
use App\Model\Article;
|
|
|
use App\Model\ArticleData;
|
|
|
use App\Model\Category;
|
|
|
-use App\Model\Website;
|
|
|
use App\Model\WebsiteCategory;
|
|
|
+use App\Model\ArticleSurvey;
|
|
|
+use App\Model\Good;
|
|
|
+
|
|
|
use Hyperf\DbConnection\Db;
|
|
|
use Hyperf\RpcServer\Annotation\RpcService;
|
|
|
use App\Tools\Result;
|
|
|
-use App\Model\ArticleSurvey;
|
|
|
+use Ramsey\Uuid\Uuid;
|
|
|
+use Hyperf\Utils\Random;
|
|
|
+
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -22,41 +26,62 @@ class NewsService implements NewsServiceInterface
|
|
|
public function getCategoryList(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if(isset($data['name']) && $data['name']){
|
|
|
- array_push($where, ['category.name','like','%'.$data['name'].'%']);
|
|
|
+ if (isset($data['name']) && $data['name']) {
|
|
|
+ array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
|
|
|
}
|
|
|
- if(isset($data['department_id']) && $data['department_id']){
|
|
|
- array_push($where, ['category.department_id','=',$data['department_id']]);
|
|
|
+ if (isset($data['department_id']) && $data['department_id']) {
|
|
|
+ array_push($where, ['category.department_id', '=', $data['department_id']]);
|
|
|
}
|
|
|
- $city_id='';
|
|
|
- if(isset($data['city_id']) && $data['city_id']){
|
|
|
+ $city_id = '';
|
|
|
+ if (isset($data['city_id']) && $data['city_id']) {
|
|
|
$city_id = intval($data['city_id']);
|
|
|
}
|
|
|
$rep = Category::where($where)
|
|
|
->when($city_id, function ($query) use ($city_id) {
|
|
|
- if(isset($city_id) && $city_id) {
|
|
|
+ if (isset($city_id) && $city_id) {
|
|
|
$query->whereJsonContains("category.city_arr_id", $city_id);
|
|
|
}
|
|
|
})
|
|
|
- ->leftJoin('district','category.city_id','district.id')
|
|
|
- ->leftJoin('department','category.department_id','department.id')
|
|
|
- ->select("category.*","district.name as city_name","department.name as department_name")
|
|
|
- ->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page']-1)*$data['pageSize'])->get();
|
|
|
- $count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
|
|
|
- if(isset($city_id) && $city_id) {
|
|
|
+ ->leftJoin('district', 'category.city_id', 'district.id')
|
|
|
+ ->leftJoin('department', 'category.department_id', 'department.id')
|
|
|
+ ->select("category.*", "district.name as city_name", "department.name as department_name")
|
|
|
+ ->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page'] - 1) * $data['pageSize'])->get();
|
|
|
+ $count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
|
|
|
+ if (isset($city_id) && $city_id) {
|
|
|
$query->whereJsonContains("category.city_arr_id", $city_id);
|
|
|
}
|
|
|
})->count();
|
|
|
$data = [
|
|
|
- 'rows'=>$rep->toArray(),
|
|
|
- 'count'=>$count
|
|
|
+ 'rows' => $rep->toArray(),
|
|
|
+ 'count' => $count,
|
|
|
];
|
|
|
- if(empty($rep->toArray())){
|
|
|
+ if (empty($rep->toArray())) {
|
|
|
return Result::error("没有导航池数据");
|
|
|
}
|
|
|
return Result::success($data);
|
|
|
}
|
|
|
-
|
|
|
+ public function myCategoryList(array $data): array
|
|
|
+ {
|
|
|
+ $sszq = $data['sszq'] ?? '';
|
|
|
+ unset($data['sszq']);
|
|
|
+ //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
|
|
|
+ $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
|
|
|
+ $where[] = [
|
|
|
+ 'pid', '=', $data['pid'],
|
|
|
+ ];
|
|
|
+ if (isset($data['name'])) {
|
|
|
+ array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
|
|
|
+ }
|
|
|
+ var_dump($where);
|
|
|
+ //根据分类id,从category表中取出分类信息
|
|
|
+ $result = Category::where($where)
|
|
|
+ ->whereIn('category.id', $catorytids)
|
|
|
+ ->select('category.*', 'category.id as category_id')->get();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有栏目数据");
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
/**
|
|
|
* @param array $data
|
|
|
* @return array
|
|
@@ -64,14 +89,14 @@ class NewsService implements NewsServiceInterface
|
|
|
public function categoryList(array $data): array
|
|
|
{
|
|
|
$where[] = [
|
|
|
- 'pid','=',$data['pid']
|
|
|
+ 'pid', '=', $data['pid'],
|
|
|
];
|
|
|
- if(isset($data['name'])){
|
|
|
- array_push($where, ['category.name','like','%'.$data['name'].'%']);
|
|
|
+ if (isset($data['name'])) {
|
|
|
+ array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
|
|
|
}
|
|
|
var_dump($where);
|
|
|
- $result = Category::where($where)->select('category.*','category.id as category_id')->get();
|
|
|
- if(empty($result)){
|
|
|
+ $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
|
|
|
+ if (empty($result)) {
|
|
|
return Result::error("没有栏目数据");
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -83,10 +108,10 @@ class NewsService implements NewsServiceInterface
|
|
|
public function addCategory(array $data): array
|
|
|
{
|
|
|
$id = Category::insertGetId($data);
|
|
|
- if(empty($id)){
|
|
|
+ if (empty($id)) {
|
|
|
return Result::error("添加失败");
|
|
|
}
|
|
|
- return Result::success(['id'=>$id]);
|
|
|
+ return Result::success(['id' => $id]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -95,18 +120,18 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function delCategory(array $data): array
|
|
|
{
|
|
|
- $categoryList = Category::where(['pid'=>$data['id']])->get();
|
|
|
- var_dump("分类列表:",$data,$categoryList);
|
|
|
- if($categoryList->toArray()){
|
|
|
+ $categoryList = Category::where(['pid' => $data['id']])->get();
|
|
|
+ var_dump("分类列表:", $data, $categoryList);
|
|
|
+ if ($categoryList->toArray()) {
|
|
|
return Result::error("分类下面有子分类不能删除");
|
|
|
}
|
|
|
- $articleList = Article::where(['catid'=>$data['id']])->get();
|
|
|
- var_dump("文章列表:",$articleList);
|
|
|
- if($articleList->toArray()){
|
|
|
+ $articleList = Article::where(['catid' => $data['id']])->get();
|
|
|
+ var_dump("文章列表:", $articleList);
|
|
|
+ if ($articleList->toArray()) {
|
|
|
return Result::error("分类下面有资讯不能删除");
|
|
|
}
|
|
|
$result = Category::where($data)->delete();
|
|
|
- if(!$result){
|
|
|
+ if (!$result) {
|
|
|
return Result::error("删除失败");
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -119,12 +144,12 @@ class NewsService implements NewsServiceInterface
|
|
|
public function updateCategory(array $data): array
|
|
|
{
|
|
|
$where = [
|
|
|
- 'id'=>$data['id']
|
|
|
+ 'id' => $data['id'],
|
|
|
];
|
|
|
$result = Category::where($where)->update($data);
|
|
|
- if($result){
|
|
|
+ if ($result) {
|
|
|
return Result::success($result);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return Result::error("更新失败");
|
|
|
}
|
|
|
}
|
|
@@ -137,12 +162,12 @@ class NewsService implements NewsServiceInterface
|
|
|
public function getCategoryInfo(array $data): array
|
|
|
{
|
|
|
$where = [
|
|
|
- 'id'=>$data['id']
|
|
|
+ 'id' => $data['id'],
|
|
|
];
|
|
|
$result = Category::where($where)->first();
|
|
|
- if($result){
|
|
|
+ if ($result) {
|
|
|
return Result::success($result);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return Result::error("更新失败");
|
|
|
}
|
|
|
}
|
|
@@ -152,38 +177,48 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function getArticleList(array $data): array
|
|
|
{
|
|
|
- $where= [];
|
|
|
+ //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
|
|
|
+ $type_id = $data['type_id'];
|
|
|
+ unset($data['type_id']);
|
|
|
+ $user_id = $data['user_id'];
|
|
|
+ unset($data['user_id']);
|
|
|
+
|
|
|
+ $where = [];
|
|
|
|
|
|
- if(isset($data['title']) && $data['title']){
|
|
|
- array_push($where,['article.title','like','%'.$data['title'].'%']);
|
|
|
+ if (isset($data['title']) && $data['title']) {
|
|
|
+ array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
|
|
|
+ }
|
|
|
+ if (isset($data['category_name']) && $data['category_name']) {
|
|
|
+ array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
|
|
|
}
|
|
|
- if(isset($data['category_name']) && $data['category_name']){
|
|
|
- array_push($where,['category.name','like','%'.$data['category_name'].'%']);
|
|
|
+ if (isset($data['author']) && $data['author']) {
|
|
|
+ array_push($where, ['article.author', '=', $data['author']]);
|
|
|
}
|
|
|
- if(isset($data['author']) && $data['author']){
|
|
|
- array_push($where,['article.author','=',$data['author']]);
|
|
|
+ if (isset($data['islink']) && $data['islink'] !== "") {
|
|
|
+ array_push($where, ['article.islink', '=', $data['islink']]);
|
|
|
}
|
|
|
- if(isset($data['islink']) && $data['islink']!==""){
|
|
|
- array_push($where,['article.islink','=',$data['islink']]);
|
|
|
+ if (isset($data['status']) && $data['status'] !== "") {
|
|
|
+ array_push($where, ['article.status', '=', $data['status']]);
|
|
|
}
|
|
|
- if(isset($data['status']) && $data['status']!==""){
|
|
|
- array_push($where,['article.status','=',$data['status']]);
|
|
|
+ //不是管理员展示个人数据;
|
|
|
+ if ($type_id != 10000) {
|
|
|
+ $where[] = ['article.admin_user_id', '=', $user_id];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$rep = Article::where($where)
|
|
|
- ->whereNotIn('article.status',[404])
|
|
|
- ->leftJoin('category','article.catid','category.id')
|
|
|
- ->select("article.*","category.name as category_name")
|
|
|
- ->orderBy("article.id","desc")
|
|
|
+ ->whereNotIn('article.status', [404])
|
|
|
+ ->leftJoin('category', 'article.catid', 'category.id')
|
|
|
+ ->select("article.*", "category.name as category_name")
|
|
|
+ ->orderBy("article.id", "desc")
|
|
|
->limit($data['pageSize'])
|
|
|
- ->offset(($data['page']-1)*$data['pageSize'])->get();
|
|
|
- $count = Article::where($where)->whereNotIn('article.status',[404])
|
|
|
- ->leftJoin('category','article.catid','category.id')->count();
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])->get();
|
|
|
+ $count = Article::where($where)->whereNotIn('article.status', [404])
|
|
|
+ ->leftJoin('category', 'article.catid', 'category.id')->count();
|
|
|
$data = [
|
|
|
- 'rows'=>$rep->toArray(),
|
|
|
- 'count'=>$count
|
|
|
+ 'rows' => $rep->toArray(),
|
|
|
+ 'count' => $count,
|
|
|
];
|
|
|
- if(empty($rep)){
|
|
|
+ if (empty($rep)) {
|
|
|
return Result::error("没有信息数据");
|
|
|
}
|
|
|
return Result::success($data);
|
|
@@ -195,25 +230,91 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function addArticle(array $data): array
|
|
|
{
|
|
|
+ var_dump($data, '----------12-----------1');
|
|
|
+ unset($data['user_type']);
|
|
|
+ // unset($data['web_site_id']);
|
|
|
+ unset($data['nav_add_pool_id']);
|
|
|
+ // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
|
|
|
Db::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
+ //处理投票
|
|
|
+ $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
|
|
|
+ $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
|
|
|
+ $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
|
|
|
+ $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
|
|
|
+ unset($data['is_survey']);
|
|
|
+ unset($data['survey_name']);
|
|
|
+ unset($data['suvey_array']);
|
|
|
+ unset($data['website_id']);
|
|
|
|
|
|
$articleData = $data;
|
|
|
unset($articleData['content']);
|
|
|
$id = Article::insertGetId($articleData);
|
|
|
$articleDataContent = [
|
|
|
- 'article_id'=>$id,
|
|
|
- 'content'=>$data['content']
|
|
|
+ 'article_id' => $id,
|
|
|
+ 'content' => $data['content'],
|
|
|
];
|
|
|
ArticleData::insertGetId($articleDataContent);
|
|
|
+
|
|
|
+ //处理投票
|
|
|
+ if ($is_survey == 1) {
|
|
|
+ //生成年月日时分秒+8位随机数
|
|
|
+ $uuid = date('YmdHis') . rand(10000000, 99999999);
|
|
|
+ $suveys_array = json_decode($suvey_array);
|
|
|
+ var_dump($suveys_array, '---------------------1');
|
|
|
+ var_dump($suvey_array, '---------------------2');
|
|
|
+ $suvey_data = [];
|
|
|
+ foreach ($suveys_array as $key => $value) {
|
|
|
+ if ($value == '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (is_array($value)) {
|
|
|
+ $suvey_data[] = [
|
|
|
+ 'sur_id' => $uuid,
|
|
|
+ 'art_id' => $id,
|
|
|
+ 'website_id' => $website_id ?? 2,
|
|
|
+ 'survey_name' => $survey_name,
|
|
|
+ 'choice_name' => $value[1],
|
|
|
+ 'is_other' => 1,
|
|
|
+ 'orther_id' => 0,
|
|
|
+ 'results' => 0,
|
|
|
+
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $suvey_data[] = [
|
|
|
+ 'sur_id' => $uuid,
|
|
|
+ 'art_id' => $id,
|
|
|
+ 'website_id' => $website_id ?? 2,
|
|
|
+ 'survey_name' => $survey_name,
|
|
|
+ 'choice_name' => $value,
|
|
|
+ 'is_other' => 0,
|
|
|
+ 'orther_id' => 0,
|
|
|
+ 'results' => 0,
|
|
|
+
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if (empty($suvey_data)) {
|
|
|
+ throw new \Exception("投票数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $result = ArticleSurvey::insert($suvey_data);
|
|
|
+ if (!$result) {
|
|
|
+ throw new \Exception("投票失败,ArticleSurvey插入失败");
|
|
|
+ }
|
|
|
+ $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
|
|
|
+ if (!$result) {
|
|
|
+ throw new \Exception("投票失败,更新主表失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Db::commit();
|
|
|
- } catch(\Throwable $ex){
|
|
|
+ return Result::success(['id' => $id]);
|
|
|
+ } catch (\Throwable $ex) {
|
|
|
Db::rollBack();
|
|
|
var_dump($ex->getMessage());
|
|
|
- return Result::error("创建失败",0);
|
|
|
+ return Result::error("创建失败", 0);
|
|
|
}
|
|
|
-
|
|
|
- return Result::success(['id'=>$id]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -223,7 +324,9 @@ class NewsService implements NewsServiceInterface
|
|
|
public function delArticle(array $data): array
|
|
|
{
|
|
|
$result = Article::where($data)->delete();
|
|
|
- if(!$result){
|
|
|
+ //survey投票删除
|
|
|
+ articleSurvey::where(['art_id' => $data['id']])->delete();
|
|
|
+ if (!$result) {
|
|
|
return Result::error("删除失败");
|
|
|
}
|
|
|
return Result::success($result);
|
|
@@ -236,9 +339,22 @@ class NewsService implements NewsServiceInterface
|
|
|
public function updateArticle(array $data): array
|
|
|
{
|
|
|
Db::beginTransaction();
|
|
|
- try{
|
|
|
- $data['cat_arr_id'] = isset($data['cat_arr_id'])?json_encode($data['cat_arr_id']):'';
|
|
|
- $data['tag'] = isset($data['tag'])?json_encode($data['tag']):'';
|
|
|
+ unset($data['user_type']);
|
|
|
+ // unset($data['web_site_id']);
|
|
|
+ unset($data['nav_add_pool_id']);
|
|
|
+ try {
|
|
|
+ //处理投票
|
|
|
+ $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
|
|
|
+ $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
|
|
|
+ $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
|
|
|
+ $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
|
|
|
+ unset($data['is_survey']);
|
|
|
+ unset($data['survey_name']);
|
|
|
+ unset($data['suvey_array']);
|
|
|
+ unset($data['website_id']);
|
|
|
+
|
|
|
+ $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
|
|
|
+ $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
|
|
|
$articleData = $data;
|
|
|
unset($articleData['content']);
|
|
|
unset($articleData['status_name']);
|
|
@@ -246,18 +362,74 @@ class NewsService implements NewsServiceInterface
|
|
|
unset($articleData['content']);
|
|
|
unset($articleData['pid_arr']);
|
|
|
unset($articleData['pid']);
|
|
|
- $id = Article::where(['id'=>$data['id']])->update($articleData);
|
|
|
+ $id = Article::where(['id' => $data['id']])->update($articleData);
|
|
|
$articleDataContent = [
|
|
|
- 'content'=>$data['content']
|
|
|
+ 'content' => $data['content'],
|
|
|
];
|
|
|
- ArticleData::where(['article_id'=>$data['id']])->update($articleDataContent);
|
|
|
- } catch(\Throwable $ex){
|
|
|
+ ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
|
|
|
+ //处理投票
|
|
|
+ $id = $data['id'];
|
|
|
+ $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
|
|
|
+ var_dump($surveydata, 'suvey_array________delete');
|
|
|
+
|
|
|
+ //处理投票
|
|
|
+ if ($is_survey == 1) {
|
|
|
+ //生成年月日时分秒+8位随机数
|
|
|
+ $uuid = date('YmdHis') . rand(10000000, 99999999);
|
|
|
+ $suveys_array = json_decode($suvey_array);
|
|
|
+ var_dump($suveys_array, '---------------------1');
|
|
|
+ var_dump($suvey_array, '---------------------2');
|
|
|
+ $suvey_data = [];
|
|
|
+ foreach ($suveys_array as $key => $value) {
|
|
|
+ if ($value == '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (is_array($value)) {
|
|
|
+ $suvey_data[] = [
|
|
|
+ 'sur_id' => $uuid,
|
|
|
+ 'art_id' => $id,
|
|
|
+ 'website_id' => $website_id ?? 2,
|
|
|
+ 'survey_name' => $survey_name,
|
|
|
+ 'choice_name' => $value[1],
|
|
|
+ 'is_other' => 1,
|
|
|
+ 'orther_id' => 0,
|
|
|
+ 'results' => 0,
|
|
|
+
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $suvey_data[] = [
|
|
|
+ 'sur_id' => $uuid,
|
|
|
+ 'art_id' => $id,
|
|
|
+ 'website_id' => $website_id ?? 2,
|
|
|
+ 'survey_name' => $survey_name,
|
|
|
+ 'choice_name' => $value,
|
|
|
+ 'is_other' => 0,
|
|
|
+ 'orther_id' => 0,
|
|
|
+ 'results' => 0,
|
|
|
+
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if (empty($suvey_data)) {
|
|
|
+ throw new \Exception("投票数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $result = ArticleSurvey::insert($suvey_data);
|
|
|
+ if (!$result) {
|
|
|
+ throw new \Exception("投票失败");
|
|
|
+ }
|
|
|
+ $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
|
|
|
+ if (!$result) {
|
|
|
+ throw new \Exception("投票失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success([]);
|
|
|
+ } catch (\Throwable $ex) {
|
|
|
Db::rollBack();
|
|
|
var_dump($ex->getMessage());
|
|
|
- return Result::error("更新失败",0);
|
|
|
+ return Result::error("更新失败", 0);
|
|
|
}
|
|
|
- return Result::success([]);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -265,249 +437,162 @@ class NewsService implements NewsServiceInterface
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function upArticleStatus(array $data):array
|
|
|
+ public function upArticleStatus(array $data): array
|
|
|
{
|
|
|
- $result = Article::where(['id'=>$data['id']])->update($data);
|
|
|
- if($result){
|
|
|
+ $result = Article::where(['id' => $data['id']])->update($data);
|
|
|
+ if ($result) {
|
|
|
return Result::success();
|
|
|
- }else{
|
|
|
- return Result::error("更新状态失败",0);
|
|
|
+ } else {
|
|
|
+ return Result::error("更新状态失败", 0);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
- * 获取新闻详情
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
public function getArticleInfo(array $data): array
|
|
|
{
|
|
|
$where = [
|
|
|
- 'article.id'=>$data['id'],
|
|
|
- 'article.status'=>1
|
|
|
+ 'article.id' => $data['id'],
|
|
|
];
|
|
|
- $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("查询失败",0);
|
|
|
+ $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
|
|
|
+ $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
|
|
|
+ $result['survey_array'] = $articleSurvey->toArray();
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result->toArray());
|
|
|
+ } else {
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
}
|
|
|
/**
|
|
|
- * 获取头条新闻
|
|
|
+ * 获取新闻
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
- */
|
|
|
- public function getWebsiteArticlett(array $data): array
|
|
|
+ */
|
|
|
+ public function getWebsiteArticlett(array $data): array
|
|
|
{
|
|
|
-
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->select('category_id')->get();
|
|
|
- $category = $category->toArray();
|
|
|
- $result= [];
|
|
|
- if($category){
|
|
|
+
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->select('category_id')->get();
|
|
|
+ $category = $category->toArray();
|
|
|
+ $result = [];
|
|
|
+ if ($category) {
|
|
|
$category_ids = [];
|
|
|
- foreach($category as $val){
|
|
|
- array_push($category_ids,$val['category_id']);
|
|
|
+ foreach ($category as $val) {
|
|
|
+ array_push($category_ids, $val['category_id']);
|
|
|
}
|
|
|
- if(isset($data['placeid'])){
|
|
|
- $placeid=$data['placeid']-1;
|
|
|
- $result=Article::where('status',1)->where('level',$data['level'])->whereIn("catid",$category_ids)->orderBy("created_at","desc")->offset($placeid)->limit($data['pageSize'])->get();
|
|
|
- }else{
|
|
|
- $result=Article::where('status',1)->where('level',$data['level'])->whereIn("catid",$category_ids)->orderBy("created_at","desc")->offset(0)->limit($data['pageSize'])->get();
|
|
|
+ if (isset($data['placeid'])) {
|
|
|
+ $placeid = $data['placeid'] - 1;
|
|
|
+ $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("created_at", "desc")->offset($placeid)->limit($data['pageSize'])->get();
|
|
|
+ } else {
|
|
|
+ $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("created_at", "desc")->offset(0)->limit($data['pageSize'])->get();
|
|
|
}
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("暂无头条新闻",0);
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
- }else{
|
|
|
- return Result::error("本网站下暂无相关栏目",0);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无头条新闻", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error("本网站下暂无相关栏目", 0);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 获取模块新闻
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
- */
|
|
|
-
|
|
|
- public function getWebsiteModelArticles(array $data): array
|
|
|
+ */
|
|
|
+
|
|
|
+ public function getWebsiteModelArticles(array $data): array
|
|
|
{
|
|
|
- $catid=$data['catid'];
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$catid)->select('category_id')->get();
|
|
|
+ $catid = $data['catid'];
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
|
|
|
$category = $category->toArray();
|
|
|
- if(!empty($category)){
|
|
|
- $where=[
|
|
|
+ if (!empty($category)) {
|
|
|
+ $where = [
|
|
|
'status' => 1,
|
|
|
- 'catid' => $catid
|
|
|
+ 'catid' => $catid,
|
|
|
];
|
|
|
if ($data['level'] == 1) {
|
|
|
$level = [
|
|
|
0 => '1',
|
|
|
1 => '4',
|
|
|
2 => '5',
|
|
|
- 3 => '0',
|
|
|
];
|
|
|
-
|
|
|
- $result = Article::where($where)->whereIn('level',$level)->orderBy("created_at","desc")->limit($data['pagesize'])->get();
|
|
|
- }elseif($data['level']==2){
|
|
|
- $level='2';
|
|
|
- $result = Article::where($where)->where('level',$level)->orderBy("created_at","desc")->limit($data['pagesize'])->get();
|
|
|
-
|
|
|
- }else{
|
|
|
- $level='3';
|
|
|
- $result = Article::where($where)->where('level',$level)->orderBy("created_at","desc")->limit($data['pagesize'])->get();
|
|
|
+ $result = Article::where($where)->whereIn('level', $level)->orderBy("created_at", "desc")->limit($data['pagesize'])->get();
|
|
|
+ } elseif ($data['level'] == 2) {
|
|
|
+ $level = '2';
|
|
|
+ $result = Article::where($where)->where('level', $level)->orderBy("created_at", "desc")->limit($data['pagesize'])->get();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $level = '3';
|
|
|
+ $result = Article::where($where)->where('level', $level)->orderBy("created_at", "desc")->limit($data['pagesize'])->get();
|
|
|
}
|
|
|
- $result= $result->toArray();
|
|
|
- if(!empty($result) && isset($data['placeid']) && !empty($data['placeid'])){
|
|
|
- $placeid=$data['placeid']-1;
|
|
|
- if($level==2 || $level==3){
|
|
|
- $where =[
|
|
|
- 'level' => $level
|
|
|
+ $result = $result->toArray();
|
|
|
+ if (!empty($result) && isset($data['placeid']) && !empty($data['placeid'])) {
|
|
|
+ $placeid = $data['placeid'] - 1;
|
|
|
+ if ($level == 2 || $level == 3) {
|
|
|
+ $where = [
|
|
|
+ 'level' => $level,
|
|
|
];
|
|
|
$result = Article::where($where)
|
|
|
- ->orderBy("created_at","desc")
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pagesize'])->get();
|
|
|
- }else{
|
|
|
- $result = Article::where($where)
|
|
|
- ->whereIn('level',$level)
|
|
|
- ->offset($placeid)
|
|
|
- ->orderBy("created_at","desc")
|
|
|
- ->limit($data['pagesize'])->get();
|
|
|
- }
|
|
|
- }
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("此栏目暂无相关新闻",0);
|
|
|
- }
|
|
|
- }else{
|
|
|
- return Result::error("此网站暂无此栏目",0);
|
|
|
-
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *获取新闻列表
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getWebsiteArticleList(array $data): array
|
|
|
- {
|
|
|
- $where[] = ['status', '=', 1];
|
|
|
- if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
|
- array_push($where,['article.title','like','%'.$data['keyword'].'%']);
|
|
|
- }
|
|
|
- if(isset($data['catid']) && !empty($data['catid'])){
|
|
|
- if(is_array($data['catid'])){
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
|
|
|
- array_push($where,['catid', 'in', $data['catid']]);
|
|
|
- }else{
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
|
|
|
- array_push($where,['catid', '=', $data['catid']]);
|
|
|
- }
|
|
|
- if(empty($category)){
|
|
|
- return Result::error("此网站暂无此栏目",0);
|
|
|
- }
|
|
|
- }
|
|
|
- // return Result::success($where);
|
|
|
-
|
|
|
- $rep = Article::where(function ($query) use ($where) {
|
|
|
- foreach ($where as $condition) {
|
|
|
- if ($condition[1] === 'in') {
|
|
|
- $query->whereIn($condition[0], $condition[2]);
|
|
|
+ ->orderBy("created_at", "desc")
|
|
|
+ ->offset($placeid)
|
|
|
+ ->limit($data['pagesize'])->get();
|
|
|
} else {
|
|
|
- $query->where($condition[0], $condition[1], $condition[2]);
|
|
|
+ $result = Article::where($where)
|
|
|
+ ->whereIn('level', $level)
|
|
|
+ ->offset($placeid)
|
|
|
+ ->orderBy("created_at", "desc")
|
|
|
+ ->limit($data['pagesize'])->get();
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
- ->orderBy("created_at", "desc")
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->get();
|
|
|
-
|
|
|
- $count = Article::where(function ($query) use ($where) {
|
|
|
- foreach ($where as $condition) {
|
|
|
- if ($condition[1] === 'in') {
|
|
|
- $query->whereIn($condition[0], $condition[2]);
|
|
|
- } else {
|
|
|
- $query->where($condition[0], $condition[1], $condition[2]);
|
|
|
- }
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此栏目暂无相关新闻", 0);
|
|
|
}
|
|
|
- })->count();
|
|
|
+ } else {
|
|
|
+ return Result::error("此网站暂无此栏目", 0);
|
|
|
|
|
|
- $data = [
|
|
|
- 'rows'=>$rep->toArray(),
|
|
|
- 'count'=>$count
|
|
|
- ];
|
|
|
-
|
|
|
- if(empty($rep)){
|
|
|
- return Result::error("没有信息数据");
|
|
|
- }
|
|
|
- return Result::success($data);
|
|
|
-
|
|
|
- }
|
|
|
- /**
|
|
|
- * 前端-获取新闻详情
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function selectWebsiteArticleInfo(array $data): array
|
|
|
- {
|
|
|
- $where = [
|
|
|
- 'article.id'=>$data['id'],
|
|
|
- 'article.status'=>1
|
|
|
- ];
|
|
|
- $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("查询失败",0);
|
|
|
}
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where(['category_id'=>$result['catid']])->first();
|
|
|
- if(empty($category)){
|
|
|
- return Result::error("查询失败",0);
|
|
|
- }
|
|
|
- $result['category_id'] = $category['category_id'];
|
|
|
- $result['cat_name'] = $category['name'];
|
|
|
return Result::success($result);
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 前端-获取网站调查问卷
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getWebsiteSurvey(array $data): array
|
|
|
+ public function getWebsiteSurvey(array $data): array
|
|
|
{
|
|
|
- if(isset($data['survey_id']) && !empty($data['survey_id'])){
|
|
|
- $website = Website::where('id',$data['website_id'])->first();
|
|
|
- if(empty($website)){
|
|
|
- return Result::error("暂无此网站",0);
|
|
|
+ if (isset($data['survey_id']) && !empty($data['survey_id'])) {
|
|
|
+ $website = Website::where('id', $data['website_id'])->first();
|
|
|
+ if (empty($website)) {
|
|
|
+ return Result::error("暂无此网站", 0);
|
|
|
}
|
|
|
}
|
|
|
- if(isset($data['art_id']) && !empty($data['art_id'])){
|
|
|
- $article = Article::where('id',$data['art_id'])->first();
|
|
|
- if(empty($article)){
|
|
|
- return Result::error("暂无此文章",0);
|
|
|
+ if (isset($data['art_id']) && !empty($data['art_id'])) {
|
|
|
+ $article = Article::where('id', $data['art_id'])->first();
|
|
|
+ if (empty($article)) {
|
|
|
+ return Result::error("暂无此文章", 0);
|
|
|
}
|
|
|
// return Result::error($data,0);
|
|
|
$where['art_id'] = $data['art_id'];
|
|
|
- // $query = ArticleSurvey::where('art_id',$data['art_id']);
|
|
|
-
|
|
|
- }else{
|
|
|
- $survey = ArticleSurvey::where('website_id',$data['website_id'])->orderBy('created_at')->first();
|
|
|
- if(empty($survey)){
|
|
|
- return Result::error("暂无调查问卷",0);
|
|
|
+ // $query = ArticleSurvey::where('art_id',$data['art_id']);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
|
|
|
+ if (empty($survey)) {
|
|
|
+ return Result::error("暂无调查问卷", 0);
|
|
|
}
|
|
|
$where['sur_id'] = $survey['sur_id'];
|
|
|
// $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
|
|
|
}
|
|
|
- $result['survey'] = ArticleSurvey::where($where)->where('is_other',0)
|
|
|
- ->leftJoin('article','article_survey.art_id','article.id')
|
|
|
- ->select('article_survey.*','article.survey_type')
|
|
|
- ->get()->all();
|
|
|
- $result['others'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
|
|
|
- $result['other'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->first();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("此文章暂无调查问卷",0);
|
|
|
+ $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
|
|
|
+ ->leftJoin('article', 'article_survey.art_id', 'article.id')
|
|
|
+ ->select('article_survey.*', 'article.survey_type')
|
|
|
+ ->get()->all();
|
|
|
+ $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
|
|
|
+ $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此文章暂无调查问卷", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
@@ -518,95 +603,95 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function addWebsiteSurveyOption(array $data): array
|
|
|
{
|
|
|
- if(isset($data['website_id']) && !empty($data['website_id'])){
|
|
|
- $website = Website::where('id',$data['website_id'])->first();
|
|
|
- if(empty($website)){
|
|
|
- return Result::error("暂无此网站",0);
|
|
|
+ if (isset($data['website_id']) && !empty($data['website_id'])) {
|
|
|
+ $website = Website::where('id', $data['website_id'])->first();
|
|
|
+ if (empty($website)) {
|
|
|
+ return Result::error("暂无此网站", 0);
|
|
|
}
|
|
|
- if(isset($data['sur_id']) && !empty($data['sur_id'])){
|
|
|
- $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
|
|
|
- if(empty($survey)){
|
|
|
- return Result::error("此调查问卷不可添加选项",0);
|
|
|
+ if (isset($data['sur_id']) && !empty($data['sur_id'])) {
|
|
|
+ $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
|
|
|
+ if (empty($survey)) {
|
|
|
+ return Result::error("此调查问卷不可添加选项", 0);
|
|
|
}
|
|
|
- if(isset($data['choice_name']) &&!empty($data['choice_name'])){
|
|
|
+ if (isset($data['choice_name']) && !empty($data['choice_name'])) {
|
|
|
$choice = [
|
|
|
- 'art_id'=>$survey['art_id'],
|
|
|
- 'website_id'=>$data['website_id'],
|
|
|
- 'survey_name'=>$survey['survey_name'],
|
|
|
- 'choice_name'=>$data['choice_name'],
|
|
|
- 'sur_id'=>$survey['sur_id'],
|
|
|
- 'is_other'=>1,
|
|
|
- 'other_id'=>$survey['id'],
|
|
|
-
|
|
|
+ 'art_id' => $survey['art_id'],
|
|
|
+ 'website_id' => $data['website_id'],
|
|
|
+ 'survey_name' => $survey['survey_name'],
|
|
|
+ 'choice_name' => $data['choice_name'],
|
|
|
+ 'sur_id' => $survey['sur_id'],
|
|
|
+ 'is_other' => 1,
|
|
|
+ 'other_id' => $survey['id'],
|
|
|
+
|
|
|
];
|
|
|
$result = ArticleSurvey::insertGetId($choice);
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("添加失败",0);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
}
|
|
|
- return Result::error("添加失败",0);
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
}
|
|
|
- return Result::error("添加失败",0);
|
|
|
-
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
+
|
|
|
}
|
|
|
/**
|
|
|
- * 前端-调查问卷投票
|
|
|
+ * 前端-调查问卷投票
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
public function addWebsiteSurveyVote(array $data): array
|
|
|
{
|
|
|
-
|
|
|
- if(isset($data['website_id']) && !empty($data['website_id'])){
|
|
|
- $website = Website::where('id',$data['website_id'])->first();
|
|
|
- if(empty($website)){
|
|
|
- return Result::error("暂无此网站",0);
|
|
|
+
|
|
|
+ if (isset($data['website_id']) && !empty($data['website_id'])) {
|
|
|
+ $website = Website::where('id', $data['website_id'])->first();
|
|
|
+ if (empty($website)) {
|
|
|
+ return Result::error("暂无此网站", 0);
|
|
|
}
|
|
|
- if(isset($data['sur_id']) && !empty($data['sur_id'])){
|
|
|
- $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('website_id',$data['website_id'])->pluck('sur_id');
|
|
|
- if(empty($survey)){
|
|
|
- return Result::error("此调查问卷不存在",0);
|
|
|
+ if (isset($data['sur_id']) && !empty($data['sur_id'])) {
|
|
|
+ $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
|
|
|
+ if (empty($survey)) {
|
|
|
+ return Result::error("此调查问卷不存在", 0);
|
|
|
}
|
|
|
// return Result::success($survey);
|
|
|
// 调查问卷类型 0:单选 1:多选
|
|
|
- $type = Article::where('survey_id',$data['sur_id'])->pluck('survey_type');
|
|
|
+ $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
|
|
|
// return Result::success($type);
|
|
|
- if(empty($type) || ($type[0]!= 1 && $type[0]!= 0)){
|
|
|
- return Result::error("此调查问卷不可投票",0);
|
|
|
+ if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
|
|
|
+ return Result::error("此调查问卷不可投票", 0);
|
|
|
}
|
|
|
// return Result::success($type[0]);
|
|
|
- if(isset($data['choice_id']) &&!empty($data['choice_id'])){
|
|
|
- if($type[0] == 0){
|
|
|
- if(is_array($data['choice_id'])){
|
|
|
- return Result::error("请选择一个选项!",0);
|
|
|
+ if (isset($data['choice_id']) && !empty($data['choice_id'])) {
|
|
|
+ if ($type[0] == 0) {
|
|
|
+ if (is_array($data['choice_id'])) {
|
|
|
+ return Result::error("请选择一个选项!", 0);
|
|
|
}
|
|
|
$data['choice_id'] = [$data['choice_id']];
|
|
|
- }else{
|
|
|
- if(!is_array($data['choice_id'])){
|
|
|
- return Result::error("请传递数组!",0);
|
|
|
+ } else {
|
|
|
+ if (!is_array($data['choice_id'])) {
|
|
|
+ return Result::error("请传递数组!", 0);
|
|
|
}
|
|
|
}
|
|
|
// return Result::success($data['choice_id']);
|
|
|
- $choice['other'] = ArticleSurvey::whereIn('id',$data['choice_id'])
|
|
|
- ->where('website_id',$data['website_id'])
|
|
|
- ->where('is_other',1)
|
|
|
- ->where('other_id','!=',0)
|
|
|
- ->first();
|
|
|
+ $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
|
|
|
+ ->where('website_id', $data['website_id'])
|
|
|
+ ->where('is_other', 1)
|
|
|
+ ->where('other_id', '!=', 0)
|
|
|
+ ->first();
|
|
|
// return Result::success($data);
|
|
|
- if(!empty($choice['other'])){
|
|
|
- array_push($data['choice_id'],$choice['other']['other_id']);
|
|
|
+ if (!empty($choice['other'])) {
|
|
|
+ array_push($data['choice_id'], $choice['other']['other_id']);
|
|
|
// return Result::success($data['choice_id']);
|
|
|
}
|
|
|
// return Result::success($data);
|
|
|
- $choice = ArticleSurvey::whereIn('id',$data['choice_id'])
|
|
|
- ->where('website_id',$data['website_id'])
|
|
|
- ->increment('results', 1);
|
|
|
- if(empty($choice)){
|
|
|
- return Result::error("请选择已有的选项!",0);
|
|
|
+ $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
|
|
|
+ ->where('website_id', $data['website_id'])
|
|
|
+ ->increment('results', 1);
|
|
|
+ if (empty($choice)) {
|
|
|
+ return Result::error("请选择已有的选项!", 0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return Result::success($choice);
|
|
|
|
|
|
}
|
|
@@ -615,7 +700,7 @@ class NewsService implements NewsServiceInterface
|
|
|
// $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
|
|
|
// }
|
|
|
}
|
|
|
- return Result::error("此调查问卷不存在",0);
|
|
|
+ return Result::error("此调查问卷不存在", 0);
|
|
|
}
|
|
|
return Result::error("参数必填!");
|
|
|
}
|
|
@@ -627,17 +712,133 @@ class NewsService implements NewsServiceInterface
|
|
|
public function checkCategoryName(array $data): array
|
|
|
{
|
|
|
$result = Category::when($data, function ($query) use ($data) {
|
|
|
- if(isset($data['name']) && $data['name']) {
|
|
|
+ if (isset($data['name']) && $data['name']) {
|
|
|
$query->where("name", $data['name']);
|
|
|
}
|
|
|
- if(isset($data['id']) && $data['id']) {
|
|
|
- $query->where("id","!=" ,$data['id']);
|
|
|
+ if (isset($data['id']) && $data['id']) {
|
|
|
+ $query->where("id", "!=", $data['id']);
|
|
|
}
|
|
|
})->first();
|
|
|
- if($result){
|
|
|
+ if ($result) {
|
|
|
return Result::error("已存在");
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return Result::success();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ //20250226 产品列表
|
|
|
+
|
|
|
+ public function getGoodList(array $data): array
|
|
|
+ {
|
|
|
+ $where = [];
|
|
|
+ //类型
|
|
|
+ if (isset($data['type_id']) && $data['type_id']) {
|
|
|
+ $where = [
|
|
|
+ 'type_id' => $data['type_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //名称
|
|
|
+ if (isset($data['name']) && $data['name']) {
|
|
|
+ $where = [
|
|
|
+ 'good.name' => $data['name'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $where1 = [];
|
|
|
+ //website_id
|
|
|
+ // if (isset($data['website_id']) && $data['website_id']) {
|
|
|
+ // $where1 = [
|
|
|
+ // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
|
|
|
+ // ];
|
|
|
+ // }
|
|
|
+ // website_name
|
|
|
+ if (isset($data['website_name']) && $data['website_name']) {
|
|
|
+ $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // catid
|
|
|
+ if (isset($data['category_name']) && $data['category_name']) {
|
|
|
+ $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // $result = Good::where($where)
|
|
|
+ // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
|
|
|
+ $result = Good::where($where)
|
|
|
+ ->when(!empty($where1), function ($query) use ($where1) {
|
|
|
+ return $query->where($where1);
|
|
|
+ })
|
|
|
+ ->leftJoin('district', 'good.city_id', '=', 'district.id')
|
|
|
+ ->leftJoin('website', 'good.website_id', '=', 'website.id')
|
|
|
+ ->leftJoin('category', 'good.catid', '=', 'category.id')
|
|
|
+ ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
|
|
|
+ ->orderBy("id", "desc")
|
|
|
+ ->limit($data['page_size'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['page_size'])
|
|
|
+ ->get();
|
|
|
+ $count = Good::where($where)
|
|
|
+ ->leftJoin('district', 'good.city_id', '=', 'district.id')
|
|
|
+ ->leftJoin('website', 'good.website_id', '=', 'website.id')
|
|
|
+ ->leftJoin('category', 'good.catid', '=', 'category.id')
|
|
|
+ ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
|
|
|
+ ->orderBy("updated_at", "desc")->count();
|
|
|
+ $data = [
|
|
|
+ 'rows' => $result->toArray(),
|
|
|
+ 'count' => $count,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此栏目暂无相关产品", 0);
|
|
|
+ }
|
|
|
+ return Result::success($data);
|
|
|
+ }
|
|
|
+ public function getGoodInfo(array $data): array
|
|
|
+ {
|
|
|
+ $result = Good::where('id', $data['id'])->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此产品不存在", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ public function addGood(array $data): array
|
|
|
+ {
|
|
|
+ // unset($data['city_arr_id']);
|
|
|
+ // unset($data['cat_arr_id']);
|
|
|
+ $data['city_id'] = end($data['city_arr_id']);
|
|
|
+ $data['catid'] = end($data['cat_arr_id']);
|
|
|
+ $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']);
|
|
|
+ $result = Good::insert($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ public function updateGood(array $data): array
|
|
|
+ {
|
|
|
+ $data['city_id'] = end($data['city_arr_id']);
|
|
|
+ $data['catid'] = end($data['cat_arr_id']);
|
|
|
+ $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']) : '';
|
|
|
+ //设置东八区
|
|
|
+ date_default_timezone_set('Asia/Shanghai');
|
|
|
+ $data['updated_at'] = date('Y-m-d H:i:s');
|
|
|
+ $result = Good::where('id', $data['id'])->update($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("更新失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ public function delGood(array $data): array
|
|
|
+ {
|
|
|
+ $result = Good::where('id', $data['id'])->delete();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("删除失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //20250226 产品列表
|
|
|
+
|
|
|
+}
|