<?php

namespace app\notify\controller;

use app\common\controller\Frontend;
use think\Db;
class Sms extends Frontend
{

    protected $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $layout = '';
    
    public function _initialize()
    {
        parent::_initialize();

        $this->model = new \app\admin\model\reservoir\Sms;
    }
    public function seting()
    {
        $list = $this->model::all();
        $this->view->assign('list',$list);
        return $this->view->fetch();
    }
        
    public function sendmsg($ids=null)
    {
        if ($this->request->isPost()) {
            $params = $this->request->post();
            $mobile = $params['mobile'];
            $code = $params['code'];
            $data = $params['data'];
            $res = \app\common\library\Sms::notice($mobile, $data, $code);
            dump($res);
        }
        $sms  = $this->model::get($ids);
        if (!$sms) {
            $this->error('短信模板不存在');
        }
        preg_match_all('/\${.*?}/', $sms->message, $matches);
        $smsvar = $matches[0];
        $values = [];
        foreach ($smsvar as $key=>$item) {
            $values[] = str_replace(['${', '}'], '', $item);
        }
        $this->view->assign([
            'smsvar'=> $values,
            'sms' => $sms
        ]);
        return $this->view->fetch();
    }
    
    
}