Exemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     $this->factory = Factory::find($this->user->getKey());
     if (empty($this->factory)) {
         return $this->error('factory.failure_noexists');
     }
     $this->viewData['_factory'] = $this->factory;
 }
Exemplo n.º 2
0
 public function doAudit()
 {
     if ($this->audited) {
         return false;
     }
     $factory = Factory::find($this->fid);
     if (empty($factory)) {
         return false;
     }
     $user = (new User())->get($this->username) ?: (new User())->add(['username' => $this->username, 'password' => substr($this->idcard, -6), 'realname' => $this->realname, 'idcard' => $this->idcard, 'phone' => $this->username], Role::AGENT);
     $agent = Agent::find($user->getKey()) ?: Agent::create(['id' => $user->getKey(), 'name' => $this->name, 'phone' => $this->phone, 'address' => $this->address]);
     $user->roles()->sync([Role::where('name', Role::AGENT)->firstOrFail()->getKey()], false);
     $factory->agents()->sync([$agent->getKey()], false);
     $agent->brands()->sync($this->brand_ids, false);
     $this->audited = true;
     $this->save();
     return true;
 }
Exemplo n.º 3
0
 public function destroy(Request $request, $id)
 {
     empty($id) && !empty($request->input('id')) && ($id = $request->input('id'));
     $id = (array) $id;
     foreach ($id as $v) {
         $factory = Factory::destroy($v);
     }
     return $this->success('', count($id) > 5, compact('id'));
 }
Exemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     $this->agent_ids = Factory::find($this->factory->getKey())->agent_ids()->toArray();
 }