Patrol.php
2.8 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
88
89
90
91
92
93
<?php
namespace app\api\controller\xunjian;
use app\api\controller\tencentim\Openim;
use app\common\controller\Api;
use fast\Tree;
use think\Db;
use think\exception\PDOException;
/**
* 巡检人员
*/
class Patrol extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* 3. 查询水库管理员(巡检员)
*/
public function getStaffList()
{
$reservoir_id = $this->request->param("reservoir_id", "");//水库id
$except_id = $this->request->param("except_id","");//排除某个员工id
$where = [];
$where2 = [];
if (!empty($reservoir_id)) {
$where = ["a.reservoir_id" => $reservoir_id];
}
if(!empty($except_id)){
$where2["a.id"] = ["neq",$except_id];
}
$list = Db::name("inspection_staff")->alias("a")
->join("user u", "u.id=a.user_id", "LEFT")
->join("inspection_depart p", "p.id=a.depart_id", "LEFT")
->field("a.id,a.staff_code,a.staff_name,a.mobile,a.is_screen_mng,u.clientid,p.depart_name")
->where($where)
->where($where2)
->order("a.id desc")
->select();
$back_data = [];
if (!empty($list)) {
$count =count($list);
$addnum = 500;//因为即时通讯人员状态每次限制查500人;所以得分开查
for($i=0;$i<$count;$i=$i+$addnum){
if($count-$i>0){
$j=$i-1>0?$i:0;
$data = array_slice($list,$j,$addnum);
$mobile_list = array_column($data,"mobile");
$openim_api = new Openim();
$r = $openim_api->query_online_status(["To_Account"=>$mobile_list]);
if($r['state']==true){
$back_data=$back_data+$r['data'];
}
}
}
foreach ($list as $lk=>$lv){
//追加在线状态
$list[$lk]["online_status"] =$back_data[$lv['mobile']]['Status']?$back_data[$lv['mobile']]['Status']:"Offline";
$list[$lk]["online_status_cn"] =$back_data[$lv['mobile']]['StatusCn']?$back_data[$lv['mobile']]['StatusCn']:"下班";
}
}
$this->success("巡检人员数据获取成功", $list);
}
/**
* 获取腾讯云某个App管理员帐号的签名
* @throws \Exception
*/
// public function userSig()
// {
// Vendor("tencent.TLSSigAPIv2");
// $api = new \TLSSigAPIv2(1400645108, '249c08eef888876a00cd6fc9d6e10fa2a767802b959129494ce86f4db1ef106c');
// $sig = $api->genUserSig('hcanxyz', 86400 * 365 * 5);//有效期5年
// echo $sig . "\n";
//
// }
}