first commit

This commit is contained in:
2026-05-07 16:37:25 +08:00
commit 822ed9a099
67 changed files with 1799 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?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
}
}