webman_duanju/app/admin/model/PayDetails.php

59 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}