Просмотр исходного кода

Merge branch 'v0.2' of http://git.caihongxingqiu.net/rainbow/cms-manage into v0.2

durong лет назад: 5
Родитель
Сommit
8196d04b8c

+ 12 - 0
app/Http/Controllers/V2/TopicGroupController.php

@@ -25,6 +25,7 @@ class TopicGroupController extends Controller {
     {
         $this->topicGroupRepository = $topicGroupRepository;
     }
+    
     //列表
     public function index(Request $request){
         $topicGroup = $this->topicGroupRepository->index($request->all());
@@ -84,5 +85,16 @@ class TopicGroupController extends Controller {
         $info = $this->topicGroupRepository->view($data);
         return $this->response->item($info, new DetailTopicGroupTransformer());
     }
+    //删除
+    public function delete(Request $request){
+        $data = $request->only('id','status');
+        $validator = Validator::make($data, [
+            'id' => 'required|integer|max:12',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->topicGroupRepository->delete($data);
+    }
 
 }

+ 22 - 0
app/Repositories/TopicGroupRepository.php

@@ -120,4 +120,26 @@ class TopicGroupRepository {
     public function view($request){
        return $this->topicGroup->where(['id'=>$request['id']])->first();
     }
+    //删除
+    public function delete($request){
+        $topicGroup = $this->topicGroup->where(['id'=>$request['id']])->first();
+        DB::beginTransaction();
+        try{
+            if($topicGroup){
+                $res = $this->topicGroup->where(['id'=>$request['id']])->delete();
+                if($res){
+                    $this->topicGroupInfo->where(['topic_group_id'=>$topicGroup->id])->delete();
+                }
+            }
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('删除推荐话题组:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '删除推荐话题组失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+
+    }
 }

+ 1 - 0
database/migrations/2019_04_28_025052_create_cms_subject_product_table.php

@@ -16,6 +16,7 @@ class CreateCmsSubjectProductTable extends Migration
         Schema::create('cms_subject_product', function (Blueprint $table) {
             $table->bigIncrements('id');
             $table->integer('sort')->comment('商品排序');
+            $table->integer('product_id',20)->comment('商品ID');
             $table->timestamps();
             $table->softDeletes();
         });

+ 2 - 0
routes/api.php

@@ -122,6 +122,8 @@ $api->version('v1', [
             $api->put('TopicGroupEdit', 'TopicGroupController@edit');
             //详情
             $api->get('TopicGroupView', 'TopicGroupController@view');
+            //删除
+            $api->delete('TopicGroupDelete', 'TopicGroupController@delete');
         });
 
     });