customer.php
13.9 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
/**
* description...
*
* @author Tinyhu
* @package AdminController
*/
class CustomerController extends Controller
{
public $layout='admin';
private $top = null;
public $needRightActions = array('*'=>true);
public function init()
{
$menu = new Menu();
$this->assign('mainMenu',$menu->getMenu());
$menu_index = $menu->current_menu();
$this->assign('menu_index',$menu_index);
$this->assign('subMenu',$menu->getSubMenu($menu_index['menu']));
$this->assign('menu',$menu);
$nav_act = Req::get('act')==null?$this->defaultAction:Req::get('act');
$nav_act = preg_replace("/(_edit)$/", "_list", $nav_act);
$this->assign('nav_link','/'.Req::get('con').'/'.$nav_act);
$this->assign('node_index',$menu->currentNode());
$this->safebox = Safebox::getInstance();
$this->assign('manager',$this->safebox->get('manager'));
$currentNode = $menu->currentNode();
if(isset($currentNode['name']))$this->assign('admin_title',$currentNode['name']);
}
public function noRight()
{
$this->redirect("admin/noright");
}
//充值与退款
public function balance_op()
{
$user_id = Filter::int(Req::args('user_id'));
$type = Filter::int(Req::args('type'));
$amount = Filter::float(Req::args('amount'));
//事件类型: 0:订单支付 1:用户充值 2:管理员充值 3:提现 4:退款到余额
$model = new Model("customer");
$obj = $model->where("user_id=$user_id")->find();
$info = array('status'=>'fail');
$range = 1000000000-$obj['balance'];
if($obj && $amount>0 && $amount<=$range){
if($type==2){
$model->data(array('balance'=>"`balance`+".$amount))->where("user_id=$user_id")->update();
Log::balance($amount,$user_id,'管理员为您充值,充值的金额为:'.$amount,2,$this->manager['id']);
$info = array('status'=>'success','msg'=>'充值成功。');
}else if($type==4){
$model->data(array('balance'=>"`balance`+".$amount))->where("user_id=$user_id")->update();
Log::balance($amount,$user_id,'管理员退款到您的余额中,退款金额为:'.$amount,4,$this->manager['id']);
$info = array('status'=>'success','msg'=>'退款成功。');
}
}else{
$info = array('status'=>'fail','msg'=>'此用户可充值的金额范围0.01-'.sprintf("%01.2f",$range));
}
echo JSON::encode($info);
}
public function balance_list()
{
$condition = Req::args("condition");
$condition_str = Common::str2where($condition);
if($condition_str) $this->assign("where",$condition_str);
else $this->assign("where","1=1");
$this->assign("condition",$condition);
$this->redirect();
}
public function withdraw_list()
{
$condition = Req::args("condition");
$condition_str = Common::str2where($condition);
if($condition_str) $this->assign("where",$condition_str);
else $this->assign("where","1=1");
$this->assign("condition",$condition);
$this->redirect();
}
public function withdraw_view()
{
$this->layout = "blank";
$id =Filter::int(Req::args('id'));
if($id){
$model = new Model('withdraw as wd');
$withdraw = $model->fields("wd.*,us.name as uname,cu.balance")->join("left join user as us on wd.user_id = us.id left join customer as cu on wd.user_id = cu.user_id")->where("wd.id=$id")->find();
$this->assign("withdraw",$withdraw);
$this->redirect();
}
}
//处理提现
public function withdraw_act()
{
$id = Filter::int(Req::args('id'));
$status = intval(Req::args('status'));
$re_note = Filter::text(Req::args('re_note'));
$model = new Model('withdraw as wd');
$obj = $model->fields("wd.*,cu.balance")->join("left join customer as cu on wd.user_id = cu.user_id")->where("wd.id=$id and wd.status=0")->find();
if($obj){
if($obj['amount']<=$obj['balance']){
$model->table('withdraw')->data(array('status'=>$status,'re_note'=>$re_note))->where("id=$id")->update();
if($status==1){
$model->table('customer')->data(array('balance'=>"`balance`-".$obj['amount']))->where('user_id='.$obj['user_id'])->update();
Log::balance(0-$obj['amount'],$obj['user_id'],'提现到'.$obj['type_name'].',账号:'.$obj['account'],3,$this->manager['id']);
$statusInfo = '通过';
}else{
$statusInfo = '未通过';
}
//退换货申请处理提醒
$user_info = $model->table('customer')->where('user_id='.$obj['user_id'])->find();
if(isset($user_info['mobile'])){
$template_data = array('amount'=>$obj['amount'],'status'=>$statusInfo,'tousers'=>$user_info['mobile']);
$NoticeService = new NoticeService();
$NoticeService->send('withdrawal_action',$template_data);
}
echo "<script>parent.close_dialog();</script>";
}
else{
echo"<script>alert('提现金额大于了余额。')</script>";
}
//扣除账户里的余额
}
}
public function export_excel()
{
$this->layout = '';
$condition = Req::args("condition");
$fields = Req::args("fields");
$condition = Common::str2where($condition);
$notify_model = new Model("notify as n");
if($condition){
$items = $notify_model->fields("n.*,go.name as goods_name,u.name as user_name")->join("left join user as u on n.user_id = u.id left join goods as go on n.goods_id = go.id")->where($condition)->findAll();
if($items){
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=csat.xls");
$fields_array = array('email'=>'邮件','mobile'=>'电话','user_name'=>'用户名','goods_name'=>'商品名','register_time'=>'登记时间','notify_status'=>'是否通知');
$str = "<table border=1><tr>";
foreach ($fields as $value) {
$str .= "<th>".iconv("UTF-8","GB2312",$fields_array[$value])."</th>";
}
$str .= "</tr>";
foreach ($items as $item) {
$str .= "<tr>";
foreach ($fields as $value) {
$str .= "<td>".iconv("UTF-8","GB2312",$item[$value])."</td>";
}
$str .= "</tr>";
}
$str .= "</table>";
echo $str;
exit;
}else{
$this->msg=array("warning","没有符合该筛选条件的数据,请重新筛选!");
$this->redirect("notify_list",false,Req::args());
}
}else{
$this->msg=array("warning","请选择筛选条件后再导出!");
$this->redirect("notify_list",false);
}
}
public function send_notify()
{
$condition = Req::args("condition");
$notify_model = new Model("notify as n");
$condition = Common::str2where($condition);
if($condition!=null){
$items = $notify_model->fields("n.*,go.name as goods_name,u.name as user_name")->join("left join user as u on n.user_id = u.id left join goods as go on n.goods_id = go.id")->where($condition)->findAll();
$mail = new Mail();
$msg_model = new Model("msg_template");
$template = $msg_model->where("id=1")->find();
$success = 0;
$fail = 0;
foreach($items as $item){
$subject = str_replace(array('{$user_name}','{$goods_name}'), array($item['user_name'],$item['goods_name']), $template['title']);
$body = str_replace(array('{$user_name}','{$goods_name}'), array($item['user_name'],$item['goods_name']), $template["content"]);
$status = $mail->send_email($item['email'],$subject , $body);
if($status){
$data = array('notify_time'=>date('Y-m-d H:i:s'),'notify_status'=>'1');
$notify_model->data($data)->where('id='.$item['id'])->update();
$success++;
}
else{
$fail++;
}
}
$return = array('isError' => false, 'count' => count($items), 'success' => $success, 'fail' => $fail);
}
else{
$return = array('isError' => true, 'msg' => '没有选择筛选条件!');
}
echo JSON::encode($return);
}
public function message_send()
{
$condition = Req::post("condition");
$condition = Common::str2where($condition);
$model = new Model();
Req::post("time",date('Y-m-d H:i:s'));
$has_user = true;
if($condition!=''){
$users = $model->table("customer")->where($condition)->find();
if($users) $has_user = true;
else $has_user = false;
}
if($has_user){
$last_id = $model->table("message")->insert();
$model->table("customer")->data(array('message_ids'=>"concat_ws (',',`message_ids`,'$last_id')"));
if($condition!='') $model->where($condition)->update();
else $model->update();
$this->redirect("message_list");
}else{
$this->msg=array("warning","发送的对象不存在,因此无法发送,请修改筛选条件重新发送!");
$this->redirect("message_edit",false,Req::args());
}
}
public function message_edit()
{
$model = new Model('grade');
$rows = $model->findAll();
$grade = '';
foreach ($rows as $row) {
$grade .= $row['id'].":'".$row['name']."',";
}
$grade = trim($grade,',');
$this->assign('grade',$grade);
$this->redirect();
}
function ask_edit()
{
$id = intval(Req::args("id"));
if($id){
$model = new Model("ask");
$obj = $model->where("id=$id")->find();
if($obj){
$goods = $model->table("goods")->fields("name,id")->where("id=".$obj['goods_id'])->find();
$user = $model->table("user")->fields("name")->where("id=".$obj['user_id'])->find();
$obj['goods_name'] = isset($goods['name'])?$goods['name']:'<h1 class="red">商品已经不存在</h1>';
$obj['goods_id'] = isset($goods['id'])?$goods['id']:0;
$obj['user_name'] = isset($user['name'])?$user['name']:'用户已不存在';
$this->redirect("ask_edit",false,$obj);
}
else{
$this->msg=array("error","此咨询不存在,查证后再试!");
$this->redirect("ask_edit",false,Req::args());
}
}else{
$this->msg=array("error","此咨询不存在,查证后再试!");
$this->redirect("ask_edit",false,Req::args());
}
}
//商品咨询
function ask_list()
{
$condition = Req::args("condition");
$condition_str = Common::str2where($condition);
if($condition_str) $this->assign("where",$condition_str);
else $this->assign("where","1=1");
$this->assign("condition",$condition);
$this->redirect();
}
//商品评价
function review_list()
{
$condition = Req::args("condition");
$condition_str = Common::str2where($condition);
if($condition_str) $this->assign("where",$condition_str);
else $this->assign("where","1=1");
$this->assign("condition",$condition);
$this->redirect();
}
//对应article的验证与过滤
function ask_validator()
{
$manager = $this->safebox->get('manager');
$rules = array('content:required:内容不能为空!');
$info = Validator::check($rules);
if($info==true) {
Filter::form(array('text'=>'content'));
$content = TString::nl2br(Req::args('content'));
Req::args('content',$content);
if(Req::args('id')!=null){
Req::args('reply_time',date('Y-m-d H:i:s'));
Req::args('status',1);
Req::args('admin_id',$manager['id']);
}
}
return $info;
}
function customer_list()
{
$condition = Req::args("condition");
$condition_str = Common::str2where($condition);
if($condition_str) $this->assign("where",$condition_str);
else $this->assign("where","1=1");
$this->assign("condition",$condition);
$this->redirect();
}
public function customer_edit()
{
$id = Req::args("id");
$customer = Req::args();
if($id){
$model = new Model("customer as c");
$customer = $model->join("user as u on c.user_id = u.id")->where("c.user_id=".$id)->find();
}
$this->redirect('customer_edit',false,$customer);
}
public function customer_del()
{
$id = Req::args("id");
if(is_array($id)){
$cond = ' in ('.implode(",",$id).')';
}
else{
$cond = " = $id";
}
$model = new Model();
$users = $model->table("user")->where("id $cond")->findAll();
$model->table("customer")->where("user_id $cond")->delete();
$model->table("user")->where("id $cond")->delete();
if($users){
$user_names = "";
foreach ($users as $user) {
$user_names .= $user['name']."、";
}
$user_names = trim($user_names,'、');
Log::op($this->manager['id'],"删除会员","管理员[".$this->manager['name']."]:删除了会员 ".$user_names);
}
$this->redirect("customer_list");
}
public function customer_save()
{
$id = Req::args("id");
$name = Req::args("name");
$email = Req::args("email");
$password = Req::args("password");
$birthday = Req::post("birthday");
$userModel = new Model("user");
$customerModel = new Model("customer");
if($id){
$user = $userModel->where("id=$id")->find();
if($user){
if($name && $email)$userModel->data(array('name'=>$name,'email'=>$email))->where("id=$id")->update();
Req::args('user_id',$id);
$customerModel->where("user_id=$id")->update();
Log::op($this->manager['id'],"修改会员","管理员[".$this->manager['name']."]:修改了会员 ".$user['name']." 的信息");
}
}else{
$user = $userModel->where("name = '$name' or email = '$email'")->find();
if($user){
$this->msg=array("error","用户名或邮箱已经存在!");
$this->redirect("customer_edit",false);
exit;
}else{
$validcode = CHash::random(8);
$last_id = $userModel->data(array('name'=>$name,'password'=>CHash::md5($password,$validcode),'validcode'=>$validcode,'email'=>$email))->add();
Req::args('user_id',$last_id);
if(!Validator::date(Req::post('birthday')))Req::post('birthday',date('Y-m-d'));
$customerModel->insert();
Log::op($this->manager['id'],"添加会员","管理员[".$this->manager['name']."]:添加了会员 ".$name." 的信息");
}
}
$this->redirect("customer_list");
}
public function customer_password()
{
$id = Req::post("id");
$password = Req::post("password");
$repassword = Req::post("repassword");
$info = array('status'=>'fail');
if($id && $password && $password == $repassword){
$model = new Model("user");
$validcode = CHash::random(8);
$flag = $model->where("id=$id")->data(array('password'=>CHash::md5($password,$validcode),'validcode'=>$validcode))->update();
if($flag)$info = array('status'=>'success');
}
echo JSON::encode($info);
}
}