Sys.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  4. use library\basic\BaseModel;
  5. use library\traits\JwtAuthModelTrait;
  6. use library\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * @mixin \think\Model
  10. */
  11. class Sys extends Model
  12. {
  13. use ModelTrait;
  14. use JwtAuthModelTrait;
  15. /**
  16. * 保存数据
  17. * @param $save
  18. */
  19. public function saveSys($save) {
  20. $this->where('id',1)->save($save);
  21. }
  22. /**
  23. * 微信配置信息
  24. * @param type $data
  25. */
  26. public function saveWxConfig($data){
  27. $save=[
  28. "appid" => empty($data["appid"])?"":$data["appid"],
  29. "secret" => empty($data["secret"])?"":$data["secret"],
  30. "mchid" => empty($data["mchid"])?"":$data["mchid"],
  31. "apiv2key" => empty($data["apiv2key"])?"":$data["apiv2key"],
  32. "apiclient_key" => empty($data["apiclient_key"])?"":$data["apiclient_key"],
  33. "apiclient_cert" => empty($data["apiclient_cert"])?"":$data["apiclient_cert"],
  34. "notify_url" => empty($data["notify_url"])?"":$data["notify_url"],
  35. ];
  36. $this->where("id",1)->update(["wxconfig"=> serialize($save)]);
  37. }
  38. /**
  39. * 分享配置信息
  40. * @param type $data
  41. */
  42. public function saveShareConfig($data){
  43. $save=[
  44. "img" => empty($data["img"]) ?"":$data["img"],
  45. "title" => empty($data["title"])?"":$data["title"],
  46. "query" => empty($data["query"])?"":$data["query"],
  47. "content" => empty($data["content"])?"":$data["content"],
  48. ];
  49. $this->where("id",1)->update(["shareconfig"=> serialize($save)]);
  50. }
  51. /**
  52. * 获取配置详情
  53. * @return type
  54. */
  55. public function getDataInfo($code=""){
  56. $sys = $this->where("id", 1)->find();
  57. $data = $sys->toArray();
  58. //微信配置
  59. if(empty($data["wxconfig"])){
  60. $data["wxconfig"]=[
  61. "appid"=>"",
  62. "secret"=>"",
  63. "mchid"=>"",
  64. "apiv2key"=>"",
  65. "apiclient_key"=>"",
  66. "apiclient_cert"=>"",
  67. "notify_url"=>""
  68. ];
  69. }else{
  70. // $data["wxconfig"] = unserialize($data["wxconfig"]);
  71. }
  72. //分享配置
  73. if(empty($data["shareconfig"])){
  74. $data["shareconfig"]=[
  75. "img"=>"",
  76. "title"=>"",
  77. "query"=>"",
  78. "content"=>"",
  79. ];
  80. }else{
  81. // $data["shareconfig"] = unserialize($data["wxconfig"]);
  82. }
  83. if($code=="weixin"){
  84. return $data["wxconfig"];
  85. }
  86. if($code=="share"){
  87. return $data["shareconfig"];
  88. }
  89. return $data;
  90. }
  91. }