SubhomeController.php
3.0 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/12/2
* Time: 14:58
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class SubhomeController extends AdminBaseController
{
public function index()
{
$where['a.delete_time'] = ['eq',0];
$param = $this->request->param();
$startTime = empty($param['start_time']) ? '' : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? '' : (strtotime($param['end_time']));
if (!empty($startTime) && !empty($endTime)) {
$where['a.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
} else {
if (!empty($startTime)) {
$where['a.create_time'] = ['>= time', $startTime];
}
if (!empty($endTime)) {
$where['a.create_time'] = ['<= time', $endTime];
}
}
$data = Db::name('subhome')
->alias('a')
->join('home r','a.home_id = r.id')
->join('user u','a.user_id = u.id')
->join('service s','a.service_id = s.id')
->field('a.*,r.home_name,s.sever_name,u.user_nickname')
->where($where)
->order('a.id desc')
->paginate(10);
$list=$data->items();
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
$this->assign([
'data'=>$list,
'page'=>$data->render(),
]);
return $this->fetch();
}
//订单详情
public function edit()
{
$id = $this->request->param('id');
if($this->request->isPost()){
$param = $this->request->param();
$data = Db::name('subhome')
->where('id',$id)
->update(['status'=>$param['status']]);
if(!empty($data)){
$this->success('更新成功!');
}else{
$this->error('sql运行失败');
}
}else{
$param = $this->request->param();
$data = Db::name('subhome')
->alias('a')
->join('home h','a.home_id = h.id')
->join('service s','a.service_id = s.id')
->join('user u','a.user_id = u.id')
->field('a.*,h.home_name,u.user_nickname,s.sever_name')
->where('a.id',$id)
->find();
$address = Db::name('homeadress')->where('id',$data['homeaddress_id'])->find();
$data['name'] = $address['name'];
$data['phone'] = $address['phone'];
$data['address'] = $address['address'];
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
$this->assign('data',$data);
return $this->fetch();
}
}
}