|
@@ -0,0 +1,171 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Admin\Controllers;
|
|
|
+
|
|
|
+use App\Admin\Actions\Grid\AppearanceImport;
|
|
|
+use App\Admin\Actions\Grid\ProductAudit;
|
|
|
+use App\Admin\Repositories\DistAdminDistributor;
|
|
|
+use App\Admin\Repositories\DistAppearance;
|
|
|
+use App\Admin\Repositories\DistProduct;
|
|
|
+use App\Admin\Repositories\DistProductCategory;
|
|
|
+use App\Libraries\CommonHelper;
|
|
|
+use Dcat\Admin\Admin;
|
|
|
+use Dcat\Admin\Form;
|
|
|
+use Dcat\Admin\Grid;
|
|
|
+use Dcat\Admin\Http\Controllers\AdminController;
|
|
|
+use Dcat\Admin\Layout\Content;
|
|
|
+use Dcat\Admin\Show;
|
|
|
+
|
|
|
+class DistProductAuditController extends AdminController
|
|
|
+{
|
|
|
+
|
|
|
+ protected function title()
|
|
|
+ {
|
|
|
+ return admin_trans('admin.product');
|
|
|
+ }
|
|
|
+
|
|
|
+ * page index
|
|
|
+ */
|
|
|
+ public function index(Content $content)
|
|
|
+ {
|
|
|
+ return $content
|
|
|
+ ->header(admin_trans( 'admin.products_list'))
|
|
|
+ ->description(admin_trans('admin.all'))
|
|
|
+ ->description('')
|
|
|
+
|
|
|
+ ->body($this->grid());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * Make a grid builder.
|
|
|
+ *
|
|
|
+ * @return Grid
|
|
|
+ */
|
|
|
+ protected function grid()
|
|
|
+ {
|
|
|
+ return Grid::make(DistProduct::with(['distProductCategory','images']), function (Grid $grid) {
|
|
|
+
|
|
|
+ $grid->paginate(config('admin.per_page'));
|
|
|
+
|
|
|
+ $grid->column('id')->display(function () {
|
|
|
+ return $this->_index+1;
|
|
|
+ });
|
|
|
+ $grid->column('title');
|
|
|
+ $grid->column('sku');
|
|
|
+ $grid->column('dist_product_category.name',admin_trans_label('category_name'));
|
|
|
+ $grid->column('images')->display(function ($images) {
|
|
|
+ $images = $images->toArray();
|
|
|
+ $dataImages = array_column($images, 'image_url');
|
|
|
+
|
|
|
+ $dataImages = array_slice($dataImages, 0, 1);
|
|
|
+ return CommonHelper::displayImage($dataImages,100);
|
|
|
+ });
|
|
|
+
|
|
|
+ $grid->column('dist_id',admin_trans_label('distributor_name')) ->display(function () {
|
|
|
+ return DistAdminDistributor::getClientCodeById($this->dist_id);
|
|
|
+ });
|
|
|
+
|
|
|
+ $grid->column('status')->using(admin_trans_array(config('dictionary.dist_product_status')))->label([
|
|
|
+ -1 => 'danger',
|
|
|
+ 0 => 'gray',
|
|
|
+ 1 => 'orange1',
|
|
|
+ 2 => 'success',
|
|
|
+ ])->display(function($status) {
|
|
|
+ if ($this->status == -1) {
|
|
|
+ return '<span class="status-popover" data-container="body" data-toggle="popover" data-placement="top" data-content="'.$this->review_reply.'">'.$status.'</span>';
|
|
|
+ }
|
|
|
+ return $status;
|
|
|
+ });
|
|
|
+ $grid->column('created_at')->sortable();
|
|
|
+
|
|
|
+
|
|
|
+ $grid->filter(function (Grid\Filter $filter) {
|
|
|
+ $filter->panel();
|
|
|
+ $filter->expand();
|
|
|
+ $filter->like('title')->width(2);
|
|
|
+ $filter->equal('sku')->width(2);
|
|
|
+ $filter->equal('status')->select(admin_trans_array(config('dictionary.dist_product_status')))->width(2);
|
|
|
+ $filter->equal('dist_id',admin_trans_label('distributor_name'))->select(DistAdminDistributor::selectOptionsNew(300))->width(3);
|
|
|
+ });
|
|
|
+
|
|
|
+ $grid->model()->orderBy('created_at', 'desc')->orderBy('id', 'desc');
|
|
|
+
|
|
|
+ $grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
|
+ if ($this->status == 1) {
|
|
|
+ $actions->append(new ProductAudit());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $grid->disableDeleteButton();
|
|
|
+ $grid->disableEditButton();
|
|
|
+ $grid->disableBatchDelete();
|
|
|
+ $this->addGridJS();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * Make a show builder.
|
|
|
+ *
|
|
|
+ * @param mixed $id
|
|
|
+ *
|
|
|
+ * @return Show
|
|
|
+ */
|
|
|
+ protected function detail($id)
|
|
|
+ {
|
|
|
+
|
|
|
+ return Show::make($id, DistProduct::with(['distProductCategory','images']), function (Show $show) {
|
|
|
+ $show->field('title');
|
|
|
+ $show->field('sku');
|
|
|
+ $show->field('dist_product_category.name',admin_trans_label('category_name'));
|
|
|
+ $show->field('keywords');
|
|
|
+ $show->field('description');
|
|
|
+ $show->field('issuance_date');
|
|
|
+ $show->field('parameters',admin_trans_label('attribute_name'))->as(function ($items) {
|
|
|
+ if (is_array($items)) {
|
|
|
+
|
|
|
+ $table = '<table class="table table-bordered table-condensed">';
|
|
|
+
|
|
|
+ foreach ($items as $item) {
|
|
|
+ $table .= '<tr>';
|
|
|
+ $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>';
|
|
|
+ $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>';
|
|
|
+ $table .= '</tr>';
|
|
|
+ }
|
|
|
+ $table .= '</table>';
|
|
|
+ return $table;
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+ })->unescape();
|
|
|
+ $show->field('images')->as(function ($images) {
|
|
|
+
|
|
|
+ $dataImages = array_column($images, 'image_url');
|
|
|
+ return CommonHelper::displayImage($dataImages,150);
|
|
|
+ })->unescape();
|
|
|
+ $show->field('content')->unescape();
|
|
|
+ $show->field('seo_title');
|
|
|
+ $show->field('seo_keywords');
|
|
|
+ $show->field('seo_description');
|
|
|
+ $show->field('order');
|
|
|
+ $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled')));
|
|
|
+ $show->field('created_at');
|
|
|
+ $show->field('updated_at');
|
|
|
+ $show->disableEditButton();
|
|
|
+ $show->disableDeleteButton();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private function addGridJS()
|
|
|
+ {
|
|
|
+ Admin::script(
|
|
|
+ <<<JS
|
|
|
+ $('.status-popover').popover({
|
|
|
+ container: 'body',
|
|
|
+ trigger: 'hover'
|
|
|
+ })
|
|
|
+JS
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|