DeleteController.class.php 1.51 KB
<?php
/**
 * 【后台】删除照片接口
 * DeleteController.class.php
 * User: caijianhua
 * Date: 2017/8/29
 * Time: 下午5:15
 */

namespace Apicp\Controller\Pic;

use Common\Common\AttachOperation;
use Common\Model\CommonModel;
use Common\Service\PlanPicService;

class DeleteController extends \Apicp\Controller\AbstractController
{
    /** @var  PlanPicService 照片表 */
    protected $plan_pic_service;

    public function before_action($action = '')
    {
        if (!parent::before_action($action)) {
            return false;
        }
        $this->plan_pic_service = new PlanPicService();
        return true;
    }

    /**
     * 【后台】删除照片接口
     *
     * @author 蔡建华
     */
    public function Index_post()
    {
        $pic_id = I('post.pic_id');

        if (empty($pic_id)) {
            // 图片ID不能为空
            E('_EMPTY_PIC_ID');
        }

        // 获取照片信息
        $pic_info = $this->plan_pic_service->get($pic_id);
        $plan_id = $pic_info['plan_id'];

        // 删除照片
        $this->_result = $this->plan_pic_service->delete_by_conds(
            [
                'pic_id' => $pic_id,
            ]
        );

        // 删除附件使用表的数据
        $model = new CommonModel('AttachUselog', 'oa_common_');
        $model->delete_by_conds(['at_id' => $pic_info['pic_at_id']]);
        // 删除UC服务器附件操作
        $attach_serv = new AttachOperation();
        $attach_serv->deleteFile([$plan_id]);


        return true;
    }
}