colly_wyx
2018-03-30 5b00b28782f2c773aa9b63ac61584b70a366526c
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
<?php 
 
class AdController extends System_Controller_Admin{
 
    public function init(){
        parent::init();
        $this->ad_service = new Service_Ad();
    }
 
    /**
     * 广告列表
     */
    public function IndexAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $total = $this->ad_service->getAdTotal();
            $data['draw'] = !empty($_REQUEST['draw'])?$_REQUEST['draw']:1;
            $data['start'] = !empty($_REQUEST['start'])?$_REQUEST['start']:0;
            $data['length'] = !empty($_REQUEST['length'])?$_REQUEST['length']:10;
            $data['recordsTotal'] = $total;
            $data['recordsFiltered'] = $total;
            $data['data'] = $this->ad_service->getAdList(array(), array(), array(), $data['length'], $data['start']);
            exit($this->sendToDataTable($data));
        }
    }
 
    /**
     * 添加广告
     */
    public function AddAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $data['name'] = $this->getRequest()->getPost('name');
            if(FileUpload::upload('logo')){
 
            }
            $data['is_publish'] = $this->getRequest()->getPost('is_publish');
            $data['content'] = $this->getRequest()->getPost('content');
            $data['create_time'] = date('Y-m-d H:i:s');
             if($this->ad_service->add($data)){
                exit($this->showSuccess('广告添加成功', true));
            }
            else{
                exit($this->showError($this->user_service->error, 400, true));
            }
        }
        $role_service = new service_Role();
        $roles = $role_service->getRoleList();
        $this->getView()->assign('roles', $roles);
    }
 
    /**
     * 修改用户
     */
    public function EditAction($id){
        $user = $this->user_service->getUserInfo(array('_id' => $id));
        if($user){
            if($this->getRequest()->isXmlHttpRequest()){
                $data['nickname'] = $this->post('nickname');
                $password = $this->post('password');
                if(!empty($password))
                $data['password'] = md5(md5($password).$user['encrypt']);
                $data['refresh_frequency'] = $this->post('refresh_frequency');
                $data['is_open_upload'] = $this->post('is_open_upload');
                $data['video'] = $this->post('video');
                $data['role'] = $this->post('role');
                $data['edit_time'] = time();
                $data['is_lock'] = $this->post('is_lock');
                if($this->user_service->update($data, array('_id' => $id))){
                    exit($this->showSuccess('用户修改成功', true));
                }
                else{
                    exit($this->showError($this->user_service->error, 400, true));
                }
            }
            $role_service = new Service_Role();
            $roles = $role_service->getRoleList();
            $this->getView()->assign(array('user' => $user, 'roles' => $roles));
        }
        else{
            $this->redirect('/error/show/type/no_data');
        }
    }
 
    /**
     * 修改我的信息
     */
    public function MyAction(){
        $user_id = $this->session['user']['user_id'];
        $user = $this->user_service->getUserInfo(array('_id' => $user_id));
        if($user){
            if($this->getRequest()->isXmlHttpRequest()){
                $data['nickname'] = $this->post('nickname');
                $password = $this->post('password');
                if(!empty($password))
                $data['password'] = md5(md5($password).$user['encrypt']);
                $data['refresh_frequency'] = $this->post('refresh_frequency');
                $data['is_open_upload'] = $this->post('is_open_upload');
                $data['video'] = $this->post('video');
                $data['edit_time'] = time();
                if($this->user_service->update($data, array('_id' => $user_id))){
                    exit($this->showSuccess('用户修改成功', true));
                }
                else{
                    exit($this->showError($this->user_service->error, 400, true));
                }
            }
            $role_service = new Service_Role();
            $roles = $role_service->getRoleList();
            $this->getView()->assign(array('user' => $user, 'roles' => $roles));
        }
        else{
            $this->redirect('/error/show/type/no_data');
        }
    }
 
    /**
     * 验证手机号码是否存在
     */
    public function CheckPhoneAction(){
        $phone = $this->post('phone');
        $result = $this->_checkPhone($phone);
        if($this->isAjax()){
            exit($this->send(array('valid' => $result)));
        }
        else{
            return $result;
        }
    }
 
    /**
     * 验证号码是否存在
     * @param  [type] $phone [description]
     * @return [type]        [description]
     */
    public function _checkPhone($phone){
        $user = $this->user_service->getUserInfo(array('phone' => $phone));
        if($user)
            return false;
        else
            return true;
    }
 
}