作者 赵彬吉
... ... @@ -11,6 +11,7 @@ use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
... ... @@ -270,20 +271,56 @@ class ProductController extends BaseController
$v['is_renovation'] = $this->getProductIsRenovation($templateInfo,$v['id']);
$v['url'] = $this->user['domain'].$v['route'];
//获取当前数据扩展字段及值
$v['extend'] = $this->getExtendInfo($v['id']);
return $v;
}
/**
* @remark :获取扩展字段详情
* @name :getExtendInfo
* @author :lyh
* @method :post
* @time :2023/11/14 9:45
*/
public function getExtendInfo($product_id){
$extendModel = new Extend();
$list = $extendModel->list([],'id',['type','key','title']);
if(empty($list)){
return [];
}
$extendInfoModel = new ExtendInfo();
$v['extend'] = $extendInfoModel->list(['product_id'=>$v['id']],'created_at');
foreach ($v['extend'] as $k1=>$v1){
if($v1['type'] == 3){
$v1['values'] = getImageUrl($v1['values']);
}elseif ($v1['type'] == 4){
$v1['values'] = getFileUrl($v1['values']);
foreach ($list as $k=>$v){
$info = $extendInfoModel->read(['key'=>$v['key'],'product_id'=>$product_id]);
if($info == false){
if($v['type'] == 3 || $v['type'] == 4){
$v['values'] = [];
}else{
$v['values'] = '';
}
}else{
if($v['type'] == 3){
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = getImageUrl($v1);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getImageUrl($v1);
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
}else{
$v['values'] = $info['values'];
}
}
$v['extend'][$k1] = $v1;
$list[$k] = $v;
}
return $v;
return $list;
}
/**
* @remark :保存产品数据
* @name :save
... ...
<?php
/**
* @remark :
* @name :BTemplateModuleProjectController.php
* @author :lyh
* @method :post
* @time :2023/11/14 14:34
*/
namespace App\Http\Controllers\Bside\Template;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\BTemplateModuleProjectLogic;
use App\Models\Template\BModuleProject;
class BTemplateModuleProjectController extends BaseController
{
/**
* @remark :获取私有化模块列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/11/14 14:34
*/
public function lists(BModuleProject $BModuleProject){
$list = $BModuleProject->list($this->map);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :保存私有化左侧模块
* @name :save
* @author :lyh
* @method :post
* @time :2023/11/14 14:38
*/
public function save(BTemplateModuleProjectLogic $logic){
$this->request->validate([
'name'=>'required',
'html'=>'required',
],[
'name.required' => '模板名称不能为空',
'html.required' => 'html不能为空',
]);
$logic->moduleProjectSave();
return $this->response('success');
}
}
... ...
<?php
/**
* @remark :
* @name :VisualizationController.php
* @author :lyh
* @method :post
* @time :2023/11/15 9:55
*/
namespace App\Http\Controllers\Bside\Template;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\VisualizationLogic;
use App\Models\Visualization\Visualization;
/**
* @remark :定制项目处理
* @name :VisualizationController
* @author :lyh
* @method :post
* @time :2023/11/15 9:55
*/
class VisualizationController extends BaseController
{
/**
* @remark :获取当前定制代码块详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/11/15 10:26
*/
public function info(Visualization $visualization){
//查看当前模板是否在可视化中保存
$info = $visualization->read(['source'=>$this->map['source']],['html','source','id','project_id']);
if($info === false){
$info = [];
}
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :保存定制项目html
* @name :save
* @author :lyh
* @method :post
* @time :2023/11/15 10:08
*/
public function save(VisualizationLogic $logic){
$this->request->validate([
'source'=>'required',
'html'=>'required',
],[
'source.required' => '类型不能为空',
'html.required' => 'html不能为空',
]);
$logic->saveVisualization();
$this->response('success');
}
/**
* @remark :可视化保存
* @name :saveHtml
* @author :lyh
* @method :post
* @time :2023/11/15 11:20
*/
public function getHtml(VisualizationLogic $logic){
$this->request->validate([
'source'=>'required',
'source_id'=>'required',
],[
'source.required' => '类型不能为空',
'source_id.required' => 'source_id不能为空',
]);
$data = $logic->getHtml();
$this->response('success',Code::SUCCESS,['html'=>$data]);
}
/**
* @remark :保存html
* @name :saveHtml
* @author :lyh
* @method :post
* @time :2023/11/15 11:44
*/
public function saveHtml(VisualizationLogic $logic){
$this->request->validate([
'source'=>'required',
'source_id'=>'required',
],[
'source.required' => '类型不能为空',
'source_id.required' => 'source_id不能为空',
]);
$logic->saveHtml();
$this->response('success');
}
}
... ...
... ... @@ -81,6 +81,9 @@ class ProjectLogic extends BaseLogic
if(empty($info['payment']['renewal_record'])){
$info['payment']['renewal_record'] = [["amount"=> null, "remark"=> null, "expire_at"=> null]];
}
if(isset($info['is_customized']) && $info['is_customized'] == 1){
$info['is_visualization'] = json_decode($info['is_visualization']);
}
return $this->success($info);
}
... ... @@ -130,12 +133,9 @@ class ProjectLogic extends BaseLogic
//保存售后信息
$this->saveProjectAfter($this->param['project_after']);
//创建站点
$this->createSite($this->param);
// $this->createSite($this->param);
}
DB::commit();
}catch (AsideGlobalException $e){
DB::rollBack();
$this->fail($e->getMessage());
}catch (\Exception $e){
DB::rollBack();
$this->fail('请填写完整后再提交');
... ... @@ -188,6 +188,11 @@ class ProjectLogic extends BaseLogic
'upload_max_size' => $param['upload_config']['upload_max_size'] ?? 5,
];
}
if(isset($param['is_customized']) && ($param['is_customized'] == 1)){
if(!empty($param['is_visualization'])){
$param['is_visualization'] = json_encode($param['is_visualization']);
}
}
$this->model->edit($param,['id'=>$param['id']]);
Common::del_user_cache($this->model->getTable(),$param['id']);
return $this->success();
... ... @@ -400,7 +405,7 @@ class ProjectLogic extends BaseLogic
$menuModel = new ProjectMenu();
$ids = $menuModel->where(['status'=>0])->pluck('id')->toArray();
$data = [
'name'=>'超级管理员',
'name'=>'管理员',
'role_menu'=>implode(',',$ids),
'project_id'=>$project_id,
'type'=>1,
... ...
<?php
/**
* @remark :
* @name :BTemplateModuleProjectLogic.php
* @author :lyh
* @method :post
* @time :2023/11/14 14:41
*/
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\BModuleProject;
class BTemplateModuleProjectLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BModuleProject();
$this->param = $this->requestAll;
}
/**
* @remark :保存私有化左侧模块
* @name :moduleProjectSave
* @author :lyh
* @method :post
* @time :2023/11/14 14:46
*/
public function moduleProjectSave(){
try {
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
$this->model->add($this->param);
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
}
... ...
<?php
/**
* @remark :
* @name :VisualizationLogic.php
* @author :lyh
* @method :post
* @time :2023/11/15 10:09
*/
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Visualization\Visualization;
class VisualizationLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Visualization();
$this->param = $this->requestAll;
}
/**
* @remark :保存定制html
* @name :saveHtml
* @author :lyh
* @method :post
* @time :2023/11/15 10:12
*/
public function saveVisualization(){
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->model->add($this->param);
}
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :可视化装修获取html
* @name :getHtml
* @author :lyh
* @method :post
* @time :2023/11/15 11:30
*/
public function getHtml(){
//查询可视化是否第一次保存
$bTemplateModel = new BTemplate();
$TemplateInfo = $bTemplateModel->read([
'source'=>$this->param['source'],
'project_id'=>$this->user['project_id'],
'source_id'=>$this->param['source_id'],
]);
if($this->param['source'] == 2){
if($this->param['source_id'] == 0){$source = 3;}else{$source = 2;}
}
if($this->param['source'] == 3){
if($this->param['source_id'] == 0){$source = 5;}else{$source = 4;}
}
if($this->param['source'] == 4){
if($this->param['source_id'] == 0){$source = 7;}else{$source = 6;}
}
if($TemplateInfo === false){
$info = $this->model->read(['source'=>$source],['html','source','id','project_id']);
if($info === false){
$this->fail('请先上传定制代码块');
}
return $info['html'];
}
return $TemplateInfo['html'];
}
/**
* @remark :保存定制项目可视化
* @name :saveHtml
* @author :lyh
* @method :post
* @time :2023/11/15 11:47
*/
public function saveHtml(){
$bTemplateModel = new BTemplate();
$templateInfo = $bTemplateModel->read([
'source'=>$this->param['source'],
'project_id'=>$this->user['project_id'],
'source_id'=>$this->param['source_id'],
]);
try {
if($templateInfo === false){
$this->param['project_id'] = $this->user['project_id'];
$bTemplateModel->add($this->param);
}else{
$bTemplateModel->edit(['html'=>$this->param['html']],['source'=>$this->param['source'],'source_id'=>$this->param['source_id']]);
}
}catch (\Exception $e){
$this->fail('系统错误请联系管理员');
}
return $this->success();
}
}
... ...
... ... @@ -38,7 +38,7 @@ class ExtendLogic extends BaseLogic
if($info !== false){
$this->fail('当前扩展名称已存在');
}
$key = trim(strtolower(preg_replace('/[\W]+/', '-', trim(Translate::tran($this->param['title'], 'en')))), '-');
$key = 'pd_extended_field_';
$this->param['key'] = $this->getKey($key);
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
... ... @@ -56,11 +56,10 @@ class ExtendLogic extends BaseLogic
* @method :post
* @time :2023/11/9 15:55
*/
public function getKey($key){
$info = $this->model->read(['key'=>$key]);
public function getKey($key,$i = 1){
$info = $this->model->read(['key'=>$key.$i]);
if($info !== false){
$key .= '-'.rand(1, 100);
return $this->getKey($key);
return $this->getKey($key,$i+1);
}
return $key;
}
... ...
... ... @@ -99,28 +99,28 @@ class ProductLogic extends BaseLogic
* @method :post
* @time :2023/11/9 15:02
*/
public function saveExtendInfo($id,$extend){
public function saveExtendInfo($product_id,$extend){
//先删除以前的数据
$extendInfoModel = new ExtendInfo();
$extendInfoModel->del(['project_id'=>$id]);
if(!empty($extend)){
foreach ($extend as $v){
unset($v['title']);
if(!empty($v['values'])){
if($v['type'] == 3 || $v['type'] || 4){
if(is_array($v['values'])){
foreach ($v['values'] as $k1=>$v1){
$v1 = str_replace_url($v1);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}
}
$v['project_id'] = $this->user['project_id'];
$v['product_id'] = $id;
$extendInfoModel->add($v);
$extendInfoModel->del(['product_id'=>$product_id]);
if(empty($extend)) {
return $this->success();
}
foreach ($extend as $k => $v){
if(empty($v['values'])){
continue;
}
unset($v['title']);
if($v['type'] == 3 || $v['type'] == 4){
foreach ($v['values'] as $k1=>$v1){
$v1 = str_replace_url($v1);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}
$v['project_id'] = $this->user['project_id'];
$v['product_id'] = $product_id;
$extendInfoModel->add($v);
}
return $this->success();
}
... ...
... ... @@ -168,6 +168,9 @@ class UserLoginLogic
$info['upload_config'] = $project['upload_config'];
$info['image_max'] = $project['image_max'];
$info['configuration'] = $project['deploy_build']['configuration'];
if($info['is_customized'] == 1){
$info['is_visualization'] = json_decode($project['is_visualization']);
}
//保存项目缓存
Cache::put('user-'.$info['project_id'],$project,$minutes = null);
return $this->success($info);
... ... @@ -196,14 +199,17 @@ class UserLoginLogic
$info['is_customized'] = $project['is_customized'];
$info['is_upload_manage'] = $project['is_upload_manage'];
$info['upload_config'] = $project['upload_config'];
$info['image_max'] = $project['image_max'];
$info['configuration'] = $project['deploy_build']['configuration'];
if($info['is_customized'] == 1){
$info['is_visualization'] = json_decode($project['is_visualization']);
}
//保存项目缓存
Cache::put('user-'.$info['project_id'],$project,$minutes = null);
return $this->success($info);
}
/**
* @remark :获取项目数据详情
* @name :getProjectInfo
... ...
... ... @@ -41,6 +41,8 @@ class Category extends Base
return $ids;
}
/**
* 关联产品数量
* @param $cate_id
... ... @@ -50,7 +52,16 @@ class Category extends Base
*/
public static function getProductNum($cate_id){
$cate_ids = self::getChildIdsArr($cate_id);
$product_ids = CategoryRelated::whereIn('cate_id', $cate_ids)->groupBy('product_id')->select(['product_id'])->get();
return count($product_ids);
$str = 0;
foreach ($cate_ids as $v){
$info = self::where('pid',$v)->first();
if($info){
continue;
}else{
$count = Product::where('category_id','like','%,'.$v.',%')->count();
$str = $str+$count;
}
}
return $str;
}
}
... ...
<?php
/**
* @remark :
* @name :BModuleProject.php
* @author :lyh
* @method :post
* @time :2023/11/14 14:31
*/
namespace App\Models\Template;
use App\Models\Base;
/**
* @remark :私有化左侧模块
* @name :BModuleProject
* @author :lyh
* @method :post
* @time :2023/11/14 14:33
*/
class BModuleProject extends Base
{
protected $table = 'gl_public_template_module_project';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
<?php
/**
* @remark :
* @name :TemplateProject.php
* @author :lyh
* @method :post
* @time :2023/11/15 14:38
*/
namespace App\Models\Template;
use App\Models\Base;
class TemplateProject extends Base
{
protected $table = 'gl_web_setting_template';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
<?php
/**
* @remark :
* @name :Visualization.php
* @author :lyh
* @method :post
* @time :2023/11/15 10:11
*/
namespace App\Models\Visualization;
use App\Models\Base;
class Visualization extends Base
{
protected $table = 'gl_visualization_html';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -320,6 +320,13 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/type', [\App\Http\Controllers\Bside\Template\BTemplateModuleController::class, 'getType'])->name('template_module_getType');
});
// 保存私有模块
Route::prefix('moduleProject')->group(function () {
//获取所有左侧模版
Route::any('/', [\App\Http\Controllers\Bside\Template\BTemplateModuleProjectController::class, 'lists'])->name('template_module_project_lists');
Route::any('/save', [\App\Http\Controllers\Bside\Template\BTemplateModuleProjectController::class, 'save'])->name('template_module_project_save');
});
//编辑记录
Route::prefix('log')->group(function () {
//获取所有左侧模版
... ... @@ -328,6 +335,15 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/rollbackVersion', [\App\Http\Controllers\Bside\Template\BTemplateLogController::class, 'rollbackVersion'])->name('template_log_rollbackVersion');
});
});
//定制项目上传代码块
Route::prefix('visualization')->group(function () {
Route::any('/info', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'info'])->name('visualization_info');
Route::any('/save', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'save'])->name('visualization_save');
Route::any('/getHtml', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'getHtml'])->name('visualization_getHtml');
Route::any('/saveHtml', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'saveHtml'])->name('visualization_saveHtml');
});
// 自定义页面,专题页
Route::prefix('custom')->group(function () {
Route::any('/', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'lists'])->name('custom_lists');
... ...