function test_action_update() { $mobile = "18601628937"; $stf_id = \Model_Admin_Staff::get_staff_id_by_mobile($mobile); $auth_user_info = \Model_Admin_Staff::get_auth_user_by_stf_id($stf_id); var_export($auth_user_info); $staff_info = $this->obj->get_detail($stf_id); var_export($staff_info); $row = json_encode(array("stf_name" => "王八", "mobile" => $mobile, "password" => "")); $res = $this->obj->action_update($stf_id, $row); var_export($res); }
static function check_login($username, $password) { $res = false; if (Utils::is_mobile($username)) { $stf_id = Model_Admin_Staff::get_staff_id_by_mobile($username); if (!$stf_id) { _throw("员工不存在"); } self::_debug(array(__METHOD__, $stf_id)); $user = Model_Admin_Staff::get_auth_user_by_stf_id($stf_id); self::_debug(array("auth user", $stf_id, $user)); if (!$user) { _throw("员工未授权"); } $_password = $user['password']; $salt = $user['salt']; if ($_password !== self::gen_password($password, $salt)) { _throw("密码不正确"); } $res = true; } return $res; }
function action_update($id, $row) { $table = self::table(); $res = self::getSaveRow($row, false); $password = null; if (!empty($res['row']['mobile'])) { $mobile = $res['row']['mobile']; $staff = self::_db()->row("select mobile from {$table} where stf_id <> ? and mobile = ?", $id, $mobile); if ($staff) { _throw("手机号已存在"); } } if (!empty($res['row']['password'])) { $password = $res['row']['password']; } unset($res['row']['password']); self::_db()->update($table, $res['row'], array("stf_id" => $id)); $auth_user = \Model_Admin_Staff::get_auth_user_by_stf_id($id); if ($password) { //修改密码 if ($auth_user) { $salt = $auth_user['salt']; } else { $salt = \Model_Admin_Auth::gen_salt(); } //生成密码 $password = \Model_Admin_Auth::gen_password($password, $salt); if ($auth_user) { $user_row = array("password" => $password); self::_db()->update(self::_table("user"), $user_row, array("user_id" => $auth_user['user_id'])); } else { $table_user = self::_table("user"); $user_mobile = self::_db()->row("select user_id from {$table_user} where mobile = ?", $res['row']['mobile']); if (!$user_mobile) { $user_row = array("password" => $password, "salt" => $salt, "mobile" => $res['row']['mobile'], "add_time" => Utils::date_time_now()); $user_id = self::_db()->insert($table_user, $user_row); } else { $user_id = $table_user['user_id']; } self::_db()->insert(self::_table("staff_user"), array("stf_id" => $id, "user_id" => $user_id)); } } //修改登陆手机号 if ($auth_user && !empty($res['row']['mobile'])) { $mobile = $res['row']['mobile']; self::_db()->update(self::_table("user"), array("mobile" => $mobile), array("user_id" => $auth_user['user_id'])); } return array("stf_id" => $id, "row" => self::get_detail($id)); }