Conf.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace app\controller\admin;
  3. use app\service\ConfServiceFacade;
  4. use laytp\controller\Backend;
  5. use laytp\library\CommonFun;
  6. use laytp\library\UploadDomain;
  7. use app\service\api\MiniappServiceFacade;
  8. use think\facade\Db;
  9. /**
  10. * 系统配置控制器
  11. * Class Conf
  12. * @package app\admin\controller
  13. */
  14. class Conf extends Backend
  15. {
  16. protected $model;
  17. protected $noNeedAuth = ['getGroupConf', 'saveGroupConf'];
  18. public function _initialize()
  19. {
  20. $this->model = new \app\model\Conf();
  21. }
  22. /**
  23. * 获取某个分组下所有的配置项
  24. */
  25. public function getGroupConf()
  26. {
  27. $group = $this->request->param('group');
  28. $return = ConfServiceFacade::groupGet($group, true);
  29. return $this->success('获取成功', $return);
  30. }
  31. /**
  32. * 保存配置
  33. */
  34. public function saveGroupConf()
  35. {
  36. global $_W;
  37. // $data = \app\model\Conf::where(['group'=>'system.wechat'])->select()->toArray();
  38. // if(!empty($data[0]['uniacid']) && $data[0]['uniacid'] != $_W['uniacid']){
  39. // return $this->error('系统只支持单开');
  40. // }
  41. $post = $this->request->post();
  42. if (isset($post['laytpUploadFile'])) {
  43. unset($post['laytpUploadFile']);
  44. }
  45. $group = $post['group'];
  46. unset($post['group']);
  47. $formType = $post['form_type'];
  48. unset($post['form_type']);
  49. $allConf = [];
  50. foreach ($post as $key => $value) {
  51. if (is_array($value)) {
  52. $temp = [];
  53. foreach ($value['key'] as $arrK => $arrV) {
  54. if ($arrV) {
  55. $temp[$arrV] = $value['value'][$arrK];
  56. }
  57. }
  58. $value = $temp;
  59. }
  60. $conf['group'] = $group;
  61. $conf['key'] = $key;
  62. $conf['value'] = $value;
  63. $conf['form_type'] = $formType[$key];
  64. $conf['uniacid'] = $_W['uniacid'];
  65. $allConf[] = $conf;
  66. }
  67. ConfServiceFacade::groupSet($allConf);
  68. return $this->success('保存成功', $allConf);
  69. }
  70. /**
  71. * 删除某个分组下某个key的配置信息
  72. * 这个不在配置页面进行调用,后续要做生成工具的时候统一管理所有的key
  73. */
  74. public function del()
  75. {
  76. $group = $this->request->param('group');
  77. $key = $this->request->param('key');
  78. ConfServiceFacade::del($group, $key);
  79. return $this->success('删除成功');
  80. }
  81. public function getSystemWords()
  82. {
  83. $Filter = new \ins\Words('*');
  84. $words = $Filter->getWords();
  85. return $this->success('获取成功',$words);
  86. }
  87. // 获得公众号链接
  88. public function wechatLinkInfo()
  89. {
  90. global $_W;
  91. // print_r($_SERVER);
  92. $site = $_SERVER['HTTP_ORIGIN'];
  93. $link = $site . SURL . 'h5/?uniacid=' . $_W['uniacid'];
  94. return $this->success('获取成功',$link);
  95. }
  96. // 获得大数据链接
  97. public function bigdataLinkInfo()
  98. {
  99. global $_W;
  100. $site = $_SERVER['HTTP_ORIGIN'];
  101. $link = $site . SURL . '/bigdata?uniacid=' . $_W['uniacid'];
  102. return $this->success('获取成功',$link);
  103. }
  104. // 获得公众号二维码
  105. public function wechatQrcode()
  106. {
  107. global $_W; //获取二维码生成的地址
  108. }
  109. // 获得小程序链接
  110. public function miniappQrcode()
  111. {
  112. global $_W;
  113. $conf = ConfServiceFacade::groupGet('system.miniapp', true);
  114. if(!$conf['appid'] || !$conf['appsecret']){
  115. return $this->error('操作失败');
  116. }
  117. $app = MiniappServiceFacade::option();
  118. $response = $app->app_code->get('pages/index/index', [
  119. 'width' => 600,
  120. 'line_color' => [
  121. 'r' => 105,
  122. 'g' => 166,
  123. 'b' => 134,
  124. ],
  125. ]);
  126. if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
  127. $time = time();
  128. $filename = $response->saveAs(IA_ROOT_WK.'/public/static/storage/presets/', $time.'appcode.png');
  129. }
  130. return $this->success('获取成功',request()->domain() . STATIC_PATH . '/storage/presets/' . $time.'appcode.png');
  131. }
  132. // 获得订阅消息
  133. public function miniappNotification()
  134. {
  135. $conf = ConfServiceFacade::groupGet('system.notification', true);
  136. $tid = $this->request->param('tid');
  137. $app = MiniappServiceFacade::option();
  138. // print_r($app->subscribe_message->getTemplateKeywords($tid));
  139. // return;
  140. switch($tid){
  141. case 2039:
  142. $kidList = [1,4,10,11,12];
  143. break;
  144. case 1185:
  145. $kidList = [2,3,7,16];
  146. break;
  147. case 786:
  148. $kidList = [1,2,7,15,4];
  149. break;
  150. case 10291:
  151. $kidList = [1,2,3];
  152. break;
  153. }
  154. $sceneDesc = '订阅';
  155. $res = $app->subscribe_message->addTemplate($tid, $kidList, $sceneDesc);
  156. return $this->success('获取成功',$res);
  157. }
  158. }