engineering/app/adminapi/logic/marketing/MarketingBidEvaluationLogic.php
2024-04-12 14:48:11 +08:00

223 lines
8.3 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\marketing;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\marketing\MarketingBidEvaluation;
use app\common\model\marketing\MarketingBidInfo;
use app\common\model\marketing\MarketingBusinessOpportunity;
use app\common\model\marketing\MarketingCustom;
use app\common\model\oa\FlowApprove;
use think\facade\Db;
/**
* 市场经营--投标管理--投标评审逻辑
* Class MarketingBidEvaluationLogic
* @package app\adminapi\logic\marketing
*/
class MarketingBidEvaluationLogic extends BaseLogic
{
/**
* @notes 添加市场经营--投标管理--投标评审
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/11 15:42
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
MarketingBidEvaluation::create([
'business_opportunity_id' => $params['business_opportunity_id'],
'bid_type' => $params['bid_type'] ?? 0,
'bid_nature' => $params['bid_nature'] ?? 0,
'bid_code' => $params['bid_code'],
'bid_margin' => $params['bid_margin'] ?? 0,
'bid_amount' => $params['bid_amount'] ?? 0,
'quotation_amount' => $params['quotation_amount'] ?? 0,
'end_date' => !empty($params['end_date']) ? strtotime($params['end_date']) : 0,
'bid_date' => !empty($params['bid_date']) ? strtotime($params['bid_date']) : 0,
'service_duration' => $params['service_duration'] ?? '',
'bid_address' => $params['bid_address'] ?? '',
'bid_agency' => $params['bid_agency'] ?? '',
'bid_agency_address' => $params['bid_agency_address'] ?? '',
'bid_agency_contacts' => $params['bid_agency_contacts'] ?? '',
'bid_agency_telephone' => $params['bid_agency_telephone'] ?? '',
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
]);
MarketingBusinessOpportunity::where('id', $params['business_opportunity_id'])->update(['status' => 1]);
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/04/11 15:42
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
MarketingBidEvaluation::where('id', $params['id'])->update([
'business_opportunity_id' => $params['business_opportunity_id'],
'bid_type' => $params['bid_type'] ?? 0,
'bid_nature' => $params['bid_nature'] ?? 0,
'bid_code' => $params['bid_code'],
'bid_margin' => $params['bid_margin'] ?? 0,
'bid_amount' => $params['bid_amount'] ?? 0,
'quotation_amount' => $params['quotation_amount'] ?? 0,
'end_date' => !empty($params['end_date']) ? strtotime($params['end_date']) : 0,
'bid_date' => !empty($params['bid_date']) ? strtotime($params['bid_date']) : 0,
'service_duration' => $params['service_duration'] ?? '',
'bid_address' => $params['bid_address'] ?? '',
'bid_agency' => $params['bid_agency'] ?? '',
'bid_agency_address' => $params['bid_agency_address'] ?? '',
'bid_agency_contacts' => $params['bid_agency_contacts'] ?? '',
'bid_agency_telephone' => $params['bid_agency_telephone'] ?? '',
'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/04/11 15:42
*/
public static function reg(array $params): bool
{
Db::startTrans();
try {
MarketingBidEvaluation::where('id', $params['id'])->update([
'reg_date' => !empty($params['reg_date']) ? strtotime($params['reg_date']) : 0,
'review_status' => $params['review_status'] ?? 0,
'reg_result' => $params['reg_result'] ?? 0,
]);
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/04/11 15:42
*/
public static function delete(array $params): bool
{
$bid_info = MarketingBidInfo::where('bid_evaluation_id', 'in', $params['id'])->findOrEmpty();
if (!$bid_info->isEmpty()) {
self::setError('此数据关联了投标信息内容,需删除投标信息内容');
return false;
}
return MarketingBidEvaluation::destroy($params['id']);
}
/**
* @notes 获取市场经营--投标管理--投标评审详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/04/11 15:42
*/
public static function detail($params): array
{
$data = MarketingBidEvaluation::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']);
$data['bid_type_text'] = $data->bid_type_text;
$data['bid_nature_text'] = $data->bid_nature_text;
$data['approve_check_status_text'] = $data->approve_check_status_text;
//业务机会
$business_opportunity = MarketingBusinessOpportunity::withoutField('create_time,update_time,delete_time')->where('id', $data['business_opportunity_id'])->findOrEmpty();
$data['business_opportunity'] = $business_opportunity;
$construct_company = MarketingCustom::field('name')->where('id', $business_opportunity['construct_company'])->findOrEmpty();
$admin = Admin::where('id', 'in', [$business_opportunity['head'], $business_opportunity['leader']])->column('name', 'id');
$dept = Dept::field('name')->where('id', $business_opportunity['dept'])->findOrEmpty();
$data['business_opportunity']['construct_company_name'] = $construct_company?->name;
$data['business_opportunity']['business_nature_text'] = $business_opportunity->business_nature_text;
$data['business_opportunity']['industry_nature_text'] = $business_opportunity->industry_nature_text;
$data['business_opportunity']['info_sources_text'] = $business_opportunity->info_sources_text;
$data['business_opportunity']['fund_sources_text'] = $business_opportunity->fund_sources_text;
$data['business_opportunity']['const_area_text'] = $business_opportunity->const_area_text;
$data['business_opportunity']['status_text'] = $business_opportunity->status_text;
$data['business_opportunity']['dept_name'] = $dept?->name;
$data['business_opportunity']['head_name'] = $admin[$business_opportunity['head']] ?? '';
$data['business_opportunity']['leader_name'] = $admin[$business_opportunity['leader']] ?? '';
return $data->toArray();
}
public static function approve($params, $admin_id): bool
{
$data = MarketingBidEvaluation::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\marketing\MarketingBidEvaluation',
$params['path'],
$params['flow_id'],
$admin_id
);
if ($res) {
MarketingBidEvaluation::where('id', $params['id'])->update([
'approve_id' => $res,
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}