|
...
|
...
|
@@ -32,4 +32,124 @@ class News extends Base |
|
|
|
public function getRelatedProductIdAttribute($value){
|
|
|
|
return Arr::setToArr($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :扩展字段根据type返回类型
|
|
|
|
* @name :setTypValues
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 14:43
|
|
|
|
*/
|
|
|
|
public function getExtendInfo($news_id){
|
|
|
|
$extendModel = new NewsExtend();
|
|
|
|
$list = $extendModel->list([],'id',['id','type','key','title']);
|
|
|
|
if(empty($list)){
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
$extendInfoModel = new NewsExtendInfo();
|
|
|
|
$infoList = $extendInfoModel->list(['news_id'=>$news_id],'created_at');
|
|
|
|
foreach ($list as $k=>$v){
|
|
|
|
if($v['type'] == 3 || $v['type'] == 4){
|
|
|
|
$v['values'] = [];
|
|
|
|
}else{
|
|
|
|
$v['values'] = '';
|
|
|
|
}
|
|
|
|
if(!empty($infoList)){
|
|
|
|
foreach ($infoList as $values){
|
|
|
|
if($v['key'] == $values['key']){
|
|
|
|
$v = $this->setTypValues($v,$values);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$list[$k] = $v;
|
|
|
|
}
|
|
|
|
return $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'],$this->user['storage_type'],$this->user['project_location']);
|
|
|
|
$arr[$k1] = $v1;
|
|
|
|
}
|
|
|
|
$v['values'] = $arr;
|
|
|
|
}elseif($v['type'] == 4){
|
|
|
|
$arr1 = json_decode($info['values']);
|
|
|
|
foreach ($arr1 as $k1=>$v1){
|
|
|
|
$v1 = (array)$v1;
|
|
|
|
if(isset($v1['url'])){
|
|
|
|
$v1['url'] = getFileUrl($v1['url'],$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0);
|
|
|
|
}else{
|
|
|
|
$v1 = getFileUrl($v1,$this->user['storage_type'],$this->user['project_location'],$this->user['file_cdn'] ?? 0);
|
|
|
|
}
|
|
|
|
$arr1[$k1] = $v1;
|
|
|
|
}
|
|
|
|
$v['values'] = $arr1;
|
|
|
|
}else{
|
|
|
|
$v['values'] = $info['values'];
|
|
|
|
}
|
|
|
|
return $v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存扩展字段
|
|
|
|
* @name :saveExtend
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/9 15:02
|
|
|
|
*/
|
|
|
|
public function saveExtendInfo($news_id,$extend){
|
|
|
|
//先删除以前的数据
|
|
|
|
$extendInfoModel = new NewsExtendInfo();
|
|
|
|
$extendInfoModel->del(['news_id'=>$news_id]);
|
|
|
|
if(empty($extend)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
foreach ($extend as $k => $v){
|
|
|
|
if(empty($v['values'])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$v = $this->saveHandleExtend($v,$news_id);
|
|
|
|
$extendInfoModel->add($v);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存扩展字段时处理数据
|
|
|
|
* @name :saveHandleExtend
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 15:11
|
|
|
|
*/
|
|
|
|
public function saveHandleExtend(&$v,$news_id){
|
|
|
|
unset($v['title']);
|
|
|
|
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['url'] = str_replace_url($v1['url']);
|
|
|
|
$v['values'][$k1] = $v1;
|
|
|
|
}
|
|
|
|
$v['values'] = json_encode($v['values']);
|
|
|
|
}
|
|
|
|
$v['project_id'] = $this->user['project_id'];
|
|
|
|
$v['news_id'] = $news_id;
|
|
|
|
return $v;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|