|
@@ -1,11 +1,8 @@
|
|
|
<?php
|
|
|
namespace App\Repositories;
|
|
|
-use App\Models\Banner;
|
|
|
use App\Models\StarNews;
|
|
|
use Dingo\Api\Http\Response;
|
|
|
-use Illuminate\Support\Facades\Log;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
-use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
/**
|
|
|
* Created by PhpStorm.
|
|
|
* User: durong
|
|
@@ -59,19 +56,19 @@ class StarNewsRepository
|
|
|
|
|
|
public function edit($request)
|
|
|
{
|
|
|
- $starNews = $this->starNews->where('id', $request['id'])->first();
|
|
|
- $starNews->title = $request['title'];
|
|
|
- $starNews->content = $request['content'];
|
|
|
- $starNews->cover_img = $request['cover_img'];
|
|
|
- $starNews->sort = $request['sort'] ?? 0;
|
|
|
- $starNews->status = $request['status'] ?? 0;
|
|
|
- $starNews->updated_at = date('Y-m-d H:i:s');
|
|
|
+ $starNew = $this->starNews->where('id', $request['id'])->first();
|
|
|
+ $starNew->title = $request['title'];
|
|
|
+ $starNew->content = $request['content'];
|
|
|
+ $starNew->cover_img = $request['cover_img'];
|
|
|
+ $starNew->sort = $request['sort'] ?? 0;
|
|
|
+ $starNew->status = $request['status'] ?? 0;
|
|
|
+ $starNew->updated_at = date('Y-m-d H:i:s');
|
|
|
|
|
|
$open_news = $this->starNews->where('status',1)->count();
|
|
|
if ($open_news >= 5 && $request['status'] == 1){
|
|
|
throw new HttpException(500, '最多开启5条新闻');
|
|
|
}
|
|
|
- $res = $starNews->save();
|
|
|
+ $res = $starNew->save();
|
|
|
if (!$res) {
|
|
|
throw new HttpException(500, '星球新闻更新失败');
|
|
|
}
|
|
@@ -80,8 +77,8 @@ class StarNewsRepository
|
|
|
|
|
|
public function delete($request)
|
|
|
{
|
|
|
- $starNews = $this->starNews->where('id', $request['id'])->first();
|
|
|
- $res = $starNews->delete();
|
|
|
+ $starNew = $this->starNews->where('id', $request['id'])->first();
|
|
|
+ $res = $starNew->delete();
|
|
|
if (!$res){
|
|
|
return Response::create([
|
|
|
'message' => '删除失败,请重试',
|
|
@@ -92,14 +89,14 @@ class StarNewsRepository
|
|
|
|
|
|
public function editStatus($request)
|
|
|
{
|
|
|
- $starNews = $this->starNews->find($request['id']);
|
|
|
- $starNews->status = $request['status'];
|
|
|
- $starNews->updated_at = date('Y-m-d H:i:s');
|
|
|
+ $starNew = $this->starNews->find($request['id']);
|
|
|
+ $starNew->status = $request['status'];
|
|
|
+ $starNew->updated_at = date('Y-m-d H:i:s');
|
|
|
$open_news = $this->starNews->where('status',1)->count();
|
|
|
if ($open_news >= 5 && $request['status'] == 1){
|
|
|
throw new HttpException(500, '最多开启5条新闻');
|
|
|
}
|
|
|
- $res = $starNews->save();
|
|
|
+ $res = $starNew->save();
|
|
|
|
|
|
if (!$res) {
|
|
|
throw new HttpException(500, '修改状态失败');
|