DeleteController.class.php 1006 Bytes
<?php
/**
 * 【后台】删除分类接口
 * DeleteController.class.php
 * @author:daijun
 * @date:2017-08-31
 */

namespace Apicp\Controller\Category;

use Common\Service\CategoryService;
use Common\Service\EducationService;

class DeleteController extends \Apicp\Controller\AbstractController
{
    /**
     * 删除分类接口
     * @author daijun
     */
    public function Index_post()
    {
        // 获取参数
        $ca_id = I('post.ca_id', 0, 'intval');

        if (empty($ca_id)) {

            E('_EMPTY_CATEGORY_ID');
        }

        $education_service = new EducationService();

        // 查询分类下是否有培训
        $edu_num = $education_service->count_by_conds(['ca_id' => $ca_id]);

        if ($edu_num > 0) {
            // 如果分类下存在培训,则不能删
            E('_ERR_CATEGORY_DELETE');
        }

        $cate_service = new CategoryService();

        // 删除分类
        $cate_service->delete($ca_id);

        return true;
    }
}