This commit is contained in:
2025-08-14 17:19:26 +08:00
parent 30abda5ba7
commit 281248fd04
245 changed files with 21051 additions and 61 deletions

View File

@@ -0,0 +1,59 @@
<?php
namespace app\admin\model;
use app\common\library\DatabaseRoute;
use think\Model;
/**
* UserGroup 模型
*/
class PayDetails extends Model
{
protected $autoWriteTimestamp = true;
public static function selectSumPayByClassify($classify, $flag, $time, $payClassify)
{
$result = DatabaseRoute::getAllDbData('pay_details', function ($query) use($time, $flag, $classify, $payClassify){
$query->where('state', 1) // 固定条件state=1
->field('sum(money) as total'); // 聚合计算总金额
// 添加分类条件
if (!is_null($classify)) {
$query->where('classify', $classify);
}
// 添加时间条件
if (!is_null($flag)) {
switch ($flag) {
case 1:
// 按日匹配(精确到天)
$query->whereRaw("date_format(create_time, '%Y-%m-%d') = date_format(?, '%Y-%m-%d')", [$time]);
break;
case 2:
// 按月匹配(精确到月)
$query->whereRaw("date_format(create_time, '%Y-%m') = date_format(?, '%Y-%m')", [$time]);
break;
case 3:
// 按年匹配(精确到年)
$query->whereRaw("date_format(create_time, '%Y') = date_format(?, '%Y')", [$time]);
break;
default:
// 无效flag不添加时间条件
break;
}
}
// 添加支付分类条件
if (!is_null($payClassify) && $payClassify != 0) {
$query->where('pay_classify', $payClassify);
}
return $query;
})->find();
return $result['total'] ?? 0.0;
}
}