Index.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Author: DOUBLE Y
* Date: 2019/3/12 16:49
* Email: 731633799@qq.com
*/
namespace addons\voicenotice\controller;
use addons\voicenotice\library\Voice;
use app\admin\library\Auth;
use think\Lang;
use think\Validate;
use think\addons\Controller;
use app\admin\model\AuthGroup;
use app\admin\model\Admin;
class Index extends Controller
{
protected $noNeedRight = ['index'];
private $admin_auth = null;
protected $lang = 'auth';
public function _initialize()
{
$this->admin_auth = Auth::instance();
if (!$this->admin_auth->isLogin()) {
$this->error("请先登录管理后台", "");
}
Lang::load(APP_PATH . "admin" . '/lang/' . $this->request->langset() . '.php');
$list = AuthGroup::all();
$list = collection($list)->toArray();
$admin = Admin::all();
$admin = collection($admin)->toArray();
$this->assign("list", $list);
$this->assign("admin", $admin);
}
public function index()
{
if ($this->request->isPost()) {
$post = $this->request->post();
!isset($post['admin']) && !isset($post['group']) && $this->error("管理员/管理组请至少选择一项",
addon_url('voicenotice/index/index'));
$text = $post['text'];
$rule = [
'text' => 'require|length:2,100',
];
$msg = [
'text.require' => '消息不能为空',
'text.length' => '消息内容在2-100之间',
];
$data = [
'text' => $text,
'admin' => !isset($post['admin']) ? false : $post['admin'],
'group' => !isset($post['group']) ? false : $post['group']
];
$validate = new Validate($rule, $msg);
$result = $validate->check($data);
if (!$result) {
$this->error(__($validate->getError()));
}
empty($post['loop']) && $post['loop'] = true;
$worker = Voice::init();
if ($post['url_type'] == "open") {
$worker->open($post['url']);
}
if ($post['url_type'] == "addtabs") {
$worker->addtabs($post['url']);
}
$worker = $worker->admin($data['admin'])->group($data['group'])->loop($post['loop'])->send($data['text']);
if (!$worker) {
$this->error("提交失败", addon_url('voicenotice/index/index'));
}
$this->success("提交成功", addon_url('voicenotice/index/index'));
}
return $this->view->fetch();
}
}