MoneyController.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace api\portal\controller;
use think\Controller;
use think\Db;
/**
* @title 后台财务与消息
* @description 财务列表与消息列表相关接口
*/
class MoneyController extends Controller
{
/**
* @title 财务列表首页
* @description
* @author panhaowen
* @url /portal/money/index
* @method POST
* @param name:param type:array require:0 desc:搜索条件(user_login,mobile)
*/
public function index()
{
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
$count1=Db::name('business_order')->where(['create_time'=>[ 'between time', [$beginToday,$endToday]],'status'=>4])->count();
$count2=Db::name('market_order')->where(['create_time'=>[ 'between time', [$beginToday,$endToday]],'status'=>4])->count();
$today_orders=$count1+$count2;
$count3=Db::name('business_order')->where(['status'=>4])->count();
$count4=Db::name('market_order')->where(['status'=>4])->count();
$all_orders=$count3+$count4;
$money1=Db::name('business_order')->where(['create_time'=>[ 'between time', [$beginToday,$endToday]],'status'=>4])->sum('money');
$money2=Db::name('market_order')->where(['create_time'=>[ 'between time', [$beginToday,$endToday]],'status'=>4])->sum('money');
$today_money=$money1+$money2;
$money3=Db::name('business_order')->where(['status'=>4])->sum('money');
$money4=Db::name('market_order')->where(['status'=>4])->sum('money');
$all_money=$money3+$money4;
$param=$this->request->param();
$where=[];
$where['user_type']=['neq',1];
$where['user_status']=1;
if (!empty($param['user_login'])){
$where['user_login']=['like','%'.$param['user_login'].'%'];
}
if (!empty($param['mobile'])){
$where['mobile']=['like','%'.$param['mobile'].'%'];
}
$data=Db::name('user')->where($where)->paginate(10)->each(function ($item) {
$item['money1'] = Db::name('business_order') ->where(['user_id'=>$item['id'],'status'=>4])->sum('money');
$item['money2'] = Db::name('market_order') ->where(['user_id'=>$item['id'],'status'=>4])->sum('money');
$item['money']= $item['money1']+ $item['money2'];
return $item;
});
$this->success('获取信息成功',['today_orders'=>$today_orders,'all_orders'=>$all_orders,'today_money'=>$today_money,'all_money'=>$all_money,$data]);
}
/**
* @title 用户明细
* @description
* @author panhaowen
* @url /portal/money/detail
* @method POST
* @param name:id type:id require:1 desc:用户id
* @param name:param type:array require:0 desc:搜索条件(start_time,end_time,type:1在线充值,2微博粉丝购买,3文章发稿,4拒稿退回,5退款)
*/
public function detail()
{
$param=$this->request->param();
$where=[];
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
if (!empty($startTime) && !empty($endTime)) {
$where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
} else {
if (!empty($startTime)) {
$where['create_time'] = ['>= time', $startTime];
}
if (!empty($endTime)) {
$where['create_time'] = ['<= time', $endTime];
}
}
if (!empty($param['type'])){
$where['type']=$param['type'];
}
$user=Db::name('user')->where('id',$param['id'])->find();
$data=Db::name('money_log')->where('user_id',$param['id'])->paginate(10);
$this->success('获取信息成功',['user_login'=>$user['user_login'],$data]);
}
/**
* @title 发布系统消息
* @description
* @author panhaowen
* @url /portal/money/message
* @param name:message type:varchar require:1 desc:系统消息内容
* @method POST
*/
public function message()
{
$param=$this->request->param();
$param['create_time']=time();
$re=Db::name('message')->insert($param);
if ($re){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
}