信呼OA版本v2.3.8
This commit is contained in:
114
webmain/model/reimplat/agentModel.php
Normal file
114
webmain/model/reimplat/agentModel.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* 应用管理方法
|
||||
*/
|
||||
class reimplat_agentClassModel extends reimplatModel
|
||||
{
|
||||
/**
|
||||
* 获取所有应用
|
||||
*/
|
||||
public function listdata()
|
||||
{
|
||||
$url = $this->geturl('openagent','listdata');
|
||||
$result = c('curl')->getcurl($url);
|
||||
|
||||
$barr = $this->recordchu($result);
|
||||
if($barr['success']){
|
||||
$list = $barr['data']['agentlist'];
|
||||
$stra = array();
|
||||
foreach($list as $k=>$rs)$stra[$rs['num']] = $rs['name'];
|
||||
$this->option->setval('reimplat_agentlist@-7', json_encode($stra, JSON_UNESCAPED_UNICODE));
|
||||
return returnsuccess($list);
|
||||
}
|
||||
return $barr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发应用消息
|
||||
*/
|
||||
public function sendtext($touid,$agentnum, $mess)
|
||||
{
|
||||
$touids = $this->gettouid($touid);
|
||||
if(!$touids)return returnerror(''.$touid.'未关注');
|
||||
$url = $this->geturl('openagent','sendmsg');
|
||||
$data['agentnum'] = $agentnum;
|
||||
$data['touser'] = $touids;
|
||||
$data['msgtype'] = 'text';
|
||||
$data['content'] = $mess;
|
||||
|
||||
$result = c('curl')->postcurl($url, json_encode($data));
|
||||
$barr = $this->recordchu($result);
|
||||
|
||||
return $barr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发卡片消息
|
||||
*/
|
||||
public function sendtextcard($touid,$agentnum, $wxarr)
|
||||
{
|
||||
$touids = $this->gettouid($touid);
|
||||
if(!$touids)return returnerror(''.$touid.'未关注');
|
||||
$url = $this->geturl('openagent','sendmsg');
|
||||
$data['agentnum'] = $agentnum;
|
||||
$data['touser'] = $touids;
|
||||
$data['msgtype'] = 'textcard';
|
||||
$data['content'] = $wxarr;
|
||||
|
||||
$result = c('curl')->postcurl($url, json_encode($data));
|
||||
$barr = $this->recordchu($result);
|
||||
return $barr;
|
||||
}
|
||||
|
||||
private function gettouid($touid)
|
||||
{
|
||||
if($touid=='@all' || $touid=='all')return '@all';
|
||||
$uarrs = $this->db->getall("select a.`user`,a.`name` from `[Q]admin` a left join `[Q]zreim_user` b on a.`user`=b.`user` where a.`status`=1 and b.id is not null and b.`status`=1 and a.`id` in($touid)");
|
||||
$uids = '';
|
||||
foreach($uarrs as $k=>$rs)$uids.=','.$rs['user'].'';
|
||||
if($uids)$uids = substr($uids, 1);
|
||||
return $uids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
public function sendxiao($touid, $agentname, $wxarr=array(),$iszs=false)
|
||||
{
|
||||
$liststr = $this->option->getval('reimplat_agentlist');
|
||||
if(isempt($liststr))return returnerror('请先获取应用');
|
||||
|
||||
if(!$iszs && getconfig('asynsend')=='1'){
|
||||
$cans['touid'] = $touid;
|
||||
$cans['agentname'] = $agentname;
|
||||
$cans['wxarr'] = $wxarr;
|
||||
$barr = c('rockqueue')->push('cli,reimplatsend', array(
|
||||
'body' => $this->rock->jm->base64encode(json_encode($cans))
|
||||
));
|
||||
if($barr['success'])return returnsuccess('anaysend');
|
||||
}
|
||||
|
||||
$yarr = json_decode($liststr, true);
|
||||
$num = $dnum = '';
|
||||
foreach($yarr as $k=>$v){
|
||||
if($dnum=='')$dnum = $k;
|
||||
if($agentname==$v || $agentname==$k)$num = $k;
|
||||
}
|
||||
if($num==''){
|
||||
$num = $this->reimplat_devnum;
|
||||
if(isempt($num))$num = $dnum;
|
||||
}
|
||||
if(isempt($num))return returnerror('没有找到对应应用('.$agentname.')');
|
||||
if(is_string($wxarr))$wxarr = array('title'=>$wxarr);
|
||||
|
||||
if(arrvalue($wxarr, 'url')){
|
||||
$barr = $this->sendtextcard($touid, $num, $wxarr);
|
||||
}else{
|
||||
$des = arrvalue($wxarr,'description');
|
||||
$cont = $wxarr['title'];
|
||||
if($des)$cont.='<br>'.$des.'';
|
||||
$barr = $this->sendtext($touid, $num, $cont);
|
||||
}
|
||||
return $barr;
|
||||
}
|
||||
}
|
||||
147
webmain/model/reimplat/deptModel.php
Normal file
147
webmain/model/reimplat/deptModel.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
class reimplat_deptClassModel extends reimplatModel
|
||||
{
|
||||
|
||||
public function initReimplat()
|
||||
{
|
||||
$this->settable('zreim_user');
|
||||
}
|
||||
|
||||
//获取部门
|
||||
public function getdeptlist()
|
||||
{
|
||||
$url = $this->geturl('opendept','deptlist');
|
||||
$result = c('curl')->getcurl($url);
|
||||
|
||||
$barr = $this->recordchu($result);
|
||||
if(!$barr['success'])return $barr;
|
||||
|
||||
return returnsuccess($barr['data']['deptlist']);
|
||||
}
|
||||
|
||||
//获取所有用户
|
||||
public function getuserlist()
|
||||
{
|
||||
$url = $this->geturl('opendept','useralllist');
|
||||
$result = c('curl')->getcurl($url);
|
||||
|
||||
$barr = $this->recordchu($result);
|
||||
if($barr['success']){
|
||||
$userarr = $barr['data']['userlist'];
|
||||
$ids = '0';
|
||||
foreach($userarr as $k=>$rs){
|
||||
$id1 = $this->userupdates($rs);
|
||||
$ids.=','.$id1.'';
|
||||
}
|
||||
$this->delete('`id` not in('.$ids.')');
|
||||
}
|
||||
return returnsuccess();
|
||||
}
|
||||
|
||||
public function getuinfo($user)
|
||||
{
|
||||
return $this->getone("`user`='$user'");
|
||||
}
|
||||
|
||||
public function userupdates($rs)
|
||||
{
|
||||
$where = "`user`='".$rs['user']."'";
|
||||
$uars = $this->getone($where);
|
||||
if($uars){
|
||||
$id1 = $uars['id'];
|
||||
}else{
|
||||
$id1 = 0;
|
||||
$where='';
|
||||
}
|
||||
$uarr = array(
|
||||
'user' => $rs['user'],
|
||||
'name' => $rs['name'],
|
||||
'position' => $rs['position'],
|
||||
'mobile' => $rs['mobile'],
|
||||
'email' => $rs['email'],
|
||||
'tel' => $rs['tel'],
|
||||
'status' => $rs['status'],
|
||||
'deptid' => $rs['deptid'],
|
||||
);
|
||||
if(isset($rs['face']))$uarr['face'] = $rs['face'];
|
||||
$this->record($uarr, $where);
|
||||
if($id1==0)$id1 = $this->db->insert_id();
|
||||
return $id1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//用户信息
|
||||
public function getuserinfo($user)
|
||||
{
|
||||
$url = $this->geturl('opendept','userinfo', array('user'=>$user));
|
||||
$result = c('curl')->getcurl($url);
|
||||
$barr = $this->recordchu($result);
|
||||
if(!$barr['success'])return $barr;
|
||||
$rs = $barr['data']['userinfo'];
|
||||
$this->userupdates($rs);
|
||||
return returnsuccess($rs);
|
||||
}
|
||||
|
||||
//更新用户
|
||||
public function userupdate($urs)
|
||||
{
|
||||
$urs['position'] = $urs['ranking'];
|
||||
$urs['istxl'] = $urs['isvcard'];
|
||||
$urs['gender'] = ($urs['sex']=='女')?2:1;
|
||||
unset($urs['ranking']);
|
||||
unset($urs['sex']);
|
||||
unset($urs['isvcard']);
|
||||
$url = $this->geturl('opendept','userupdate');
|
||||
$result = c('curl')->postcurl($url, json_encode($urs));
|
||||
$barr = $this->recordchu($result);
|
||||
if($barr['success'])$this->getuserinfo($urs['user']);
|
||||
return $barr;
|
||||
}
|
||||
|
||||
//更新全部部门
|
||||
public function deptallupdate()
|
||||
{
|
||||
$rows = m('dept')->getall('1=1','`id`,`name`,`num`,`pid`,`sort`,`headman`');
|
||||
$arr['deptalldata'] = $rows;
|
||||
$url = $this->geturl('opendept','deptallupdate');
|
||||
$result = c('curl')->postcurl($url, json_encode($arr));
|
||||
$barr = $this->recordchu($result);
|
||||
return $barr;
|
||||
}
|
||||
|
||||
public function notinadmin($ids='')
|
||||
{
|
||||
$sql = "select a.`user` from `[Q]zreim_user` a left join `[Q]admin` b on a.`user`=b.`user` where";
|
||||
if($ids!=''){
|
||||
$sql.= " b.id in($ids)";
|
||||
}else{
|
||||
$sql.= ' b.id is null';
|
||||
}
|
||||
$rows= $this->db->getall($sql);
|
||||
$arr = array();
|
||||
foreach($rows as $k=>$rs){
|
||||
$arr[] = $rs['user'];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
//删除用户
|
||||
public function deleteuserall($ids='')
|
||||
{
|
||||
$arr = $this->notinadmin($ids);
|
||||
if(!$arr){
|
||||
return returnerror('没有可删除用户');
|
||||
}
|
||||
return $this->userdelete(join(',', $arr));
|
||||
}
|
||||
public function userdelete($user)
|
||||
{
|
||||
$url = $this->geturl('opendept','userdelete');
|
||||
$body = '{"userlist":"'.$user.'"}';
|
||||
$result = c('curl')->postcurl($url, $body);
|
||||
$barr = $this->recordchu($result);
|
||||
if($barr['success'])$this->getuserlist();
|
||||
return $barr;
|
||||
}
|
||||
}
|
||||
27
webmain/model/reimplat/oauthModel.php
Normal file
27
webmain/model/reimplat/oauthModel.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
class reimplat_oauthClassModel extends reimplatModel
|
||||
{
|
||||
public function login()
|
||||
{
|
||||
$platsign = $this->rock->session('platsign');
|
||||
if(isempt($platsign))return returnerror('无效登录');
|
||||
$url = $this->geturl('openoauth','oauthinfo', array(
|
||||
'platsign' => $platsign
|
||||
));
|
||||
|
||||
$result = c('curl')->getcurl($url);
|
||||
$barr = $this->recordchu($result);
|
||||
if(!$barr['success'])return $barr;
|
||||
|
||||
$info = $barr['data']['userinfo'];
|
||||
$user = $info['user'];
|
||||
$usr = m('admin')->getone("`status`=1 and `user`='$user'");
|
||||
if(!$usr)return returnerror('oa上用户不存在');
|
||||
c('cache')->set('login'.$usr['user'].'', $usr['id'], 60);
|
||||
|
||||
return returnsuccess(array(
|
||||
'user' => $user,
|
||||
'pass' => md5($usr['pass'])
|
||||
));
|
||||
}
|
||||
}
|
||||
54
webmain/model/reimplat/reimplat.php
Normal file
54
webmain/model/reimplat/reimplat.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
class reimplatModel extends Model
|
||||
{
|
||||
public function initReimplat(){}
|
||||
|
||||
public $reimplat_purl;
|
||||
public $reimplat_cnum;
|
||||
public $reimplat_secret;
|
||||
public $reimplat_devnum;
|
||||
public $reimplat_huitoken;
|
||||
|
||||
public function initModel()
|
||||
{
|
||||
$this->option = m('option');
|
||||
$this->reimplat_purl = $this->option->getval('reimplat_purl');
|
||||
$this->reimplat_cnum = $this->option->getval('reimplat_cnum');
|
||||
$this->reimplat_secret = $this->option->getval('reimplat_secret');
|
||||
$this->reimplat_devnum = $this->option->getval('reimplat_devnum');
|
||||
$this->reimplat_huitoken = $this->option->getval('reimplat_huitoken');
|
||||
if(getconfig('systype')=='dev')$this->reimplat_purl = 'http://localhost/app/rockreim/';
|
||||
$this->initReimplat();
|
||||
}
|
||||
|
||||
public function gethkey()
|
||||
{
|
||||
$key = $this->reimplat_huitoken;
|
||||
if(isempt($key))$key = $this->reimplat_secret;
|
||||
if(isempt($key))$key = $this->reimplat_cnum;
|
||||
return md5($key);
|
||||
}
|
||||
|
||||
//获取地址
|
||||
public function geturl($m, $a,$can=array())
|
||||
{
|
||||
$url = $this->reimplat_purl;
|
||||
if(!$url)return showreturn('','没设置REIM通信平台地址', 201);
|
||||
if(substr($url,0,4)!='http')$url = 'http://'.$url.'';
|
||||
if(substr($url,-1)!='/')$url.='/';
|
||||
$url.= 'api.php?m='.$m.'&a='.$a.'';
|
||||
$url.= '&cnum='.$this->reimplat_cnum.'';
|
||||
$url.= '&secret='.$this->reimplat_secret.'';
|
||||
foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function recordchu($cont)
|
||||
{
|
||||
$data = array('code'=>201,'success'=>false,'msg'=>'出错,返回:'.htmlspecialchars($cont).'');
|
||||
if($cont!='' && substr($cont,0,1)=='{'){
|
||||
$data = json_decode($cont, true);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
5
webmain/model/reimplat/userModel.php
Normal file
5
webmain/model/reimplat/userModel.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
class reimplat_userClassModel extends reimplatModel
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user