时间:2021-07-01 10:21:17 帮助过:24人阅读
protected function _initialize() { parent::_initialize(); $this->outData = array('status'=>0,'msg'=>'','info'=>array());//输出参数 } // 同步推荐关系 public function syncRelation() { $memberModel = D('Member'); $memberInviteeModel = D('Member_invitee'); $OriginalUsername = $this->_request('OriginalUsername','trim'); // 被推荐人号码 $RecommandUsername= $this->_request('RecommandUsername','trim'); // 推荐人号码 if ($OriginalUsername == $RecommandUsername) { $this->outData['status'] = '9'; $this->outData['msg'] = '参数有误'; $this->printOut(); } $o_member = $memberModel->getMemberByTel($OriginalUsername); if (empty($o_member)) { $this->outData['status'] = '1'; $this->outData['msg'] = '原用户'.$OriginalUsername.'不存在,关系未建立'; $this->printOut(); } $o_wxinfo = $memberModel->getWxinfo($o_member['id']); $r_member = $memberModel->getMemberByTel($RecommandUsername); if (empty($r_member)) { $this->outData['status'] = '2'; $this->outData['msg'] = '推荐用户'.$RecommandUsername.'不存在,关系未建立'; $this->printOut(); } $r_wxinfo = $memberModel->getWxinfo($r_member['id']); // 查询原用户是否存在推荐关系 $o_member_invitee = $memberInviteeModel->getInviteeWxuserMember($o_wxinfo['id'],$o_member['id']); if (empty($o_member_invitee)) { // 不存在推荐人 $r = $memberInviteeModel->setRelationship($r_member['id'],$o_member['id'],$o_wxinfo['id']); if ($r !== FALSE) { $this->outData['status'] = '3'; $this->outData['msg'] = '原用户'.$OriginalUsername.'存在,并且没有推荐人,推荐用户'.$RecommandUsername.'也存在,成功建立关系'; $this->printOut(); } else { $this->outData['status'] = '9'; $this->outData['msg'] = '查询失败,操作异常'; $this->printOut(); } } if ($o_member_invitee['member_id'] == $r_member['id']) { $this->outData['status'] = '4'; $this->outData['msg'] = '原用户'.$OriginalUsername.'存在,而且已经有了推荐人,推荐人'.$RecommandUsername.'是传递的推荐用户,关系不再重建'; $this->printOut(); } // 获取原推荐人信息 $o_member_inviter = $memberModel->getMemberById($o_member_invitee['member_id']); // 修改原有推荐关系 $o_member_invitee['member_id'] = $r_member['id']; $r = $memberInviteeModel->where(array('id'=>$o_member_invitee['id']))->save($o_member_invitee); if ($r !== FALSE) { $this->outData['status'] = '5'; $this->outData['msg'] = '原用户'.$OriginalUsername.'存在,而且已经有了推荐人,推荐人不是传递的推荐用户,关系重新建立,新推荐人'.$RecommandUsername.',原推荐人是'.$o_member_inviter['tel']; $this->printOut(); } else { $this->outData['status'] = '9'; $this->outData['msg'] = '查询失败,操作异常'; $this->printOut(); } } protected function printOut() { exit(json_encode($this->outData)); }
以上就是PHP实现的同步推荐操作API接口案例分析 的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!