20], [['phone'], 'unique'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'uid' => 'Uid', 'phone' => 'Phone', 'status' => 'Status', 'reg_time' => 'Reg Time', 'last_login' => 'Last Login', ]; } /** * Des:根据手机号获取用户ID 没有则注册一个 * Name: getUidByPhone * @param $phone * @return int|mixed * @author 倪宗锋 */ public function getUidByPhone($phone) { $info = $this->getUserInfoByPhone($phone); if (empty($info['uid'])) { $this->addUser(['phone' => $phone]); $info = $this->getUserInfoByPhone($phone); } if (empty($info['uid'])) { return 0; } return $info['uid']; } /** * Des:根据手机号获取用户的信息 * Name: getUserInfoByPhone * @param $phone * @return array * @author 倪宗锋 */ public function getUserInfoByPhone($phone) { $info = self::find() ->where(['=', 'phone', $phone]) ->asArray() ->one(); if (empty($info['uid'])) { return []; } return $info; } /** * Des: 添加用户 * Name: addUser * @param $param * @return bool * @author 倪宗锋 */ public function addUser($param) { $this->setAttributes($param); $return = $this->insert(true); return $return; } }