You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.4 KiB

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 10/3/2019
* Time: 4:42 PM
*/
namespace app\admin\controller;
use app\admin\model\User as UserModel;
use app\admin\model\User_Role;
use app\admin\model\ViewHistory as ViewHistoryModel;
use app\admin\model\WebStatus;
use think\Controller;
use think\Request;
use think\Session;
use app\admin\model\Advertisement as AdvertisementModel;
use app\admin\model\Role_Permission as Role_PermissionModel;
use app\lib\exception\HtmlException;
use app\service\InfoForViewHistory;
class Index extends BaseController
{
public function index(){
Session::get('id');
$user = UserModel::where('id', '=', Session::get('id'))->find();
$getRole =User_Role::where(['user_id'=>$user['id']])->find();
$this->assign('role_id', $getRole['role_id']);
$this->assign('user', $user['name']);
return $this->fetch();
}
public function welcome(){
//用户名
$user = UserModel::where('id', '=', Session::get('id'))->find();
//工作人员数
$users = UserModel::where(1)->select();
$count = count($users);
//今日挂号数
$todayStart = strtotime(date("Y-m-d",time()));
$todayNow = time();
$todayView = \app\admin\model\Register::where('date','between',[$todayStart,$todayNow])->select();
$todayCount = count($todayView);
//本月挂号数
$monthStart = strtotime(date("Y-m",time()));
$monthEnd = time();
$monthView = \app\admin\model\Register::where('date','between',[$monthStart,$monthEnd])->select();
$monthCount = count($monthView);
//公告
$advertise = AdvertisementModel::where(1)->select();
$this->assign('user', $user['name']);
$this->assign('dayCount', $todayCount);
$this->assign('MonthCount', $monthCount);
$this->assign('count', $count);
$this->assign('advertise', $advertise);
return $this->fetch();
}
//增加公告
public function addAdvertisement(){
$roleId = Session::get('roleId');
if ($roleId!=1){
throw new HtmlException('您没有权限进行该操作!');
}
if (Request::instance()->isPost()){
$input = Request::instance()->post();
$data = [
'content' => $input['addAdvertisement'],
];
$result = AdvertisementModel::create($data);
if (!$result){
throw new HtmlException('添加失败!');
}else {
$this->success('添加成功!');
}
}
return $this->fetch();
}
public function delAdvertisement(){
$roleId = Session::get('roleId');
if ($roleId!=1){
throw new HtmlException('您没有权限进行该操作!');
}
$contents = AdvertisementModel::where(1)->select();
$this->assign('contents',$contents);
return $this->fetch();
}
public function delAdvertisementHandle(){
$input = Request::instance()->param();
$result = AdvertisementModel::where('id','=',$input['id'])->delete();
if (!$result){
throw new HtmlException('删除失败!');
}else {
$this->success('删除成功!');
}
}
}