Profile.php
3.3 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
<?php
namespace app\admin\controller\general;
use app\admin\model\Admin;
use app\common\controller\Backend;
use fast\Random;
use think\Db;
use think\Session;
use think\Validate;
/**
* 个人配置
*
* @icon fa fa-user
*/
class Profile extends Backend
{
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
$model = model('AdminLog');
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $model
->where($where)
->where('admin_id', $this->auth->id)
->order($sort, $order)
->count();
$list = $model
->where($where)
->where('admin_id', $this->auth->id)
->order($sort, $order)
->limit($offset, $limit)
->select();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
$row = Db::name('store')->where(['admin_id'=>$this->auth->id])->find();
$this->assign('row',$row);
return $this->view->fetch();
}
/**
* 更新个人信息
*/
public function update()
{
if ($this->request->isPost()) {
$this->token();
$params = $this->request->post("row/a");
$name = $params['name'];
$money = $params['money'];
$freight = $params['freight'];
$phone = $params['phone'];
$address = $params['address'];
$lng = $params['lng'];
$lat = $params['lat'];
$content = $params['content'];
$params = array_filter(array_intersect_key(
$params,
array_flip(array('email', 'nickname', 'password', 'avatar'))
));
unset($v);
/*if (!Validate::is($params['email'], "email")) {
$this->error(__("Please input correct email"));
}*/
if (isset($params['password'])) {
if (!Validate::is($params['password'], "/^[\S]{6,16}$/")) {
$this->error(__("Please input correct password"));
}
$params['salt'] = Random::alnum();
$params['password'] = md5(md5($params['password']) . $params['salt']);
}
/*$exist = Admin::where('email', $params['email'])->where('id', '<>', $this->auth->id)->find();
if ($exist) {
$this->error(__("Email already exists"));
}*/
if ($params) {
$admin = Admin::get($this->auth->id);
$admin->save($params);
//因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
Session::set("admin", $admin->toArray());
$store_id = Db::name('admin')->where(['id'=>$this->auth->id])->value('store_id');
if(!empty($store_id)){
echo Db::name('store')->where(['id'=>$store_id])->update(['name'=>$name,'money'=>$money,'freight'=>$freight,'phone'=>$phone,'address'=>$address,'lng'=>$lng,'lat'=>$lat,'content'=>$content]);
}
$this->success();
}
$this->error();
}
return;
}
}