以下是一个简单的PHP客户关系管理系统(CRM)源码示例:
```php
class Customer {
private $id;
private $name;
private $email;
private $phone;
private $address;
public function __construct($id, $name, $email, $phone, $address) {
$this->id = $id;
$this->name = $name;
$this->email = $email;
$this->phone = $phone;
$this->address = $address;
}
public function getId() {
return $this->id;
}
public function getName() {
return $this->name;
}
public function getEmail() {
return $this->email;
}
public function getPhone() {
return $this->phone;
}
public function getAddress() {
return $this->address;
}
}
class CustomerManager {
private $customers;
public function __construct() {
$this->customers = [];
}
public function addCustomer($customer) {
$this->customers[] = $customer;
}
public function getCustomerById($id) {
foreach ($this->customers as $customer) {
if ($customer->getId() == $id) {
return $customer;
}
}
return null;
}
}
$customer1 = new Customer(1, '张三', 'zhangsan@example.com', '13800138000', '北京市海淀区');
$customer2 = new Customer(2, '李四', 'lisi@example.com', '13900139000', '上海市浦东新区');
$customerManager = new CustomerManager();
$customerManager->addCustomer($customer1);
$customerManager->addCustomer($customer2);
echo "客户ID: " . $customer1->getId() . "n";
echo "姓名: " . $customer1->getName() . "n";
echo "邮箱: " . $customer1->getEmail() . "n";
echo "电话: " . $customer1->getPhone() . "n";
echo "地址: " . $customer1->getAddress() . "n";
echo "----------------------------------------n";
$customerById = $customerManager->getCustomerById(1);
if ($customerById) {
echo "查询到的客户信息:n";
echo "客户ID: " . $customerById->getId() . "n";
echo "姓名: " . $customerById->getName() . "n";
echo "邮箱: " . $customerById->getEmail() . "n";
echo "电话: " . $customerById->getPhone() . "n";
echo "地址: " . $customerById->getAddress() . "n";
} else {
echo "未查询到指定ID的客户信息。";
}
?>
```
这个示例中,我们定义了两个类:`Customer`和`CustomerManager`。`Customer`类用于表示一个客户,包含客户的基本信息。`CustomerManager`类用于管理客户信息,包括添加客户和根据ID查询客户等功能。
在示例代码的最后部分,我们创建了两个`Customer`对象和一个`CustomerManager`实例,并使用它们来演示如何管理客户信息。