[521] | 1 | <?php
|
---|
| 2 | if (!defined('BASEPATH'))
|
---|
| 3 | exit('No direct script access allowed');
|
---|
| 4 |
|
---|
[884] | 5 | /**
|
---|
| 6 | * Class User
|
---|
| 7 | * @todo Execute actions of user
|
---|
| 8 | *
|
---|
| 9 | * @see function profile
|
---|
| 10 | * @see function packageRegister
|
---|
| 11 | * @see function finishRegisterPackage
|
---|
| 12 | * @see function regpackage
|
---|
| 13 | * @see function update_info
|
---|
| 14 | * @see function update_user
|
---|
| 15 | * @see function change_password
|
---|
| 16 | * @see function trade_history
|
---|
| 17 | * @see function getUserInfor
|
---|
| 18 | * @see function adminUpdateUser
|
---|
| 19 | * @see function regis_history
|
---|
| 20 | *
|
---|
| 21 | * @author dungnv02
|
---|
| 22 | *
|
---|
| 23 | */
|
---|
[503] | 24 | class User extends MX_Controller {
|
---|
[466] | 25 |
|
---|
[521] | 26 | const TOKENPW = 'violet';
|
---|
[503] | 27 |
|
---|
[521] | 28 | public function __construct() {
|
---|
| 29 | parent::__construct();
|
---|
[554] | 30 | $this->load->helper('cookie');
|
---|
[636] | 31 | $this->load->helper('language');
|
---|
| 32 | $this->lang->load('messages', 'message');
|
---|
[521] | 33 | }
|
---|
| 34 |
|
---|
| 35 | public function profile() {
|
---|
| 36 | $user_info = $this->session->userdata('userInfo');
|
---|
[707] | 37 |
|
---|
[503] | 38 | if ($user_info) {
|
---|
[691] | 39 | $this->load->model('User_model');
|
---|
| 40 | $this->load->model('Servicepackage_model');
|
---|
[503] | 41 | $user = $user_info['user'];
|
---|
| 42 | $us_id = $user_info['us_id'];
|
---|
| 43 | $src = "SBG";
|
---|
| 44 | $token = md5($us_id . self::TOKENPW);
|
---|
| 45 | $data = $this->get_data($src, $token, $us_id);
|
---|
[706] | 46 | $data['can_edit'] = 0;
|
---|
[691] | 47 | $u = $this->User_model->get_user_by_id($us_id);
|
---|
[706] | 48 | if ($u['p_id'] < 1) {
|
---|
| 49 | $data['can_edit'] = 1;
|
---|
| 50 | }
|
---|
| 51 | if ($data['fullname']=="")
|
---|
| 52 | {
|
---|
| 53 | $data['can_edit'] = 1;
|
---|
| 54 | }
|
---|
[508] | 55 | $data['current_tab'] = $this->uri->segment(4, 'edit-basic');
|
---|
[691] | 56 | $data['packages'] = $this->Servicepackage_model->getAllPackages();
|
---|
| 57 | $data['is_viettel'] = isset($user_info['is_viettel']) ? $user_info['is_viettel']:FALSE;
|
---|
[701] | 58 | $data['provinces'] = lang('_PROVINCES_');
|
---|
| 59 |
|
---|
[691] | 60 | $data = (is_array($u)) ? array_merge($data, $u) : $data;
|
---|
| 61 | $data = (is_array($user_info)) ? array_merge($data, $user_info):$data;
|
---|
[559] | 62 |
|
---|
[503] | 63 | $this->load->view('frontend/user_profile', $data);
|
---|
[508] | 64 | } else {
|
---|
[503] | 65 | redirect('frontend/home');
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public function packageRegister() {
|
---|
| 70 | $result = array();
|
---|
| 71 | $input = $this->input->post();
|
---|
| 72 | $this->load->model('user_model');
|
---|
| 73 | $user_info = $this->session->userdata('userInfo');
|
---|
| 74 | if ($user_info) {
|
---|
| 75 | parse_str($user_info['user'], $info);
|
---|
| 76 | $this->load->model('servicepackage_model');
|
---|
[508] | 77 |
|
---|
[503] | 78 | $package = $this->servicepackage_model->getPackage($input['p_id']);
|
---|
| 79 | $user = $user_info['user'];
|
---|
| 80 | $us_id = $user_info['us_id'];
|
---|
| 81 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
[838] | 82 | //$us = array();
|
---|
| 83 | $user['district'] = $this->user_model->getDistrictByIdAndProvince($user['district'], $user['province']);
|
---|
| 84 |
|
---|
[503] | 85 | $result['can_buy'] = 1;
|
---|
| 86 | $result['can_edit'] = 0;
|
---|
[765] | 87 |
|
---|
[503] | 88 | if ($user['acc_balanced'] < $package['p_price']) {
|
---|
| 89 | $result['can_buy'] = 0;
|
---|
| 90 | }
|
---|
[580] | 91 |
|
---|
[706] | 92 | if(strtotime($user['expire_date'])<strtotime(date('Y-m-d'))){
|
---|
| 93 | $result['can_edit'] = 1;
|
---|
| 94 | }
|
---|
[503] | 95 | if ($user['p_id'] < 1) {
|
---|
| 96 | $result['can_edit'] = 1;
|
---|
| 97 | }
|
---|
[580] | 98 | if ($info['fullname']=="")
|
---|
| 99 | {
|
---|
| 100 | $result['can_edit'] = 1;
|
---|
| 101 | }
|
---|
[503] | 102 | $result['info'] = $info;
|
---|
| 103 | $result['user'] = $user;
|
---|
| 104 | $result['package'] = $package;
|
---|
| 105 | $result['modal'] = $this->load->view('frontend/package_register_modal', $result, true);
|
---|
| 106 | } else {
|
---|
| 107 |
|
---|
| 108 | }
|
---|
| 109 | echo json_encode($result);
|
---|
| 110 | }
|
---|
[554] | 111 |
|
---|
[503] | 112 | public function finishRegisterPackage() {
|
---|
| 113 | $result = array();
|
---|
| 114 | $result['success'] = 0;
|
---|
| 115 | $this->load->model('user_model');
|
---|
| 116 | $input = $this->input->post();
|
---|
[701] | 117 | //print_r($input);
|
---|
[503] | 118 | $user_info = $this->session->userdata('userInfo');
|
---|
[508] | 119 | parse_str($user_info['user'], $info);
|
---|
[503] | 120 | if (isset($input['fullname'])) {
|
---|
[548] | 121 | if (strlen($input['fullname']) < 1) {
|
---|
[636] | 122 | $result['errors'][] = lang('_SBG_REGISTER_VIP_FULLNAME_REQUIRED_MSG');
|
---|
[503] | 123 | }
|
---|
[548] | 124 | if (strlen($input['school']) < 1) {
|
---|
[636] | 125 | $result['errors'][] = lang('_SBG_REGISTER_VIP_SCHOOL_REQUIRED_MSG');
|
---|
[503] | 126 | }
|
---|
| 127 | if (!isset($result['errors'])) {
|
---|
[490] | 128 | $user_info = $this->session->userdata('userInfo');
|
---|
[503] | 129 | if ($user_info) {
|
---|
[508] | 130 |
|
---|
[503] | 131 | $src = "SBG";
|
---|
[508] | 132 | $us_id = $user_info['us_id'];
|
---|
[503] | 133 | $input['password'] = '';
|
---|
| 134 | $input['oldpass'] = '';
|
---|
| 135 | $input['gender'] = '';
|
---|
[508] | 136 | $input['email'] = '';
|
---|
[701] | 137 | //$input['province'] = '';
|
---|
[508] | 138 | $info['fullname'] = $input['fullname'];
|
---|
| 139 | $info['school'] = $input['school'];
|
---|
[503] | 140 | $token = md5($us_id . self::TOKENPW);
|
---|
| 141 | $user = $this->get_data($src, $token, $us_id);
|
---|
[701] | 142 | //$input['district'] = '';
|
---|
[503] | 143 | if ($input) {
|
---|
[490] | 144 | $this->load->model('user_model');
|
---|
[503] | 145 | $update = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
[508] | 146 | $info = urldecode(http_build_query($info));
|
---|
[554] | 147 | $userdata = array('username' => $user_info['username'], 'user' => $info, 'us_id' => $user_info['us_id'], 'logined_in' => TRUE, 'is_viettel' => $user_info['is_viettel']);
|
---|
[503] | 148 | $this->session->set_userdata('userInfo', $userdata);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
[647] | 153 |
|
---|
[503] | 154 | if (isset($result['errors'])) {
|
---|
[554] | 155 | echo json_encode($result);
|
---|
[647] | 156 | exit();
|
---|
[503] | 157 | }
|
---|
[647] | 158 |
|
---|
[503] | 159 | $this->load->model('servicepackage_model');
|
---|
| 160 | $us_id = $user_info['us_id'];
|
---|
[700] | 161 | //$user = $this->user_model->get_user_by_id($us_id);
|
---|
| 162 | $user = $this->user_model->getUserById($us_id);
|
---|
[838] | 163 | //$user['district'] = $this->user_model->getDistrictByIdAndProvince($user['district'], $user['province']);
|
---|
[503] | 164 | $package = $this->servicepackage_model->getPackage($input['p_id']);
|
---|
[508] | 165 | $user['acc_balanced'] = $user['acc_balanced'] - $package['p_price'];
|
---|
[556] | 166 |
|
---|
[765] | 167 | $today_dt = new DateTime(date('Y-m-d 00:00:00'));
|
---|
| 168 | $expire_dt = new DateTime($user['expire_date']);
|
---|
| 169 |
|
---|
| 170 | $currentExpireDate = $user['expire_date'] == NULL || trim($user['expire_date']) == '' || $today_dt > $expire_dt ? date('Y-m-d 00:00:00') : $user['expire_date'];
|
---|
[556] | 171 | $user['expire_date'] = date('Y-m-d', strtotime("+" . $package['p_period'] . " ".$package['p_unit'], strtotime($currentExpireDate)));
|
---|
[508] | 172 | $user['p_id'] = $package['p_id'];
|
---|
[701] | 173 | $user['province'] = $input['province'];
|
---|
[838] | 174 | $user['district'] = $input['district'];
|
---|
[508] | 175 | $this->user_model->updateUser($us_id, $user);
|
---|
| 176 | $user['expire_date'] = date("d-m-Y", (strtotime($user['expire_date'])));
|
---|
| 177 | $result['expire_date'] = $user['expire_date'];
|
---|
[503] | 178 | $result['success'] = 1;
|
---|
[647] | 179 | $message = str_replace(':period:', date("d/m/Y", (strtotime($user['expire_date']))), lang('_SBG_REGISTER_VIP_SUCCESS_MSG'));
|
---|
| 180 | $result['message'] = $message;
|
---|
| 181 |
|
---|
[633] | 182 | $toDate = date("Y-m-d", (strtotime($result['expire_date'])));
|
---|
[646] | 183 | $this->user_model->insertRegisterVipLog($user['cellphone'],$package['p_code'], false);
|
---|
[503] | 184 | echo json_encode($result);
|
---|
| 185 | }
|
---|
[554] | 186 |
|
---|
| 187 | public function regpackage() {
|
---|
| 188 | $user_info = $this->session->userdata('userInfo');
|
---|
| 189 | parse_str($user_info['user'], $info);
|
---|
| 190 | $p_id = $this->input->post('p_id', TRUE);
|
---|
| 191 |
|
---|
| 192 | $us_id = (int) $info['id'];
|
---|
| 193 | $this->load->model('servicepackage_model');
|
---|
| 194 | $this->load->model('user_model');
|
---|
| 195 |
|
---|
| 196 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
[838] | 197 | $user['district'] = $this->user_model->getDistrictByIdAndProvince($user['district'], $user['province']);
|
---|
[554] | 198 | $package = $this->servicepackage_model->getPackage($p_id);
|
---|
| 199 |
|
---|
| 200 | if ($user['acc_balanced'] < $package['p_price']) {
|
---|
[636] | 201 | $aryPatterns = array('/:acc_balanced:/');
|
---|
| 202 | $message = preg_replace($aryPatterns, array(number_format($user['acc_balanced'], 0)), lang('_SBG_ACC_BALANCE_LESS_PACKAGE_PRICE_MSG'));
|
---|
[554] | 203 | } else {
|
---|
| 204 | $user['acc_balanced'] = $user['acc_balanced'] - $package['p_price'];
|
---|
[765] | 205 |
|
---|
| 206 | $today_dt = new DateTime(date('Y-m-d 00:00:00'));
|
---|
| 207 | $expire_dt = new DateTime($user['expire_date']);
|
---|
| 208 |
|
---|
| 209 | $currentExpireDate = $user['expire_date'] == NULL || trim($user['expire_date']) == '' || $today_dt > $expire_dt ? date('Y-m-d 00:00:00') : $user['expire_date'];
|
---|
[554] | 210 |
|
---|
| 211 | $user['expire_date'] = date('Y-m-d', strtotime("+" . $package['p_period'] . " " . $package['p_unit'], strtotime($currentExpireDate)));
|
---|
| 212 | //$user['expire_date'] = date("Y-m-d", (strtotime($user['expire_date']) - 1));
|
---|
| 213 |
|
---|
| 214 | $user['p_id'] = $package['p_id'];
|
---|
| 215 |
|
---|
| 216 | $this->user_model->updateUser($us_id, $user);
|
---|
[636] | 217 | $aryPatterns = array('/:period:/');
|
---|
| 218 | $message = preg_replace($aryPatterns, array(date('d-m-Y', strtotime($user['expire_date']))), lang('_SBG_REGISTER_VIP_SUCCESS_MS'));
|
---|
[646] | 219 | $this->user_model->insertRegisterVipLog($user['cellphone'], $package['p_code'], false);
|
---|
[554] | 220 | }
|
---|
| 221 |
|
---|
| 222 | $this->session->set_flashdata('message', $message);
|
---|
| 223 | redirect('frontend/user/profile#services-register');
|
---|
[521] | 224 | }
|
---|
[503] | 225 |
|
---|
| 226 | private function get_data($src, $token, $us_id) {
|
---|
| 227 | $this->load->model('user_model');
|
---|
| 228 | $user = $this->user_model->get_user_info($src, $token, $us_id);
|
---|
| 229 |
|
---|
| 230 | if (strpos($user, '&')) {
|
---|
| 231 | parse_str($user);
|
---|
| 232 | $us = $this->user_model->get_user_by_id($us_id);
|
---|
[838] | 233 | $us['district'] = $this->user_model->getDistrictByIdAndProvince($us['district'], $province);
|
---|
[503] | 234 | $data = array('us_id' => $us_id, 'username' => $username, 'fullname' => $fullname,
|
---|
[838] | 235 | 'gender' => $gender, 'email' => $email, 'phone' => $phone, 'school' => $school, 'province' => $province, 'district' => $us['district'],
|
---|
[503] | 236 | 'acc_balanced' => $us['acc_balanced'], 'expire_date' => $us['expire_date'], 'date_diff' => $this->dateDiff($us['expire_date'])
|
---|
| 237 | );
|
---|
| 238 | return $data;
|
---|
| 239 | } else {
|
---|
| 240 | return "";
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | private function dateDiff($expire_date) {
|
---|
| 245 | $date1 = date("Y-m-d");
|
---|
| 246 | if ((strtotime($expire_date) - strtotime($date1)) < 0)
|
---|
| 247 | return "0 ngà y còn lại";
|
---|
| 248 | $diff = strtotime($expire_date) - strtotime($date1);
|
---|
| 249 | $years = floor($diff / (365 * 60 * 60 * 24));
|
---|
| 250 | $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
|
---|
| 251 | $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
|
---|
| 252 | if ($years > 0) {
|
---|
| 253 | return $years . " nÄm, " . $months . " tháng, " . $days . " ngà y còn lại";
|
---|
| 254 | } else {
|
---|
| 255 | if ($months > 0) {
|
---|
| 256 | return $months . " tháng, " . $days . " ngà y còn lại";
|
---|
| 257 | } else {
|
---|
| 258 | return $days . " ngà y còn lại";
|
---|
| 259 | }
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
[604] | 262 |
|
---|
| 263 | public function update_info() {
|
---|
[636] | 264 | $result['success'] = 0;
|
---|
[580] | 265 | $user_info = $this->session->userdata('userInfo');
|
---|
| 266 | if ($user_info) {
|
---|
| 267 | $us_id = $user_info['us_id'];
|
---|
| 268 | $result = array();
|
---|
| 269 | $result['success'] = 0;
|
---|
| 270 | $src = "SBG";
|
---|
| 271 | $token = md5($us_id . self::TOKENPW);
|
---|
| 272 | $user = $this->get_data($src, $token, $us_id);
|
---|
| 273 | $input = $this->input->post();
|
---|
| 274 | parse_str($user_info['user'], $info);
|
---|
| 275 | if ($input) {
|
---|
[717] | 276 | if (array_key_exists('fullname', $input)) {
|
---|
| 277 | if (strlen($input['fullname']) == 0) {
|
---|
| 278 | $result['errors'][] = array("content"=>lang('_SBG_FULLNAME_REQUIRED_MSG'),"field"=>"fullname");
|
---|
| 279 | }
|
---|
| 280 | }else{
|
---|
| 281 | $input['fullname'] = $user['fullname'];
|
---|
| 282 | }
|
---|
[580] | 283 | if (strlen($input['school']) == 0) {
|
---|
[636] | 284 | $result['errors'][] = array("content"=>lang('_SBG_REGISTER_VIP_SCHOOL_REQUIRED_MSG'),"field"=>"school");
|
---|
[580] | 285 | }
|
---|
[721] | 286 | if (strlen($input['province']) == 0) {
|
---|
| 287 | $result['errors'][] = array("content"=>lang('_SBG_PROVINCE_REQUIRED_MSG'),"field"=>"province");
|
---|
| 288 | }
|
---|
[906] | 289 | if (strlen($input['district']) == 0) {
|
---|
| 290 | $result['errors'][] = array("content"=>lang('_SBG_DISTRICT_REQUIRED_MSG'),"field"=>"district");
|
---|
| 291 | }
|
---|
[580] | 292 | $input['password'] = '';
|
---|
| 293 | $input['oldpass'] = '';
|
---|
| 294 | $this->load->model('user_model');
|
---|
| 295 | if (!isset($result['errors'])) {
|
---|
| 296 | $result['data'] = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
| 297 | $result['success'] = 1;
|
---|
[636] | 298 | $info['fullname'] = $input['fullname'];
|
---|
| 299 | $info['school'] = $input['school'];
|
---|
[580] | 300 | $info = urldecode(http_build_query($info));
|
---|
| 301 | $userdata = array('username' => $user_info['username'], 'user' => $info, 'us_id' => $user_info['us_id'], 'logined_in' => TRUE, 'is_viettel' => $user_info['is_viettel']);
|
---|
| 302 | $this->session->set_userdata('userInfo', $userdata);
|
---|
| 303 | }
|
---|
| 304 | echo json_encode($result);
|
---|
| 305 | }
|
---|
| 306 | } else {
|
---|
| 307 | redirect('frontend/home');
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
[604] | 310 |
|
---|
[503] | 311 | public function update_user() {
|
---|
| 312 | $us_id = $this->uri->segment(4);
|
---|
| 313 | $user_info = $this->session->userdata('userInfo');
|
---|
| 314 | if ($user_info) {
|
---|
| 315 | $result = array();
|
---|
| 316 | $result['success'] = 0;
|
---|
| 317 | $src = "SBG";
|
---|
| 318 | $token = md5($us_id . self::TOKENPW);
|
---|
| 319 | $user = $this->get_data($src, $token, $us_id);
|
---|
| 320 | $input = $this->input->post();
|
---|
| 321 | if ($input) {
|
---|
| 322 | $input['username'] = $user['username'];
|
---|
[508] | 323 | if (array_key_exists('fullname', $input)) {
|
---|
| 324 | if (strlen($input['fullname']) == 0) {
|
---|
[636] | 325 | $result['errors']['fullname_err'] = lang('_SBG_FULLNAME_REQUIRED_MSG');
|
---|
[508] | 326 | }
|
---|
| 327 | } else {
|
---|
| 328 | $input['fullname'] = $user['fullname'];
|
---|
| 329 | }
|
---|
[604] | 330 |
|
---|
[503] | 331 | $input['password'] = '';
|
---|
| 332 | $input['oldpass'] = '';
|
---|
| 333 | $this->load->model('user_model');
|
---|
| 334 | if (!isset($result['errors'])) {
|
---|
| 335 | $result['data'] = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
| 336 | $result['success'] = 1;
|
---|
| 337 | }
|
---|
[490] | 338 | echo json_encode($result);
|
---|
[503] | 339 | }
|
---|
| 340 | } else {
|
---|
| 341 | redirect('frontend/home');
|
---|
[490] | 342 | }
|
---|
[508] | 343 | }
|
---|
| 344 |
|
---|
| 345 | public function change_password() {
|
---|
| 346 | $us_id = $this->uri->segment(4);
|
---|
| 347 | $user_info = $this->session->userdata('userInfo');
|
---|
| 348 | if ($user_info) {
|
---|
| 349 | $this->load->model('user_model');
|
---|
| 350 | $us_id = $user_info['us_id'];
|
---|
| 351 | $src = "SBG";
|
---|
| 352 | $token = md5($us_id . self::TOKENPW);
|
---|
| 353 | $input = $this->input->post();
|
---|
[554] | 354 |
|
---|
[508] | 355 | if (strlen($input['passwd']) == 0) {
|
---|
[636] | 356 | $result['errors']['passwd_old_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
[508] | 357 | }
|
---|
[602] | 358 |
|
---|
[508] | 359 | if (strlen($input['passwd_new']) == 0) {
|
---|
[636] | 360 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
[614] | 361 | } else if (strcmp($input['passwd'], $input['passwd_new']) == 0) {
|
---|
[636] | 362 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_DUPLICATE_MSG');
|
---|
[602] | 363 | }else
|
---|
| 364 | {
|
---|
| 365 | if (!preg_match('/^([0-9a-zA-Z]{6,65})*$/', $input['passwd_new']))
|
---|
| 366 | {
|
---|
[636] | 367 | $result['errors']['passwd_new_err'] = lang('_SBG_USER_PASSWORD_CHANGE_REQUIRED_MSG');
|
---|
[602] | 368 | }
|
---|
| 369 | }
|
---|
| 370 |
|
---|
[554] | 371 | if ($input['passwd_new'] != $input['confirm_passwd_new']) {
|
---|
[636] | 372 | $result['errors']['confirm_passwd_new_err'] = lang('_SBG_PASSWORD_CONFIRM_MSG');
|
---|
[508] | 373 | }
|
---|
[554] | 374 |
|
---|
[508] | 375 | if (!isset($result['errors'])) {
|
---|
| 376 | $user = array('username' => $user_info['username'], 'fullname' => null, 'gender' => null, 'email' => null, 'school' => null, 'province' => null, 'password' => $input['passwd_new'], 'oldpass' => $input['passwd']);
|
---|
| 377 | $data = $this->user_model->update_user($src, $token, $user, $us_id);
|
---|
| 378 | parse_str($data);
|
---|
[716] | 379 | error_log('API return ---- Data: '. var_export($data, TRUE). "\n", 3, '/srv/www/sbg/log/changepass.log');
|
---|
| 380 | switch ((int)$status) {
|
---|
[508] | 381 | case 0:
|
---|
| 382 | $result['success'] = 1;
|
---|
| 383 | break;
|
---|
| 384 | case 6:
|
---|
[636] | 385 | $result['errors']['passwd_old_err'] = lang('_SBG_OLD_PASSWORD_FAIL_MSG');
|
---|
[508] | 386 | break;
|
---|
| 387 | default:
|
---|
| 388 | break;
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | echo json_encode($result);
|
---|
| 393 | } else {
|
---|
| 394 | redirect('frontend/home');
|
---|
| 395 | }
|
---|
| 396 | }
|
---|
[574] | 397 |
|
---|
| 398 | public function trade_history()
|
---|
| 399 | {
|
---|
| 400 | $this->load->helper('pagging');
|
---|
| 401 | $us_id = $this->uri->segment(4);
|
---|
[698] | 402 |
|
---|
[574] | 403 | $user_info = $this->session->userdata('userInfo');
|
---|
[698] | 404 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 405 |
|
---|
| 406 | if ($user_info || $admin_info)
|
---|
[574] | 407 | {
|
---|
| 408 | $data['us_id'] = $us_id;
|
---|
| 409 | $data['perpage'] = 10;
|
---|
| 410 | $data['current_page'] = $this->uri->segment(6, 1);
|
---|
| 411 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
| 412 | $this->load->model('user_model');
|
---|
| 413 | $result = $this->user_model->getPaidlog($data);
|
---|
| 414 | $data['total'] = $this->user_model->countPaiglogs($us_id);
|
---|
| 415 | $data['num_links'] = 2;
|
---|
| 416 | $data['paging_url'] = base_url() . "frontend/user/trade_history/".$us_id."/page/";
|
---|
| 417 | $data['paging'] = pagging($data);
|
---|
| 418 | $paidlogs = array();
|
---|
| 419 | foreach ($result as $paidlog):
|
---|
| 420 | $paidlog['amount'] = number_format($paidlog['amount'], 0);
|
---|
[690] | 421 | $paidlog['paid_time'] = date('d/m/Y H:i:s', strtotime($paidlog['paid_time']));
|
---|
[574] | 422 | array_push($paidlogs, $paidlog);
|
---|
| 423 | endforeach;
|
---|
| 424 | $data['paidlogs'] = $paidlogs;
|
---|
| 425 | echo json_encode($data);
|
---|
| 426 | }else {
|
---|
| 427 | redirect('frontend/home');
|
---|
| 428 | }
|
---|
| 429 | }
|
---|
[730] | 430 | public function getUserInfor()
|
---|
[729] | 431 | {
|
---|
| 432 | $this->load->model('User_model');
|
---|
| 433 | $data=array();
|
---|
| 434 | $us_id = $this->uri->segment(4);
|
---|
| 435 | $src = "SBG";
|
---|
| 436 | $token = md5($us_id . self::TOKENPW);
|
---|
| 437 | $user = $this->User_model->get_user_info($src, $token, $us_id);
|
---|
| 438 | parse_str($user,$user);
|
---|
| 439 | $local=$this->User_model->get_user_by_id($us_id);
|
---|
| 440 | $data['user']= array_merge($user,$local);
|
---|
| 441 | $this->lang->load('messages', 'message');
|
---|
[771] | 442 | $admin=$this->session->userdata('adminInfo');
|
---|
| 443 | $roles=array();
|
---|
| 444 | foreach ($admin['roles'] as $role)
|
---|
| 445 | {
|
---|
| 446 | $roles[]=$role['role_name'];
|
---|
| 447 | }
|
---|
| 448 | $data['roles']=$roles;
|
---|
[729] | 449 | $data['provinces'] = lang('_PROVINCES_');
|
---|
[731] | 450 | $result['modal']=$this->load->view('frontend/user_infor', $data, TRUE);
|
---|
[729] | 451 | echo json_encode($result);
|
---|
| 452 |
|
---|
| 453 | }
|
---|
| 454 | public function adminUpdateUser()
|
---|
| 455 | {
|
---|
| 456 | $this->load->model('User_model');
|
---|
| 457 | $input=$input = $this->input->post();
|
---|
| 458 | $us_id=$input["us_id"];
|
---|
| 459 | $src = "SBG";
|
---|
| 460 | $token = md5($us_id . self::TOKENPW);
|
---|
| 461 | $api['fullname']=$input['fullname'];
|
---|
| 462 | $api['school']=$input['school'];
|
---|
| 463 | $local['district']=$input['district'];
|
---|
| 464 | $local['province']=$input['province'];
|
---|
| 465 | $update = $this->User_model->update_user($src, $token, $api, $us_id);
|
---|
| 466 | $this->User_model->update_local_user($local,$us_id);
|
---|
| 467 | $result['success']=1;
|
---|
| 468 | echo json_encode($result);
|
---|
| 469 | }
|
---|
[642] | 470 | public function regis_history()
|
---|
| 471 | {
|
---|
[883] | 472 | $this->load->model('servicepackage_model');
|
---|
[642] | 473 | $this->load->helper('pagging');
|
---|
| 474 | $us_id = $this->uri->segment(4);
|
---|
| 475 | $this->load->model('user_model');
|
---|
| 476 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
| 477 | $username = $user['cellphone'];
|
---|
| 478 | $user_info = $this->session->userdata('userInfo');
|
---|
[698] | 479 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 480 | if ($user_info || $admin_info)
|
---|
[642] | 481 | {
|
---|
[773] | 482 | $data['us_id'] = $us_id;
|
---|
[642] | 483 | $data['username'] = $username;
|
---|
[818] | 484 | $data['acc_balanced'] = number_format($user['acc_balanced']);
|
---|
[642] | 485 | $data['perpage'] = 10;
|
---|
| 486 | $data['current_page'] = $this->uri->segment(6, 1);
|
---|
| 487 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
| 488 | $this->load->model('user_model');
|
---|
| 489 | $result = $this->user_model->getPackagelog($data);
|
---|
[883] | 490 | $results = array();
|
---|
| 491 | foreach($result as $re){
|
---|
| 492 | if ($re['p_code']>0){
|
---|
| 493 | $p_price = $this->servicepackage_model->getPackagePriceByCode($re['p_code']);
|
---|
| 494 | $re['amount'] = -$p_price;
|
---|
| 495 | }
|
---|
| 496 | array_push($results, $re);
|
---|
| 497 | }
|
---|
| 498 | $data['total'] = $this->user_model->countPackagelogs($username, $us_id);
|
---|
[642] | 499 | $data['num_links'] = 2;
|
---|
| 500 | $data['paging_url'] = base_url() . "frontend/user/regis_history/".$us_id."/page/";
|
---|
| 501 | $data['paging'] = pagging($data);
|
---|
| 502 | $packagelogs = array();
|
---|
[883] | 503 | foreach ($results as $packagelog):
|
---|
[643] | 504 | $packagelog['created_time'] = date('d/m/Y H:i:s', strtotime($packagelog['created_time']));
|
---|
[642] | 505 | array_push($packagelogs, $packagelog);
|
---|
| 506 | endforeach;
|
---|
| 507 | $data['packagelogs'] = $packagelogs;
|
---|
| 508 | echo json_encode($data);
|
---|
| 509 | }else
|
---|
| 510 | {
|
---|
| 511 | redirect('frontend/home');
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | }
|
---|
[838] | 515 |
|
---|
| 516 | function getDistrict(){
|
---|
| 517 |
|
---|
| 518 | $user_info = $this->session->userdata('userInfo');
|
---|
[883] | 519 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 520 | if ($user_info || $admin_info) {
|
---|
[838] | 521 | $result = array();
|
---|
| 522 | $provinceId = $this->uri->segment(4);
|
---|
| 523 | $this->load->model ( 'user_model' );
|
---|
| 524 | if ($provinceId){
|
---|
| 525 | $results = $this->user_model->getDistrictByProvince($provinceId);
|
---|
| 526 | }
|
---|
| 527 | echo json_encode($results);
|
---|
| 528 | }else{
|
---|
| 529 | show_404();
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | }
|
---|
[508] | 533 |
|
---|
[554] | 534 | }
|
---|