91 行
3.3 KiB
PHP
91 行
3.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace addons\official\controller\web;
|
|
|
|
|
|
use addons\official\model\OfficialListOnlineMessage;
|
|
use think\Request;
|
|
use think\Validate;
|
|
|
|
class OfficialOnlineMessage extends OfficialBaseController
|
|
{
|
|
protected $model;
|
|
protected $noNeedLogin = '*';
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function __construct(Request $request = null)
|
|
{
|
|
$this->model = new OfficialListOnlineMessage();
|
|
parent::__construct($request);
|
|
}
|
|
|
|
/**
|
|
* 详情
|
|
*/
|
|
public function list()
|
|
{
|
|
$id = (int)input('param.sid');
|
|
if (!$id) {
|
|
$this->error('栏目必须存在');
|
|
}
|
|
$this->setBasic();
|
|
//查詢父级
|
|
$res = $this->get_cate_pid_in_sid();
|
|
if ($this->request->isPost()) {
|
|
$token = $this->request->post('__token__');
|
|
//验证Token
|
|
if (!$token || !\think\Validate::is($token, "token", ['__token__' => $token])) {
|
|
return json_encode(['code' => 0, 'msg' => '请先登录!']);
|
|
}
|
|
$user_register_captcha = config('fastadmin.user_register_captcha');
|
|
$param = input('param.');
|
|
$rule = [
|
|
"name" => 'require',
|
|
"phone" => 'require',
|
|
"title" => 'require',
|
|
"content" => 'require',
|
|
];
|
|
$msg = [
|
|
"name.require" => __l('online_message', 'Name') . __l('index', 'No_empty'),
|
|
"phone.require" => __l('online_message', 'Phone') . __l('index', 'No_empty'),
|
|
"title.require" => __l('online_message', 'Title') . __l('index', 'No_empty'),
|
|
"content.require" => __l('online_message', 'Content') . __l('index', 'No_empty'),
|
|
];
|
|
$data = [
|
|
"name" => $param['name'],
|
|
"phone" => $param['phone'],
|
|
"title" => $param['title'],
|
|
"content" => $param['content'],
|
|
"official_category_id" => $id,
|
|
"weigh" => time()
|
|
];
|
|
if ($user_register_captcha == 'text'){
|
|
$rule['captcha'] = 'require|captcha';
|
|
$msg['captcha.require'] = __l('index', 'Captcha') . __l('index', 'No_empty');
|
|
$msg['captcha.captcha'] = __l('index', 'The verification code is incorrect');
|
|
$data['captcha'] = $param['captcha'];
|
|
}
|
|
//验证规则
|
|
$validate = new Validate($rule, $msg);
|
|
$result = $validate->check($data);
|
|
if (!$result) {
|
|
return json_encode(['code' => 0, 'msg' => $validate->getError()]);
|
|
}
|
|
if (!empty($data['captcha'])){
|
|
unset($data['captcha']);
|
|
}
|
|
//增加数据
|
|
$official_list_form = $this->model->create($data);
|
|
if ($official_list_form) {
|
|
return json_encode(['code' => 1, 'msg' => __l('index', 'Submit successfully')]);
|
|
}
|
|
}
|
|
|
|
$this->view->assign('captchaType', config('fastadmin.user_register_captcha'));
|
|
return view("web/official_online_message/list{$this->Mobile}", compact('res'));
|
|
}
|
|
|
|
}
|