|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Logic\Bside;
|
|
|
|
|
|
|
|
use App\Models\RouteMap;
|
|
|
|
use App\Models\Template\Template;
|
|
|
|
use App\Models\Template\BSetting;
|
|
|
|
use App\Models\Template\BTemplate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/15 13:57
|
|
|
|
* Class TemplateLogic
|
|
|
|
* @package App\Http\Logic\Bside
|
|
|
|
*/
|
|
|
|
class TemplateLogic extends BaseLogic
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->model = new BTemplate();
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $param
|
|
|
|
* @return array
|
|
|
|
* @throws \App\Exceptions\AsideGlobalException
|
|
|
|
* @throws \App\Exceptions\BsideGlobalException
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/12 9:54
|
|
|
|
*/
|
|
|
|
public function save($param)
|
|
|
|
{
|
|
|
|
|
|
|
|
// 查询
|
|
|
|
$data = $this->first($param['data_source'],$param['data_source_id']);
|
|
|
|
if($data){
|
|
|
|
$param['id'] = $data['id'];
|
|
|
|
}else{
|
|
|
|
$param['template_id'] = BSetting::_get($this->user['project_id'])['template_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::save($param);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 状态修改
|
|
|
|
* @param $source
|
|
|
|
* @param $source_id
|
|
|
|
* @param $status
|
|
|
|
* @return mixed
|
|
|
|
* @throws \App\Exceptions\AsideGlobalException
|
|
|
|
* @throws \App\Exceptions\BsideGlobalException
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/15 14:41
|
|
|
|
*/
|
|
|
|
public function status($source,$source_id,$status){
|
|
|
|
|
|
|
|
$data = $this->first($source,$source_id);
|
|
|
|
|
|
|
|
if(!$data){
|
|
|
|
$this->fail('数据不存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data->status = $status;
|
|
|
|
|
|
|
|
return $data->save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $source
|
|
|
|
* @param $source_id
|
|
|
|
* @return mixed
|
|
|
|
* @author:dc
|
|
|
|
* @time 2023/5/15 14:49
|
|
|
|
*/
|
|
|
|
public function first($source,$source_id)
|
|
|
|
{
|
|
|
|
$data = BTemplate::where([
|
|
|
|
'project_id'=>$this->user['project_id'],
|
|
|
|
'data_source' => $source,
|
|
|
|
'data_source_id' => $source_id,
|
|
|
|
'template_id' => BSetting::_get($this->user['project_id'])['template_id']
|
|
|
|
])->first();
|
|
|
|
if(empty($data)){
|
|
|
|
$data = Template::where([
|
|
|
|
'id' => BSetting::_get($this->user['project_id'])['template_id']
|
|
|
|
])->first();
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :使用模版并保存数据
|
|
|
|
* @name :usingTemplates
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/27 15:26
|
|
|
|
*/
|
|
|
|
public function usingTemplates(){
|
|
|
|
//获取模版详情
|
|
|
|
$asideTemplateModel = new Template();
|
|
|
|
$templateInfo = $asideTemplateModel->read(['id'=>$this->param['template_id']]);
|
|
|
|
if($templateInfo === false){
|
|
|
|
$this->fail('当前模版不存在或已被删除');
|
|
|
|
}
|
|
|
|
$bSettingTemplateModel = new BSetting();
|
|
|
|
//查看用户模版是否已使用过
|
|
|
|
$param = [
|
|
|
|
'template_id'=>$this->param['template_id'],
|
|
|
|
'project_id'=>$this->user['project_id']
|
|
|
|
];
|
|
|
|
$bSettingTemplateInfo = $bSettingTemplateModel->read($param);
|
|
|
|
//当前用户选择模版并关联
|
|
|
|
if($bSettingTemplateInfo === false){
|
|
|
|
$rs = $bSettingTemplateModel->add($param);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($templateInfo);
|
|
|
|
}
|
|
|
|
} |