<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2017/11/20
 * Time: 16:17
 */

namespace App\Http\Controllers\Manage\SendOrder;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Manage\SendOrder\Transformers\DocumentCoverTransformer;
use App\Modules\Promotion\Services\PromotionService;
use DB;
use Illuminate\Http\Request;

class DocumentCoverController extends Controller
{


    /**
     * @api {post} document_covers/delCover 删除标题
     * @apiParam  {Number}  [id]  标题id(可不传，多个之间用逗号隔开)
     * @apiSuccessExample {json} Success-Response:
     *
     *     {
     *         "code": 0,
     *         "msg": "",
     *         "data":[]
     *     }
     */
    function delCover(Request $request)
    {
        $id = $request->has('id') ? $request->input('id') : '';
        if (empty($id)) {
            return response()->error("PARAM_EMPTY");
        }
        $ids = explode(',', $id);
        $result = PromotionService::delCover($ids);
        if ($result) {
            return response()->success();
        }
    }

    function index(Request $request)
    {
        $type = $request->has('type') ? $request->input('type') : '';
        $param = [];


        if ($type) {
            $param['type'] = $type;
        }

        $result = PromotionService::getCovers($param);
        return response()->pagination(new DocumentCoverTransformer(), $result);
    }
}