This commit is contained in:
weiz 2024-04-01 15:59:56 +08:00
parent e51d9ed831
commit 69dff92c93

View File

@ -12,141 +12,142 @@
// | author: likeadminTeam // | author: likeadminTeam
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\adminapi\logic\project; namespace app\adminapi\logic\project;
use app\common\model\auth\Admin; use app\common\logic\BaseLogic;
use app\common\model\custom\Custom; use app\common\model\auth\Admin;
use app\common\model\custom\CustomContacts; use app\common\model\custom\Custom;
use app\common\model\custom\CustomerDemand; use app\common\model\custom\CustomContacts;
use app\common\model\project\Project; use app\common\model\custom\CustomerDemand;
use app\common\model\project\ProjectEstimate; use app\common\model\project\Project;
use app\common\logic\BaseLogic; use app\common\model\project\ProjectEstimate;
use think\facade\Db; use think\facade\Db;
/** /**
* 项目概算逻辑 * 项目概算逻辑
* Class ProjectEstimateLogic * Class ProjectEstimateLogic
* @package app\adminapi\logic\project * @package app\adminapi\logic\project
*/ */
class ProjectEstimateLogic extends BaseLogic class ProjectEstimateLogic extends BaseLogic
{ {
/** /**
* @notes 添加项目概算 * @notes 添加项目概算
* @param array $params * @param array $params
* @return bool * @return bool
* @author likeadmin * @author likeadmin
* @date 2023/11/24 21:42 * @date 2023/11/24 21:42
*/ */
public static function add(array $params,$admin_id): bool public static function add(array $params, $admin_id): bool
{ {
Db::startTrans(); Db::startTrans();
try { try {
ProjectEstimate::create([ ProjectEstimate::create([
'project_id' => $params['project_id'], 'project_id' => $params['project_id'],
'customer_demand_id' => $params['customer_demand_id'], 'customer_demand_id' => $params['customer_demand_id'],
'estimate_source' => $params['estimate_source'], 'estimate_source' => $params['estimate_source'],
'contact_id' => $params['contact_id'], 'contact_id' => $params['contact_id'],
'create_user' => $params['create_user'] ?? '', 'create_user' => $params['create_user'] ?? '',
'quotation_date' => strtotime($params['quotation_date']), 'quotation_date' => strtotime($params['quotation_date']),
'invoice_type' => $params['invoice_type'] ?? 0, 'invoice_type' => $params['invoice_type'] ?? 0,
'technician' => $params['technician'] ?? 0, 'technician' => $params['technician'] ?? 0,
'estimate_amount' => $params['estimate_amount'] ?? 0, 'estimate_amount' => $params['estimate_amount'] ?? 0,
'ask' => $params['ask'] ?? '', 'ask' => $params['ask'] ?? '',
'annex' => $params['annex']? json_encode($params['annex']) : null, 'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'add_user' => $admin_id, 'add_user' => $admin_id,
'update_user' => $admin_id, 'update_user' => $admin_id,
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }
} }
/** /**
* @notes 编辑项目概算 * @notes 编辑项目概算
* @param array $params * @param array $params
* @return bool * @return bool
* @author likeadmin * @author likeadmin
* @date 2023/11/24 21:42 * @date 2023/11/24 21:42
*/ */
public static function edit(array $params,$admin_id): bool public static function edit(array $params, $admin_id): bool
{ {
Db::startTrans(); Db::startTrans();
try { try {
ProjectEstimate::where('id', $params['id'])->update([ ProjectEstimate::where('id', $params['id'])->update([
'project_id' => $params['project_id'], 'project_id' => $params['project_id'],
'customer_demand_id' => $params['customer_demand_id'], 'customer_demand_id' => $params['customer_demand_id'],
'estimate_source' => $params['estimate_source'], 'estimate_source' => $params['estimate_source'],
'contact_id' => $params['contact_id'], 'contact_id' => $params['contact_id'],
'create_user' => $params['create_user'] ?? '', 'create_user' => $params['create_user'] ?? '',
'quotation_date' => strtotime($params['quotation_date']), 'quotation_date' => strtotime($params['quotation_date']),
'invoice_type' => $params['invoice_type'] ?? 0, 'invoice_type' => $params['invoice_type'] ?? 0,
'technician' => $params['technician'] ?? 0, 'technician' => $params['technician'] ?? 0,
'estimate_amount' => $params['estimate_amount'] ?? 0, 'estimate_amount' => $params['estimate_amount'] ?? 0,
'ask' => $params['ask'] ?? '', 'ask' => $params['ask'] ?? '',
'annex' => $params['annex']? json_encode($params['annex']) : null, 'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'update_user' => $admin_id, 'update_user' => $admin_id,
'update_time' => time(), 'update_time' => time(),
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }
} }
/** /**
* @notes 删除项目概算 * @notes 删除项目概算
* @param array $params * @param array $params
* @return bool * @return bool
* @author likeadmin * @author likeadmin
* @date 2023/11/24 21:42 * @date 2023/11/24 21:42
*/ */
public static function delete(array $params): bool public static function delete(array $params): bool
{ {
return ProjectEstimate::destroy($params['id']); return ProjectEstimate::destroy($params['id']);
} }
/** /**
* @notes 获取项目概算详情 * @notes 获取项目概算详情
* @param $params * @param $params
* @return array * @return array
* @author likeadmin * @author likeadmin
* @date 2023/11/24 21:42 * @date 2023/11/24 21:42
*/ */
public static function detail($params): array public static function detail($params): array
{ {
$field = 'id,project_id,customer_demand_id,contact_id,estimate_source,create_user,quotation_date,invoice_type,technician,estimate_amount,ask,annex,add_user,update_user,create_time,update_time'; $field = 'id,project_id,customer_demand_id,contact_id,estimate_source,create_user,quotation_date,invoice_type,technician,estimate_amount,ask,annex,add_user,update_user,create_time,update_time';
$data = ProjectEstimate::field($field)->findOrEmpty($params['id']); $data = ProjectEstimate::field($field)->findOrEmpty($params['id']);
$data['estimate_source_text'] = $data->estimate_source_text; $data['estimate_source_text'] = $data->estimate_source_text;
$data['invoice_type_text'] = $data->invoice_type_text; $data['invoice_type_text'] = $data->invoice_type_text;
$project = Project::field('name,project_code,custom_id')->where('id',$data['project_id'])->findOrEmpty(); $project = Project::field('name,project_code,custom_id')->where('id', $data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id', $project['custom_id'])->findOrEmpty();
$demand = CustomerDemand::field('theme')->where('id',$data['customer_demand_id'])->findOrEmpty(); $demand = CustomerDemand::field('theme,recording_time')->where('id', $data['customer_demand_id'])->findOrEmpty();
$contract = CustomContacts::field('name,phone')->where('id',$data['contact_id'])->findOrEmpty(); $contract = CustomContacts::field('name,phone')->where('id', $data['contact_id'])->findOrEmpty();
$technician = Admin::field('name')->where('id',$data['technician'])->findOrEmpty(); $technician = Admin::field('name')->where('id', $data['technician'])->findOrEmpty();
$admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id'); $admin = Admin::where('id', 'in', [$data['add_user'], $data['update_user']])->column('name', 'id');
$data['project_name'] = $project['name']; $data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code']; $data['project_code'] = $project['project_code'];
$data['custom_name'] = $custom['name']; $data['custom_name'] = $custom['name'];
$data['customer_demand_name'] = $demand['theme']; $data['customer_demand_name'] = $demand['theme'];
$data['contact_name'] = $contract['name']; $data['recording_time'] = $demand['recording_time'];
$data['contact_phone'] = $contract['phone']; $data['contact_name'] = $contract['name'];
$data['technician_name'] = $technician['name']; $data['contact_phone'] = $contract['phone'];
$data['add_user_name'] = $admin[$data['add_user']]; $data['technician_name'] = $technician['name'];
$data['update_user_name'] = $admin[$data['update_user']]; $data['add_user_name'] = $admin[$data['add_user']];
return $data->toArray(); $data['update_user_name'] = $admin[$data['update_user']];
} return $data->toArray();
} }
}