<?php

namespace app\controller\admin\api\v1;

use support\Request;
use App\Utils\ApiResponse;
use App\model\ProjectDetailed;
use App\model\Project;
use App\model\Hotinformation;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("文章控制器")
 */
class HotinformationController{
    protected $noNeedLogin = ['get_list','get_details'];
    /**
     * @Apidoc\Title("1.0 获取所有文章")
     * @Apidoc\Url("admin/api/v1/hotinformation/get_list")
     * @Apidoc\Param("type", type="int",require=true, desc="0是热点资讯1是银龄")
     * @Apidoc\Method("POST")
     */
    public function get_list(Request $request)
    {
        $data = $request->post();
        $res = Hotinformation::where('type', $data['type'])->get();
        return ApiResponse::success(200, $res);
    }
    /**
     * @Apidoc\Title("1.0 获取文章详细")
     * @Apidoc\Url("admin/api/v1/hotinformation/get_details")
     * @Apidoc\Param("id", type="int",require=true, desc="文章id")
     * @Apidoc\Method("POST")
     */
    public function get_details(Request $request)
    {
        $data = $request->post();
        $res = Hotinformation::where('id', $data['id'])->first();
        return ApiResponse::success(200, $res);
    }
    /**
     * @Apidoc\Title("1.0 编辑文章")
     * @Apidoc\Url("admin/api/v1/hotinformation/edi")
     * @Apidoc\Param("id", type="int",require=true, desc="文章id")
     * @Apidoc\Method("POST")
     */
    public function edi(Request $request)
    {
        $data = $request->post();
        $hotinformation = Hotinformation::where('id', $data['id'])->first();
        if(!isset($hotinformation)){
            $hotinformation=new Hotinformation();
        }
        $hotinformation->title=$data['title'];
        $hotinformation->writer=$data['writer'];
        $hotinformation->content=$data['content'];
        $hotinformation->type=$data['type'];
        $hotinformation->img=$data['img'];
        $hotinformation->weight=$data['weight'];
        $hotinformation->save();
        return ApiResponse::success(200, []);
    }
    /**
     * @Apidoc\Title("1.0 删除文章")
     * @Apidoc\Url("admin/api/v1/hotinformation/del")
     * @Apidoc\Param("id", type="int",require=true, desc="文章id")
     * @Apidoc\Method("POST")
     */
    public function del(Request $request)
    {
        $data = $request->post();
        $hotinformation = Hotinformation::where('id', $data['id'])->first();
        $hotinformation->delete();
        return ApiResponse::success(200, []);
    }
}