Home > Backend Development > PHP Tutorial > Case study of synchronized recommended operation API interface implemented in PHP

Case study of synchronized recommended operation API interface implemented in PHP

黄舟
Release: 2023-03-06 06:44:01
Original
1867 people have browsed it

The example of this article analyzes the synchronization recommended operation API interface implemented by PHP. Share it with everyone for your reference, the details are as follows:

Document

1. Function

Synchronized recommendation relationship

2. Interface method

syncRelation

3. Parameter description

OriginalUsername Query user name

RecommandUsername Recommended Username

4. Return value

status 1 success 9 failure

5. Remarks

Status=1 The original user does not exist and the relationship is not established

Status=2 The recommended user does not exist and the relationship is not established

Status=3 The original user exists and there is no recommender, and the recommended user does not exist Exists, the relationship is successfully established

Status=4 The original user exists, and there is already a recommender. The recommender is the passed recommended user, and the relationship will no longer be re-established

Status=5 The original user exists, And there is already a recommender. The recommender is not the recommended user passed on. The relationship is re-established. The original recommender is XXX

Status=9. The query fails and the operation is abnormal.
##

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));
}
Copy after login



The above is the content of the case analysis of the synchronous recommended operation API interface implemented by PHP. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



-->

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template