search
HomeBackend DevelopmentPHP TutorialCase study of synchronized recommended operation API interface implemented in PHP

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));
}



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)!



-->

Statement
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
PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)