This article analyzes the PHP implementation of the synchronous recommended Operation API interface. Share to everyone for your reference, as follows:
Document
1. Function
Synchronous Referral Relationship
2. Interface Methods
Syncrelation
3. Parameter Description
Originalusername user name of the query
Recommandusername Referrer User Name
4. Return value
Status 1 Success 9 failed
5. Notes
Status=1 The original user does not exist, the relationship is not established
status=2 recommended user does not exist, relationship is not established
Status=3 The original user exists, and there is no referral, the recommended user also exists, the successful establishment of the relationship
Status=4 The original user exists, and already has a referrer, referral is a referral user, the relationship is no longer rebuilt
Status=5 The original user exists, and already has a referrer, the referral is not the referral user, the relationship re-established, the original recommendation is XXX
Status=9 query failed, operation exception
Code:
protected function _initialize () {parent::_initialize (); $this->outdata = Array (' status ' =>0, ' msg ' = ' = ', ' info ' =>array ());//output parameter}//synchronous Referral relationship Public function Syncrelation () {$memberModel = D (' Member '); $memberInviteeModel = D (' member_invitee '); $OriginalUsername = $this->_request (' originalusername ', ' trim '); Recommended person Number $RecommandUsername = $this->_request (' recommandusername ', ' trim '); Recommended person number if ($OriginalUsername = = $RecommandUsername) {$this->outdata[' status '] = ' 9 '; $this->outdata[' msg '] = ' wrong parameter '; $this->printout (); } $o _member = $memberModel->getmemberbytel ($OriginalUsername); if (Empty ($o _member)) {$this->outdata[' status '] = ' 1 '; $this->outdata[' msg '] = ' original user '. $OriginalUsername. ' No, relationship not established '; $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 ') = ' recommended'. $RecommandUsername. ' No, relationship not established '; $this->printout (); } $r _wxinfo = $memberModel->getwxinfo ($r _member[' id '); Query whether the original user has a referral relationship $o _member_invitee = $memberInviteeModel->getinviteewxusermember ($o _wxinfo[' id '), $o _member[' id ' ]); if (Empty ($o _member_invitee)) {//does not exist referrer $r = $memberInviteeModel->setrelationship ($r _member[' id '), $o _member[' id ' ], $o _wxinfo[' id ']); if ($r!== FALSE) {$this->outdata[' status '] = ' 3 '; $this->outdata[' msg '] = ' original user '. $OriginalUsername. ' exists, and no referrer, referral user '. $RecommandUsername. ' also exist, successfully build relationships '; $this->printout (); } else {$this->outdata[' status '] = ' 9 '; $this->outdata[' msg '] = ' query failed, operation exception '; $this->printout (); }} if ($o _member_invitee[' member_id ') = = $r _member[' id ']) {$this->outdata[' status '] = ' 4 '; $this->outdata[' msg '] = ' original user '. $OriginalUsername. ' exists, and already has a referrer, referrer '. $RecommandUsername. ' is the referral user, the relationship is no longer rebuilt '; $this->printout (); }//Get original referrer information $o _member_inviter = $memberModel->getmemberbyid ($o _member_invitee[' member_id '); Modify the original referral relationship $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 '] = ' original user '. $OriginalUsername. ' exists, and already has a referrer, the referrer is not a referral user to pass, the relationship is re-established, the new referrer '. $ Recommandusername. ', the original referrer is '. $o _member_inviter[' Tel ']; $this->printout (); } else {$this->outdata[' status '] = ' 9 '; $this->outdata[' msg '] = ' query failed, operation exception '; $this->printout (); }}protected function PrintOut () {exit (Json_encode ($this->outdata));
The above is the PHP implementation of the synchronous recommended Operation API interface case analysis, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!