query()->insertGetId($data); // 返回结果 return $id; } /** * 添加数据 * */ public function edit($id,$data) { // 更新时间 $data['update_time'] = time(); // 写入数据表 $result = $this->query()->where(['id'=>$id])->update($data); // 失败返回0 if( !$result ) return 0; // 返回结果 return $id; } /** * 编码转id * * @param string $code 编码 * */ public function codeToId($code){ return intval(str_ireplace('klqw','',$code)); } /** * id转编码 * * @param int $id 编码 * */ public function idToCode($id){ return 'klqw'. str_pad($id, 9, '0', STR_PAD_LEFT);; } /** * 添加数据 * */ public function getOne($id) { // 返回结果 $custom = $this->query()->where([['id','=',$id]])->first(['id','external_userid','custom_uid','avatar','name','gender','status','work_type','user_type']); // 返回结果 if( !$custom ) return []; // 数据结构 return $custom->toArray(); } /** * 添加数据 * * @param int $id 客户ID * @param string $field 字段 */ public function getValue($id,$field) { // 返回结果 $result = $this->query()->where([['id','=',$id]])->value($field); // 数据结构 return $result; } /** * 通过外部联系人ID查询用户 * * @param string $extUserId 联系人ID * */ public function getOneByExtUserId($extUserId) { // 返回结果 $custom = $this->query()->where([['external_userid','=',$extUserId]])->first(['id','external_userid','custom_uid','avatar','name','gender','status','work_type','user_type']); // 返回结果 if( !$custom ) return []; // 数据结构 return $custom->toArray(); } /** * 获取列表 * * @param array $extUserIds 联系人ID列表 * */ public function getPluckInFiled($filed,$extUserIds,$column,$key) { // 返回结果 $custom = $this->query()->whereIn($filed,$extUserIds)->pluck($column,$key); // 返回结果 if( !$custom ) return []; // 数据结构 return $custom->toArray(); } /** * 企微用户添加注册 * * @param array $extUser 外部联系人信息 * */ public function workAdd($extUser){ // 名称 // 外部联系人ID $custom['external_userid'] = empty($extUser['external_userid'])?'':$extUser['external_userid']; // 联系人名称 $custom['name'] = empty($extUser['name'])?'':$extUser['name']; // 头像 $custom['avatar'] = empty($extUser['avatar'])?'':$extUser['avatar']; // 性别 $custom['gender'] = empty($extUser['gender'])?'':$extUser['gender']; // 联系人类型 $custom['work_type'] = empty($extUser['type'])? 0 :$extUser['type']; // 添加用户 $id = $this->add($custom); // 返回结果 return $id; } }