134 lines
4.5 KiB
PHP
134 lines
4.5 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\project;
|
||
|
||
|
||
use app\common\model\build\BuildPlan;
|
||
use app\common\model\build\BuildReport;
|
||
use app\common\model\build\BuildReportDetail;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectAttendanceDetail;
|
||
use app\common\model\project\ProjectPersonnel;
|
||
use app\common\model\project\ProjectSalaryDetail;
|
||
use app\common\model\project\ProjectSalaryPayment;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 工资付款逻辑
|
||
* Class ProjectSalaryPaymentLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectSalaryPaymentLogic extends BaseLogic
|
||
{
|
||
|
||
/**
|
||
* @notes 添加工资付款
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/27 16:08
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = ProjectSalaryPayment::create([
|
||
'payment_code' => data_unique_code('项目工资付款单'),
|
||
'project_id' => $params['project_id'],
|
||
'payment_type' => $params['payment_type'],
|
||
'apply_date' => strtotime($params['apply_date']),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
foreach($params['payment_detail'] as $v){
|
||
ProjectSalaryDetail::create([
|
||
'salary_payment_id' => $res->id,
|
||
'person_id' => $v['person_id'],
|
||
'apply_date' => strtotime($params['apply_date']),
|
||
'apply_amount' => $v['apply_amount'],
|
||
'remark' => $v['remark'] ?? '',
|
||
]);
|
||
}
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectSalaryPayment::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'payment_type' => $params['payment_type'],
|
||
'apply_date' => strtotime($params['apply_date']),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
'update_time' => time(),
|
||
]);
|
||
foreach($params['payment_detail'] as $v){
|
||
if(isset($v['id']) && $v['id'] != ''){
|
||
ProjectSalaryDetail::where('id',$v['id'])->update([
|
||
'salary_payment_id' => $params['id'],
|
||
'person_id' => $v['person_id'],
|
||
'apply_date' => strtotime($params['apply_date']),
|
||
'apply_amount' => $v['apply_amount'],
|
||
'remark' => $v['remark'] ?? '',
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
ProjectSalaryDetail::create([
|
||
'salary_payment_id' => $params['id'],
|
||
'person_id' => $v['person_id'],
|
||
'apply_date' => strtotime($params['apply_date']),
|
||
'apply_amount' => $v['apply_amount'],
|
||
'remark' => $v['remark'] ?? '',
|
||
]);
|
||
}
|
||
}
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取工资付款详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/27 16:08
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectSalaryPayment::field('id,payment_code,project_id,payment_type,apply_date,remark,annex')->findOrEmpty($params['id']);
|
||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
//总工资付款
|
||
$data['total_amount'] = ProjectSalaryDetail::where('salary_payment_id',$data['id'])->sum('apply_amount');
|
||
return $data->toArray();
|
||
}
|
||
} |