2023-07-15 10:16:32 +08:00
|
|
|
|
<?php
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
|
|
|
// | 开源版本可自由商用,可去除界面版权logo
|
|
|
|
|
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
|
|
|
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
|
|
|
// | 访问官网:https://www.likeadmin.cn
|
|
|
|
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | author: likeadminTeam
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
|
|
use app\api\lists\AccountLogLists;
|
2023-07-24 14:30:57 +08:00
|
|
|
|
use think\facade\Db;
|
2023-07-15 10:16:32 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 账户流水
|
|
|
|
|
* Class AccountLogController
|
|
|
|
|
* @package app\api\controller
|
|
|
|
|
*/
|
|
|
|
|
class AccountLogController extends BaseApiController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @notes 账户流水
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/2/24 14:34
|
|
|
|
|
*/
|
|
|
|
|
public function lists()
|
|
|
|
|
{
|
|
|
|
|
return $this->dataLists(new AccountLogLists());
|
|
|
|
|
}
|
2023-07-24 14:30:57 +08:00
|
|
|
|
|
2023-08-02 23:13:05 +08:00
|
|
|
|
//个人月份统计
|
2023-07-24 14:30:57 +08:00
|
|
|
|
public function year_count()
|
|
|
|
|
{
|
|
|
|
|
$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');
|
|
|
|
|
$change_amount_1 = Db::name('user_account_log')
|
|
|
|
|
->whereYear('create_time', $year)
|
|
|
|
|
->where('action', 1)
|
|
|
|
|
->field('DATE_FORMAT(FROM_UNIXTIME(create_time), "%Y-%m") as month, SUM(change_amount) as total')
|
|
|
|
|
->group('month')
|
|
|
|
|
->order('month')
|
|
|
|
|
->select();
|
|
|
|
|
$change_amount_2 = Db::name('user_account_log')
|
|
|
|
|
->whereYear('create_time', $year)
|
|
|
|
|
->where('action', 2)
|
|
|
|
|
->field('DATE_FORMAT(FROM_UNIXTIME(create_time), "%Y-%m") as month, SUM(change_amount) as total')
|
|
|
|
|
->group('month')
|
|
|
|
|
->order('month')
|
|
|
|
|
->select();
|
|
|
|
|
foreach($data as $k=>$v){
|
|
|
|
|
foreach($change_amount_1 as $key=>$val){
|
|
|
|
|
if($v['month'] == $val['month']){
|
|
|
|
|
$data[$k]['income'] = $val['total'];
|
|
|
|
|
if(!isset($data[$k]['expenditure'])){
|
|
|
|
|
$data[$k]['expenditure'] = 0;
|
|
|
|
|
}
|
|
|
|
|
$data[$k]['income'] = $val['total'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach($change_amount_2 as $key=>$val){
|
|
|
|
|
if($v['month'] == $val['month']){
|
|
|
|
|
$data[$k]['expenditure'] = $val['total'];
|
|
|
|
|
if(!isset($data[$k]['income'])){
|
|
|
|
|
$data[$k]['income'] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!isset($data[$k]['income'])||!isset($data[$k]['expenditure'])){
|
|
|
|
|
unset($data[$k]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-24 21:03:18 +08:00
|
|
|
|
return $this->success('ok',array_reverse($data));
|
2023-07-24 14:30:57 +08:00
|
|
|
|
}
|
2023-08-02 23:13:05 +08:00
|
|
|
|
|
|
|
|
|
//公司日流水统计
|
|
|
|
|
public function company_lists(){
|
|
|
|
|
return $this->dataLists(new AccountLogLists(),'company_lists');
|
|
|
|
|
}
|
|
|
|
|
//公司月流水统计
|
|
|
|
|
public function company_year_count(){
|
|
|
|
|
return $this->dataLists(new AccountLogLists(),'company_year_count');
|
|
|
|
|
}
|
2023-07-24 14:30:57 +08:00
|
|
|
|
}
|