256 lines
7.7 KiB
PHP
256 lines
7.7 KiB
PHP
<?php
|
||
namespace app\master\controller;
|
||
|
||
use think\Controller;
|
||
use think\Db;
|
||
use think\Cache;
|
||
|
||
/**
|
||
* @title 管理员接口
|
||
* @description 管理员相关操作
|
||
* @group 管理员相关
|
||
*/
|
||
class Admin extends Controller
|
||
{
|
||
protected $admin_obj = '';
|
||
|
||
public function __construct(\think\Request $request = null) {
|
||
parent::__construct($request);
|
||
$this->admin_obj = Db::name('admin');
|
||
}
|
||
|
||
public function index()
|
||
{
|
||
|
||
}
|
||
|
||
/**
|
||
* @title 测试demo接口
|
||
* @description 接口说明
|
||
* @author 开发者
|
||
* @url /index/demo
|
||
* @method GET
|
||
*
|
||
* @header name:device require:1 default: desc:设备号
|
||
*
|
||
* @param name:id type:int require:1 default:1 other: desc:唯一ID
|
||
*
|
||
* @return name:名称
|
||
* @return mobile:手机号
|
||
* @return list_messages:消息列表@
|
||
* @list_messages message_id:消息ID content:消息内容
|
||
* @return object:对象信息@!
|
||
* @object attribute1:对象属性1 attribute2:对象属性2
|
||
* @return array:数组值#
|
||
* @return list_user:用户列表@
|
||
* @list_user name:名称 mobile:手机号 list_follow:关注列表@
|
||
* @list_follow user_id:用户id name:名称
|
||
*/
|
||
public function demo()
|
||
{
|
||
//接口代码
|
||
$device = $this->request->header('device');
|
||
echo json_encode(["code"=>200, "message"=>"success", "data"=>['device'=>$device]]);
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @title 管理员登陆
|
||
* @description 管理员登陆
|
||
* @author wangjinlei
|
||
* @url /master/Admin/login
|
||
* @method POST
|
||
*
|
||
*
|
||
* @param name:account type:string require:1
|
||
* @param name:password type:string require:1
|
||
*
|
||
* @return account:名称
|
||
* @return phone:手机号
|
||
* @return realname:真是姓名
|
||
* @return role:角色(0管理员1编辑)
|
||
*/
|
||
public function login(){
|
||
$data = $this->request->post();
|
||
$where['account'] = $data['account'];
|
||
$where['password'] = md5($data['password']);
|
||
$res = $this->admin_obj->where($where)->find();
|
||
if($res){
|
||
return json(['code'=>0,'msg'=>'','data'=>$res]);
|
||
}else{
|
||
return json(['code'=>1,'msg'=>'account or password error!']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @title 更改密码
|
||
* @description 更改密码
|
||
* @author wangjinlei
|
||
* @url /master/Admin/changepasswd
|
||
* @method POST
|
||
*
|
||
*
|
||
* @param name:account type:string require:1
|
||
* @param name:password type:string require:1
|
||
* @param name:new_password type:string require:1
|
||
* @param name:re_password type:string require:1
|
||
*
|
||
*/
|
||
public function changepasswd(){
|
||
$data = $this->request->post();
|
||
//验证密码是否一致
|
||
if($data['new_password']!=$data['re_password']){
|
||
return json(['code'=>1,'msg'=>'The two passwords do not match']);
|
||
}
|
||
//验证用户名密码是否正确
|
||
$check_res = $this->admin_obj->where('account',$data['account'])->where('password', md5($data['password']))->find();
|
||
if($check_res==null){
|
||
return json(['code'=>1,'msg'=>'account or password is error!']);
|
||
}
|
||
//修改逻辑
|
||
$this->admin_obj->where('account',$data['account'])->update(['password'=> md5($data['new_password'])]);
|
||
return json(['code'=>0,'msg'=>'success']);
|
||
}
|
||
|
||
/**
|
||
* @title 获取管理员信息
|
||
* @description 获取管理员信息
|
||
* @author wangjinlei
|
||
* @url /master/Admin/getAdminBase
|
||
* @method POST
|
||
*
|
||
*
|
||
* @param name:account type:string require:1
|
||
*
|
||
* @return account:名称
|
||
* @return phone:手机号
|
||
* @return realname:真实姓名
|
||
* @return role:角色(0管理员1编辑)
|
||
*/
|
||
public function getAdminBase(){
|
||
$data = $this->request->post();
|
||
$res = $this->admin_obj->where('account',$data['account'])->find();
|
||
return json(['code'=>0,'msg'=>'success','data'=>$res]);
|
||
}
|
||
|
||
/**
|
||
* @title 管理员信息修改
|
||
* @description 管理员信息修改
|
||
* @author wangjinlei
|
||
* @url /master/Admin/editAdminBase
|
||
* @method POST
|
||
*
|
||
*
|
||
* @param name:account type:string require:1
|
||
* @param name:password type:string require:1 desc:密码
|
||
* @param name:realname type:string require:1
|
||
* @param name:phone type:string require:1
|
||
*
|
||
*/
|
||
public function editAdminBase(){
|
||
$data = $this->request->post();
|
||
$this->admin_obj->where('account',$data['account'])->update(['realname'=>$data['realname'],'password'=> md5($data['password']),'phone'=>$data['phone']]);
|
||
return json(['code'=>0,'msg'=>'success']);
|
||
}
|
||
|
||
/**
|
||
* @title 数据同步
|
||
* @description 数据同步
|
||
* @author wangjinlei
|
||
* @url /master/Admin/synchronization
|
||
* @method POST
|
||
*
|
||
*/
|
||
public function synchronization(){
|
||
$ptime = Cache::get('synchronization');
|
||
if($ptime){
|
||
jsonError('Synchronization minimum interval is 10 minute , last update time:'.$ptime);
|
||
}
|
||
Cache::set('synchronization',date('Y-m-d H:i:s'),10*60);
|
||
$url = "http://api.tmrjournals.cn/public/index.php/master/Admin/cn_synchronization";
|
||
$res = myPost($url);
|
||
return $res;
|
||
}
|
||
|
||
|
||
/**
|
||
* 触发cn同步方法
|
||
*/
|
||
public function cn_synchronization(){
|
||
$ptime = Cache::get('synchronization');
|
||
if($ptime){
|
||
return jsonError('Synchronization minimum interval is 10 minute , last update time:'.$ptime);
|
||
}
|
||
Cache::set('synchronization',date('Y-m-d H:i:s'),10*60);
|
||
exec('curl http://journalapi.tmrjournals.com/public/index.php/api/Main/pushImgFile');
|
||
exec("sh /etc/mysql/tongbu.sh");
|
||
return jsonSuccess([]);
|
||
}
|
||
|
||
/**
|
||
* @title 添加管理员
|
||
* @description 添加管理员
|
||
* @author wangjinlei
|
||
* @url /master/Admin/addAdmin
|
||
* @method POST
|
||
*
|
||
*
|
||
* @param name:account type:string require:1
|
||
* @param name:password type:string require:1 desc:密码
|
||
* @param name:realname type:string require:1
|
||
* @param name:phone type:string require:1
|
||
* @param name:role type:int require:1 default:1 desc:角色(0admin1editor)
|
||
*
|
||
*/
|
||
public function addAdmin(){
|
||
$data = $this->request->post();
|
||
$add_data['account'] = trim($data['account']);
|
||
$add_data['password'] = md5($data['password']);
|
||
$add_data['realname'] = $data['realname'];
|
||
$add_data['phone'] = $data['phone'];
|
||
$add_data['role'] = $data['role'];
|
||
$res = $this->admin_obj->insert($add_data);
|
||
if($res){
|
||
return json(['code'=>0,'msg'=>'success']);
|
||
}else{
|
||
return json(['code'=>1,'msg'=>'system error']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @title 获取管理员列表
|
||
* @description 获取管理员列表
|
||
* @author wangjinlei
|
||
* @url /master/Admin/getAdminList
|
||
* @method POST
|
||
*
|
||
*
|
||
* @return adminlist:管理员列表@
|
||
* @adminlist account:账号 realname:真实姓名 role:角色 phone:电话
|
||
*
|
||
*/
|
||
public function getAdminList(){
|
||
$list = $this->admin_obj->where('state',0)->select();
|
||
return json(['code'=>0,'msg'=>'success','adminlist'=>$list]);
|
||
}
|
||
|
||
/**
|
||
* @title 删除管理员
|
||
* @description 删除管理员
|
||
* @author wangjinlei
|
||
* @url /master/Admin/delAdmin
|
||
* @method POST
|
||
*
|
||
* @param name:admin_id type:int require:1 desc:管理员主键
|
||
*
|
||
*/
|
||
public function delAdmin(){
|
||
$data = $this->request->post();
|
||
$res = $this->admin_obj->where('admin_id',$data['admin_id'])->update(['state'=>1]);
|
||
return json(['code'=>0,'msg'=>'success']);
|
||
}
|
||
|
||
|
||
}
|