AyrShareLogic.php 4.7 KB
<?php

namespace App\Http\Logic\Bside\AyrShare;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\AyrShare\AyrShare;
use App\Models\File\File as FileModel;
use App\Models\File\Image as ImageModel;

class AyrShareLogic extends BaseLogic
{


    public function __construct()
    {
        parent::__construct();
        $this->model = new AyrShare();
        $this->param = $this->requestAll;
    }

    /**
     * @name   :(创建账号并绑定写入数据库)ayr_add
     * @author :lyh
     * @method :post
     * @time   :2023/5/6 9:19
     */
    public function ayr_share_add($res){
        //插入数据库
        $param = [
            'title'=>$res['title'],
            'ref_id'=>$res['refId'],
            'profile_key'=>$res['profileKey'],
            'user_id'=>$this->user['id'],
            'project_id'=>$this->user['project_id'],
            'name'=>$this->param['name'],
        ];
        $rs = $this->model->add($param);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @name   :(获取当前数据详情)ayr_share_del
     * @author :lyh
     * @method :post
     * @time   :2023/5/6 10:16
     */
    public function ayr_share_info(){
        $info = $this->model->read(['id'=>$this->param['share_id']]);
        if($info === false){
            $this->fail('当前数据不存在或已被删除');
        }
        return $this->success($info);
    }

    /**
     * @name   :(更新)ayr_share_edit
     * @author :lyh
     * @method :post
     * @time   :2023/5/9 14:44
     */
    public function ayr_share_edit($param){
        $rs = $this->model->edit($param,['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }
    /**
     * @name   :(删除ayr数据并同步删除)
     * @author :lyh
     * @method :post
     * @time   :2023/5/6 10:18
     */
    public function ayr_share_del(){
        $this->param['id'] = ['in',$this->param['id']];
        $rs = $this->model->del($this->param);
        if($rs === false){
            $this->fail('删出失败');
        }
        return $this->success();
    }
    /**
     * @name   :(更新图片库)save_info_info
     * @author :lyh
     * @method :post
     * @time   :2023/5/10 15:01
     */
    public function save_img_info($hash){
        $imageModel = new ImageModel();
        $info = $imageModel->read(['hash'=>$hash]);
        if($info === false){
            $this->fail('error');
        }
        return $this->success($info);
    }

    /**
     * @name   :(更新图片库)save_info_info
     * @author :lyh
     * @method :post
     * @time   :2023/5/10 15:01
     */
    public function save_file_info($hash){
        $fileModel = new FileModel();
        $info = $fileModel->read(['hash'=>$hash]);
        if($info === false){
            $this->fail('error');
        }
        return $this->success($info);
    }

    /**
     * @name   :(更新图片库)save_img
     * @author :lyh
     * @method :post
     * @time   :2023/5/10 15:01
     */
    public function save_img($param_data){
        //根据文件hash存入数据库
        $ayr_data = [
            'ayr_id'=>$param_data['id'],
            'ayr_url'=>$param_data['url'],
            'ayr_url_link'=>$param_data['url_1080']
        ];
        $imageModel = new ImageModel();
        $rs = $imageModel->edit($ayr_data,['hash'=>$this->param['hash']]);
        if($rs === false){
            $this->fail('更新失败');
        }
        return $this->success();
    }

    /**
     * @name   :(获取图片的base64)base_img_content
     * @author :lyh
     * @method :post
     * @time   :2023/5/12 9:28
     */
    public function base_img_content($hash){
        $imageModel = new ImageModel();
        $info = $imageModel->read(['hash'=>$hash]);
        if($info === false){
            $this->fail('当前数据不存在');
        }
        $content = file_get_contents($info['path']);
        $img_type = $info['type'];
        $content = base64_encode($content);
        $img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
        return $img_base64;
    }
    /**
     * @name   :(更新文件库)save_img
     * @author :lyh
     * @method :post
     * @time   :2023/5/10 15:01
     */
    public function save_file($param_data){
        //根据文件hash存入数据库
        $ayr_data = [
            'ayr_id'=>$param_data['id'],
            'ayr_url'=>$param_data['url'],
            'ayr_url_link'=>$param_data['url_1080']
        ];
        $imageModel = new FileModel();
        $rs = $imageModel->edit($ayr_data,['hash'=>$this->param['hash']]);
        if($rs === false){
            $this->fail('更新失败');
        }
        return $this->success();
    }
}