Sys.php 4.8 KB

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