Merge pull request '公司流水统计查询' (#27) from mkm into master

Reviewed-on: http://git.excellentkk.cn/mkm/TaskSystem/pulls/27
This commit is contained in:
mkm 2023-08-03 16:10:43 +08:00
commit dbbbb1918e

View File

@ -35,9 +35,9 @@ class AccountLogLists extends BaseApiDataLists
public function queryWhere() public function queryWhere()
{ {
// 指定用户 // 指定用户
if(isset($this->params['user_id']) && $this->params['user_id'] > 0){ if (isset($this->params['user_id']) && $this->params['user_id'] > 0) {
$where[] =['user_id','=', $this->params['user_id']]; $where[] = ['user_id', '=', $this->params['user_id']];
}else{ } else {
$where[] = ['user_id', '=', $this->userId]; $where[] = ['user_id', '=', $this->userId];
} }
@ -52,10 +52,10 @@ class AccountLogLists extends BaseApiDataLists
} }
// 变动时间 // 变动时间
if (!empty($this->params['time'])) { if (!empty($this->params['time'])) {
$date= strtotime($this->params['time']); $date = strtotime($this->params['time']);
$startTime = $date - 3600; // 获取该日期零点的时间戳 $startTime = $date - 3600; // 获取该日期零点的时间戳
$endTime = $date + 86400; // 获取该日期24小时后的时间戳 $endTime = $date + 86400; // 获取该日期24小时后的时间戳
$where[] = ['create_time', 'between time',[$startTime, $endTime]]; $where[] = ['create_time', 'between time', [$startTime, $endTime]];
} }
return $where; return $where;
} }
@ -107,9 +107,16 @@ class AccountLogLists extends BaseApiDataLists
public function company_lists(): array public function company_lists(): array
{ {
$field = 'change_type,change_amount,action,create_time,remark,user_id'; $field = 'change_type,change_amount,action,create_time,remark,user_id';
$where=[ $where[] = [
'company_id'=>$this->params['company_id'] 'company_id' => $this->params['company_id']
]; ];
// 变动时间
if (!empty($this->params['time'])) {
$date = strtotime($this->params['time']);
$startTime = $date - 3600; // 获取该日期零点的时间戳
$endTime = $date + 86400; // 获取该日期24小时后的时间戳
$where[] = ['create_time', 'between time', [$startTime, $endTime]];
}
$lists = UserAccountLog::field($field) $lists = UserAccountLog::field($field)
->where($where) ->where($where)
->with(['userInfo']) ->with(['userInfo'])
@ -133,15 +140,15 @@ class AccountLogLists extends BaseApiDataLists
*/ */
public function company_year_count() public function company_year_count()
{ {
$where=[ $where = [
'company_id'=>$this->params['company_id'], 'company_id' => $this->params['company_id'],
'action'=>1, 'action' => 1,
]; ];
$where2=[ $where2 = [
'company_id'=>$this->params['company_id'], 'company_id' => $this->params['company_id'],
'action'=>2, 'action' => 2,
]; ];
$data = [['month'=>date('Y').'-01'],['month'=>date('Y').'-02'],['month'=>date('Y').'-03'],['month'=>date('Y').'-04'],['month'=>date('Y').'-05'],['month'=>date('Y').'-06'],['month'=>date('Y').'-07'],['month'=>date('Y').'-08'],['month'=>date('Y').'-09'],['month'=>date('Y').'-10'],['month'=>date('Y').'-11'],['month'=>date('Y').'-12']]; $data = [['month' => date('Y') . '-01'], ['month' => date('Y') . '-02'], ['month' => date('Y') . '-03'], ['month' => date('Y') . '-04'], ['month' => date('Y') . '-05'], ['month' => date('Y') . '-06'], ['month' => date('Y') . '-07'], ['month' => date('Y') . '-08'], ['month' => date('Y') . '-09'], ['month' => date('Y') . '-10'], ['month' => date('Y') . '-11'], ['month' => date('Y') . '-12']];
$year = date('Y'); $year = date('Y');
$change_amount_1 = UserAccountLog::whereYear('create_time', $year) $change_amount_1 = UserAccountLog::whereYear('create_time', $year)
->where($where) ->where($where)
@ -155,26 +162,26 @@ class AccountLogLists extends BaseApiDataLists
->group('month') ->group('month')
->order('month') ->order('month')
->select(); ->select();
foreach($data as $k=>$v){ foreach ($data as $k => $v) {
foreach($change_amount_1 as $key=>$val){ foreach ($change_amount_1 as $key => $val) {
if($v['month'] == $val['month']){ if ($v['month'] == $val['month']) {
$data[$k]['income'] = $val['total']; $data[$k]['income'] = $val['total'];
if(!isset($data[$k]['expenditure'])){ if (!isset($data[$k]['expenditure'])) {
$data[$k]['expenditure'] = 0; $data[$k]['expenditure'] = 0;
} }
$data[$k]['income'] = $val['total']; $data[$k]['income'] = $val['total'];
} }
} }
foreach($change_amount_2 as $key=>$val){ foreach ($change_amount_2 as $key => $val) {
if($v['month'] == $val['month']){ if ($v['month'] == $val['month']) {
$data[$k]['expenditure'] = $val['total']; $data[$k]['expenditure'] = $val['total'];
if(!isset($data[$k]['income'])){ if (!isset($data[$k]['income'])) {
$data[$k]['income'] = 0; $data[$k]['income'] = 0;
} }
} }
} }
$data[$k]['remark']='任务收益'; $data[$k]['remark'] = '任务收益';
if(!isset($data[$k]['income'])||!isset($data[$k]['expenditure'])){ if (!isset($data[$k]['income']) || !isset($data[$k]['expenditure'])) {
unset($data[$k]); unset($data[$k]);
} }
} }