WebSettingServiceLogic.php 1.9 KB
<?php

namespace App\Http\Logic\Bside\Setting;

use App\Http\Controllers\ImageLogic;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Image;
use App\Models\WebSetting\WebSettingService;
use Illuminate\Support\Facades\DB;

class WebSettingServiceLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();

        $this->model = new WebSettingService();
        $this->param = $this->requestAll;
    }

    /**
     * @name   : (客服设置列表)setting_service_list
     * @author :lyh
     * @method :post
     * @time   :2023/5/4 11:23
     */
    public function setting_service_info(){
        $info = $this->model->read(['project_id'=>$this->param['project_id']]);
        return $this->success($info);
    }

    /**
     * @name   : (客服设置)setting_service_save
     * @author :lyh
     * @method :post
     * @time   :2023/5/4 11:10
     */
    public function setting_service_save(){
        if(isset($this->param['id'])){
            $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        }else{
            $rs = $this->model->add($this->param);
        }
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }


    /**
     * @name   :(删除客服图片)setting_service_del
     * @author :lyh
     * @method :post
     * @time   :2023/5/4 11:29
     */
    public function setting_service_del(){
        DB::beginTransaction();
        try {
            //获取当前图片资源
            $image = new Image();
            $info = $image->read(['hash'=>$this->param['hash']]);
            if($info !== false){
                $image->del(['id'=>$info['id']]);
                //删除资源文件
                shell_exec('rm -rf '.$info['path']);
            }
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            $this->fail('error');
        }
    }
}