RentController.php
4.84 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
154
155
156
157
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/2/9
* Time: 15:07
*/
namespace App\Http\Controllers\Backend\Rent;
use App\Exceptions\GeneralException;
use App\Http\Controllers\Controller;
use App\Http\Requests\Backend\Rent\DrawbackRequest;
use App\Http\Requests\Backend\Rent\StoreRentRequest;
use Illuminate\Http\Request;
use App\Modules\Models\Rent\Rent;
use App\Repositories\Backend\Rent\RentRepository;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use App\Common\Http;
use Illuminate\Support\Facades\Log;
class RentController extends Controller
{
private $rent;
public function __construct(RentRepository $rent)
{
$this->rent = $rent;
}
public function index()
{
// $id=Create_num::add();die();
return view('backend.rent.index');
}
public function info($request)
{
if(!empty($request)){
$info= DB::table('rent')->
select('rent.id','rent.rent_no', 'rent.number', 'rent.deposit', 'rent.one_day_price', 'rent.real_total',
'rent.pay_time as add_time','rent.rent_type', 'production.return_time', 'spot.spotname', 'machine.mac_no',
'customers.nick_name', 'customers.phone','rent.total', 'rent.is_pay', 'rent.is_take', 'rent.is_cancel',
'production.refund_no', 'production.refund_time', 'production.is_refund', 'production.power_no',
'production.rent_hatch_no', 'production.is_return')
->leftjoin('spot', 'rent.spot_id', '=', 'spot.id')
->leftjoin('machine', 'rent.machine_id', '=', 'machine.id')
->leftjoin('production', 'rent.id', '=', 'production.rent_id')
->leftjoin('customers', 'rent.customer_id', '=', 'customers.id')
->where('rent.id','=',$request)
->get();
}
return view('backend.rent.info',[
'info'=>$info
]);
}
public function downLoad()
{
$spot=$this->spot();
$busienss=$this->business();
return view('backend.rent.download',['spot'=>$spot,'business'=>$busienss]);
}
public function store(StoreRentRequest $request)
{
$data =$request->all();
if($data['start']>$data['end']){
throw new GeneralException(trans('alerts.backend.rent.error'));
}
$start= $data['start']." 00:00:00";
$end= $data['end']." 23:59:59";
$info= Rent::
select('rent.rent_no', 'rent.real_total',
'rent.add_time', 'customers.platform', 'spot.spotname','production.is_return',
'customers.phone'
)
->leftjoin('spot', 'rent.spot_id', '=', 'spot.id')
->leftjoin('production', 'rent.id', '=', 'production.rent_id')
->leftjoin('customers', 'rent.customer_id', '=', 'customers.id')
->where('production.return_time','>=',$start)
->where('production.return_time','<=',$end)
->where('customers.platform','=',$data['platform'])
->where('rent.spot_id','=',$data['spot_id'])
->get()
->toArray();
foreach($info as $key=>$infos){
if($infos['platform']==1){
$infos['platform']= '微信';
}else if($infos['platform']==2){
$infos['platform']='支付宝';
}
$infos['real_total'] = $infos['real_total'] * 0.01;
if($infos['is_return']==1){
$infos['is_return'] = '已归还';
} else if ($infos['is_return']==0){
$infos['is_return'] = '没有还';
}
$res[0]= ['订单号','支付金额','租借时间','支付方式','景点','是否归还','手机号'];
$res[$key+1]=$infos;
}
Excel::create('租借小程序',function($excel) use ($res){
$excel->sheet('score', function($sheet) use ($res){
$sheet->rows($res);
ob_end_clean();
});
})->export('xls');
}
public function manage()
{
}
public function Drawback(DrawbackRequest $request)
{
$req = $request->all();
$datas = "machine=".$req["mac_no"].
"&hatch_no=".$req["hatch_no"].
"&power_no=".$req["power_no"].
"&has_power=80".
"&backTime=".date('Y-m-d ').$req["backTime"].
"&isTrue=0";
Log::info('[手动归还退款: ]'.$datas);
// $data = "machine=".$request->input("machine")."&hatch_no=".$request->input("hatch_no")."&power_no=".$request->input("power_no")."&has_power=80&backTime=".$request->input("backTime")."&isTrue=0";
$url = "http://api.ssw-htzn.com/api/v1/customers/manualReturn";
$result = json_decode( Http::post($datas, $url ), true) ;
return $this->info($req['rentId']);
}
}