Merge branch 'zbj_new' of http://47.244.231.31:8099/zhl/globalso-v6 into develop
正在显示
5 个修改的文件
包含
159 行增加
和
2 行删除
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Controllers\Bside\Nav; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +use App\Enums\Common\Code; | ||
| 7 | +use App\Http\Controllers\Bside\BaseController; | ||
| 8 | +use App\Models\Nav\BNavGroup; | ||
| 9 | +use Illuminate\Http\Request; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 导航组 | ||
| 13 | + * Class NavGroupController | ||
| 14 | + * @package App\Http\Controllers\Bside\Nav | ||
| 15 | + * @author zbj | ||
| 16 | + * @date 2023/10/9 | ||
| 17 | + */ | ||
| 18 | +class NavGroupController extends BaseController | ||
| 19 | +{ | ||
| 20 | + | ||
| 21 | + public function index(BNavGroup $nav_group){ | ||
| 22 | + $this->map['project_id'] = $this->user['project_id']; | ||
| 23 | + $lists = $nav_group->list($this->map, 'id', ['id', 'name'], 'asc'); | ||
| 24 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public function save(Request $request){ | ||
| 28 | + $request->validate([ | ||
| 29 | + 'name'=> ['required','max:100'], | ||
| 30 | + ],[ | ||
| 31 | + 'name.required' => '菜单组名称不能为空', | ||
| 32 | + 'name.max' => '菜单组名称不能超过100个字符' | ||
| 33 | + ]); | ||
| 34 | + if(empty($this->param['id'])){ | ||
| 35 | + $nav_group = new BNavGroup(); | ||
| 36 | + }else{ | ||
| 37 | + if(in_array($this->param['id'], [BNavGroup::DEFAULT_HEADER_ID,BNavGroup::DEFAULT_FOOTER_ID])){ | ||
| 38 | + $this->fail('系统内置菜单组不能修改'); | ||
| 39 | + } | ||
| 40 | + $nav_group = BNavGroup::find($this->param['id']); | ||
| 41 | + if(!$nav_group){ | ||
| 42 | + $this->fail('数据不存在或者已经删除'); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + $nav_group->project_id = $this->user['project_id']; | ||
| 46 | + $nav_group->name = $this->param['name']; | ||
| 47 | + $nav_group->save(); | ||
| 48 | + | ||
| 49 | + $this->response('success'); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public function delete(Request $request){ | ||
| 53 | + $request->validate([ | ||
| 54 | + 'id'=>'required', | ||
| 55 | + ],[ | ||
| 56 | + 'id.required' => 'ID不能为空', | ||
| 57 | + ]); | ||
| 58 | + if(in_array($this->param['id'], [BNavGroup::DEFAULT_HEADER_ID,BNavGroup::DEFAULT_FOOTER_ID])){ | ||
| 59 | + $this->fail('系统内置菜单组不能删除'); | ||
| 60 | + } | ||
| 61 | + $nav_group = BNavGroup::find($this->param['id']); | ||
| 62 | + if(!$nav_group){ | ||
| 63 | + $this->response('数据不存在或者已经删除'); | ||
| 64 | + } | ||
| 65 | + $nav_group->delete(); | ||
| 66 | + | ||
| 67 | + $this->response('success'); | ||
| 68 | + } | ||
| 69 | +} |
| @@ -4,10 +4,11 @@ namespace App\Http\Logic\Aside\Template; | @@ -4,10 +4,11 @@ namespace App\Http\Logic\Aside\Template; | ||
| 4 | 4 | ||
| 5 | use App\Http\Logic\Aside\BaseLogic; | 5 | use App\Http\Logic\Aside\BaseLogic; |
| 6 | use App\Models\Service\Service as ServiceSettingModel; | 6 | use App\Models\Service\Service as ServiceSettingModel; |
| 7 | +use App\Models\Template\BCommonTemplate; | ||
| 7 | use App\Models\Template\Template; | 8 | use App\Models\Template\Template; |
| 8 | use App\Models\Template\Setting; | 9 | use App\Models\Template\Setting; |
| 10 | +use App\Services\ProjectServer; | ||
| 9 | use Illuminate\Support\Facades\DB; | 11 | use Illuminate\Support\Facades\DB; |
| 10 | -use mysql_xdevapi\Exception; | ||
| 11 | 12 | ||
| 12 | class ATemplateLogic extends BaseLogic | 13 | class ATemplateLogic extends BaseLogic |
| 13 | { | 14 | { |
| @@ -141,7 +142,7 @@ class ATemplateLogic extends BaseLogic | @@ -141,7 +142,7 @@ class ATemplateLogic extends BaseLogic | ||
| 141 | ]; | 142 | ]; |
| 142 | $serviceSettingModel->insert($data); | 143 | $serviceSettingModel->insert($data); |
| 143 | DB::commit(); | 144 | DB::commit(); |
| 144 | - }catch (Exception $e){ | 145 | + }catch (\Exception $e){ |
| 145 | DB::rollBack(); | 146 | DB::rollBack(); |
| 146 | $this->fail('error'); | 147 | $this->fail('error'); |
| 147 | } | 148 | } |
| @@ -184,6 +185,49 @@ class ATemplateLogic extends BaseLogic | @@ -184,6 +185,49 @@ class ATemplateLogic extends BaseLogic | ||
| 184 | if($rs === false){ | 185 | if($rs === false){ |
| 185 | $this->fail('error'); | 186 | $this->fail('error'); |
| 186 | } | 187 | } |
| 188 | + $html = Template::where('id', $this->param['template_id'])->value('html'); | ||
| 189 | + | ||
| 190 | + $this->splitTemplate($html); | ||
| 191 | + | ||
| 187 | return $this->success(); | 192 | return $this->success(); |
| 188 | } | 193 | } |
| 194 | + | ||
| 195 | + /** | ||
| 196 | + * 保存拆分模板 | ||
| 197 | + * @author zbj | ||
| 198 | + * @date 2023/10/11 | ||
| 199 | + */ | ||
| 200 | + public function splitTemplate($html){ | ||
| 201 | + $data['main_html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'); | ||
| 202 | + $data['main_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'); | ||
| 203 | + | ||
| 204 | + $common['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'); | ||
| 205 | + $common['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'); | ||
| 206 | + $common['head_style'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'); | ||
| 207 | + $common['footer_style'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'); | ||
| 208 | + $common['other_html'] = str_replace('<header', '', characterTruncation($html,'/<link id="google-fonts-link"(.*?)<header/s')); | ||
| 209 | + | ||
| 210 | + //保存公共部门 | ||
| 211 | + ProjectServer::useProject($this->param['project_id']); | ||
| 212 | + $common_info = DB::connection('custom_mysql')->table('gl_web_common_template') | ||
| 213 | + ->where('project_id', $this->param['project_id']) | ||
| 214 | + ->where('template_id', $this->param['template_id']) | ||
| 215 | + ->first(); | ||
| 216 | + | ||
| 217 | + $common['updated_at'] = date('Y-m-d H:i:s'); | ||
| 218 | + if(!$common){ | ||
| 219 | + $common['project_id'] = $this->param['project_id']; | ||
| 220 | + $common['template_id'] = $this->param['template_id']; | ||
| 221 | + $common['created_at'] = date('Y-m-d H:i:s'); | ||
| 222 | + DB::connection('custom_mysql')->table('gl_web_common_template')->insert($common); | ||
| 223 | + }else{ | ||
| 224 | + DB::connection('custom_mysql')->table('gl_web_common_template') | ||
| 225 | + ->where('project_id', $this->param['project_id']) | ||
| 226 | + ->where('template_id', $this->param['template_id']) | ||
| 227 | + ->update($common); | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + //返回main | ||
| 231 | + return $data; | ||
| 232 | + } | ||
| 189 | } | 233 | } |
| @@ -32,6 +32,7 @@ class NavRequest extends FormRequest | @@ -32,6 +32,7 @@ class NavRequest extends FormRequest | ||
| 32 | public function rules() | 32 | public function rules() |
| 33 | { | 33 | { |
| 34 | $rule = [ | 34 | $rule = [ |
| 35 | + 'group_id' => ['required','integer'], | ||
| 35 | 'pid' => ['required','integer'], | 36 | 'pid' => ['required','integer'], |
| 36 | 'name' => ['required','max:100'], | 37 | 'name' => ['required','max:100'], |
| 37 | ]; | 38 | ]; |
| @@ -41,6 +42,8 @@ class NavRequest extends FormRequest | @@ -41,6 +42,8 @@ class NavRequest extends FormRequest | ||
| 41 | public function messages() | 42 | public function messages() |
| 42 | { | 43 | { |
| 43 | return [ | 44 | return [ |
| 45 | + 'group_id.required' => '未定义菜单组', | ||
| 46 | + 'group_id.integer' => '菜单组错误', | ||
| 44 | 'pid.required' => '上级选择错误', | 47 | 'pid.required' => '上级选择错误', |
| 45 | 'pid.gte' => '上级选择错误', | 48 | 'pid.gte' => '上级选择错误', |
| 46 | 'pid.integer' => '上级选择错误', | 49 | 'pid.integer' => '上级选择错误', |
app/Models/Nav/BNavGroup.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Models\Nav; | ||
| 4 | + | ||
| 5 | +use App\Models\Base; | ||
| 6 | +use Illuminate\Database\Eloquent\SoftDeletes; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Class BNavGroup | ||
| 10 | + * @package App\Models\Nav | ||
| 11 | + * @author zbj | ||
| 12 | + * @date 2023/10/9 | ||
| 13 | + */ | ||
| 14 | +class BNavGroup extends Base | ||
| 15 | +{ | ||
| 16 | + | ||
| 17 | + protected $table = 'gl_web_nav_group'; | ||
| 18 | + //连接数据库 | ||
| 19 | + protected $connection = 'custom_mysql'; | ||
| 20 | + use SoftDeletes; | ||
| 21 | + | ||
| 22 | + public $hidden = ['deleted_at']; | ||
| 23 | + | ||
| 24 | + const DEFAULT_HEADER_ID = 1; | ||
| 25 | + const DEFAULT_FOOTER_ID = 2; | ||
| 26 | + | ||
| 27 | +} |
-
请 注册 或 登录 后发表评论