This commit is contained in:
mkm 2023-07-15 14:46:25 +08:00
parent 86197929c4
commit 8b171b0e56
5 changed files with 475 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\CompanyLists;
use app\adminapi\logic\CompanyLogic;
use app\adminapi\validate\CompanyValidate;
/**
* Company控制器
* Class CompanyController
* @package app\adminapi\controller
*/
class CompanyController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function lists()
{
return $this->dataLists(new CompanyLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function add()
{
$params = (new CompanyValidate())->post()->goCheck('add');
$result = CompanyLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(CompanyLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function edit()
{
$params = (new CompanyValidate())->post()->goCheck('edit');
$result = CompanyLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(CompanyLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function delete()
{
$params = (new CompanyValidate())->post()->goCheck('delete');
CompanyLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function detail()
{
$params = (new CompanyValidate())->goCheck('detail');
$result = CompanyLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\Company;
use app\common\lists\ListsSearchInterface;
/**
* Company列表
* Class CompanyLists
* @package app\adminapi\lists
*/
class CompanyLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function setSearch(): array
{
return [
'=' => ['level_two', 'level_one', 'company_name', 'organization_code', 'city', 'district', 'town', 'company_type', 'master_name', 'master_position', 'master_phone', 'master_email', 'other_contacts', 'area_manager', 'is_contract', 'account', 'password', 'deposit', 'deposit_time', 'qualification', 'status'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function lists(): array
{
return Company::where($this->searchWhere)
->field(['id', 'level_two', 'level_one', 'company_name', 'organization_code', 'city', 'district', 'town', 'company_type', 'master_name', 'master_position', 'master_phone', 'master_email', 'other_contacts', 'area_manager', 'is_contract', 'account', 'password', 'deposit', 'deposit_time', 'qualification', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function count(): int
{
return Company::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,146 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\model\Company;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* Company逻辑
* Class CompanyLogic
* @package app\adminapi\logic
*/
class CompanyLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/07/15 14:43
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Company::create([
'level_two' => $params['level_two'],
'level_one' => $params['level_one'],
'company_name' => $params['company_name'],
'organization_code' => $params['organization_code'],
'city' => $params['city'],
'district' => $params['district'],
'town' => $params['town'],
'company_type' => $params['company_type'],
'master_name' => $params['master_name'],
'master_position' => $params['master_position'],
'master_phone' => $params['master_phone'],
'master_email' => $params['master_email'],
'other_contacts' => $params['other_contacts'],
'area_manager' => $params['area_manager'],
'is_contract' => $params['is_contract'],
'account' => $params['account'],
'password' => $params['password'],
'deposit' => $params['deposit'],
'deposit_time' => $params['deposit_time'],
'qualification' => $params['qualification'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/07/15 14:43
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Company::where('id', $params['id'])->update([
'level_two' => $params['level_two'],
'level_one' => $params['level_one'],
'company_name' => $params['company_name'],
'organization_code' => $params['organization_code'],
'city' => $params['city'],
'district' => $params['district'],
'town' => $params['town'],
'company_type' => $params['company_type'],
'master_name' => $params['master_name'],
'master_position' => $params['master_position'],
'master_phone' => $params['master_phone'],
'master_email' => $params['master_email'],
'other_contacts' => $params['other_contacts'],
'area_manager' => $params['area_manager'],
'is_contract' => $params['is_contract'],
'account' => $params['account'],
'password' => $params['password'],
'deposit' => $params['deposit'],
'deposit_time' => $params['deposit_time'],
'qualification' => $params['qualification'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/07/15 14:43
*/
public static function delete(array $params): bool
{
return Company::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/07/15 14:43
*/
public static function detail($params): array
{
return Company::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
use app\common\validate\BaseValidate;
/**
* Company验证器
* Class CompanyValidate
* @package app\adminapi\validate
*/
class CompanyValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'company_name' => 'require',
'organization_code' => 'require',
'master_name' => 'require',
'master_position' => 'require',
'master_phone' => 'require',
'master_email' => 'require',
'account' => 'require',
'password' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'company_name' => '公司名称',
'organization_code' => '组织机构代码',
'master_name' => '主联系人姓名',
'master_position' => '主联系人职务',
'master_phone' => '主联系人手机',
'master_email' => '主联系人邮箱',
'account' => '账号',
'password' => '密码',
];
/**
* @notes 添加场景
* @return CompanyValidate
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function sceneAdd()
{
return $this->only(['company_name','organization_code','master_name','master_position','master_phone','master_email','account','password']);
}
/**
* @notes 编辑场景
* @return CompanyValidate
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function sceneEdit()
{
return $this->only(['id','company_name','organization_code','master_name','master_position','master_phone','master_email','account','password']);
}
/**
* @notes 删除场景
* @return CompanyValidate
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return CompanyValidate
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model;
use app\common\model\BaseModel;
/**
* Company模型
* Class Company
* @package app\common\model
*/
class Company extends BaseModel
{
protected $name = 'company';
}