作者 邓超

模板

... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Models\Template\ATemplate;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplate;
use Illuminate\Support\Facades\DB;
... ... @@ -20,7 +21,7 @@ class TemplateController extends BaseController
/**
* 列表
* 模板列表
* @return \Illuminate\Http\JsonResponse
* @author:dc
* @time 2023/5/9 14:20
... ... @@ -30,7 +31,7 @@ class TemplateController extends BaseController
$limit = intval($this->param['limit']??20);
$data = ATemplate::_bAll($limit);
$data = ATemplate::_bAll($limit)->toArray();
... ... @@ -39,6 +40,23 @@ class TemplateController extends BaseController
}
/**
* 当前使用的模板
* @author:dc
* @time 2023/5/9 15:19
*/
public function info(){
$conf = BSetting::_get($this->user['project_id']);
$data = ATemplate::_bFind($conf['template_id']);
$this->success([
'template_id' => $data['id']??0,
'name' => $data['name']??'',
'thumb' => $data['thumb']??'',
'time' => $conf['time']
]);
}
... ...
... ... @@ -53,6 +53,32 @@ class ATemplate extends \App\Models\Base{
->paginate($limit);
}
/**
* @param $id
* @return array
* @author:dc
* @time 2023/5/9 15:16
*/
public static function _bFind($id)
{
$data = static::where('id',$id)->first();
if(!$data || $data->status === static::STATUS_DISABLED){
return [];
}
return $data;
}
/**
* 获取默认模板
* @return mixed
* @author:dc
* @time 2023/5/9 15:09
*/
public static function _default()
{
return static::where(['status'=>static::STATUS_ACTIVE,'is_default'=>1])->first();
}
... ...
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 当前用户的模板
* @author:dc
* @time 2023/5/9 15:03
* Class BSetting
* @package App\Models\Template
*/
class BSetting extends \App\Models\Base{
protected $table = 'gl_web_setting_template';
/**
* b 端调用
* @param int $limit
* @return mixed
* @author:dc
* @time 2023/5/9 14:14
*/
public static function _get(int $project_id)
{
$data = static::where('project_id',$project_id)->first();
if($data){
return [
'template_id' => $data['template_id'],
'time' => $data['updated_at']
];
}
// 米有数据
// 读取默认的模板
$temp = ATemplate::_default();
// 保存
self::_save($project_id,$temp['id']);
return [
'template_id' => $temp['id'],
'time' => date('Y-m-d H:i:s')
];
}
/**
* 模板保存
* @param int $project_id
* @param int $template_id
* @return mixed
* @author:dc
* @time 2023/5/9 15:13
*/
public static function _save(int $project_id, int $template_id)
{
$data = static::where('project_id',$project_id)->first();
if(!$data){
$data = new static();
$data->project_id = $project_id;
}
$data->template_id = $template_id;
$data->save();
return $data->id;
}
}
... ...