140 lines
4.6 KiB
PHP
140 lines
4.6 KiB
PHP
<?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\material;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dept\Orgs;
|
||
use app\common\model\material\MaterialWarehouse;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\project\Project;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 仓库管理逻辑
|
||
* Class MaterialWarehouseLogic
|
||
* @package app\adminapi\logic\material
|
||
*/
|
||
class MaterialWarehouseLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加仓库管理
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/04 14:23
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
MaterialWarehouse::create([
|
||
'org_id' => $params['org_id'],
|
||
'dept_id' => $params['dept_id'],
|
||
'project_id' => $params['project_id'],
|
||
'code' => data_unique_code('CK'),
|
||
'name' => $params['name'],
|
||
'is_mrp' => $params['is_mrp'],
|
||
'head_user' => $params['head_user'],
|
||
'address' => $params['address'] ?? '',
|
||
'telephone' => $params['telephone'],
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
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/04 14:23
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
MaterialWarehouse::where('id', $params['id'])->update([
|
||
'org_id' => $params['org_id'],
|
||
'dept_id' => $params['dept_id'],
|
||
'project_id' => $params['project_id'],
|
||
'code' => data_unique_code('CK'),
|
||
'name' => $params['name'],
|
||
'is_mrp' => $params['is_mrp'],
|
||
'head_user' => $params['head_user'],
|
||
'address' => $params['address'] ?? '',
|
||
'telephone' => $params['telephone'],
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
'update_time' => time()
|
||
]);
|
||
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/04 14:23
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return MaterialWarehouse::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取仓库管理详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/04 14:23
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = MaterialWarehouse::field('id,org_id,dept_id,project_id,code,name,is_mrp,head_user,address,telephone,remark,annex')->findOrEmpty($params['id']);
|
||
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
|
||
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
|
||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$admin = Admin::field('name')->where('id',$data['head_user'])->findOrEmpty();
|
||
$data['org_name'] = $org['name'];
|
||
$data['dept_name'] = $dept['name'];
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['head_user_name'] = $admin['name'];
|
||
$data['is_mrp_text'] = $data->is_mrp_text;
|
||
return $data->toArray();
|
||
}
|
||
} |