engineering/app/adminapi/logic/bid/BidBiddingDecisionLogic.php
2024-02-19 15:14:34 +08:00

186 lines
7.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\bid;
use app\common\model\bid\BidBiddingDecision;
use app\common\model\custom\Custom;
use app\common\logic\BaseLogic;
use app\common\model\oa\FlowApprove;
use app\common\model\project\Project;
use think\facade\Db;
/**
* 投标决策逻辑
* Class BidBiddingDecisionLogic
* @package app\adminapi\logic\bid
*/
class BidBiddingDecisionLogic extends BaseLogic
{
/**
* @notes 添加投标决策
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/27 18:14
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
BidBiddingDecision::create([
'code' => data_unique_code('投标决策'),
'project_id' => $params['project_id'],
'project_estimation' => $params['project_estimation'],
'bidding_project_fund_source' => $params['bidding_project_fund_source'] ?? 0,
'bidding_time' => !empty($params['bidding_time']) ? strtotime($params['bidding_time']) : 0,
'bid_type' => $params['bid_type'] ?? 0,
'competitor' => $params['competitor'] ?? '',
'is_margin' => $params['is_margin'] ?? 0,
'margin_amount' => $params['margin_amount'] ?? 0,
'bid_opening_date' => !empty($params['bid_opening_date']) ? strtotime($params['bid_opening_date']) : 0,
'margin_amount_return_date' => !empty($params['margin_amount_return_date']) ? strtotime($params['margin_amount_return_date']) : 0,
'is_internal_resources' => $params['is_internal_resources'] ?? 0,
'project_assurance' => $params['project_assurance'] ?? 0,
'bid_project_overview' => $params['bid_project_overview'] ?? '',
'project_desc' => $params['project_desc'] ?? '',
'annex' => $params['annex']? json_encode($params['annex']) : null,
]);
Project::where('id',$params['project_id'])->update([
'status' => 2,
'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 2023/11/27 18:14
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
BidBiddingDecision::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'project_estimation' => $params['project_estimation'],
'bidding_project_fund_source' => $params['bidding_project_fund_source'] ?? 0,
'bidding_time' => !empty($params['bidding_time']) ? strtotime($params['bidding_time']) : 0,
'bid_type' => $params['bid_type'] ?? 0,
'competitor' => $params['competitor'] ?? '',
'is_margin' => $params['is_margin'] ?? 0,
'margin_amount' => $params['margin_amount'] ?? 0,
'bid_opening_date' => !empty($params['bid_opening_date']) ? strtotime($params['bid_opening_date']) : 0,
'margin_amount_return_date' => !empty($params['margin_amount_return_date']) ? strtotime($params['margin_amount_return_date']) : 0,
'is_internal_resources' => $params['is_internal_resources'] ?? 0,
'project_assurance' => $params['project_assurance'] ?? 0,
'bid_project_overview' => $params['bid_project_overview'] ?? '',
'project_desc' => $params['project_desc'] ?? '',
'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 2023/11/27 18:14
*/
public static function delete(array $params): bool
{
return BidBiddingDecision::destroy($params['id']);
}
/**
* @notes 获取投标决策详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/27 18:14
*/
public static function detail($params): array
{
$data = BidBiddingDecision::findOrEmpty($params['id']);
$project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['custom_name'] = $custom['name'];
$data['bidding_project_fund_source'] = $data->bidding_project_fund_source_text;
$data['bid_type'] = $data->bid_type_text;
$data['is_margin'] = $data->is_margin_text;
$data['is_internal_resources'] = $data->is_internal_resources_text;
$data['project_assurance'] = $data->project_assurance_text;
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
$data['approve_check_status'] = $approve_data['check_status'];
unset($data['org_id'],$data['dept_id'],$data['project_id'],$data['delete_time']);
return $data->toArray();
}
public static function approve($params,$admin_id): bool{
$data = BidBiddingDecision::where('id',$params['id'])->findOrEmpty();
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
if(!empty($data['approve_id']) && $approve_data['check_status'] != 3){
self::setError('当前内容存在审核信息,请勿重复提交');
return false;
}
Db::startTrans();
try {
$res = addApprove(
'投标决策',
$params['id'],
'app\common\model\bid\BidBiddingDecision',
$params['path'],
$params['flow_id'],
$admin_id
);
if($res){
BidBiddingDecision::where('id',$params['id'])->update([
'approve_id' => $res,
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}