DetailController.class.php
4.88 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* CrmBindController.class.php
* 与劲霸 CRM 进行绑定接口
* @author Deepseath
* @version $Id$
*/
namespace Open\Controller\User;
use Common\Common\User;
use Common\Service\UserService;
/**
* 用于与劲霸 CRM 进行绑定的接口:员工信息查询
*/
class DetailController extends AbstractController
{
/**
* 劲霸员工信息查询接口
* @desc 劲霸对外接口,提供给 crm 进行员工信息查询之用
* @param string userid:true 员工企业微信帐号 userid
* @param string timestamp:true (公共参数)请求的 Unix 时间戳,单位:秒
* @param string noncestr:true (公共参数)请求的随机字符串
* @param string signature:true (公共参数)请求的参数签名
* @param string requester:true (公共参数)请求的身份名,固定为:crm
* @return <pre>
* array(
* "userid" => "e071e97f2bdec1db598abf2a6107ba67", // 企业微信 userid
* "mobile" => "13812345678", // 手机号
* "storecode" => "xxx", // 导购编号
)
* </pre>
*/
public function Index()
{
if (!$this->__checkInputParams()) {
// 检查当前业务的参数合法性
return false;
}
// 根据 userid 查询人员列表
$userServer = User::instance();
$r = $userServer->listByConds([
'userids' => [
$this->_input['userid']
]
]);
if (empty($r) || empty($r['list'])) {
return $this->_set_error('_ERR_CONTACT_OPEN_USER_NOT_EXISTS_90004');
}
// 获取单人结果数据
reset($r['list']);
$result = current($r['list']);
unset($r);
if (stripos($result['memUserid'], $this->_input['userid']) !== 0) {
// 查出的人员信息微信 userid 不匹配,为了确保不混淆,返回错误信息
return $this->_set_error('_ERR_CONTACT_OPEN_USER_ERROR_90005');
}
// 所在组织信息,只提取第一个组织的信息,其他的忽略考虑(需求方要求)
$department = [];
if (!empty($result['dpName']) && is_array($result['dpName'])) {
foreach ($result['dpName'] as $_dp) {
if (!empty($_dp['dpSerialNum'])) {
$department = $_dp;
break;
}
}
unset($_dp);
}
// 目前就是人 手机号 导购编号 门店 这些信息
$this->_result = [
//'user' => $result
'userid' => (string) $result['memUserid'],
// 手机号
'mobile' => (string) $result['memMobile'],
// 组织编号
'storecode' => isset($department['dpSerialNum']) ? (string) $department['dpSerialNum'] : '',
// 姓名
'username' => (string) $result['memUsername'],
// 导购编号
'salesnumber' => $this->__getCustomField('salesNumberField', $result),
// 组织名称
'storename' => isset($department['dpName']) ? (string) $department['dpName'] : '',
// 邮箱
'email' => (string) $result['memEmail'],
// 性别, 0: 未知, 1:男; 2:女
'gender' => (int)$result['memGender'],
// 微信号
'weixin' => (string) $result['memWeixin'],
// 岗位
'job' => (string) $result['memJob'],
// 角色
'role' => (string) $result['memRole'],
// 座机
'telphoneField' => $this->__getCustomField('custom1', $result),
// OA帐号
'accountOA' => $this->__getCustomField('custom2', $result),
// CRM帐号
'accountCRM' => $this->__getCustomField('custom3', $result),
// DRP 帐号
'accountDRP' => $this->__getCustomField('custom4', $result),
// CM 帐号
'accountCM' => $this->__getCustomField('custom5', $result),
// 订货会帐号
'accountOrderMeeting' => $this->__getCustomField('custom6', $result),
// 生日
'birthday' => $this->__getCustomField('custom8', $result),
// 入职日期
'joinDate' => $this->__getCustomField('custom9', $result)
];
return true;
}
/**
* 请求参数的检查
* @return boolean
*/
private function __checkInputParams()
{
if (empty($this->_input['userid']) || !is_scalar($this->_input['userid'])) {
$this->_set_error('_ERR_CONTACT_OPEN_USERID_NULL_90006');
return false;
}
return true;
}
/**
* 解出自定义字段
* @param unknown $field
* @param unknown $result
*/
private function __getCustomField($field, $result)
{
return isset($result[$this->_KBoxing[$field]]) ? (string) $result[$this->_KBoxing[$field]] : '';
}
}