$data) { $refer[$data[$pk]] = &$list[$key]; } foreach ($list as $key => $data) { $parentId = $data[$pid]; if ($root == $parentId) { $tree[] = &$list[$key]; } else { if (isset($refer[$parentId])) { $parent = &$refer[$parentId]; $parent[$child][] = &$list[$key]; } } } } return $tree; } /** * 生成报告编号 * 国中规则:区域inquiry.brankCom_id + 报告方向report.report_dir + 年份 + * 报告(对象)类型report.report_obj_type + 客户类型bank.custom_type + * 类型report.report_class + 月份 + 流水号 + 机构简称 bank.short_name * * @param $quot_id 询价ID * @param string $business_type * @return array */ /** * 生成报告类型: 1:报告类型,2:预估类型,3、咨询类型 */ public const GENERATE_TYPE_REPORT = 1; // 鉴证类型 public const GENERATE_TYPE_ESTIMATE = 2;// 预估类型 public const GENERATE_TYPE_CONSULT = 3; // 咨询类型 public const GENERATE_TYPE_REVIEW = 4; // 复合类型 /** * Generates a report number based on specific business rules * * The report number follows GZI rules combining: * - Region (inquiry.brankCom_id) * - Report direction (report.report_dir) * - Year * - Report object type (report.report_obj_type) * - Customer type (bank.custom_type) * - Report class (report.report_class) * - Month * - Serial number * - Institution abbreviation (bank.short_name) * * @param int $quot_id The inquiry ID to generate number for * @param string $generate_type Type of generation, e.g.,1-报告,2-预估,3、咨询. * @param string $business_type Business type identifier * @return array Returns array with generated number and status: * ['report_no' => string, * 'second' => string, * 'code' => int, * 'msg' => string] */ /*public static function generateNo($quot_id ,$generate_type ,$business_type = '' ) { $number_array = ['report_no' => "", 'second' => "", 'code'=>'0','msg'=>'success!']; // 国中规则:区域inquiry.brankCom_id + 报告方向report.report_dir + 年份 + // 报告(对象)类型report.report_obj_type + 客户类型bank.custom_type + // 类型report.report_class + 月份 + 流水号 + 机构简称 bank.short_name // 区域 $inquiry = Db::name('inquiry')->field('type,bank_id,eva_purpose,is_simple,branchCom_id,report_class,report_obj_type')->where('id', $quot_id)->find(); //检查inquiry表数据是否存在 if(!$inquiry){ $number_array['code'] = -1; $number_array['msg'] = '询价ID:['.$quot_id.']的询价表数据不存在'; return $number_array; } // 报告方向 鉴证类:(评)字、预估类:(预)字、咨询类:(咨)字、复核类:(核)字 $reportDirItem = Enumcfg::findById(Enumcfg::reportDir, $generate_type); if(null == $reportDirItem){ $number_array['code'] = -5; $number_array['msg'] = '报告方向:['.$generate_type.']的枚举表数据不存在'; return $number_array; } $reportDir = $reportDirItem['shortName']; // 报告对象类型 F:房产 T:土地 Z:资产 $reportObjTypeItem = Enumcfg::findById( Enumcfg::reportObjType, $inquiry['report_obj_type']); if(null == $reportObjTypeItem){ $number_array['code'] = -6; $number_array['msg'] = '报告对象类型:['.$inquiry['report_obj_type'].']的枚举表数据不存在'; return $number_array; } $reportObjType = $reportObjTypeItem['shortName']; // 报告类型: $reportClassItem = Enumcfg::findById( Enumcfg::reportClass, $inquiry['report_class']); if(null == $reportClassItem){ $number_array['code'] = -7; $number_array['msg'] = '报告类型:['.$inquiry['report_class'].']的枚举表数据不存在'; return $number_array; } $reportClass = $reportClassItem ['shortName']; // 机构简称 $branchComConfig = Db::name('branchcom_config')->where('id', $inquiry['branchCom_id']) // 或者根据实际关联字段调整查询条件 ->field('short_name') ->find(); if(!$branchComConfig){ $number_array['code'] = -2; $number_array['msg'] = '机构代码:['.$inquiry['branchCom_id'].']的机构表数据不存在'; return $number_array; } $short_name = $branchComConfig['short_name']; // 机构简称 暂时用银行简称代替,后续需要改成机构简称 $bankInfo = Db::name('bank')->field('bank_abbreviation,bank_type,bank_code')->where('id', $inquiry['bank_id'])->find(); if(!$bankInfo){ $number_array['code'] = -3; $number_array['msg'] = '询价ID:['.$quot_id.']的机构表数据不存在'; return $number_array; } $customType = $bankInfo['bank_type']; // 机构客户类型 // 机构代码 $bankCode = $bankInfo['bank_code']; // 机构代码 $s_no = -1; $now_year = date('Y'); $now_month = date('m'); switch ($generate_type) { case Tools::GENERATE_TYPE_ESTIMATE: //计算一个流水号:要求 当年的流水号从1开始,branchCom_id与report_dir相同的所有的询价数量+1 $s_no = $inquirisCountINfo = Db::name('inquiry')->field('id') ->where('seal_time', 'like', $now_year . '-' . $now_month . '%') ->where('branchCom_id', $inquiry['branchCom_id']) ->where('estimated_no','<>', '') ->whereNotNull('estimated_no') ->count()+1; break; case Tools::GENERATE_TYPE_REPORT: case Tools::GENERATE_TYPE_CONSULT: case Tools::GENERATE_TYPE_REVIEW: $s_no = Db::name('report')->field('id') ->where('branchCom_id', $inquiry['branchCom_id']) ->where('report_no','<>', '') ->whereNotNull('report_no') ->where('create_time', 'like', $now_year . '-' . $now_month . '%') ->count() + 1; break; default: // 报错 $number_array['code'] = -4; $number_array['msg'] = '生成类型:['.$generate_type.']的枚举表数据不存在'; return $number_array; } // 生成报告编号 $new_number = env('service.estimate_short_name'). $short_name . '('. $reportDir . ')'. '字【'.$now_year .'】第'. $reportObjType . $customType . $reportClass . $now_month . str_pad($s_no, 4, '0', STR_PAD_LEFT). '-'.$bankCode.'号'; $number_array['code'] = 0; $number_array['msg'] = '生成成功'; $number_array['data'] = $new_number; return $number_array; }*/ /** * Generates a report number based on specific business rules * * The report number follows GZI rules combining: * - Region (inquiry.brankCom_id) * - Report direction (report.report_dir) * - Year * - Report object type (report.report_obj_type) * - Customer type (bank.custom_type) * - Report class (report.report_class) * - Month * - Serial number * - Institution abbreviation (bank.short_name) * * @param int $quot_id The inquiry ID to generate number for * @param string $generate_type Type of generation, e.g.,1-报告,2-预估,3、咨询. * @param string $business_type Business type identifier * @return array Returns array with generated number and status: * ['report_no' => string, * 'second' => string, * 'code' => int, * 'msg' => string] */ // 深国中评字SZ[2025]第GA-1127001-PA号 public static function generateNo($quot_id ,$generate_type ,$business_type = '' ) { $number_array = ['report_no' => "", 'second' => "", 'code'=>'0','msg'=>'success!']; $now_year = date('Y'); $now_month = date('m'); $now_day = date('d'); if ($generate_type == static::GENERATE_TYPE_REPORT) { //报告编号 $inquiry = Db::name('inquiry')->field('loan_type,type,bank_id,eva_purpose,is_simple,branchCom_id,report_class,report_obj_type')->where('id', $quot_id)->find(); if(!$inquiry){ $number_array['code'] = -1; $number_array['msg'] = '询价ID:['.$quot_id.']的询价表数据不存在'; return $number_array; } $cnStr = '评'; // 除了报告类型是Z(咨询)类的叫咨,其他都叫评。 // 对公 if ($inquiry['loan_type'] == '对公') { $dateStr = $now_month; $reportType = 'C'; if (strtoupper($inquiry['report_obj_type']) == 'T') { $reportType = 'TD'; } else if (strtoupper($inquiry['report_obj_type']) == 'Z') { $cnStr = '咨'; $reportType = 'A'; } $s_no = Db::name('report')->field('id') ->where('report_no', 'like', '%第' . $reportType . '%') ->where('create_time', 'like', $now_year . '-' . $now_month . '%') ->count() + 1; $s_no = str_pad($s_no, 4, '0', STR_PAD_LEFT); } else { // 其他的非对公 $dateStr = $now_month.$now_day; $property_cert_info = Db::name('property_cert_info')->where('quot_id', $quot_id)->select(); if (!$property_cert_info) { $number_array['code'] = -1; $number_array['msg'] = '询价ID:['.$quot_id.']的物业表数据不存在'; return $number_array; } $ownership_type = array_column($property_cert_info, 'ownership_type'); $reportTypeConcatStr = 'A'; if (in_array('2', $ownership_type)) { $reportTypeConcatStr = 'B'; } $reportType = 'G' . $reportTypeConcatStr; $s_no = Db::name('report')->field('id') ->where('report_no', 'like', '%第G%') ->where('create_time', 'like', $now_year . '-' . $now_month . '-' . $now_day . '%') ->count() + 1; $s_no = str_pad($s_no, 3, '0', STR_PAD_LEFT); } // 机构简称 $branchComConfig = Db::name('branchcom_config') ->where('id', $inquiry['branchCom_id']) // 或者根据实际关联字段调整查询条件 ->field('short_name') ->find(); if(!$branchComConfig){ $number_array['code'] = -2; $number_array['msg'] = '机构代码:['.$inquiry['branchCom_id'].']的机构表数据不存在'; return $number_array; } $short_name = $branchComConfig['short_name']; // 机构简称 暂时用银行简称代替,后续需要改成机构简称 $bankInfo = Db::name('bank')->field('bank_abbreviation,bank_type,bank_code')->where('id', $inquiry['bank_id'])->find(); if(!$bankInfo){ $number_array['code'] = -3; $number_array['msg'] = '询价ID:['.$quot_id.']的机构表数据不存在'; return $number_array; } // 机构代码 $bankCode = $bankInfo['bank_code']; // 机构代码 // 生成报告编号 $new_number = '深'. env('service.estimate_short_name'). $cnStr. '字'. EnumCfg::branchComShortNameToEnName[$short_name]. '['.$now_year.']'. '第'. $reportType . '-'. $dateStr. $s_no. '-'. $bankCode. '号'; } else if ($generate_type == static::GENERATE_TYPE_ESTIMATE) { //预估编号 $estimated_no = Db::name('inquiry')->field('id') ->where('estimated_no', 'like', $now_year . '-GZ' . $now_month . $now_day . '%') ->count()+1; $new_number = $now_year.'-GZ'.$now_month.$now_day.str_pad($estimated_no,5,'0',STR_PAD_LEFT); } else { $number_array['code'] = -4; $number_array['msg'] = '生成类型:['.$generate_type.']的枚举表数据不存在'; return $number_array; } Log::error('生成编号:'.$new_number); $number_array['data'] = $new_number; return $number_array; } /** * 创建二维码 * * @param string $url 目录 http://www.xxx.com or https://xx.xx.xx.xx * @param string $type * @return void */ public static function createQRCode($url, $type=''){ require_once "../vendor/phpqrcode/phpqrcode.php"; $value = $url; //二维码内容 $errorCorrectionLevel = 'L'; //容错级别 $matrixPointSize = 7; //生成图片大小 //生成二维码图片 $sha1 = "GZQR";//"qrcode"; $path = date("YmdHis",time()).rand(1000,9999); $extract = $sha1."_".$path; $date = date('Ymd'); $Path = config('uploadFile.img_path') . DS . 'uploads' . DS . $date; if (!file_exists($Path)) { //检查是否有该文件夹,如果没有就创建,并给予最高权限 mkdir($Path, 0777, true); } if (empty($type)) { $filename = DS . 'uploads' . DS . $date . DS . $extract . ".png"; $filePath = $Path . DS . "$extract.png"; QRcode::png($value,$filePath , $errorCorrectionLevel, $matrixPointSize, 2); $QR = $filePath; //已经生成的原始二维码图片文件 $QR = imagecreatefromstring(file_get_contents($QR)); //输出图片 imagepng($QR, 'qrcode.png'); imagedestroy($QR); } else {//报告防伪二维码 $errorCorrectionLevel = 'H';//容错级别 $matrixPointSize = 4;//生成图片大小 $filename = DS . 'uploads' . DS . $date . DS . $extract . ".png"; $filePath = $Path . DS . "$extract.png"; $logo = ROOT_PATH . 'public' . DS . 'static/Qrcode.png'; QRcode::png($value, $filePath , $errorCorrectionLevel, $matrixPointSize, 2); $QR = $filePath; //已经生成的原始二维码图片文件 $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR);//二维码图片宽度 $QR_height = imagesy($QR);//二维码图片高度 $logo_width = imagesx($logo);//logo图片宽度 $logo_height = imagesy($logo);//logo图片高度 $logo_qr_width = $QR_width / 5; $scale = $logo_width/$logo_qr_width; $logo_qr_height = $logo_height/$scale; $from_width = ($QR_width - $logo_qr_width) / 2; //重新组合图片并调整大小 imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); //输出图片 imagepng($QR, $filePath); imagedestroy($QR); } $upload = ossUpload(trim(str_replace("\\", "/", $filename), '/'), $filePath); unlink($filePath); //把本地图片删除(原图) //二维码地址 $url = config('uploadFile.url') . str_replace("\\", "/", $filename); return $url; } /** * 数字转金额 * @param $num * @return string * @api * @author fd * @date-time 2020/5/13-10:22 */ public function get_amount($num){ $c1 = "零壹贰叁肆伍陆柒捌玖"; $c2 = "分角元拾佰仟万拾佰仟亿"; $num = round($num, 2); $num = $num * 100; if (strlen($num) > 10) { return "数据太长,检查下"; } $i = 0; $c = ""; while (1) { if ($i == 0) { $n = substr($num, strlen($num)-1, 1); } else { $n = $num % 10; } $p1 = substr($c1, 3 * $n, 3); $p2 = substr($c2, 3 * $i, 3); if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) { $c = $p1 . $p2 . $c; } else { $c = $p1 . $c; } $i = $i + 1; $num = $num / 10; $num = (int)$num; if ($num == 0) { break; } } $j = 0; $slen = strlen($c); while ($j < $slen) { $m = substr($c, $j, 6); if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') { $left = substr($c, 0, $j); $right = substr($c, $j + 3); $c = $left . $right; $j = $j-3; $slen = $slen-3; } $j = $j + 3; } if (substr($c, strlen($c)-3, 3) == '零') { $c = substr($c, 0, strlen($c)-3); } if (empty($c)) { return "零元整"; }else{ return $c . "整"; } } /** * 将日期中数字转成大写 * @param $str * @return string * @api * @author fd * @date-time 2020/5/13-10:53 */ function chinanum($str){ $china=array('〇','一','二','三','四','五','六','七','八','九',); $arr=str_split($str); $strChange = ''; for($i=0;$i