|
@@ -0,0 +1,210 @@
|
|
1
|
+<?php
|
|
2
|
+/**
|
|
3
|
+ * Created by Sublime.
|
|
4
|
+ * User: Williamslife Wang
|
|
5
|
+ * Date: 17/10/18
|
|
6
|
+ * Time: 上午11:20
|
|
7
|
+ */
|
|
8
|
+namespace App\Http\Controllers\Admin;
|
|
9
|
+use App\Http\Controllers\Controller;
|
|
10
|
+use App\Admin;
|
|
11
|
+use Illuminate\Http\Request;
|
|
12
|
+use App\CustomerInfo;
|
|
13
|
+use App\CustomerDeposit;
|
|
14
|
+use App\CustomerConsum;
|
|
15
|
+use App\CustomerDepositPackages;
|
|
16
|
+use Illuminate\Support\Facades\DB;
|
|
17
|
+
|
|
18
|
+class CustomerDepositController extends Controller
|
|
19
|
+{
|
|
20
|
+ /**
|
|
21
|
+ * @return \Illuminate\View\View
|
|
22
|
+ */
|
|
23
|
+ public function customerList(Request $request)
|
|
24
|
+ {
|
|
25
|
+ $phone = trim( $request->input('phone') );
|
|
26
|
+ $name = trim( $request->input('name') );
|
|
27
|
+ $page = (int)$request->input('page');
|
|
28
|
+ $pageSize = 20;
|
|
29
|
+ if($page<=0){
|
|
30
|
+ $page = 1;
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ $offset = ($page-1) * $pageSize;
|
|
34
|
+
|
|
35
|
+ $count = CustomerInfo::where(function($query) use($phone, $name){
|
|
36
|
+ if($phone) $query->where('phone', $phone);
|
|
37
|
+ if($name) $query->where('name', 'like', '%'. $name. '%');
|
|
38
|
+ })->count();
|
|
39
|
+ if ($count > 1) {
|
|
40
|
+ // 总页数
|
|
41
|
+ $pages = ceil($count/$pageSize);
|
|
42
|
+ }else{
|
|
43
|
+ // 总页数
|
|
44
|
+ $pages = 1;
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ $result = CustomerInfo::where(function($query) use($phone, $name){
|
|
48
|
+ if($phone) $query->where('phone', $phone);
|
|
49
|
+ if($name) $query->where('name', 'like', '%'. $name. '%');
|
|
50
|
+ })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
51
|
+ $result = json_decode(json_encode($result),true);
|
|
52
|
+
|
|
53
|
+ return view('deposit/customerList', ['result' =>$result,
|
|
54
|
+ 'page' =>$page,
|
|
55
|
+ 'count' =>$count,
|
|
56
|
+ 'pages' =>$pages,
|
|
57
|
+ 'phone' =>$phone,
|
|
58
|
+ 'name' =>$name,
|
|
59
|
+ ]);
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ /**
|
|
63
|
+ * @return \Illuminate\View\View
|
|
64
|
+ */
|
|
65
|
+ public function index(Request $request)
|
|
66
|
+ {
|
|
67
|
+ $phone = $request->input('phone');
|
|
68
|
+ $page = (int)$request->input('page');
|
|
69
|
+ $pageSize = 20;
|
|
70
|
+ if($page<=0){
|
|
71
|
+ $page = 1;
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ $offset = ($page-1) * $pageSize;
|
|
75
|
+
|
|
76
|
+ $count = CustomerDeposit::where(function($query) use($phone){
|
|
77
|
+ if($phone) $query->where('phone', $phone);
|
|
78
|
+ })->where('is_del',0)->count();
|
|
79
|
+ if ($count > 1) {
|
|
80
|
+ // 总页数
|
|
81
|
+ $pages = ceil($count/$pageSize);
|
|
82
|
+ }else{
|
|
83
|
+ // 总页数
|
|
84
|
+ $pages = 1;
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ $result = CustomerDeposit::where(function($query) use($phone){
|
|
88
|
+ if($phone) $query->where('phone', $phone);
|
|
89
|
+ })->where('is_del',0)->orderBy('pay_time', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
90
|
+ $result = json_decode(json_encode($result),true);
|
|
91
|
+
|
|
92
|
+ return view('deposit/index', ['result' =>$result,
|
|
93
|
+ 'page' =>$page,
|
|
94
|
+ 'count' =>$count,
|
|
95
|
+ 'pages' =>$pages,
|
|
96
|
+ 'phone' =>$phone
|
|
97
|
+ ]);
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ /**
|
|
101
|
+ * @return \Illuminate\View\View
|
|
102
|
+ */
|
|
103
|
+ public function create(Request $request)
|
|
104
|
+ {
|
|
105
|
+ $phone = $request->input('phone');
|
|
106
|
+ //查询套餐
|
|
107
|
+ $packages = CustomerDepositPackages::where('is_del', 0)->orderBy('pay_amount', 'asc')->get();
|
|
108
|
+ return view('deposit/create', ['packages'=>$packages, 'phone'=>$phone]);
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ /**
|
|
112
|
+ * @param Request $request
|
|
113
|
+ * @return \Illuminate\Http\RedirectResponse
|
|
114
|
+ */
|
|
115
|
+ public function store(Request $request)
|
|
116
|
+ {
|
|
117
|
+ $this->validate($request, [
|
|
118
|
+ 'phone' => 'required',
|
|
119
|
+ 'package_id' => 'required',
|
|
120
|
+ 'pay_time' => 'required',
|
|
121
|
+
|
|
122
|
+ ], [
|
|
123
|
+ 'phone.required' => '手机号不能为空',
|
|
124
|
+ 'package_id.required' => '必须选择套餐',
|
|
125
|
+ 'pay_time.required' => '充值时间必须选择',
|
|
126
|
+
|
|
127
|
+ ]);
|
|
128
|
+ $admin_id = session('admin_id');
|
|
129
|
+ $package_id = (int)$request->input('package_id');
|
|
130
|
+ $package_info = CustomerDepositPackages::where('id', $package_id)->first();
|
|
131
|
+
|
|
132
|
+ $deposit = new CustomerDeposit();
|
|
133
|
+ $deposit->phone = $request->input('phone');
|
|
134
|
+ $deposit->pay_amount = $package_info->pay_amount;
|
|
135
|
+ $deposit->discount = $package_info->discount;
|
|
136
|
+ $deposit->deposit_amount = $deposit->pay_amount + $deposit->discount;
|
|
137
|
+ $deposit->note = $package_info->note;
|
|
138
|
+ $deposit->admin_id = $admin_id;
|
|
139
|
+ $deposit->pay_time = $request->input('pay_time');
|
|
140
|
+
|
|
141
|
+ if($deposit->save()){
|
|
142
|
+ //变更余额
|
|
143
|
+ $name = trim( $request->input('name') );
|
|
144
|
+ $customerInfo = CustomerInfo::where('phone', $deposit->phone)->first();
|
|
145
|
+ if(!empty($customerInfo)){
|
|
146
|
+ $customerInfo->balance = $customerInfo->balance + $deposit->deposit_amount;
|
|
147
|
+ $customerInfo->deposit_total = $customerInfo->deposit_total + $deposit->deposit_amount;
|
|
148
|
+ $customerInfo->deposit_times = $customerInfo->deposit_times + 1;
|
|
149
|
+ $customerInfo->save();
|
|
150
|
+ }else{
|
|
151
|
+ $customerInfo = new CustomerInfo();
|
|
152
|
+ $customerInfo->phone = $deposit->phone;
|
|
153
|
+ $customerInfo->deposit_times = 1;
|
|
154
|
+ $customerInfo->balance = $deposit->deposit_amount;
|
|
155
|
+ $customerInfo->deposit_total = $deposit->deposit_amount;
|
|
156
|
+ if(!empty($name)) $customerInfo->name = $name;
|
|
157
|
+ $customerInfo->admin_id = $admin_id;
|
|
158
|
+ $customerInfo->save();
|
|
159
|
+ }
|
|
160
|
+ }
|
|
161
|
+ return redirect('/admin/deposit/index?phone='.$deposit->phone)->with('info', '添加成功');
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ /**
|
|
165
|
+ * @param $id
|
|
166
|
+ * @return \Illuminate\View\View
|
|
167
|
+ */
|
|
168
|
+ public function edit($id)
|
|
169
|
+ {
|
|
170
|
+ $deposit = CustomerDeposit::findOrFail($id);
|
|
171
|
+ return view('deposit/edit', ['deposit' => $deposit, 'id'=>$id]);
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+ /**
|
|
175
|
+ * @param Request $request
|
|
176
|
+ * @return \Illuminate\Http\RedirectResponse
|
|
177
|
+ */
|
|
178
|
+ public function update(Request $request)
|
|
179
|
+ {
|
|
180
|
+ $id = (int)$request->input('id');
|
|
181
|
+ $this->validate($request, [
|
|
182
|
+ 'phone' => 'required',
|
|
183
|
+ 'pay_amount' => 'required',
|
|
184
|
+ 'discount' => 'required',
|
|
185
|
+ ], [
|
|
186
|
+ 'phone.required' => '手机号不能为空',
|
|
187
|
+ 'pay_amount.required' => '参数有误',
|
|
188
|
+ 'discount.required' => '参数有误',
|
|
189
|
+
|
|
190
|
+ ]);
|
|
191
|
+
|
|
192
|
+ $template = Templates::findOrFail($id);
|
|
193
|
+ $template->url = trim($request->input('url'));
|
|
194
|
+ $template->note = trim($request->input('note'));
|
|
195
|
+
|
|
196
|
+ //图片上传 阿里云oss
|
|
197
|
+ if ($request->hasFile('img') && $request->file('img')->isValid()) {
|
|
198
|
+ $file = $request->file('img');
|
|
199
|
+ $ossClient=new oss();
|
|
200
|
+ // 上传阿里云
|
|
201
|
+ $file = $ossClient->upload($file->getClientOriginalExtension(), $file->getRealPath(), 'upload/seafoodPic'.date("Y-m-d",time()).'/'.date('His'));
|
|
202
|
+ $img=$file['oss-request-url'];
|
|
203
|
+ $template->img=str_replace("kx-youhuiquan.oss-cn-beijing.aliyuncs.com","imgs.726p.com",$img);
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+ $template->save();
|
|
207
|
+ return redirect('/admin/template/index')->with('info', '修改模板成功');
|
|
208
|
+ }
|
|
209
|
+
|
|
210
|
+}
|