<?php

namespace App\Http\Controllers;

use App\OrderIssueOnTop;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;

class OrderIssueOnTopController extends Controller
{

    public function index()
    {
    }

    public function create()
    {
    }

    public function store(Request $request)
    {
    }

    public function show(OrderIssueOnTop $orderIssueOnTop)
    {
    }

    public function edit(OrderIssueOnTop $orderIssueOnTop)
    {
    }

    public function update(Request $request, OrderIssueOnTop $orderIssueOnTop)
    {
    }

    public function destroy(OrderIssueOnTop $orderIssueOnTop)
    {
    }

    public function apiDestroy(Request $request){
        if (!Gate::allows('订单管理-问题件-置顶')) ['success' => false, 'fail_info' => '没有对应权限'];
        if (!$request->has('id'))return ['success' => false, 'fail_info' => '没有传入对应的id'];

        return ['success' => OrderIssueOnTop::query()->where('id', $request->input('id'))->delete()];
    }

    public function apiStore(Request $request){
        if (!Gate::allows('订单管理-问题件-置顶')) return ['success' => false, 'fail_info' => '没有对应权限'];
        if (!$request->filled('id')) return ['success' => false, 'fail_info' => '没有传入对应参数'];
        if (!$request->filled('remark')) return ['success' => false, 'fail_info' => '没有写入备注'];

        $orderIssueOnTop = OrderIssueOnTop::query()->create(['order_issue_id' => $request->input('id'), 'remark' => $request->input('remark')]);
        if ($orderIssueOnTop) return ['success' => true,'data'=>$orderIssueOnTop];

        return ['success' => false, 'fail_info' => '置顶失败'];
    }
}
