<?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]] : ''; } }