172 lines
5.6 KiB
PHP
172 lines
5.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\supervision_work;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\supervision_work\SupervisionMaterialEntry;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\supervision_work\SupervisionMaterialEntryDetail;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 材料进场逻辑
|
||
* Class SupervisionMaterialEntryLogic
|
||
* @package app\adminapi\logic\supervision_work
|
||
*/
|
||
class SupervisionMaterialEntryLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加材料进场
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/02/28 13:41
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = SupervisionMaterialEntry::create([
|
||
'project_id' => $params['project_id'],
|
||
'company_id' => $params['company_id'],
|
||
'theme' => $params['theme'],
|
||
'code' => data_unique_code('CLJC'),
|
||
'enter_time' => !empty($params['enter_time']) ? strtotime($params['enter_time']) : 0,
|
||
'co_participant' => $params['co_participant'],
|
||
'enter_result' => $params['enter_result'],
|
||
'parallel_test' => $params['parallel_test'],
|
||
'remark' => $params['remark'],
|
||
'create_user' => $admin_id,
|
||
]);
|
||
if(!empty($params['entry_detail'])){
|
||
foreach($params['entry_detail'] as $v) {
|
||
SupervisionMaterialEntryDetail::create([
|
||
'material_entry_id' => $res->id,
|
||
'name' => $v['name'],
|
||
'brand' => $v['brand'],
|
||
'model' => $v['model'],
|
||
'unit' => $v['unit'],
|
||
'contract_brand' => $v['contract_brand'],
|
||
'entry_number' => $v['entry_number']
|
||
]);
|
||
}
|
||
}
|
||
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/02/28 13:41
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
SupervisionMaterialEntry::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'company_id' => $params['company_id'],
|
||
'theme' => $params['theme'],
|
||
'enter_time' => !empty($params['enter_time']) ? strtotime($params['enter_time']) : 0,
|
||
'co_participant' => $params['co_participant'],
|
||
'enter_result' => $params['enter_result'],
|
||
'parallel_test' => $params['parallel_test'],
|
||
'remark' => $params['remark'],
|
||
'update_time' => time(),
|
||
]);
|
||
if(!empty($params['entry_detail'])){
|
||
foreach($params['entry_detail'] as $v) {
|
||
if(!empty($v['id'])){
|
||
SupervisionMaterialEntryDetail::where('id',$v['id'])->update([
|
||
'material_entry_id' => $params['id'],
|
||
'name' => $v['name'],
|
||
'brand' => $v['brand'],
|
||
'model' => $v['model'],
|
||
'unit' => $v['unit'],
|
||
'contract_brand' => $v['contract_brand'],
|
||
'entry_number' => $v['entry_number'],
|
||
'update_time' => time()
|
||
]);
|
||
}else{
|
||
SupervisionMaterialEntryDetail::create([
|
||
'material_entry_id' => $params['id'],
|
||
'name' => $v['name'],
|
||
'brand' => $v['brand'],
|
||
'model' => $v['model'],
|
||
'unit' => $v['unit'],
|
||
'contract_brand' => $v['contract_brand'],
|
||
'entry_number' => $v['entry_number']
|
||
]);
|
||
}
|
||
}
|
||
}
|
||
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/02/28 13:41
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
$entry_detail = SupervisionMaterialEntryDetail::where('material_entry_id',$params['id'])->findOrEmpty();
|
||
if(!$entry_detail->isEmpty()){
|
||
self::setError('当前数据下存在材料信息记录,请先删除材料信息记录');
|
||
return false;
|
||
}
|
||
return SupervisionMaterialEntry::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取材料进场详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/02/28 13:41
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = SupervisionMaterialEntry::withoutField('update_time,delete_time')->findOrEmpty($params['id']);
|
||
$create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty();
|
||
$data['create_user_name'] = $create_user['name'];
|
||
$data['enter_result_text'] = $data->enter_result_text;
|
||
$data['parallel_test_text'] = $data->parallel_test_text;
|
||
return $data->toArray();
|
||
}
|
||
} |