public function __construct($data = array()) { parent::__construct($data); $this->setPropertiesDefine(array('parent_id' => array('alias' => '上级部门', 'options' => function () { $data = Department::find()->field('id', 'parent_id', 'name')->all(true); $tmp = array_combine(array_column($data, 'id'), array_column($data, 'name')); array_unshift_assoc($tmp, 0, '顶级'); return $tmp; }, 'form' => function ($val = null, self $instance = null) { $data = Department::find()->field('id', 'parent_id', 'name')->all(true); return ViewBase::generateParentTreeSelector($data, $instance); }), 'manager_id' => array('alias' => '负责人', 'options' => function () { $data = User::find('state=?', User::STATE_ENABLED)->field('id', 'name')->all(true); return array_combine(array_column($data, 'id'), array_column($data, 'name')); }, 'display' => function (self $item) { $tmp = User::findOneByPk($item->manager_id); if (!$tmp) { return ''; } return $tmp->state == User::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>'; }), 'stage_id' => array('options' => function () { return WorkStage::$work_stage_list; }), 'stage_name' => array('getter' => function ($item) { if ($item->stage_id) { return WorkStage::$work_stage_list[$item->stage_id]; } return ''; }, 'alias' => '负责流程'))); }
public function __construct($data = array()) { parent::__construct($data); //extra properties define $this->setPropertiesDefine(array('customer_no' => array('description' => '规则:xxx-xx-33'), 'create_time' => array('setter' => function () { return time(); }), 'op_user_id' => array('setter' => function () { return Auth::instance()->getLoginUserId(); }, 'options' => function () { $tmp = User::find()->all(true); return array_combine(array_column($tmp, 'id'), array_column($tmp, 'name')); }), 'source' => array('options' => function () { $tmp = CustomerSource::find('state = ?', CustomerSource::STATE_ENABLED)->all(true); return array_combine(array_column($tmp, 'id'), array_column($tmp, 'name')); }, 'display' => function (self $item) { $tmp = CustomerSource::findOneByPk($item->source); if (!$tmp) { return ''; } return $tmp->state == CustomerSource::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>'; }), 'type' => array('options' => function () { $tmp = CustomerType::find('state = ?', CustomerType::STATE_ENABLED)->all(true); return array_combine(array_column($tmp, 'id'), array_column($tmp, 'name')); }, 'display' => function (self $item) { $tmp = CustomerType::findOneByPk($item->type); if (!$tmp) { return ''; } return $tmp->state == CustomerType::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>'; }))); }
public function login($get, $post) { $access = Auth::instance(); $use_captcha = Config::get('app/login/use_captcha'); session_start(); $REF_SS_KEY = 'LOGIN_REF_SS_KEY'; $ref = $_SESSION[$REF_SS_KEY]; if (!$ref) { $ref = $_SERVER['HTTP_REFERER']; $c = Router::getUrl('index/login'); $tmp = parse_url($ref); if (stripos($ref, $c) !== false || stripos($_SERVER['HTTP_HOST'], $tmp['host']) === false) { $ref = Router::getUrl(); } $_SESSION[$REF_SS_KEY] = $ref; } if ($access->isLogin()) { Router::jumpTo($ref); } if ($post) { if ($use_captcha) { if (empty($post['captcha'])) { return new Result('请输入验证码', false, 'captcha'); } if (strtolower($post['captcha']) != strtolower(Auth::getCaptcha())) { Auth::setCaptcha(''); return new Result('您输入的验证码不正确,请重新输入', false, 'captcha'); } Auth::setCaptcha(''); } if (!User::find('name=?', $post['name'])->count()) { return new Result('当前用户名未登记'); } $user_info = User::validatePsw($post['name'], $post['password']); if ($user_info) { if ($user_info['state'] != User::STATE_ENABLED) { return new Result('当前账号已禁用'); } if ($post['auto_login']) { $access->setCookieExpired(Config::get('app/login/expired')); } else { $access->setCookieExpired(0); } Auth::instance()->login($user_info); unset($_SESSION[$REF_SS_KEY]); return new Result('登录成功', true, null, $ref); } return new Result('用户名或密码错误'); } return array('use_captcha' => $use_captcha); }
public function updatePassword($get, $post) { $id = $get['id']; $user = User::findOneByPk($id); if ($post) { if (!$post['password']) { return new Result('请输入密码'); } if ($post['password'] != $post['repeat_password']) { return new Result('两次输入的密码不一致,请重新输入'); } $user->password = md5($post['password']); $user->save(); return new Result('密码修改成功', true); } return array('data' => $user); }
/** * 从用户ID中获取用户信息 * @param $user_id * @return array | null */ public function getUserInfoFromId($user_id) { return User::findOneByPk($user_id, true); }
/** * 校验用户名密码 * @param $name * @param $password * @return array */ public static function validatePsw($name, $password) { return User::find('name=? AND password=?', $name, md5($password))->one(true); }