Files
NewTicket/app/admin/service/CustomersService.php
2026-05-07 16:37:25 +08:00

49 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\admin\service;
use app\common\model\Customers as CustomersModel;
use app\common\model\CustomerEmployees;
class CustomersService
{
public function selectCustomersWithEmployees()
{
//with 预载入 ,解决N+1问题
$list = CustomersModel::with('employees')->select();
return $list;
}
public function addCustomer($companyName)
{
$id = CustomersModel::create([
'company_name' => $companyName
]);
return $id;
}
public function addEmployee($empName, $Id)
{
$id = CustomersModel::where('id', $Id)->find()->employees()->save([
'employee_name' => $empName
]);
return $id;
}
public function deleteEmployee($empId)
{
$result = CustomerEmployees::destroy($empId);
return $result; // 返回受影响的行数删除一行就1,没有删除就是0
}
public function deleteCustomer($customerId)
{
// 删除客户单位会自动删除关联的员工(假设你在模型中设置了级联删除)
$result = CustomersModel::destroy($customerId);
return $result; // 返回受影响的行数删除一行就1,没有删除就是0
}
}