|
...
|
...
|
@@ -10,7 +10,15 @@ |
|
|
|
namespace App\Http\Logic\Bside\CustomModule;
|
|
|
|
|
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\CustomModule\CustomModuleCategory;
|
|
|
|
use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
use App\Models\CustomModule\CustomModuleExtend;
|
|
|
|
use App\Models\CustomModule\CustomModuleExtentContent;
|
|
|
|
use App\Models\Product\Extend;
|
|
|
|
use App\Models\Product\ExtendInfo;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use mysql_xdevapi\Exception;
|
|
|
|
|
|
|
|
class CustomModuleContentLogic extends BaseLogic
|
|
|
|
{
|
|
...
|
...
|
@@ -28,23 +36,253 @@ class CustomModuleContentLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/4 16:10
|
|
|
|
*/
|
|
|
|
public function getCustomModuleContentInfo(){
|
|
|
|
public function getContentInfo(){
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
if($info === false){
|
|
|
|
$this->fail('当前数据不存在或已被删除');
|
|
|
|
}
|
|
|
|
$info['extend'] = $this->getExtendInfo($info['module_id'],$info['id']);
|
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取扩展字段详情
|
|
|
|
* @name :getExtendInfo
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/14 9:45
|
|
|
|
*/
|
|
|
|
public function getExtendInfo($module_id,$content_id){
|
|
|
|
$extendModel = new CustomModuleExtend();
|
|
|
|
$list = $extendModel->list(['module_id'=>$module_id],'id',['id','type','key','title']);
|
|
|
|
if(empty($list)){
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
$extendContentModel = new CustomModuleExtentContent();
|
|
|
|
foreach ($list as $k=>$v){
|
|
|
|
$info = $extendContentModel->read(['key'=>$v['key'],'content_id'=>$content_id]);
|
|
|
|
if($info == false){
|
|
|
|
if($v['type'] == 3 || $v['type'] == 4){
|
|
|
|
$v['values'] = [];
|
|
|
|
}else{
|
|
|
|
$v['values'] = '';
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$v = $this->setTypValues($v,$info);
|
|
|
|
}
|
|
|
|
$list[$k] = $v;
|
|
|
|
}
|
|
|
|
return $this->success($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :扩展字段根据type返回类型
|
|
|
|
* @name :setTypValues
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 14:43
|
|
|
|
*/
|
|
|
|
public function setTypValues($v,$info){
|
|
|
|
if($v['type'] == 3){
|
|
|
|
$arr = json_decode($info['values']);
|
|
|
|
foreach ($arr as $k1=>$v1){
|
|
|
|
$v1 = (array)$v1;
|
|
|
|
$v1['url'] = getImageUrl($v1['url']);
|
|
|
|
$arr[$k1] = $v1;
|
|
|
|
}
|
|
|
|
$v['values'] = $arr;
|
|
|
|
}elseif($v['type'] == 4){
|
|
|
|
$arr1 = json_decode($info['values']);
|
|
|
|
foreach ($arr1 as $k1=>$v1){
|
|
|
|
$v1 = getFileUrl($v1);
|
|
|
|
$arr1[$k1] = $v1;
|
|
|
|
}
|
|
|
|
$v['values'] = $arr1;
|
|
|
|
}else{
|
|
|
|
$v['values'] = $info['values'];
|
|
|
|
}
|
|
|
|
return $this->success($v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存数据
|
|
|
|
* @name :ModuleSave
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/4 15:47
|
|
|
|
*/
|
|
|
|
public function customModuleContentSave(){
|
|
|
|
public function contentSave(){
|
|
|
|
$extend = $this->handleExtent();
|
|
|
|
$this->param = $this->handleParam($this->param);
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
$id = $this->contentEdit();
|
|
|
|
}else{
|
|
|
|
$id = $this->contentAdd();
|
|
|
|
}
|
|
|
|
//保存扩展字段
|
|
|
|
$this->saveExtendInfo($id,$extend);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :处理扩展字段
|
|
|
|
* @name :handleExtent
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 15:06
|
|
|
|
*/
|
|
|
|
public function handleExtent(){
|
|
|
|
//扩展字段
|
|
|
|
$extend = [];
|
|
|
|
if(!empty($this->param['extend'])){
|
|
|
|
$extend = $this->param['extend'];
|
|
|
|
unset($this->param['extend']);
|
|
|
|
}
|
|
|
|
return $extend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :添加数据
|
|
|
|
* @name :contentAdd
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/7 15:04
|
|
|
|
*/
|
|
|
|
public function contentAdd(){
|
|
|
|
try {
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE.$this->param['module_id'],
|
|
|
|
$id, $this->user['project_id']);
|
|
|
|
$this->addUpdateNotify(RouteMap::SOURCE_MODULE.$this->param['module_id'],$route);
|
|
|
|
$this->curlDelRoute(['new_route'=>$route]);
|
|
|
|
$this->edit(['route' => $route], ['id' => $id]);
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->fail('系统错误,请联系管理员');
|
|
|
|
}
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑数据
|
|
|
|
* @name :contentEdit
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/7 15:04
|
|
|
|
*/
|
|
|
|
public function contentEdit(){
|
|
|
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE.$this->param['module_id'],
|
|
|
|
$this->param['id'], $this->user['project_id']);
|
|
|
|
$this->editRoute($this->param['id'],$route);
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('系统错误,请连续管理员');
|
|
|
|
}
|
|
|
|
return $this->param['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :(参数处理)paramProcessing
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/13 11:30
|
|
|
|
*/
|
|
|
|
public function handleParam($param)
|
|
|
|
{
|
|
|
|
$param['operator_id'] = $this->user['id'];
|
|
|
|
if(!isset($param['id']) || empty($param['id'])){
|
|
|
|
$param['project_id'] = $this->user['project_id'];
|
|
|
|
}
|
|
|
|
if(isset($param['category_id']) && !empty($param['category_id'])){
|
|
|
|
$param['category_id'] = $this->getLastCategory($param['category_id']);
|
|
|
|
}
|
|
|
|
return $this->success($param);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :查看是否编辑路由
|
|
|
|
* @name :editCategoryRoute
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 11:05
|
|
|
|
*/
|
|
|
|
public function editRoute($id, $route)
|
|
|
|
{
|
|
|
|
//生成一条删除路由记录
|
|
|
|
$info = $this->model->read(['id' => $id], ['id', 'route']);
|
|
|
|
if ($info['route'] != $route) {
|
|
|
|
$this->addUpdateNotify(RouteMap::SOURCE_MODULE.$this->param['module_id'],$route);
|
|
|
|
$this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取最后一级分类id
|
|
|
|
* @name :getLastCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/20 9:02
|
|
|
|
*/
|
|
|
|
public function getLastCategory($category){
|
|
|
|
$str = '';
|
|
|
|
$cateModel = new CustomModuleCategory();
|
|
|
|
foreach ($category as $v){
|
|
|
|
$info = $cateModel->read(['pid'=>$v]);
|
|
|
|
if($info === false){
|
|
|
|
$str .= $v.',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ','.$str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存扩展字段
|
|
|
|
* @name :saveExtend
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/9 15:02
|
|
|
|
*/
|
|
|
|
public function saveExtendInfo($content_id,$extend){
|
|
|
|
//先删除以前的数据
|
|
|
|
$extendInfoModel = new ExtendInfo();
|
|
|
|
$extendInfoModel->del(['content_id'=>$content_id]);
|
|
|
|
if(empty($extend)) {
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
foreach ($extend as $v){
|
|
|
|
if(empty($v['values'])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$v = $this->saveHandleExtend($v,$content_id);
|
|
|
|
$extendInfoModel->add($v);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存扩展字段时处理数据
|
|
|
|
* @name :saveHandleExtend
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 15:11
|
|
|
|
*/
|
|
|
|
public function saveHandleExtend(&$v,$content_id){
|
|
|
|
if($v['type'] == 3){
|
|
|
|
foreach ($v['values'] as $k1=>$v1){
|
|
|
|
$v1['url'] = str_replace_url($v1['url']);
|
|
|
|
$v['values'][$k1] = $v1;
|
|
|
|
}
|
|
|
|
$v['values'] = json_encode($v['values']);
|
|
|
|
}elseif ($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['content_id'] = $content_id;
|
|
|
|
return $this->success($v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -54,7 +292,34 @@ class CustomModuleContentLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/4 15:47
|
|
|
|
*/
|
|
|
|
public function customModuleContentDel(){
|
|
|
|
public function contentDel(){
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
foreach ($this->param['id'] as $id) {
|
|
|
|
$this->delRoute($id);
|
|
|
|
$this->model->del(['id' => $id]);
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('系统错误,请联系管理员');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除路由
|
|
|
|
* @name :delRoute
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 10:50
|
|
|
|
*/
|
|
|
|
public function delRoute($id)
|
|
|
|
{
|
|
|
|
RouteMap::delRoute(RouteMap::SOURCE_MODULE.$this->param['module_id'], $id, $this->user['project_id']);
|
|
|
|
//通知
|
|
|
|
$info = $this->model->read(['id' => $id], ['id', 'url']);
|
|
|
|
$this->curlDelRoute(['route'=>$info['url']]);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|