|
|
@@ -63,7 +63,6 @@ class MoneyLog Extends Model
|
|
|
|
|
|
//按照类型年统计 收入- 支出
|
|
|
public static function getCountYearBalance(string $time = '')
|
|
|
-
|
|
|
{
|
|
|
$income = self::where('type', self::TYPE_INCOME)->where('status', self::STATUS_NORMAL);
|
|
|
if(!empty($time)){
|
|
|
@@ -96,5 +95,66 @@ class MoneyLog Extends Model
|
|
|
return $list;
|
|
|
}
|
|
|
|
|
|
+ //支收总览
|
|
|
+ public static function getCountAllBalance(int $type, string $time = '', string $user_ids='')
|
|
|
+ {
|
|
|
+ $list = self::where('status', self::STATUS_NORMAL);
|
|
|
+ if($type == 1 && !empty($time)) $list = $list->whereMonth('create_date', $time);
|
|
|
+ if($type == 2 && !empty($time)) $list = $list->whereYear('create_date', $time);
|
|
|
+ if($type == 3 && !empty($time)){
|
|
|
+ $expTime = explode(',', $time);
|
|
|
+ $list = $list->whereTime('create_date', [$expTime[0], $expTime[1]]);
|
|
|
+ }
|
|
|
+ if(!empty($user_ids)) $list = $list->whereIn('user_id', $user_ids);
|
|
|
+ $list = $list
|
|
|
+ ->field('type, sum(if(type=1,`change`,0)) as income, sum(if(type=2,`change`, 0)) as expenditure')
|
|
|
+ ->group('type')
|
|
|
+ ->select();
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //统计用户余额
|
|
|
+ public static function getCountAllUserBalance(int $type, string $time = '', string $user_ids='')
|
|
|
+ {
|
|
|
+ $list = self::alias('a')
|
|
|
+ ->join('user b', 'a.user_id=b.id')
|
|
|
+ ->where('a.status', self::STATUS_NORMAL);
|
|
|
+
|
|
|
+ if($type == 1 && !empty($time)) $list = $list->whereMonth('create_date', $time);
|
|
|
+ if($type == 2 && !empty($time)) $list = $list->whereYear('create_date', $time);
|
|
|
+ if($type == 3 && !empty($time)){
|
|
|
+ $expTime = explode(',', $time);
|
|
|
+ $list = $list->whereTime('create_date', [$expTime[0], $expTime[1]]);
|
|
|
+ }
|
|
|
+ if(!empty($user_ids)) $list = $list->whereIn('user_id', $user_ids);
|
|
|
+ $list = $list
|
|
|
+ ->field('a.user_id, sum(if(a.type=1,`change`,0)) as income, sum(if(a.type=2,`change`, 0)) as expenditure,b.nickname,b.avatar')
|
|
|
+ ->group('user_id')
|
|
|
+ ->select();
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //统计所有月统计
|
|
|
+ public static function getCountAllMonthBalance(int $type, string $time = '', string $user_ids='')
|
|
|
+ {
|
|
|
+ $list = self::where('status', self::STATUS_NORMAL);
|
|
|
|
|
|
+ if($type == 1 && !empty($time)) $list = $list->whereMonth('create_date', $time);
|
|
|
+ //年
|
|
|
+ if($type == 2 && !empty($time)) $list = $list->whereYear('create_date', $time);
|
|
|
+ //自定义
|
|
|
+ if($type == 3 && !empty($time)){
|
|
|
+ $expTime = explode(',', $time);
|
|
|
+ $list = $list->whereTime('create_date', [$expTime[0], $expTime[1]]);
|
|
|
+ }
|
|
|
+ if(!empty($user_ids)) $list = $list->whereIn('user_id', $user_ids);
|
|
|
+ //月
|
|
|
+ $list = $list
|
|
|
+ ->field('create_month, sum(if(type=1,`change`,0)) as income, sum(if(type=2,`change`, 0)) as expenditure')
|
|
|
+ ->group('create_month')
|
|
|
+ ->order('create_month desc')
|
|
|
+ ->select();
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
}
|