2024-09-30 16:52:40 +08:00
< ? php
namespace app\app\controller ;
use think\Db ;
use Exception ;
class Cardpublic extends Base {
2024-11-23 16:46:38 +08:00
protected $cardpublic_use_db_name = [
'1' => 'app_user_data' ,
'2' => 'app_card_data_sub_item' ,
'3' => 'app_card_data_sub_item_data' ,
'4' => 'admin_estimate' ,
'5' => 'app_card_data'
];
protected $curve_color = [ '#f7b03e' , '#fb7b92' , '#ff9f40' , '#3fcba7' ,];
2024-09-30 16:52:40 +08:00
protected $level_data = [
[ 'min_val' => '0' , 'max_val' => '59' , 'text' => '不及格' , 'color' => '#FB5755' ],
[ 'min_val' => '60' , 'max_val' => '79' , 'text' => '及格' , 'color' => '#FCAE00' ],
[ 'min_val' => '80' , 'max_val' => '89' , 'text' => '良好' , 'color' => '#58CF67' ],
[ 'min_val' => '90' , 'max_val' => '150' , 'text' => '优秀' , 'color' => '#6691EF' ],
];
2024-11-23 16:46:38 +08:00
// 获取卡片数据
2024-12-18 09:19:51 +08:00
public function get_card_content ( $data = [ 'aud_id' => '11' , 'acd_id' => '13' , 'token' => 'caadd1be045a65f30b92aa805f1de54a' ]){
2024-11-23 16:46:38 +08:00
// try {
// // 你的业务逻辑
// $return_data =
// // 成功
// $this->record_api_log($data, null, $return_data);
// return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["flie"] = $e->getFile();
// $logContent["line"] = $e->getLine();
// $logContent['all_content'] = "异常信息:\n";
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
// $this->record_api_log($data, $logContent, null);
// return $this->msg(99999);
// }
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'token' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'acd_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 );
}
$return_data = $this -> get_card_content_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
}
}
// {"acd_id":"11","name":"200米","record_time":"2024-09-27","data":"02:00","aud_id":"1","token":"57bd45e3a963b372ea2d873e4bd8d1f8","aan_id":"1"}
// 存储信息
public function data_save ( $data = [ 'aud_id' => '11' , 'acd_id' => '16' , 'name' => '排球' , 'data' => '33' , 'record_time' => '2024-10-18' ]){
// {"acd_id":"10","name":"1000米","record_time":"2024-10-18","data":"05:00","aud_id":"24","token":"6441bf7dabea7b3360a30240d3b19fc5","aan_id":"4"}
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'name' , $data ) || ! array_key_exists ( 'data' , $data ) || ! array_key_exists ( 'record_time' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'acd_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'name' ], 'str' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'record_time' ], 'datetime' )){
return $this -> msg ( 10005 );
}
$return_data = $this -> data_save_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
}
}
// 获取标签项目信息
public function get_label_list ( $data = [ 'aud_id' => '1' , 'token' => 'caadd1be045a65f30b92aa805f1de54a' ]){
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'token' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 );
}
$return_data = $this -> get_label_list_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
}
}
// 卡片运动曲线
public function card_motion_curve ( $data = [ 'aud_id' => '1' , 'acd_id' => '10' , 's_time' => '2024-04-01' , 'e_time' => '2024-11-25' , 'token' => 'caadd1be045a65f30b92aa805f1de54a' ]){
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 's_time' , $data ) || ! array_key_exists ( 'e_time' , $data ) || ! array_key_exists ( 'token' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'acd_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 's_time' ], 'datetime' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'e_time' ], 'datetime' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 );
}
$return_data = $this -> card_motion_curve_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
}
// 数据对比-获取数据
public function data_contrast_obtain_data ( $data = [ 'aud_id' => '1' , 'acd_id' => '10' , 'name' => '1000米' , 's_time' => '2024-04-01' , 'e_time' => '2024-10-03' ]){
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'name' , $data ) || ! array_key_exists ( 's_time' , $data ) || ! array_key_exists ( 'e_time' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'acd_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 's_time' ], 'datetime' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'e_time' ], 'datetime' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'name' ], 'str' )){
return $this -> msg ( 10005 );
}
$return_data = $this -> data_contrast_obtain_data_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
// 数据对比-对比数据(暂时荒废)
public function data_contrast_contrast_data ( $data = [ 'before_id' => '1' , 'after_id' => '3' ]){
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'before_id' , $data ) || ! array_key_exists ( 'after_id' , $data )){
return $this -> msg ( 10001 );
}
$return_data = $this -> data_contrast_contrast_data_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
}
// 历史记录
public function obtain_history_record ( $data = [ 'aud_id' => '1' , 'acd_id' => '10' , 'name' => '1000米' , 'page' => '1' ]){
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'name' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'acd_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'page' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'name' ], 'str' )){
return $this -> msg ( 10005 );
}
$return_data = $this -> obtain_history_record_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
}
// 历史记录
public function history_record_del ( $data = [ 'id' => '10' ]){
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'id' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
$return_data = $this -> history_record_del_action ( $data );
// 成功
$this -> record_api_log ( $data , null , $return_data );
return $return_data ;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
// 获取手动记录内容
public function obtain_manual_record_content ( $data = [ 'aud_id' => 11 ]){
2024-12-18 09:19:51 +08:00
try {
// 你的业务逻辑
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
if ( ! array_key_exists ( 'aud_id' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
$user_data = Db :: table ( $this -> cardpublic_use_db_name [ '1' ]) -> where ([ 'id' => $data [ 'aud_id' ]]) -> field ( 'id,gender' ) -> find ();
if ( ! $user_data ){
return $this -> msg ( 10004 );
}
$card_data_c = Db :: table ( $this -> cardpublic_use_db_name [ '2' ])
-> where ([ 'is_del' => 0 ])
-> field ( 'id,name,type,unit,unit2,suit_gender,acd_id' )
-> select ();
$card_data_c2 = [];
foreach ( $card_data_c as $key => $value ) {
2024-11-23 16:46:38 +08:00
$temporary_arr = [];
2024-12-18 09:19:51 +08:00
$temporary_arr [ 'id' ] = $value [ 'acd_id' ];
$temporary_arr [ 'height' ] = false ;
$temporary_arr [ 'weight' ] = false ;
$temporary_arr [ 'number' ] = false ;
$temporary_arr [ 'time' ] = false ;
$temporary_arr [ 'list' ] = [];
$card_data_c2 [ $value [ 'acd_id' ]] = $temporary_arr ;
}
foreach ( $card_data_c as $key => $value ) {
if ( in_array ( $user_data [ 'gender' ], explode ( " , " , $value [ 'suit_gender' ]))){
$temporary_arr = [];
$temporary_arr [ 'id' ] = $value [ 'id' ];
$temporary_arr [ 'name' ] = $value [ 'name' ];
$temporary_arr [ 'number' ] = $value [ 'unit2' ] == '时长' ? false : true ;
$temporary_arr [ 'type' ] = $value [ 'type' ];
$temporary_arr [ 'time' ] = $value [ 'unit2' ] == '时长' ? true : false ;
$temporary_arr [ 'describe' ] = $value [ 'unit2' ];
$temporary_arr [ 'unit' ] = $value [ 'unit' ] == " 分/秒 " ? '' : $value [ 'unit' ];
array_push ( $card_data_c2 [ $value [ 'acd_id' ]][ 'list' ], $temporary_arr );
} else {
continue ;
}
2024-11-23 16:46:38 +08:00
}
2024-12-18 09:19:51 +08:00
$card_data = [
[ 'id' => '2' , 'height' => true , 'weight' => true , 'number' => false , 'time' => false , 'list' => []],
[ 'id' => '6' , 'height' => false , 'weight' => false , 'number' => true , 'time' => true , 'list' => []],
];
foreach ( $card_data_c2 as $key => $value ) {
array_push ( $card_data , $value );
}
// 成功
$this -> record_api_log ( $data , null , $card_data );
return $this -> msg ( $card_data );
// return $return_data;
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
}
2024-09-30 16:52:40 +08:00
}
################################################################action################################################################
################################################################action################################################################
##################################################get_card_content##################################################
public function get_card_content_action ( $data ){
2024-11-23 16:46:38 +08:00
2024-09-30 16:52:40 +08:00
// 查找用户是存在
2024-11-23 16:46:38 +08:00
$user_data = Db :: table ( $this -> cardpublic_use_db_name [ '1' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( 'id,gender' ) -> find ();
2024-09-30 16:52:40 +08:00
if ( ! $user_data ){
return $this -> msg ( 10004 );
}
2024-11-23 16:46:38 +08:00
2024-09-30 16:52:40 +08:00
// 卡片是否存在,以及是否含有子项
2024-11-23 16:46:38 +08:00
$card_data_sub_item = Db :: table ( $this -> cardpublic_use_db_name [ '2' ]) -> where ( " acd_id = " . $data [ 'acd_id' ] . " and is_del = 0 and suit_gender LIKE '% " . $user_data [ 'gender' ] . " %' " ) -> field ( 'id,type,name,unit' ) -> select ();
2024-09-30 16:52:40 +08:00
if ( ! $card_data_sub_item ){
return $this -> msg ( 10004 );
}
$return_data = [
'icon' => '' ,
'label_list' => [],
'line_list' => [],
'label_data' => [],
];
$data_this_time = [];
$today_time = date ( 'Y-m-d' );
foreach ( $card_data_sub_item as $key => $value ) {
// 设置单项数据模板
$temporary_arr_c = [
'project_name' => $value [ 'name' ],
'score' => '' ,
'max_score' => '' ,
'standard' => '' ,
'this_time_title' => '本次成绩' ,
'this_time_value' => '' ,
'today_time_title' => '今日总计' ,
'today_times' => 0 ,
'today_time_value' => 0 ,
'all_time_title' => '总计平均' ,
'all_times' => 0 ,
'all_time_value' => 0 ,
'describe' => '' ,
'color' => '' ,
'offset' => '' ,
'unit_data' => '' ,
2024-11-23 16:46:38 +08:00
'record_time' => '' ,
2024-09-30 16:52:40 +08:00
];
// 添加标签
array_push ( $return_data [ 'label_list' ], $value [ 'name' ]);
// 添加线性轴描述
$return_data [ 'line_list' ] = $this -> level_data ;
// 查询最后一次成绩
2024-11-23 16:46:38 +08:00
$data_this_time = Db :: table ( $this -> cardpublic_use_db_name [ '3' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ], 'acdsi_id' => $value [ 'id' ], 'is_del' => 0 ]) -> order ( 'record_time desc' ) -> field ( 'id,detailed_msg,achievement,record_time' ) -> find ();
2024-12-18 09:19:51 +08:00
2024-09-30 16:52:40 +08:00
if ( $data_this_time ){
$data_this_time [ 'detailed_msg' ] = json_decode ( $data_this_time [ 'detailed_msg' ], true );
// 设置基础数据
$temporary_arr_c [ 'score' ] = $data_this_time [ 'detailed_msg' ][ 'score' ] . '分' ;
$temporary_arr_c [ 'max_score' ] = $data_this_time [ 'detailed_msg' ][ 'max_score' ];
$temporary_arr_c [ 'standard' ] = $data_this_time [ 'detailed_msg' ][ 'standard' ];
$temporary_arr_c [ 'describe' ] = $data_this_time [ 'detailed_msg' ][ 'describe' ];
$temporary_arr_c [ 'color' ] = $data_this_time [ 'detailed_msg' ][ 'color' ];
$temporary_arr_c [ 'offset' ] = $data_this_time [ 'detailed_msg' ][ 'offset' ];
$temporary_arr_c [ 'unit_data' ] = $data_this_time [ 'detailed_msg' ][ 'unit_data' ];
2024-11-23 16:46:38 +08:00
$temporary_arr_c [ 'record_time' ] = $data_this_time [ 'record_time' ];
2024-09-30 16:52:40 +08:00
// 获取到该项所有数据
2024-11-23 16:46:38 +08:00
$all_time_title = Db :: table ( $this -> cardpublic_use_db_name [ '3' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ], 'acdsi_id' => $value [ 'id' ], 'is_del' => 0 ]) -> order ( 'id desc' ) -> field ( 'id,achievement,LEFT(record_time,10) AS r_t' ) -> select ();
2024-09-30 16:52:40 +08:00
// 处理今日,以及总计数据
if ( $data_this_time [ 'detailed_msg' ][ 'unit_data' ] == '分/秒' ){
// 如果是分秒形式的数据
// 设置今日数据跟总计数据的格式
$temporary_arr_c [ 'today_time_value' ] = " 0:00 " ;
$temporary_arr_c [ 'all_time_value' ] = " 0:00 " ;
// 处理本次数据最终格式
list ( $minutes , $seconds ) = explode ( ':' , $data_this_time [ 'achievement' ]);
$temporary_arr_c [ 'this_time_value' ] = $minutes . '分' . sprintf ( '%02d' , $seconds ) . '秒' ;
// 计算今日总计&所有平均
$temporary_arr_c [ 'all_times' ] = count ( $all_time_title );
foreach ( $all_time_title as $k1 => $v1 ) {
$temporary_arr_c [ 'all_time_value' ] = $this -> sumTimes ( $temporary_arr_c [ 'all_time_value' ], $v1 [ 'achievement' ]);
if ( $v1 [ 'r_t' ] == $today_time ){
$temporary_arr_c [ 'today_times' ] = $temporary_arr_c [ 'today_times' ] + 1 ;
$temporary_arr_c [ 'today_time_value' ] = $this -> sumTimes ( $temporary_arr_c [ 'today_time_value' ], $v1 [ 'achievement' ]);
}
}
$temporary_arr_c [ 'all_time_value' ] = $this -> averageTime ( $temporary_arr_c [ 'all_time_value' ], $temporary_arr_c [ 'all_times' ]);
list ( $minutes , $seconds ) = explode ( ':' , $temporary_arr_c [ 'today_time_value' ]);
$temporary_arr_c [ 'today_time_value' ] = $minutes . '分' . sprintf ( '%02d' , $seconds ) . '秒' ;
} else {
$temporary_arr_c [ 'this_time_value' ] = $data_this_time [ 'achievement' ] . $data_this_time [ 'detailed_msg' ][ 'unit_data' ];
$temporary_arr_c [ 'all_times' ] = count ( $all_time_title );
foreach ( $all_time_title as $k1 => $v1 ) {
$temporary_arr_c [ 'all_time_value' ] = $temporary_arr_c [ 'all_time_value' ] + $v1 [ 'achievement' ];
if ( $v1 [ 'r_t' ] == $today_time ){
$temporary_arr_c [ 'today_times' ] = $temporary_arr_c [ 'today_times' ] + 1 ;
$temporary_arr_c [ 'today_time_value' ] = $temporary_arr_c [ 'today_time_value' ] + $v1 [ 'achievement' ];
}
}
$temporary_arr_c [ 'today_time_value' ] = $temporary_arr_c [ 'today_time_value' ] . $data_this_time [ 'detailed_msg' ][ 'unit_data' ];
$temporary_arr_c [ 'all_time_value' ] = bcdiv ( $temporary_arr_c [ 'all_time_value' ], $temporary_arr_c [ 'all_times' ], 1 ) . $data_this_time [ 'detailed_msg' ][ 'unit_data' ];
}
$temporary_arr_c [ 'today_times' ] = $temporary_arr_c [ 'today_times' ] . '次' ;
$temporary_arr_c [ 'all_times' ] = $temporary_arr_c [ 'all_times' ] . '次' ;
2024-12-18 09:19:51 +08:00
} else {
$project_describe = Db :: table ( $this -> cardpublic_use_db_name [ '2' ]) -> where ([ 'id' => $value [ 'id' ], 'is_del' => 0 ]) -> field ( 'id,project_describe' ) -> find ();
if ( $project_describe ){
$temporary_arr_c [ 'describe' ] = $project_describe [ 'project_describe' ];
}
2024-09-30 16:52:40 +08:00
}
array_push ( $return_data [ 'label_data' ], $temporary_arr_c );
}
return $this -> msg ( $return_data );
}
##################################################data_save##################################################
public function data_save_action ( $data ){
// 查找用户是存在
2024-11-23 16:46:38 +08:00
$user_data = Db :: table ( $this -> cardpublic_use_db_name [ '1' ]) -> where ([ 'id' => $data [ 'aud_id' ]]) -> field ( 'id,gender' ) -> find ();
2024-09-30 16:52:40 +08:00
if ( ! $user_data ){
return $this -> msg ( 10004 );
}
// 查找项目是否存在,以及获取项目信息
2024-11-23 16:46:38 +08:00
$card_data_sub_item_data = Db :: table ( $this -> cardpublic_use_db_name [ '2' ]) -> where ( " name = ' " . $data [ 'name' ] . " ' and suit_gender LIKE '% " . $user_data [ 'gender' ] . " %' " ) -> field ( 'id,type,name,unit,acd_id' ) -> find ();
2024-09-30 16:52:40 +08:00
if ( ! $card_data_sub_item_data ){
2024-11-23 16:46:38 +08:00
return $this -> msg ( 10004 , '1' );
2024-09-30 16:52:40 +08:00
}
// 如果项目数据类型为分秒格式
if ( $card_data_sub_item_data [ 'type' ] == 1 ){
// 判断是否为整型,或者字符串类型的整型数字
if ( ! $this -> isValidInteger ( $data [ 'data' ])){
return $this -> msg ( 10005 );
}
} else if ( $card_data_sub_item_data [ 'type' ] == 4 ){
// 检查字符串格式是否为“数字”+“:”+“数字”的格式, 且冒号后的数字小于等于59
if ( ! $this -> isValidFormatWithLimit ( $data [ 'data' ])){
return $this -> msg ( 10005 );
}
} else if ( $card_data_sub_item_data [ 'type' ] == 2 ){
// 判断一个字符串是否为两位以内小数
if ( ! $this -> isTwoDecimalOrLess ( $data [ 'data' ])){
return $this -> msg ( 10005 );
}
}
2024-11-23 16:46:38 +08:00
$score_all_data = $this -> calculation_score ( $user_data [ 'gender' ], $data , $card_data_sub_item_data [ 'type' ], $card_data_sub_item_data [ 'unit' ]);
2024-09-30 16:52:40 +08:00
$save_data = [
'acd_id' => $card_data_sub_item_data [ 'acd_id' ],
'acdsi_id' => $card_data_sub_item_data [ 'id' ],
'aud_id' => $data [ 'aud_id' ],
'achievement' => $data [ 'data' ],
'record_time' => $data [ 'record_time' ] . date ( ' H:i:s' ),
'create_time' => date ( 'Y-m-d H:i:s' ),
'unit' => $card_data_sub_item_data [ 'unit' ],
'score' => $score_all_data [ 'score' ],
'detailed_msg' => json_encode ( $score_all_data ),
];
2024-11-23 16:46:38 +08:00
$result = Db :: table ( $this -> cardpublic_use_db_name [ '3' ]) -> insert ( $save_data );
2024-09-30 16:52:40 +08:00
// $result = true;
if ( $result ){
if ( $save_data [ 'unit' ] == '分/秒' ){
list ( $minutes , $seconds ) = explode ( ':' , $data [ 'data' ]);
$score_all_data [ 'this_time_value' ] = $minutes . '分' . sprintf ( '%02d' , $seconds ) . '秒' ;
} else {
$score_all_data [ 'this_time_value' ] = $data [ 'data' ] . $save_data [ 'unit' ];
}
return $this -> msg ( $score_all_data );
} else {
return $this -> msg ( 10002 );
}
}
##################################################get_label_list##################################################
public function get_label_list_action ( $data ){
// 查找用户是存在
2024-11-23 16:46:38 +08:00
$user_data = Db :: table ( $this -> cardpublic_use_db_name [ '1' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( 'id,gender' ) -> find ();
2024-09-30 16:52:40 +08:00
if ( ! $user_data ){
return $this -> msg ( 10004 );
}
2024-11-23 16:46:38 +08:00
$label_data = Db :: table ( $this -> cardpublic_use_db_name [ '2' ]) -> where ( " is_del = 0 and suit_gender LIKE '% " . $user_data [ 'gender' ] . " %' " ) -> field ( 'id,acd_id,name,unit,type' ) -> select ();
2024-09-30 16:52:40 +08:00
if ( count ( $label_data ) <= 0 ){
return $this -> msg ( 10004 );
}
2024-11-23 16:46:38 +08:00
$return_data = [];
$temporary_arr = [];
2024-09-30 16:52:40 +08:00
foreach ( $label_data as $key => $value ) {
2024-11-23 16:46:38 +08:00
if ( ! array_key_exists ( $value [ 'acd_id' ], $temporary_arr )){
$temporary_arr [ $value [ 'acd_id' ]] = [ $value [ 'name' ]];
} else {
array_push ( $temporary_arr [ $value [ 'acd_id' ]], $value [ 'name' ]);
2024-09-30 16:52:40 +08:00
}
}
2024-11-23 16:46:38 +08:00
foreach ( $temporary_arr as $key => $value ) {
array_push ( $return_data ,[
'acd_id' => $key ,
'list' => $value ,
]);
}
return $this -> msg ( $return_data );
2024-09-30 16:52:40 +08:00
}
2024-11-23 16:46:38 +08:00
##################################################card_motion_curve##################################################
public function card_motion_curve_action ( $data ){
$user_data = Db :: table ( $this -> cardpublic_use_db_name [ '1' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( 'id,gender' ) -> find ();
if ( ! $user_data ){
return $this -> msg ( 10004 );
}
$card_sub_item_data = Db :: table ( $this -> cardpublic_use_db_name [ '3' ]) -> where ([ 'acd_id' => $data [ 'acd_id' ], 'aud_id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> order ( 'record_time desc' ) -> field ( 'id,acdsi_id,score,LEFT(record_time,10) as r_t,record_time' ) -> select ();
$card_sub_item_type = Db :: table ( $this -> cardpublic_use_db_name [ '2' ]) -> where ( " acd_id = " . $data [ 'acd_id' ] . " and is_del = 0 and suit_gender LIKE '% " . $user_data [ 'gender' ] . " %' " ) -> field ( 'id,name,unit' ) -> select ();
$temporary_arr = [];
$return_data = [];
// 处理一个临时数据
foreach ( $card_sub_item_type as $key => $value ) {
$temporary_arr [ $value [ 'id' ]] = [ 'name' => $value [ 'name' ], 'unit' => $value [ 'unit' ], 'time' => [], 'data' => []];
}
// 往临时数组内填入数据
foreach ( $card_sub_item_data as $key => $value ) {
array_push ( $temporary_arr [ $value [ 'acdsi_id' ]][ 'time' ], $value [ 'r_t' ]);
array_push ( $temporary_arr [ $value [ 'acdsi_id' ]][ 'data' ], $this -> convertStringToNumber ( $value [ 'score' ]));
}
$num = 0 ;
foreach ( $temporary_arr as $key => $value ) {
if (( $num + 1 ) > count ( $this -> curve_color )){
$num = 0 ;
}
array_push ( $return_data ,[
'title' => $value [ 'name' ],
'key' => $value [ 'name' ],
'line' => [
'categories' => $value [ 'time' ],
'series' => [
[
'color' => $this -> curve_color [ $num ],
'name' => $value [ 'name' ],
'data' => $value [ 'data' ],
]
],
],
]);
$num = $num + 1 ;
}
return $this -> msg ( $return_data );
}
##################################################data_contrast_obtain_data##################################################
public function data_contrast_obtain_data_action ( $data ){
// $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find();
$card_data = Db :: table ( $this -> cardpublic_use_db_name [ '2' ]) -> where ([ 'acd_id' => $data [ 'acd_id' ], 'name' => $data [ 'name' ], 'is_del' => 0 ]) -> find ();
$result_data = Db :: table ( $this -> cardpublic_use_db_name [ '3' ])
-> where ([ 'aud_id' => $data [ 'aud_id' ], 'acdsi_id' => $card_data [ 'id' ], 'is_del' => 0 ])
-> whereTime ( 'record_time' , 'between' , [ $data [ 's_time' ], $data [ 'e_time' ]])
-> field ( 'id,achievement,score,unit,record_time' )
-> order ( 'record_time desc' )
-> select ();
$return_data = [];
foreach ( $result_data as $key => $value ) {
if ( $value [ 'unit' ] == '分/秒' ){
$temporary_arr_e1 = explode ( ':' , $value [ 'achievement' ]);
$temporary_arr_e2 = explode ( '/' , $value [ 'unit' ]);
}
$temporary_arr = [
" id " => $value [ 'id' ],
// "v1"=> $value['achievement'].$value['unit'],
" v1 " => $value [ 'unit' ] == '分/秒' ? $temporary_arr_e1 [ 0 ] . $temporary_arr_e2 [ 0 ] . $temporary_arr_e1 [ 1 ] . $temporary_arr_e2 [ 1 ] : $value [ 'achievement' ] . $value [ 'unit' ],
" v2 " => $this -> convertStringToNumber ( $value [ 'score' ]) . '分' ,
" v1_name " => " 成绩 " ,
" v2_name " => " 得分 " ,
" r_t " => substr ( $value [ 'record_time' ], 0 , 10 )
];
array_push ( $return_data , $temporary_arr );
}
return $this -> msg ( $return_data );
}
##################################################data_contrast_contrast_data##################################################
public function data_contrast_contrast_data_action ( $data ){
$tj = " id IN ( " . $data [ 'before_id' ] . " , " . $data [ 'after_id' ] . " ) " ;
$card_data = Db :: table ( $this -> cardpublic_use_db_name [ '3' ]) -> where ( $tj ) -> select ();
if ( count ( $card_data ) < 2 ){
return $this -> msg ( 10004 );
}
if ( $card_data [ 0 ][ 'acdsi_id' ] != $card_data [ 1 ][ 'acdsi_id' ]){
return $this -> msg ( 10003 );
}
}
##################################################obtain_history_record##################################################
public function obtain_history_record_action ( $data ){
$card_data = Db :: table ( $this -> cardpublic_use_db_name [ '2' ]) -> where ([ 'acd_id' => $data [ 'acd_id' ], 'name' => $data [ 'name' ], 'is_del' => 0 ]) -> find ();
$result_count = Db :: table ( $this -> cardpublic_use_db_name [ '3' ])
-> where ([ 'aud_id' => $data [ 'aud_id' ], 'acdsi_id' => $card_data [ 'id' ], 'is_del' => 0 ])
-> count ();
$result_data = Db :: table ( $this -> cardpublic_use_db_name [ '3' ])
-> where ([ 'aud_id' => $data [ 'aud_id' ], 'acdsi_id' => $card_data [ 'id' ], 'is_del' => 0 ])
-> field ( 'id,achievement,score,unit,record_time' )
-> order ( 'record_time desc' )
-> page ( $data [ 'page' ] . " ,10 " )
-> select ();
$return_data = [
'totalrows' => $result_count ,
'rows' => [],
'pagenow' => $data [ 'page' ],
'pagesize' => 10 ,
'totalpage' => ceil ( $result_count / 10 ),
];
foreach ( $result_data as $key => $value ) {
$temporary_arr = [];
if ( $value [ 'unit' ] == '分/秒' ){
$temporary_arr_e1 = explode ( ':' , $value [ 'achievement' ]);
$temporary_arr_e2 = explode ( '/' , $value [ 'unit' ]);
}
$temporary_arr = [
" id " => $value [ 'id' ],
// "v1"=> $value['achievement'].$value['unit'],
" v1 " => $value [ 'unit' ] == '分/秒' ? $temporary_arr_e1 [ 0 ] . $temporary_arr_e2 [ 0 ] . $temporary_arr_e1 [ 1 ] . $temporary_arr_e2 [ 1 ] : $value [ 'achievement' ] . $value [ 'unit' ],
" v2 " => $this -> convertStringToNumber ( $value [ 'score' ]) . '分' ,
" v1_name " => " 成绩 " ,
" v2_name " => " 得分 " ,
" record_time " => $value [ 'record_time' ]
];
array_push ( $return_data [ 'rows' ], $temporary_arr );
}
return $this -> msg ( $return_data );
}
##################################################history_record_del##################################################
public function history_record_del_action ( $data ){
$result_count = Db :: table ( $this -> cardpublic_use_db_name [ '3' ])
-> where ([ 'id' => $data [ 'id' ]])
-> update ([ 'is_del' => 1 ]);
if ( $result_count ){
return $this -> msg ([]);
} else {
return $this -> msg ( 10002 );
}
}
2024-09-30 16:52:40 +08:00
################################################################tool################################################################
################################################################tool################################################################
// 计算得分成绩以及线性进度
2024-11-23 16:46:38 +08:00
public function calculation_score ( $gender , $data , $type , $unit_msg ){
2024-09-30 16:52:40 +08:00
$card_name [ 'project_name' ] = $data [ 'name' ];
$card_name [ 'score' ] = 0 ;
$card_name [ 'offset' ] = 0 ;
$describe_list = $this -> level_data ;
$card_name [ 'rule' ] = [];
// 计算得分
// 获取评分细则
2024-11-23 16:46:38 +08:00
$estimate = Db :: table ( $this -> cardpublic_use_db_name [ '4' ]) -> where ([ 'type' => 3 ]) -> find ();
2024-09-30 16:52:40 +08:00
$estimate = json_decode ( $estimate [ 'content' ], true );
// 根据男女循环出项目细则
foreach ( $estimate [ $gender ][ '公共考核标准' ] as $key => $value ) {
if ( count ( $card_name [ 'rule' ]) > 0 ){
break ;
}
foreach ( $value [ 'list' ] as $k => $v ) {
if ( $k == $data [ 'name' ]){
$card_name [ 'rule' ] = $v ;
break ;
}
}
}
foreach ( $card_name [ 'rule' ][ 'content' ] as $key => $value ) {
2024-11-23 16:46:38 +08:00
if ( $type == '4' ){
2024-09-30 16:52:40 +08:00
$rule_result = $this -> convertMinutesSecondsToStringSeconds ( $value [ 0 ]);
$data_result = $this -> convertMinutesSecondsToStringSeconds ( $data [ 'data' ]);
} else {
$rule_result = $value [ 0 ];
$data_result = $data [ 'data' ];
}
switch ( $value [ 1 ]) {
case " <= " :
$result = $data_result <= $rule_result ;
break ;
case " >= " :
$result = $data_result >= $rule_result ;
break ;
case " < " :
$result = $data_result < $rule_result ;
break ;
case " > " :
$result = $data_result > $rule_result ;
break ;
case " == " :
$result = $data_result == $rule_result ;
break ;
case " != " :
$result = $data_result != $rule_result ;
break ;
default :
// 如果比较符号不是上述任何一个,可以抛出一个异常或错误
throw new Exception ( " Unsupported comparison operator: " . $value [ 1 ]);
}
2024-11-23 16:46:38 +08:00
2024-09-30 16:52:40 +08:00
if ( $result == true ){
$card_name [ 'score' ] = $value [ 2 ];
break ;
}
}
2024-11-23 16:46:38 +08:00
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
2024-09-30 16:52:40 +08:00
foreach ( $describe_list as $key => $value ) {
if ( $card_name [ 'score' ] >= $value [ 'min_val' ] && $card_name [ 'score' ] <= $value [ 'max_val' ]){
$card_name [ 'standard' ] = $value [ 'text' ];
$card_name [ 'color' ] = $value [ 'color' ];
2024-11-23 16:46:38 +08:00
if ( $card_name [ 'score' ] < 100 ){
// 计算当前区间内的比值()
$card_name [ 'offset' ] = bcmul ( bcdiv ( bcsub ( $card_name [ 'score' ], $value [ 'min_val' ], 20 ), bcsub ( $value [ 'max_val' ], $value [ 'min_val' ], 20 ), 4 ), 25 , 2 );
// 计算全线性下比值
$card_name [ 'offset' ] = bcadd ( $card_name [ 'offset' ], bcmul (( $key ), 25 , 0 ), 0 );
} else {
$card_name [ 'offset' ] = '100' ;
}
2024-09-30 16:52:40 +08:00
break ;
}
}
$card_name [ 'max_score' ] = $card_name [ 'rule' ][ 'content' ][ 0 ][ 2 ];
$card_name [ 'describe' ] = $card_name [ 'rule' ][ 'describe' ];
2024-11-23 16:46:38 +08:00
$card_name [ 'unit_data' ] = $unit_msg ;
2024-09-30 16:52:40 +08:00
// $card_name['default_data_format'] = $card_name['rule']['value'];
// $card_name['default_data_type'] = $card_name['rule']['type'];
// $card_name['list'] = $describe_list;
2024-11-23 16:46:38 +08:00
2024-09-30 16:52:40 +08:00
unset ( $card_name [ 'rule' ]);
2024-11-23 16:46:38 +08:00
2024-09-30 16:52:40 +08:00
return $card_name ;
}
// 获取标签列表,以及标签列表下数据
public function get_other_data (){
}
################################################################其他################################################################
################################################################其他################################################################
// 检查字符串格式是否为“数字”+“:”+“数字”的格式, 且冒号后的数字小于等于59
public function isValidFormatWithLimit ( $str ){
// 使用正则表达式匹配“数字:数字”的格式
if ( preg_match ( '/^(\d+):(\d+)$/' , $str , $matches )) {
// 提取冒号前后的数字
$firstNumber = $matches [ 1 ];
$secondNumber = $matches [ 2 ];
// 检查冒号后的数字是否小于等于60
if ( $secondNumber <= 59 ) {
return true ;
}
}
return false ;
}
// 两个时间相加4:20、5:15
function sumTimes ( $time1 , $time2 ) {
// 将时间字符串拆分为分钟和秒
list ( $min1 , $sec1 ) = explode ( ':' , $time1 );
list ( $min2 , $sec2 ) = explode ( ':' , $time2 );
// 将分钟和秒转换为整数
$totalMin = ( int ) $min1 + ( int ) $min2 ;
$totalSec = ( int ) $sec1 + ( int ) $sec2 ;
// 如果秒数超过或等于60, 则进位到分钟
if ( $totalSec >= 60 ) {
$totalMin += floor ( $totalSec / 60 );
$totalSec = $totalSec % 60 ;
}
// 格式化总时间为"分:秒"
// $totalTime = sprintf('%d分%02d秒', $totalMin, $totalSec);
$totalTime = $totalMin . " : " . $totalSec ;
// 返回结果
return $totalTime ;
}
// 处理平均时间
function averageTime ( $timeStr , $divisor ) {
// 步骤1: 拆分时间字符串
list ( $minutes , $seconds ) = explode ( ':' , $timeStr );
// 步骤2: 转换为总秒数
$totalSeconds = ( $minutes * 60 ) + $seconds ;
// 步骤3: 除以参数
$averageSeconds = $totalSeconds / $divisor ;
// 步骤4: 转换回分钟和秒
$averageMinutes = floor ( $averageSeconds / 60 );
$remainingSeconds = round ( $averageSeconds % 60 ); // 使用round来处理小数秒, 如果需要更精确的四舍五入
// 步骤5: 格式化结果为“分:秒”
$formattedTime = sprintf ( '%d分%02d秒' , $averageMinutes , $remainingSeconds );
return $formattedTime ;
}
}