Merge pull request '新增材料预算明细模块' (#136) from zhangwei into dev

Reviewed-on: #136
This commit is contained in:
weiz 2024-01-08 22:00:43 +08:00
commit 6a57ca15c9
5 changed files with 443 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\project;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\project\ProjectMaterialBudgetDetailLists;
use app\adminapi\logic\project\ProjectMaterialBudgetDetailLogic;
use app\adminapi\validate\project\ProjectMaterialBudgetDetailValidate;
/**
* 材料预算明细控制器
* Class ProjectMaterialBudgetDetailController
* @package app\adminapi\controller\project
*/
class ProjectMaterialBudgetDetailController extends BaseAdminController
{
/**
* @notes 获取材料预算明细列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function lists()
{
return $this->dataLists(new ProjectMaterialBudgetDetailLists());
}
/**
* @notes 添加材料预算明细
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function add()
{
$params = (new ProjectMaterialBudgetDetailValidate())->post()->goCheck('add');
$result = ProjectMaterialBudgetDetailLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectMaterialBudgetDetailLogic::getError());
}
/**
* @notes 编辑材料预算明细
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function edit()
{
$params = (new ProjectMaterialBudgetDetailValidate())->post()->goCheck('edit');
$result = ProjectMaterialBudgetDetailLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectMaterialBudgetDetailLogic::getError());
}
/**
* @notes 删除材料预算明细
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function delete()
{
$params = (new ProjectMaterialBudgetDetailValidate())->post()->goCheck('delete');
ProjectMaterialBudgetDetailLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取材料预算明细详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function detail()
{
$params = (new ProjectMaterialBudgetDetailValidate())->goCheck('detail');
$result = ProjectMaterialBudgetDetailLogic::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\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\ProjectMaterialBudgetDetail;
use app\common\lists\ListsSearchInterface;
/**
* 材料预算明细列表
* Class ProjectMaterialBudgetDetailLists
* @package app\adminapi\listsproject
*/
class ProjectMaterialBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function setSearch(): array
{
return [
'=' => ['material_budget_id', 'material_id', 'budget_type'],
];
}
/**
* @notes 获取材料预算明细列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function lists(): array
{
return ProjectMaterialBudgetDetail::where($this->searchWhere)
->field(['id', 'material_budget_id', 'material_id', 'budget_type', 'price', 'num', 'amount', 'remark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取材料预算明细数量
* @return int
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function count(): int
{
return ProjectMaterialBudgetDetail::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,118 @@
<?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\project;
use app\common\model\project\ProjectMaterialBudgetDetail;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 材料预算明细逻辑
* Class ProjectMaterialBudgetDetailLogic
* @package app\adminapi\logic\project
*/
class ProjectMaterialBudgetDetailLogic extends BaseLogic
{
/**
* @notes 添加材料预算明细
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/08 21:52
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ProjectMaterialBudgetDetail::create([
'material_budget_id' => $params['material_budget_id'],
'material_id' => $params['material_id'],
'budget_type' => $params['budget_type'],
'price' => $params['price'],
'num' => $params['num'],
'amount' => $params['amount'],
'remark' => $params['remark'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑材料预算明细
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/08 21:52
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectMaterialBudgetDetail::where('id', $params['id'])->update([
'material_budget_id' => $params['material_budget_id'],
'material_id' => $params['material_id'],
'budget_type' => $params['budget_type'],
'price' => $params['price'],
'num' => $params['num'],
'amount' => $params['amount'],
'remark' => $params['remark'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除材料预算明细
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/08 21:52
*/
public static function delete(array $params): bool
{
return ProjectMaterialBudgetDetail::destroy($params['id']);
}
/**
* @notes 获取材料预算明细详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/08 21:52
*/
public static function detail($params): array
{
return ProjectMaterialBudgetDetail::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,106 @@
<?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\project;
use app\common\validate\BaseValidate;
/**
* 材料预算明细验证器
* Class ProjectMaterialBudgetDetailValidate
* @package app\adminapi\validate\project
*/
class ProjectMaterialBudgetDetailValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'material_budget_id' => 'require',
'material_id' => 'require',
'budget_type' => 'require',
'price' => 'require',
'num' => 'require',
'amount' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'material_budget_id' => '材料预算id',
'material_id' => '材料id',
'budget_type' => '预算类型',
'price' => '材料单价',
'num' => '材料数量',
'amount' => '金额',
];
/**
* @notes 添加场景
* @return ProjectMaterialBudgetDetailValidate
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function sceneAdd()
{
return $this->only(['material_budget_id','material_id','budget_type','price','num','amount']);
}
/**
* @notes 编辑场景
* @return ProjectMaterialBudgetDetailValidate
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function sceneEdit()
{
return $this->only(['id','material_budget_id','material_id','budget_type','price','num','amount']);
}
/**
* @notes 删除场景
* @return ProjectMaterialBudgetDetailValidate
* @author likeadmin
* @date 2024/01/08 21:52
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectMaterialBudgetDetailValidate
* @author likeadmin
* @date 2024/01/08 21:52
*/
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\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 材料预算明细模型
* Class ProjectMaterialBudgetDetail
* @package app\common\model\project
*/
class ProjectMaterialBudgetDetail extends BaseModel
{
use SoftDelete;
protected $name = 'project_material_budget_detail';
protected $deleteTime = 'delete_time';
}