yingzi 2 rokov pred
rodič
commit
a338e473a5
2 zmenil súbory, kde vykonal 88 pridanie a 21 odobranie
  1. 67 0
      app/model/api/Sys.php
  2. 21 21
      app/system/controller/Sys.php

+ 67 - 0
app/model/api/Sys.php

@@ -22,4 +22,71 @@ class Sys extends Model
     public function saveSys($save) {
         $this->where('id',1)->save($save);
     }
+    /**
+     * 微信配置信息
+     * @param type $data
+     */
+    public function saveWxConfig($data){
+        $save=[
+            "appid"          => empty($data["appid"])?"":$data["appid"],
+            "secret"         => empty($data["secret"])?"":$data["secret"],
+            "mchid"          => empty($data["mchid"])?"":$data["mchid"],
+            "apiv2key"       => empty($data["apiv2key"])?"":$data["apiv2key"],
+            "apiclient_key"  => empty($data["apiclient_key"])?"":$data["apiclient_key"],
+            "apiclient_cert" => empty($data["apiclient_cert"])?"":$data["apiclient_cert"],
+            "notify_url"     => empty($data["notify_url"])?"":$data["notify_url"],
+        ];
+        $this->where("id",1)->update(["wxconfig"=> serialize($save)]);
+    }
+    /**
+     * 分享配置信息
+     * @param type $data
+     */
+    public function saveShareConfig($data){
+        $save=[
+            "img"   => empty($data["img"])  ?"":$data["img"],
+            "title" => empty($data["title"])?"":$data["title"],
+            "query" => empty($data["query"])?"":$data["query"],
+        ];
+        $this->where("id",1)->update(["shareconfig"=> serialize($save)]);
+    }
+    /**
+     * 获取配置详情
+     * @return type
+     */
+    public function getDataInfo($code=""){
+        $sys = (new SysModel)->where("id", 1)->find();
+        $data = $sys->toArray();
+        //微信配置
+        if(empty($data["wxconfig"])){
+            $data["wxconfig"]=[
+                "appid"=>"",
+                "secret"=>"",
+                "mchid"=>"",
+                "apiv2key"=>"",
+                "apiclient_key"=>"",
+                "apiclient_cert"=>"",
+                "notify_url"=>""
+            ];
+        }else{
+            $data["wxconfig"] = unserialize($data["wxconfig"]);
+        }
+        //分享配置
+        if(empty($data["shareconfig"])){
+            $data["shareconfig"]=[
+                "img"=>"",
+                "title"=>"",
+                "query"=>"",
+            ];
+        }else{
+            $data["shareconfig"] = unserialize($data["wxconfig"]);
+        }
+        if($code=="weixin"){
+            return $data["wxconfig"];
+        }
+        if($code=="share"){
+            return $data["shareconfig"];
+        }
+        return $data;
+    }
 }

+ 21 - 21
app/system/controller/Sys.php

@@ -26,25 +26,14 @@ class Sys extends BaseController
      * 基本设置
      */
     public function index(){
-        $sys = (new SysModel)->where("id", 1)->find();
-        $data = $sys->toArray();
-        
-        if(empty($data["wxconfig"])){
-            $data["wxconfig"]=[
-                "appid"=>"",
-                "secret"=>"",
-                "mchid"=>"",
-                "apiv2key"=>"",
-                "apiclient_key"=>"",
-                "apiclient_cert"=>"",
-                "notify_url"=>""
-            ];
-        }else{
-            $data["wxconfig"] = unserialize($data["wxconfig"]);
-        }
-        return app('json')->success($data);
+        $sys = (new SysModel)->getDataInfo();
+        return app('json')->success($sys);
     }
-    public function wxsave(){
+    /**
+     * 微信配置
+     * @return type
+     */
+    public function wxSave(){
         $post = UtilService::getMore([
             ['appid', ''],
             ['secret', ''],
@@ -54,9 +43,20 @@ class Sys extends BaseController
             ['apiclient_cert', ''],
             ['notify_url', ''],
         ], $request);
-        $save=[];
-        $save['wxconfig']= serialize($post);
-        (new SysModel())->saveSys($save);
+        (new SysModel())->saveWxConfig($post);
+        return app('json')->success("数据保存成功");
+    }
+    /**
+     * 分享配置
+     * @return type
+     */
+    public function shareSave(){
+        $post = UtilService::getMore([
+            ['title', ''],
+            ['img', ''],
+            ['query', ''],
+        ], $request);
+        (new SysModel())->saveShareConfig($post);
         return app('json')->success("数据保存成功");
     }
     /**