123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace app\controller\admin;
- use app\service\ConfServiceFacade;
- use laytp\controller\Backend;
- use laytp\library\CommonFun;
- use laytp\library\UploadDomain;
- use app\service\api\MiniappServiceFacade;
- use think\facade\Db;
- /**
- * 系统配置控制器
- * Class Conf
- * @package app\admin\controller
- */
- class Conf extends Backend
- {
- protected $model;
- protected $noNeedAuth = ['getGroupConf', 'saveGroupConf'];
- public function _initialize()
- {
- $this->model = new \app\model\Conf();
- }
- /**
- * 获取某个分组下所有的配置项
- */
- public function getGroupConf()
- {
- $group = $this->request->param('group');
- $return = ConfServiceFacade::groupGet($group, true);
- return $this->success('获取成功', $return);
- }
- /**
- * 保存配置
- */
- public function saveGroupConf()
- {
- global $_W;
- // $data = \app\model\Conf::where(['group'=>'system.wechat'])->select()->toArray();
- // if(!empty($data[0]['uniacid']) && $data[0]['uniacid'] != $_W['uniacid']){
- // return $this->error('系统只支持单开');
- // }
- $post = $this->request->post();
- if (isset($post['laytpUploadFile'])) {
- unset($post['laytpUploadFile']);
- }
- $group = $post['group'];
- unset($post['group']);
- $formType = $post['form_type'];
- unset($post['form_type']);
- $allConf = [];
- foreach ($post as $key => $value) {
- if (is_array($value)) {
- $temp = [];
- foreach ($value['key'] as $arrK => $arrV) {
- if ($arrV) {
- $temp[$arrV] = $value['value'][$arrK];
- }
- }
- $value = $temp;
- }
- $conf['group'] = $group;
- $conf['key'] = $key;
- $conf['value'] = $value;
- $conf['form_type'] = $formType[$key];
- $conf['uniacid'] = $_W['uniacid'];
- $allConf[] = $conf;
- }
- ConfServiceFacade::groupSet($allConf);
- return $this->success('保存成功', $allConf);
- }
- /**
- * 删除某个分组下某个key的配置信息
- * 这个不在配置页面进行调用,后续要做生成工具的时候统一管理所有的key
- */
- public function del()
- {
- $group = $this->request->param('group');
- $key = $this->request->param('key');
- ConfServiceFacade::del($group, $key);
- return $this->success('删除成功');
- }
- public function getSystemWords()
- {
- $Filter = new \ins\Words('*');
- $words = $Filter->getWords();
- return $this->success('获取成功',$words);
- }
- // 获得公众号链接
- public function wechatLinkInfo()
- {
- global $_W;
- // print_r($_SERVER);
- $site = $_SERVER['HTTP_ORIGIN'];
- $link = $site . SURL . 'h5/?uniacid=' . $_W['uniacid'];
- return $this->success('获取成功',$link);
- }
- // 获得大数据链接
- public function bigdataLinkInfo()
- {
- global $_W;
- $site = $_SERVER['HTTP_ORIGIN'];
- $link = $site . SURL . '/bigdata?uniacid=' . $_W['uniacid'];
- return $this->success('获取成功',$link);
- }
- // 获得公众号二维码
- public function wechatQrcode()
- {
- global $_W; //获取二维码生成的地址
- }
- // 获得小程序链接
- public function miniappQrcode()
- {
- global $_W;
- $conf = ConfServiceFacade::groupGet('system.miniapp', true);
- if(!$conf['appid'] || !$conf['appsecret']){
- return $this->error('操作失败');
- }
- $app = MiniappServiceFacade::option();
- $response = $app->app_code->get('pages/index/index', [
- 'width' => 600,
- 'line_color' => [
- 'r' => 105,
- 'g' => 166,
- 'b' => 134,
- ],
- ]);
- if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
- $time = time();
- $filename = $response->saveAs(IA_ROOT_WK.'/public/static/storage/presets/', $time.'appcode.png');
- }
- return $this->success('获取成功',request()->domain() . STATIC_PATH . '/storage/presets/' . $time.'appcode.png');
- }
- // 获得订阅消息
- public function miniappNotification()
- {
- $conf = ConfServiceFacade::groupGet('system.notification', true);
- $tid = $this->request->param('tid');
- $app = MiniappServiceFacade::option();
- // print_r($app->subscribe_message->getTemplateKeywords($tid));
- // return;
- switch($tid){
- case 2039:
- $kidList = [1,4,10,11,12];
- break;
- case 1185:
- $kidList = [2,3,7,16];
- break;
- case 786:
- $kidList = [1,2,7,15,4];
- break;
- case 10291:
- $kidList = [1,2,3];
- break;
- }
- $sceneDesc = '订阅';
- $res = $app->subscribe_message->addTemplate($tid, $kidList, $sceneDesc);
- return $this->success('获取成功',$res);
- }
- }
|