|
@@ -8,16 +8,19 @@
|
|
namespace App\Repositories;
|
|
namespace App\Repositories;
|
|
|
|
|
|
use App\Models\Category;
|
|
use App\Models\Category;
|
|
|
|
+use App\Models\CategorySuggest;
|
|
use App\Models\CategoryTopic;
|
|
use App\Models\CategoryTopic;
|
|
use Dingo\Api\Http\Response;
|
|
use Dingo\Api\Http\Response;
|
|
|
|
+use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class CategoryRepository {
|
|
class CategoryRepository {
|
|
- public function __construct(Category $category,CategoryTopic $categoryTopic){
|
|
|
|
|
|
+ public function __construct(Category $category,CategoryTopic $categoryTopic,CategorySuggest $categorySuggest){
|
|
$this->category = $category;
|
|
$this->category = $category;
|
|
$this->categoryTopic = $categoryTopic;
|
|
$this->categoryTopic = $categoryTopic;
|
|
|
|
+ $this->categorySuggest = $categorySuggest;
|
|
}
|
|
}
|
|
//列表
|
|
//列表
|
|
public function index($request){
|
|
public function index($request){
|
|
@@ -180,4 +183,55 @@ class CategoryRepository {
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 编辑话题分类(推荐内容首页用)
|
|
|
|
+ */
|
|
|
|
+ public function suggestEdit($request)
|
|
|
|
+ {
|
|
|
|
+ $date = Carbon::now()->toDateTimeString();
|
|
|
|
+
|
|
|
|
+ $data = [];
|
|
|
|
+ $ids = array_unique($request['category_ids']);
|
|
|
|
+ foreach($ids as $id){
|
|
|
|
+ $data[] = [
|
|
|
|
+ 'category_id' => $id,
|
|
|
|
+ 'created_at' => $date,
|
|
|
|
+ 'updated_at' => $date
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ $this->categorySuggest->where('id', '>', 0)->delete();
|
|
|
|
+ $this->categorySuggest->insert($data);
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ return Response::create();
|
|
|
|
+
|
|
|
|
+ } catch (QueryException $exception) {
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('编辑话题分类失败:' . $exception->getMessage());
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '编辑失败,请重试',
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 话题分类详情(推荐内容首页用)
|
|
|
|
+ */
|
|
|
|
+ public function suggestDetail()
|
|
|
|
+ {
|
|
|
|
+ $lists = $this->categorySuggest->get();
|
|
|
|
+ $data = [];
|
|
|
|
+ foreach($lists as $item){
|
|
|
|
+ $data[] = [
|
|
|
|
+ 'id' => $item->category_id,
|
|
|
|
+ 'name' => $item->category->name
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ return $data;
|
|
|
|
+ }
|
|
}
|
|
}
|