hasOne(Anchor::class,'openid','openid')->select('name','openid','pic','mobile'); } public function anchorV2(){ return $this->hasOne(Anchor::class,'m_id','id')->select('id','m_id','name','openid','pic','mobile','channel'); } public function liveAnchor(){ return $this->hasOne(Anchor::class,'m_id','id'); } public function follow(){ return $this->hasOne(MerchantFollow::class,'merchant_id','id')->orderBy('id','desc'); } public function info(){ return $this->hasOne(MerchantInfo::class,'m_id','id'); } public static function get_token($token) { try { // $token = $request->bearerToken(); $result = decrypt($token); if(!$result) return false; $key = explode('-', $result); if(time()-$key[2]>604800) return false; if($key[0]){ $account_id = $key[0]; return $account_id; } } catch (\Exception $e) { return false; } } // 推广人数 public static function PromotionIncome($merchant_id) { // 用户人数 $ids = AccessRecord::where('account_id',$merchant_id)->pluck('open_id'); $sql = AccessRecord::orderBy('id','asc')->limit(1000); $result = AccessRecord::from(\DB::raw('('.$sql->toSql().') as a'))->wherein('open_id',$ids)->groupBy('open_id')->get(); $user = []; foreach ($result as $key => $value) { if($value->account_id==$merchant_id){ $user[$value['open_id']]=$value->created_at->toDateTimeString(); } } $user_key = array_keys($user); $viewer = Viewer::wherein('openid',$user_key)->get(); foreach ($viewer as $key => $value) { if (!isset($user[$value['openid']])) continue; if($value->created_at<$user[$value['openid']]){ unset( $user[$value['openid']]); } } return count($user); } }