lizhen_gitee 1 gadu atpakaļ
vecāks
revīzija
09e4cbc0b3

+ 35 - 0
application/api/controller/News.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 咨询新闻
+ */
+class News extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    public function lists(){
+        $list = Db::name('news')->field('content',true)->where('is_show',1)->order('weigh desc,id desc')->autopage()->select();
+        $list = list_domain_image($list,['image']);
+
+        $this->success('success',$list);
+    }
+    
+    public function info(){
+        $id = input('id',0);
+        if(!$id){
+            $this->error();
+        }
+
+        $info = Db::name('news')->where('id',$id)->find();
+        $info = info_domain_image($info,['image']);
+
+        $this->success('success',$info);
+    }
+
+
+}

+ 6 - 6
application/common.php

@@ -543,24 +543,25 @@ function info_domain_image($data,$field){
     }
     foreach($data as $key => $val){
         if(in_array($key,$field)){
-            $data[$key] = one_domain_image($val);
+            $more = strpos($key,'images');
+            $data[$key] = one_domain_image($val,$more);
         }
     }
     return $data;
 }
 //支持单个字段,需要增加domain_cdnurl
 //支持image,images
-function one_domain_image($one){
+function one_domain_image($one,$more = false){
     if(!$one){
         return $one;
     }
-    if(strpos($one,',')){
+    if(strpos($one,',') || $more !== false){
         //逗号隔开的多个图片
         $one = explode(',',$one);
         foreach($one as $k => $v){
             $one[$k] = localpath_to_netpath($v);
         }
-        $one = implode(',',$one);
+//        $one = implode(',',$one);
     }else{
         $one = localpath_to_netpath($one);
     }
@@ -574,10 +575,9 @@ function localpath_to_netpath($path)
     } elseif (strrpos($path, 'http') !== false) {
         return $path;
     } else {
-        return config('site.domain_cdnurl') . str_replace("\\", "/", $path);
+        return config('domain_cdnurl') . str_replace("\\", "/", $path);
     }
 }
-
 //秒 转换 日月分
 function Sec2Time($time){
     if(is_numeric($time)){

+ 3 - 0
application/config.php

@@ -308,6 +308,9 @@ return [
     //注册用户默认头像
     'default_avatar'=> 'https://zucheapp.oss-cn-hangzhou.aliyuncs.com/uploads/20230309/ca004cf1d9cd67cf420b5c35c1bbd37a.png',
 
+    //图片地址
+    'domain_cdnurl' => 'http://mingxiang.huxiukeji.cn',
+
     //小程序
     'wxMiniProgram' => [
         'appid'=>'wxfbf1d5e8ade16b4d', //公司测试