AdminMoneyController.php
3.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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use think\Db;
/**
* Class AdminMoneyController
* @package app\portal\controller
* @adminMenuRoot(
* 'name' =>'财务管理',
* 'action' =>'default',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 30,
* 'icon' =>'th',
* 'remark' =>'财务管理'
* )
*/
class AdminMoneyController extends AdminBaseController
{
/**
* 财务列表
* @adminMenu(
* 'name' => '财务列表',
* 'parent' => 'portal/AdminMoney/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '财务列表',
* 'param' => ''
* )
*/
public function index()
{
//接收搜索参数
$param = $this->request->param();
//添加搜索条件
$where=[];
$temple = empty($param['temple']) ? '' : $param['temple'];
if (!empty($temple)) {
$where['t.name'] = ['like', "%$temple%"];
}
$address=empty($param['address']) ? '' : $param['address'];
if (!empty($address)) {
$where['t.address'] = $address;
}
//所有地区
$address_choose=Db::name('temple')->field('address')->distinct('address',true)->select();
$this->assign('address_choose',$address_choose);
//数据提取
$data=Db::name('temple')->alias('t')->join('light l','l.temple_id=t.id','right')->where($where)->field('t.*,l.id as lid')->paginate(10)->each(function ($item) {
$item['money'] = Db::name('light_order')->where('light_id', $item['lid'])->whereNotNull('pay_time')->sum('money');
$item['real_money']=$item['money']*$item['percent'];
return $item;
});
//向地址传参
$data->appends($param);
$this->assign('page',$data->render());
$this->assign('address', isset($param['address']) ? $param['address'] : '');
$this->assign('temple', isset($param['temple']) ? $param['temple'] : '');
$this->assign('list', $data);
return $this->fetch();
}
/**
* 删除财务
* @adminMenu(
* 'name' => '删除财务',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除财务',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id');
$re=Db::name('light_order')
->alias('lo')
->join('light l','lo.light_id=l.id')
->where(['l.temple_id'=>$id,'lo.end_time'=>['>',time()]])
->find();
if ($re){
$this->error('该寺庙下有进行中的订单,不允许删除');
}
Db::name('temple')->where('id', $id)->delete();
$this->success('删除成功');
}
}