new-admin-api/app/controller/supplier/system/SupplierAdmin.php

189 lines
5.1 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
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\supplier\system;
use app\controller\supplier\AuthController;
use app\services\supplier\LoginServices;
use app\services\supplier\SystemSupplierServices;
use app\services\system\admin\SystemAdminServices;
use think\facade\{App};
/**
* Class SystemAdmin
* @package app\controller\admin\v1\setting
*/
class SupplierAdmin extends AuthController
{
/**
* @var LoginServices|null
*/
protected $services = NUll;
/**
* @var SystemAdminServices|null
*/
protected $adminServices = NUll;
/**
* SystemAdmin constructor.
* @param App $app
* @param SystemSupplierServices $services
* @param SystemAdminServices $adminServices
*/
public function __construct(App $app, SystemSupplierServices $services, SystemAdminServices $adminServices)
{
parent::__construct($app);
$this->services = $services;
$this->adminServices = $adminServices;
}
/**
* 显示管理员资源列表
*
* @return \think\Response
*/
public function index()
{
$where = [
// 'is_del' => 0,
'admin_type' => 4,
// 'relation_id' => $this->supplierId,
// 'level' => 1
];
$data = $this->adminServices->getAdminList($where);
return app('json')->success('', $data);
}
/**
* 创建表单
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function create()
{
return app('json')->success('',$this->adminServices->createForm(0, '/admin'));
}
/**
* 保存管理员
* @return mixed
*/
public function save()
{
$data = $this->request->postMore([
['account', ''],
['phone', ''],
['conf_pwd', ''],
['pwd', ''],
['real_name', ''],
['phone', ''],
['roles', []],
['status', 0],
['head_pic', ''],
]);
$this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class, 'supplier_save');
$data['admin_type'] = 4;
$data['relation_id'] = $this->supplierId;
if ($this->adminServices->create($data)) {
return app('json')->success('添加成功');
} else {
return app('json')->fail('添加失败');
}
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit(int $id)
{
if (!$id) {
return app('json')->fail('管理员信息读取失败');
}
return app('json')->success('',$this->adminServices->updateForm(0, (int)$id, '/admin/'));
}
/**
* 更新管理员
* @param int $id
* @return mixed
*/
public function update(int $id)
{
$data = $this->request->postMore([
['account', ''],
['phone', ''],
['conf_pwd', ''],
['pwd', ''],
['real_name', ''],
['phone', ''],
['roles', []],
['status', 0],
['head_pic', ''],
]);
$this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class, 'supplier_update');
if ($this->adminServices->save($id, $data)) {
return app('json')->success('修改成功');
} else {
return app('json')->fail('修改失败');
}
}
/**
* 管理员详情
* @param int $id
* @return mixed
*/
public function read(int $id)
{
$info = $this->adminServices->get($id);
if (!$info) {
return app('json')->fail('获取失败');
}
return app('json')->success('',$info->toArray());
}
/**
* 删除管理员
* @param int $id
* @return void
*/
public function delete(int $id)
{
if (!$id) {
return app('json')->fail('删除失败,缺少参数');
}
if ($this->adminServices->update($id, ['is_del' => 1, 'status' => 0])) {
return app('json')->success('删除成功!');
} else {
return app('json')->fail('删除失败');
}
}
/**
* 修改状态
* @param $id
* @param $status
* @return mixed
*/
public function set_status($id, $status)
{
$this->adminServices->update((int)$id, ['status' => $status]);
return app('json')->success($status == 0 ? '关闭成功' : '开启成功');
}
}