Sys.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * @param type $data
  54. */
  55. public function saveInviteConfig($data){
  56. $save=[
  57. "img" => empty($data["img"]) ? "" : $data["img"],
  58. ];
  59. $this->where("id",1)->update(["inviteconfig"=> serialize($save)]);
  60. }
  61. /**
  62. * 获取配置详情
  63. * @return type
  64. */
  65. public function getDataInfo($code=""){
  66. $sys = $this->where("id", 1)->find();
  67. //微信配置
  68. $wxconfig=[
  69. "appid"=>"",
  70. "secret"=>"",
  71. "mchid"=>"",
  72. "apiv2key"=>"",
  73. "apiclient_key"=>"",
  74. "apiclient_cert"=>"",
  75. "notify_url"=>""
  76. ];
  77. if(!empty($sys->wxconfig)){
  78. $wxconfig = unserialize($sys->wxconfig);
  79. }
  80. //分享配置
  81. $shareconfig=[
  82. "img"=>"",
  83. "title"=>"",
  84. "query"=>"",
  85. "content"=>"",
  86. ];
  87. if(!empty($sys->shareconfig)){
  88. $shareconfig = unserialize($sys->shareconfig);
  89. }
  90. //邀请配置
  91. $inviteconfig=[
  92. "img"=>"",
  93. ];
  94. if(!empty($sys->inviteconfig)){
  95. $inviteconfig = unserialize($sys->inviteconfig);
  96. }
  97. if($code=="weixin"){
  98. return $wxconfig;
  99. }
  100. if($code=="share"){
  101. return $shareconfig;
  102. }
  103. if($code=="invite"){
  104. return $inviteconfig;
  105. }
  106. $data = $sys->toArray();
  107. $data["wxconfig"] = $wxconfig;
  108. $data["shareconfig"] = $shareconfig;
  109. $data["inviteconfig"] = $inviteconfig;
  110. return $data;
  111. }
  112. /**
  113. * 获取微信配置
  114. * @return bool
  115. */
  116. public function getWeixinConfig(){
  117. $data = $this->getDataInfo("weixin");
  118. foreach($data as $k=>$v){
  119. if(empty($v)){
  120. return false;
  121. }
  122. }
  123. $return=[
  124. "APPID" => $data["appid"],
  125. "APPSECRET" => $data["secret"],
  126. "MCHID" => $data["mchid"],
  127. "ApiV2Key" => $data["apiv2key"],
  128. "ApiclientKey" => "file://".app()->getRootPath()."/".trim($data["apiclient_key"],"/"),
  129. "ApiclientCert" => "file://".app()->getRootPath()."/".trim($data["apiclient_cert"],"/"),
  130. "NOTIFY_URL" => $data["notify_url"],
  131. ];
  132. return $return;
  133. }
  134. }