<?php


namespace frontend\modules\api\controllers;


use common\services\CaseService;
use frontend\modules\api\components\BaseAdminController;
use Yii;
use yii\web\Response;

class CaseManageController extends BaseAdminController
{
    /**
     * 查询案例是否重名
     * @return Response
     */
    public function actionCheck()
    {
        $post = Yii::$app->request->post();
        if (isset($post['id'])) {
            $otherInfo = CaseService::getCaseQuery()
                ->andWhere(["and", ['title' => $post['title']], ['<>', 'id', $post['id']]])
                ->one();
            if ($otherInfo) {
                return $this->asJson([], 1, "案件名称已存在！"); //通知前端
            }
            return $this->asJson([]);
        }
        if ($post['category'] == 'title') {
            $info = CaseService::getCaseQuery()->andWhere(['title' => $post['title']])
                ->one();
            if ($info) {
                return $this->asJson([], 1, "案件名称已存在！"); //通知前端
            }
        }
        return $this->asJson([]);
    }
}