Sys.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. var_dump(serialize($save));
  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. ];
  79. }else{
  80. $data["shareconfig"] = unserialize($data["wxconfig"]);
  81. }
  82. if($code=="weixin"){
  83. return $data["wxconfig"];
  84. }
  85. if($code=="share"){
  86. return $data["shareconfig"];
  87. }
  88. return $data;
  89. }
  90. }