Profile.php
2.6 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
namespace app\teacher\controller\general;
use app\common\controller\TeacherBase;
use app\teacher\model\basic\Teacher;
use fast\Random;
use think\Exception;
use think\Session;
use think\Validate;
use app\common\model\Territory;
/**
* 商家信息配置
*
* @icon fa fa-user
*/
class Profile extends TeacherBase
{
protected $teacher = null;
public function _initialize()
{
$this->teacher = $this->getSessionData();
parent::_initialize(); // TODO: Change the autogenerated stub
$this->view->assign("territoryList", Territory::getTerritoryList());
}
/**
* 查看
*/
public function index()
{
$teacher = $this->teacher;
$teacher = Teacher::get($teacher['id']);
$teacher['territory_id'] = !empty($teacher['territory_id']) ? explode(',',$teacher['territory_id']) : '';
$this->view->assign('statusList',[0=>'待审核',1=>'审核通过',2=>'审核拒绝']);
$this->view->assign('teacher',$teacher);
return $this->view->fetch();
}
/**
* 更新个人信息
*/
public function update()
{
if ($this->request->isPost()) {
$this->token();
$params = $this->request->post("row/a");
$params = array_filter(array_intersect_key(
$params,
array_flip(array('email', 'nickname', 'password', 'avatar','image','territory_id'))
));
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 = Teacher::where('email', $params['email'])->where('id', '<>', $this->teacher['id'])->find();
if ($exist) {
$this->error(__("Email already exists"));
}
if(!empty($params['territory_id'][0])) {
$params['territory_id'] = implode(',',$params['territory_id']);
}else{
$params['territory_id'] = '';
}
if ($params) {
$teacher = Teacher::get( $this->teacher['id']);
$teacher->save($params);
Session::set("teacher", $teacher->toArray());
$this->success();
}
$this->error();
}
return;
}
}