Sys.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. ];
  48. $this->where("id",1)->update(["shareconfig"=> serialize($save)]);
  49. }
  50. /**
  51. * 获取配置详情
  52. * @return type
  53. */
  54. public function getDataInfo($code=""){
  55. $sys = (new SysModel)->where("id", 1)->find();
  56. $data = $sys->toArray();
  57. //微信配置
  58. if(empty($data["wxconfig"])){
  59. $data["wxconfig"]=[
  60. "appid"=>"",
  61. "secret"=>"",
  62. "mchid"=>"",
  63. "apiv2key"=>"",
  64. "apiclient_key"=>"",
  65. "apiclient_cert"=>"",
  66. "notify_url"=>""
  67. ];
  68. }else{
  69. $data["wxconfig"] = unserialize($data["wxconfig"]);
  70. }
  71. //分享配置
  72. if(empty($data["shareconfig"])){
  73. $data["shareconfig"]=[
  74. "img"=>"",
  75. "title"=>"",
  76. "query"=>"",
  77. ];
  78. }else{
  79. $data["shareconfig"] = unserialize($data["wxconfig"]);
  80. }
  81. if($code=="weixin"){
  82. return $data["wxconfig"];
  83. }
  84. if($code=="share"){
  85. return $data["shareconfig"];
  86. }
  87. return $data;
  88. }
  89. }