最新版本
This commit is contained in:
@@ -6,21 +6,44 @@ use app\common\model\User as UserModel;
|
||||
|
||||
class AccountService
|
||||
{
|
||||
|
||||
/* 查询所有用户 */
|
||||
public function getAllUsers()
|
||||
{
|
||||
$users = UserModel::with('company')->select();
|
||||
return $users->map(function ($user) {
|
||||
return [
|
||||
'id' => $user->id,
|
||||
'company' => [
|
||||
'id' => $user->company_id,
|
||||
'company_name' => $user->company->company_name
|
||||
],
|
||||
'username' => $user->username,
|
||||
'real_name' => $user->real_name,
|
||||
'role' => $user->role,
|
||||
'status' => $user->status,
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/* 注册账户 */
|
||||
public function createAccount($data)
|
||||
{
|
||||
if (empty($data['username'])) {
|
||||
$data['username'] = $data['real_name'];
|
||||
{
|
||||
if (empty($data['real_name'])) {
|
||||
$data['real_name'] = $data['username'];
|
||||
}
|
||||
|
||||
# 检查数据库中是否有相同用户名账户
|
||||
$exist = UserModel::where('username', $data['username'])->find();
|
||||
|
||||
if ($exist) {
|
||||
throw new \Exception('用户名已存在');
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'username' => $data['username'] ?? $data['real_name'],
|
||||
'real_name' => $data['real_name'],
|
||||
'company_id' => $data['company_id'] ?? 0,
|
||||
'username' => $data['username'],
|
||||
'real_name' => $data['real_name'] ?? $data['username'],
|
||||
'password' => password_hash('123456', PASSWORD_DEFAULT),
|
||||
'role' => $data['role'] ?? 'user',
|
||||
'status' => 1,
|
||||
@@ -31,4 +54,32 @@ class AccountService
|
||||
/** @var \think\Model $user */
|
||||
return $user->visible(['id', 'username', 'real_name', 'role', 'status'])->toArray();
|
||||
}
|
||||
|
||||
/* 更新用户状态 */
|
||||
public function updateAccountStatus($id, $status)
|
||||
{
|
||||
$user = UserModel::find($id);
|
||||
if (!$user) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
$user->status = $status;
|
||||
$user->save();
|
||||
|
||||
return $user->visible(['id', 'username', 'real_name', 'role', 'status'])->toArray();
|
||||
}
|
||||
|
||||
|
||||
/* 删除用户 */
|
||||
public function deleteAccount($id)
|
||||
{
|
||||
$user = UserModel::find($id);
|
||||
if (!$user) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
|
||||
return ['id' => $id];
|
||||
}
|
||||
}
|
||||
|
||||
46
app/admin/service/CompanyOperatorsService.php
Normal file
46
app/admin/service/CompanyOperatorsService.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
use app\common\model\CompanyOperators;
|
||||
use app\common\model\Companys;
|
||||
|
||||
|
||||
class CompanyOperatorsService
|
||||
{
|
||||
public function deleteOperator($id)
|
||||
{
|
||||
$result = CompanyOperators::destroy($id);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function deleteCompany($id)
|
||||
{
|
||||
$result = Companys::customDelete($id);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function addCompany($data){
|
||||
|
||||
# 判断该公司名称是否已存在
|
||||
$existingCompany = Companys::where('company_name', $data['company_name'])->find();
|
||||
if ($existingCompany) {
|
||||
throw new \Exception('公司名称已存在');
|
||||
}
|
||||
|
||||
$result = Companys::create($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function addOperator($data){
|
||||
|
||||
# 判断运营人员是否存在
|
||||
$existingOperator = CompanyOperators::where('operator_name', $data['operator_name'])->find();
|
||||
if ($existingOperator) {
|
||||
throw new \Exception('运营人员已存在');
|
||||
}
|
||||
$result = CompanyOperators::create($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
20
app/admin/service/UtillService.php
Normal file
20
app/admin/service/UtillService.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\common\model\Tickets;
|
||||
|
||||
class UtillService
|
||||
{
|
||||
/* 获取需要导出的数据 */
|
||||
public function getExportData($range)
|
||||
{
|
||||
$list = Tickets::with(['ticketStaff', 'ticketOperator'])->whereTime('lock_time', $range)->select();
|
||||
|
||||
foreach ($list as $item) {
|
||||
$item->visible(['id', 'website', 'datanum', 'remark', 'create_time', 'lock_time']);
|
||||
$item->append(['username', 'operator_name'])->hidden(['ticketStaff', 'ticketOperator']);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user