DeleteController.class.php 1.24 KB
<?php
/**
 * 【积分抽奖-后台】删除活动接口
 * User: yingcai
 * Date: 2018/3/23
 * Time: 下午3:40
 */

namespace Apicp\Controller\Activity;

use Common\Common\AttachOperation;
use Common\Service\ActivityService;
use Common\Service\RightService;
use Think\Exception;

class DeleteController extends \Apicp\Controller\AbstractController
{
    public function Index_post()
    {
        $activity_service = new ActivityService();

        $ids = I('post.ac_ids');

        if (empty($ids) || !is_array($ids)) {

            E('_EMPTY_ACTIVITY_ID');
        }

        $right_service = new RightService();

        $conds = array('ac_id' => $ids);
        try {
            // 删除开始
            $activity_service->start_trans();

            // 删除活动
            $activity_service->delete($ids);
            // 删除权限
            $right_service->delete_by_conds($conds);

            // 提交修改
            $activity_service->commit();
        } catch (Exception $e) {

            $activity_service->rollback();
            E('_ERR_DELETE_FAILED');
        }

        // 删除附件操作
        $attach_serv = new AttachOperation();
        $attach_serv->delete_attach(APP_DIR, 'activity', $ids);

        return true;
    }
}