MoneyController.php
5.5 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?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'=>$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('操作失败');
}
}
/**
* @title 消息列表
* @description
* @author panhaowen
* @url /portal/money/messageIndex
* @method POST
*/
public function messageIndex()
{
$user=$this->getUser();
$data=Db::name('message')->paginate(5)->each(function($item){
$item['create_time']=date('Y.m.d H:i:s',$item['create_time']);
return $item;
});
foreach ($data as $k=>$v){
$re=Db::name('message_read')->where(['user_id'=>$user['id'],'message_id'=>$data[$k]['id']])->find();
if ($re){
$data[$k]['status']=1;
}else{
$data[$k]['status']=0;
}
}
$this->success('获取数据成功',$data);
}
/**
* @title 消息删除
* @description
* @author panhaowen
* @url /portal/money/messageDelete
* @param name:id type:int require:1 desc:系统消息id
* @method POST
*/
public function messageDelete()
{
$param=$this->request->param();
$data=Db::name('message')->where('id',$param['id'])->delete();
$this->success('操作成功');
}
}