123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- namespace App\Distributor\controllers;
- use Dcat\Admin\Layout\Content;
- use Illuminate\Routing\Controller;
- class AdminDistController extends Controller
- {
-
- protected $title;
-
- protected $description = [
-
-
-
-
- ];
-
- protected $translation;
-
- protected function title()
- {
- return $this->title ?: admin_trans_label();
- }
-
- protected function description()
- {
- return $this->description;
- }
-
- protected function translation()
- {
- return $this->translation;
- }
-
- public function index(Content $content)
- {
- return $content
- ->translation($this->translation())
- ->title($this->title())
- ->description($this->description()['index'] ?? trans('admin.list'))
- ->body($this->grid());
- }
-
- public function show($id, Content $content)
- {
- if ($this->distFindCountByID($id) === 0) {
- abort(404);
- }
- return $content
- ->translation($this->translation())
- ->title($this->title())
- ->description($this->description()['show'] ?? trans('admin.show'))
- ->body($this->detail($id));
- }
-
- public function edit($id, Content $content)
- {
- if ($this->distFindCountByID($id) === 0) {
- abort(404);
- }
- return $content
- ->translation($this->translation())
- ->title($this->title())
- ->description($this->description()['edit'] ?? trans('admin.edit'))
- ->body($this->form()->edit($id));
- }
-
- public function create(Content $content)
- {
- return $content
- ->translation($this->translation())
- ->title($this->title())
- ->description($this->description()['create'] ?? trans('admin.create'))
- ->body($this->form());
- }
-
- public function update($id)
- {
- if ($this->distFindCountByID($id) === 0) {
- abort(404);
- }
- return $this->form()->update($id);
- }
-
- public function store()
- {
- return $this->form()->store();
- }
-
- public function destroy($id)
- {
- if ($this->distFindCountByID($id) === 0) {
- abort(404);
- }
- return $this->form()->destroy($id);
- }
-
- protected function distFindCountByID($id)
- {
-
- if (method_exists($this, 'Form')) {
- $idArray = explode(',', $id);
-
- $idArray = array_map('intval', $idArray);
- $form = $this->Form();
- $repository = $form->repository();
- $count = $repository->model()->where('dist_id', getDistributorId())->wherein('id', $idArray)->count();
- if ($count === 0) {
-
- return 0;
- } else if ($count !== count($idArray)) {
-
- return 0;
- } else {
-
- return 1;
- }
- }
-
- return -1;
- }
- }
|