generate_sn(ProjectCommission::class,'dataid'), 'num' => generate_sn(ProjectCommission::class,'num'), 'project_id' => $params['project_id'], 'rate' => $params['rate'], 'bczfze' => $params['bczfze'], 'djr' => $params['djr'], 'apptime' => !empty($params['apptime']) ? strtotime($params['apptime']) : 0, 'remark' => $params['remark'] ?? '', ]); if(!empty($params['project_commission_detail'])){ foreach ($params['project_commission_detail'] as $item) { $item['project_commission_id'] = $projectCommission->id; ProjectCommissionDetailLogic::add($item); } } 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/23 09:37 */ public static function edit(array $params): bool { Db::startTrans(); try { ProjectCommission::where('id', $params['id'])->update([ 'project_id' => $params['project_id'], 'rate' => $params['rate'], 'bczfze' => $params['bczfze'], 'djr' => $params['djr'], 'apptime' => !empty($params['apptime']) ? strtotime($params['apptime']) : 0, 'remark' => $params['remark'] ?? '', 'update_time' => time(), ]); if(!empty($params['project_commission_detail'])){ foreach ($params['project_commission_detail'] as $item) { if(!empty($item['id'])){ ProjectCommissionDetailLogic::edit($item); }else{ $item['project_commission_id'] = $params['id']; ProjectCommissionDetailLogic::add($item); } } } 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/23 09:37 */ public static function delete(array $params): bool { $detail = ProjectCommissionDetail::where('project_commission_id','in',$params['id'])->findOrEmpty(); if(!$detail->isEmpty()){ self::setError('此数据关联了提成明细信息,须删除提成明细信息'); return false; } return ProjectCommission::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2024/02/23 09:37 */ public static function detail($params): array { $data = ProjectCommission::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id'])->toArray(); $project = CostProject::field('project_name,project_num,contract_id')->where('id',$data['project_id'])->findOrEmpty(); $contract = CostApprovedProject::field('contract_name,project_director,industry_nature')->where('id',$project['contract_id'])->findOrEmpty(); $data['project_name'] = $project['project_name']; $data['project_num'] = $project['project_num']; $data['contract_name'] = $contract['contract_name']; $data['project_director'] = $contract['project_director']; $data['industry_nature_text'] = $contract->industry_nature_text; $data['industry_nature'] = (string)$contract['industry_nature']; //到账金额 $data['total_refund_amount'] = ZjzxRefund::where('project_id',$data['project_id'])->sum('amount'); //已支付总额 $data['total_pay_amount'] = ProjectCommission::where('project_id',$data['project_id'])->sum('bczfze'); //应提成总金额 $data['total_commission_amount'] = $data['total_refund_amount'] * ($data['rate'] / 100); $data['project_commission_detail'] = ProjectCommissionDetail::field('id,engineer,task_name,task_type,professional_type,zj_amount,sk_amount,tc_rate,tc_amount,pay_amount,other_fee,remark')->where('project_commission_id', $data['id'])->select()->each(function($data){ $data['task_type_text'] = $data->task_type_text; $data['professional_type_text'] = $data->professional_type_text; })->toArray(); return $data; } public static function datas() { $datas = ProjectCommission::field(['id', 'num']) ->order(['id' => 'desc']) ->select() ->toArray(); foreach ($datas as &$item) { $item['projectinfo'] = 'ID:' . $item['id'] . ' / 单号:' . $item['num']; } return $datas; } }