diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php index 3aea5e165..81bca0ba5 100644 --- a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php @@ -137,6 +137,24 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt $query->where('user_id', 'in', $userIds)->whereOr('financial_record_sn', 'like', "%{$this->params['keyword']}%"); }); }) + ->when(!empty($this->params['date_type']) && !empty($this->params['date']), function (Query $query) { + switch ($this->params['date_type']) { + case 2: + $start = new \DateTime($this->params['date']); + $start = $start->getTimestamp(); + $end = $start + (86400 * 7); + break; + case 3: + $start = strtotime($this->params['date']); + $end = strtotime('+1 month', strtotime($this->params['date'])); + break; + default: + $start = strtotime($this->params['date']); + $end = strtotime($this->params['date']) + 86400; + break; + } + $query->whereBetweenTime('create_time', $start, $end); + }) ->count(); } diff --git a/app/common/lists/StoreBillLists.php b/app/common/lists/StoreBillLists.php index 1cff791e5..8109b6b17 100644 --- a/app/common/lists/StoreBillLists.php +++ b/app/common/lists/StoreBillLists.php @@ -74,15 +74,21 @@ class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface $query->whereTime('create_time', '<=', $this->params['end_time']); }) ->when(!empty($this->params['type']), function (Query $query) { + $income = 1; + $expense = 0; + if (!empty($this->request->adminInfo['store_id'])) { + $income = 0; + $expense = 1; + } switch ($this->params['type']) { case 2: - $query->fieldRaw("*,sum(number) as total_amount,YEAR(FROM_UNIXTIME(create_time)) as year,WEEK(FROM_UNIXTIME(create_time), 1) as week")->group("year,week,financial_pm"); + $query->fieldRaw("*,sum(IF(financial_pm=$income,number,0)) as income,sum(IF(financial_pm=$expense,number,0)) as expense,YEAR(FROM_UNIXTIME(create_time)) as year,WEEK(FROM_UNIXTIME(create_time), 1) as week")->group("year,week"); break; case 3: - $query->fieldRaw("*,sum(number) as total_amount,FROM_UNIXTIME(create_time, '%Y-%m') as time")->group("time,financial_pm"); + $query->fieldRaw("*,sum(IF(financial_pm=$income,number,0)) as income,sum(IF(financial_pm=$expense,number,0)) as expense,FROM_UNIXTIME(create_time, '%Y-%m') as time")->group("time"); break; default: - $query->fieldRaw("*,sum(number) as total_amount,FROM_UNIXTIME(create_time, '%Y-%m-%d') as time")->group("time,financial_pm"); + $query->fieldRaw("*,sum(IF(financial_pm=$income,number,0)) as income,sum(IF(financial_pm=$expense,number,0)) as expense,FROM_UNIXTIME(create_time, '%Y-%m-%d') as time")->group("time"); break; } })