新增资产管理

This commit is contained in:
luofei 2023-08-02 16:43:39 +08:00
parent 058cbe6d7a
commit b9affdbb9d
4 changed files with 399 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\PropertyLists;
use app\adminapi\logic\PropertyLogic;
use app\adminapi\validate\PropertyValidate;
/**
* Property控制器
* Class PropertyController
* @package app\adminapi\controller
*/
class PropertyController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function lists()
{
return $this->dataLists(new PropertyLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function add()
{
$params = (new PropertyValidate())->post()->goCheck('add');
$result = PropertyLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(PropertyLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function edit()
{
$params = (new PropertyValidate())->post()->goCheck('edit');
$result = PropertyLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(PropertyLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function delete()
{
$params = (new PropertyValidate())->post()->goCheck('delete');
PropertyLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function detail()
{
$params = (new PropertyValidate())->goCheck('detail');
$result = PropertyLogic::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\Property;
use app\common\lists\ListsSearchInterface;
/**
* Property列表
* Class PropertyLists
* @package app\adminapi\lists
*/
class PropertyLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function setSearch(): array
{
return [
'=' => ['company_id', 'name', 'status', 'type'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function lists(): array
{
return Property::where($this->searchWhere)
->field(['id', 'company_id', 'name', 'status', 'type'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function count(): int
{
return Property::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,112 @@
<?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\Property;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* Property逻辑
* Class PropertyLogic
* @package app\adminapi\logic
*/
class PropertyLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/02 16:35
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Property::create([
'company_id' => $params['company_id'],
'name' => $params['name'],
'status' => $params['status'],
'type' => $params['type']
]);
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/08/02 16:35
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Property::where('id', $params['id'])->update([
'company_id' => $params['company_id'],
'name' => $params['name'],
'status' => $params['status'],
'type' => $params['type']
]);
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/08/02 16:35
*/
public static function delete(array $params): bool
{
return Property::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/02 16:35
*/
public static function detail($params): array
{
return Property::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,102 @@
<?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;
/**
* Property验证器
* Class PropertyValidate
* @package app\adminapi\validate
*/
class PropertyValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'company_id' => 'require',
'name' => 'require',
'status' => 'require',
'type' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'company_id' => '所属公司id',
'name' => '资产名称',
'status' => '资产状态 0未出租 1已出租',
'type' => '资产类型 1三轮车 2XXX 3XXX',
];
/**
* @notes 添加场景
* @return PropertyValidate
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function sceneAdd()
{
return $this->only(['company_id','name','status','type']);
}
/**
* @notes 编辑场景
* @return PropertyValidate
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function sceneEdit()
{
return $this->only(['id','company_id','name','status','type']);
}
/**
* @notes 删除场景
* @return PropertyValidate
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return PropertyValidate
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}