79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace app\common\model;
|
||
|
||
use app\common\model\Base;
|
||
use think\Model;
|
||
/**
|
||
* 账单支出
|
||
*/
|
||
class ProfitRvenue extends Base
|
||
{
|
||
// 设置当前模型对应的完整数据表名称
|
||
protected $table = 'profit_revenue';
|
||
|
||
/**
|
||
* 获取列表
|
||
*/
|
||
public static function getList($where = [], $field = '*', $order = '', $pageSize = "15")
|
||
{
|
||
$list = self::where($where)
|
||
->field($field)
|
||
->order($order)
|
||
->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
|
||
$page = $list->render();
|
||
$data['list'] = $list->toArray()['data'];
|
||
$data['count'] = $list->total();
|
||
$data['last_page'] = $list->toArray()['last_page'];
|
||
$data['page'] = $page;
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 查询当天总金额
|
||
* @param string $date 查询日期 (格式: YYYY-MM-DD)
|
||
* @param string|null $startDate 开始日期 (可选)
|
||
* @param string|null $endDate 结束日期 (可选)
|
||
* @return float 返回总金额
|
||
*/
|
||
public static function getTotalAmountByDate($date, $startDate = null, $endDate = null)
|
||
{
|
||
$query = self::where('profit_date', $date);
|
||
if ($startDate && $endDate) {
|
||
$query->whereBetween('profit_date', [$startDate, $endDate]);
|
||
}
|
||
return $query->sum('price');
|
||
}
|
||
|
||
|
||
public static function getTotalAmountByDates($startDate, $endDate)
|
||
{
|
||
$query = self::whereBetween('profit_date', [$startDate, $endDate]);
|
||
|
||
return $query->sum('price');
|
||
}
|
||
|
||
/**
|
||
* 查询每天的总金额,按日期分组排序
|
||
* @return array 返回每天的总金额,按日期分组
|
||
*/
|
||
public static function getDailyTotalAmount()
|
||
{
|
||
return self::field('profit_date, SUM(price) as total_price')
|
||
->group('profit_date')
|
||
->order('profit_date ', 'asc')
|
||
->select()
|
||
->toArray();
|
||
}
|
||
|
||
/**
|
||
* 删除方法
|
||
* @param int $id 记录ID
|
||
* @return bool 删除成功返回true,失败返回false
|
||
*/
|
||
public static function deleteData($id)
|
||
{
|
||
return self::where('id', $id)->delete();
|
||
}
|
||
|
||
} |