Ejemplo n.º 1
0
 public function __construct(Request $request)
 {
     if (!$request->header('App-token')) {
         exit;
     }
     $this->user_id = TokenService::tokenDecrypt($request->header('App-token'));
 }
Ejemplo n.º 2
0
 public static function setUserByToken($token)
 {
     $user = TokenService::decode($token);
     self::setUserId(isset($user['user_id']) ? $user['user_id'] : null);
     self::setUserType(isset($user['type']) ? $user['type'] : null);
     self::setUserName(isset($user['user_name']) ? $user['user_name'] : null);
 }
Ejemplo n.º 3
0
 /**
  * 商户设置头像
  * @param $logo_image_path
  * @param $user_id
  * @return array
  */
 public function businessNewLogo($logo_image_path, $user_id)
 {
     if (empty($logo_image_path)) {
         return ['status' => false, 'message' => '您的头像不能为空!', 'info' => []];
     }
     $user_image = new UserImage();
     $rt = $user_image->where('user_id', $user_id)->Head()->first();
     if (!empty($rt)) {
         $bool = $user_image->where('user_id', $user_id)->Head()->update(['image_url' => $logo_image_path]);
     } else {
         $user_image->user_id = $user_id;
         $user_image->image_url = $logo_image_path;
         $user_image->type = UserImage::TYPE_HEAD;
         $user_image->is_completion = UserImage::IS_COMPLETION_QINIU;
         $bool = $user_image->save();
     }
     if ($bool) {
         $info['business_logo'] = UserImage::getQiniuImagePath($logo_image_path);
         $info['business_id'] = TokenService::tokenEncode($user_id);
         return ['status' => true, 'message' => 'success', 'info' => $info];
     } else {
         return ['status' => false, 'message' => '修改成功!', 'info' => []];
     }
 }
Ejemplo n.º 4
0
 /**
  * 第三方平台注册
  * @param $params
  * @return array
  */
 public function otherRegister($params)
 {
     if (!$params->get('open_id')) {
         return ['status' => false, 'message' => '用户唯一标识不能为空!'];
     }
     if (!$params->get('type')) {
         return ['status' => false, 'message' => '登入来源标识不能为空!'];
     }
     $user_third_parth = new UserThirdParty();
     $rt = $user_third_parth->where('user_other_id', $params->get('open_id'))->where('type', $params->get('type'))->first();
     $user_base = new UserBase();
     $user_image = new UserImage();
     //如果没注册过
     if (empty($rt) && in_array($params->get('type'), [UserThirdParty::TX_QQ, UserThirdParty::WEI_XIN])) {
         $user_base->invite_code = time() . mt_rand(100, 999);
         if ($params->get('nick_name')) {
             $user_base->user_name = $params->get('nick_name');
         }
         $user_base->save();
         if ($user_base->user_id) {
             $user_third_parth->user_other_id = $params->get('open_id');
             $user_third_parth->type = $params->get('type');
             $user_third_parth->user_id = $user_base->user_id;
             $user_third_parth->save();
             $image = $user_image->where('user_id', $user_base->user_id)->head()->first();
             if (empty($image)) {
                 $user_image->image_url = $params->get('head_img') ?: UserImage::defaultImage();
                 $user_image->user_id = $user_base->user_id;
                 $user_image->is_completion = UserImage::IS_COMPLETION_TRUE;
                 $user_image->type = UserImage::TYPE_HEAD;
                 $user_image->save();
             } else {
                 $user_image->where('user_id', $user_base->user_id)->where('type', UserImage::TYPE_HEAD)->update(['image_url' => $params->get('head_img') ?: UserImage::defaultImage()]);
             }
             if (UserFinancial::getInitialize() > 0) {
                 $user_financial = new UserFinancial();
                 $user_financial->user_id = $user_base->user_id;
                 $user_financial->water_count = UserFinancial::getInitialize();
                 $user_financial->save();
             }
         } else {
             return ['status' => false, 'message' => '系统一个人去旅行了,请稍后重试!'];
         }
         $user = $user_base->where('user_id', $user_base->user_id)->IsOpen()->first()->toArray();
         if ($params->get('head_img')) {
             $user['user_head'] = $params->get('head_img');
         } else {
             $user['user_head'] = UserImage::defaultImage();
         }
         $user['token'] = TokenService::tokenEncode($user_base->user_id);
         UserLoginLog::insert_login_log($user_base->user_id);
         return $this->outputFormat(true, 'success', $this->formatUser($user));
     }
     //如果已经注册过
     $user = $user_base->where('user_id', $rt->user_id)->IsOpen()->first()->toArray();
     $image = $user_image->where('user_id', $rt->user_id)->head()->first();
     if ($image) {
         $user['user_head'] = $image->path();
     } else {
         $user['user_head'] = UserImage::defaultImage();
     }
     $user['token'] = TokenService::tokenEncode($rt->user_id);
     UserLoginLog::insert_login_log($rt->user_id);
     return $this->outputFormat(true, 'success', $this->formatUser($user));
 }