123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * 手机端令牌模型
- *
- *
- *
- *
- */
- defined('InShopNC') or exit('Access Invalid!');
- class mb_user_tokenModel extends Model
- {
- public function __construct()
- {
- parent::__construct('mb_user_token');
- }
- /**
- * 查询
- *
- * @param array $condition 查询条件
- * @return array
- */
- public function getMbUserTokenInfo($condition)
- {
- return $this->where($condition)->find();
- }
- public function getMbUserTokenInfoByToken($token)
- {
- if (empty($token)) {
- return null;
- }
- return $this->getMbUserTokenInfo(array('token' => $token));
- }
- /**
- * 新增
- *
- * @param array $param 参数内容
- * @return bool 布尔类型的返回结果
- */
- public function addMbUserToken($param)
- {
- return $this->insert($param);
- }
- /**
- * 生成token
- *
- * @param array $param 参数内容
- * @return bool 布尔类型的返回结果
- */
- public function gen_token($member_id, $member_name, $client)
- {
- //生成新的token
- $mb_user_token_info = array();
- $token = md5($member_name . strval(time()) . strval(rand(0, 999999)));
- $mb_user_token_info['member_id'] = $member_id;
- $mb_user_token_info['member_name'] = $member_name;
- $mb_user_token_info['token'] = $token;
- $mb_user_token_info['login_time'] = time();
- $mb_user_token_info['client_type'] = $client;
- $condition['member_id'] = $member_id;
- $result = $this->where($condition)->select();
- foreach($result as $value){
- $key = func::gen_token_key($value['token']);
- dcache($key);
- }
- $this->where($condition)->delete();
- $ret = $this->addMbUserToken($mb_user_token_info);
- if ($ret) {
- $key = func::gen_token_key($token);
- wcache($key, array('info' => serialize($mb_user_token_info)),'',func::token_expire);
- return $token;
- } else {
- return null;
- }
- }
- /**
- * 删除token
- *
- * @param $token
- * @return mixed
- */
- public function del_token($token){
- $key = func::gen_token_key($token);
- dcache($key);
- return $this->where(array('token'=>$token))->delete();
- }
- /**
- * 删除
- *
- * @param int $condition 条件
- * @return bool 布尔类型的返回结果
- */
- public function delMbUserToken($condition)
- {
- return $this->where($condition)->delete();
- }
- }
|