Sys.php 5.3 KB

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