public function inviteStat() { if (!$this->isAcceptedJson()) { return \View::make('man::reporter.invite'); } $list = CustomerInviteExternal::with('registered.customer')->with('owner')->orderBy('id', 'desc')->get()->all(); foreach ($list as $item) { $item->registered && $item->registered->customer && $item->registered->customer->initExistsPaid(); } return $list; }
/** * временная запись инвайта для внешнего id клиента * * @param string $phone внешний id клиента * * @return null|\Symfony\Component\HttpFoundation\Cookie */ public function registerInviteExternal($phone) { $code = Cookie::get('dh_invite'); $phone = Customer::instance()->phone($phone); if (!$code) { return null; } $cookie = Cookie::forget('dh_invite'); $owner = $this->findByCode($code); if (!$owner) { return $cookie; } // нельзя приглашать самого себя if ($owner->phone == $phone) { return $cookie; } Reporter::inviteCodeFoundExternal($phone, $owner->id, $code); $invite = CustomerInviteExternal::create(['phone' => $phone, 'owner_id' => $owner->id, 'source_id' => self::C_LINK]); Reporter::inviteCodeRegisteredExternal($phone, $owner->id, $invite->id, $code); return $cookie; }