Browse Source

supplier_id -> merchant_id && type

master
李可松 4 years ago
parent
commit
72e0492a23
  1. 15
      MySQL_change.sql
  2. 15
      app/AdminSupplier/Controllers/DiyFormController.php
  3. 2
      app/AdminSupplier/Controllers/IndustryProductController.php
  4. 2
      app/AdminSupplier/Controllers/ProductController.php
  5. 3
      resources/lang/zh_CN/diy-form.php

15
MySQL_change.sql

@ -405,3 +405,18 @@ ALTER TABLE `collect_products`
ALTER ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_agent_products` AS select `agent_products`.`id` AS `id`,`agent_products`.`agent_id` AS `agent_id`,`agent_products`.`product_id` AS `product_id`,`agent_products`.`product_ids` AS `product_ids`,`agent_products`.`price` AS `price`,`agent_products`.`original_price` AS `original_price`,`agent_products`.`sale` AS `sale`,`agent_products`.`stock` AS `stock`,`agent_products`.`channel_id` AS `channel_id`,`agent_products`.`category_id` AS `category_id`,`agent_products`.`guide_id` AS `guide_id`,`agent_products`.`guide_price` AS `guide_price`,`agent_products`.`status` AS `status`,`agent_products`.`verifier` AS `verifier`,`agent_products`.`is_rec` AS `is_rec`,`agent_products`.`type` AS `type`,`agent_products`.`title` AS `title`,`agent_products`.`pictures` AS `pictures`,`agent_products`.`know` AS `know`,`agent_products`.`content` AS `content`,`agent_products`.`deposit` AS `deposit`,`agent_products`.`deposit_timeout` AS `deposit_timeout`,`agent_products`.`earnest` AS `earnest`,`agent_products`.`earnest_timeout` AS `earnest_timeout`,`agent_products`.`is_cloud` AS `is_cloud`,`agent_products`.`agent_cloud_pid` AS `agent_cloud_pid`,`agent_products`.`created_at` AS `created_at`,`agent_products`.`updated_at` AS `updated_at`,`agent_products`.`deleted_at` AS `deleted_at`,`products`.`latitude` AS `latitude`,`products`.`longitude` AS `longitude`,`products`.`address` AS `address` from (`agent_products` join `products` on((`agent_products`.`product_id` = `products`.`id`))) ; ALTER ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_agent_products` AS select `agent_products`.`id` AS `id`,`agent_products`.`agent_id` AS `agent_id`,`agent_products`.`product_id` AS `product_id`,`agent_products`.`product_ids` AS `product_ids`,`agent_products`.`price` AS `price`,`agent_products`.`original_price` AS `original_price`,`agent_products`.`sale` AS `sale`,`agent_products`.`stock` AS `stock`,`agent_products`.`channel_id` AS `channel_id`,`agent_products`.`category_id` AS `category_id`,`agent_products`.`guide_id` AS `guide_id`,`agent_products`.`guide_price` AS `guide_price`,`agent_products`.`status` AS `status`,`agent_products`.`verifier` AS `verifier`,`agent_products`.`is_rec` AS `is_rec`,`agent_products`.`type` AS `type`,`agent_products`.`title` AS `title`,`agent_products`.`pictures` AS `pictures`,`agent_products`.`know` AS `know`,`agent_products`.`content` AS `content`,`agent_products`.`deposit` AS `deposit`,`agent_products`.`deposit_timeout` AS `deposit_timeout`,`agent_products`.`earnest` AS `earnest`,`agent_products`.`earnest_timeout` AS `earnest_timeout`,`agent_products`.`is_cloud` AS `is_cloud`,`agent_products`.`agent_cloud_pid` AS `agent_cloud_pid`,`agent_products`.`created_at` AS `created_at`,`agent_products`.`updated_at` AS `updated_at`,`agent_products`.`deleted_at` AS `deleted_at`,`products`.`latitude` AS `latitude`,`products`.`longitude` AS `longitude`,`products`.`address` AS `address` from (`agent_products` join `products` on((`agent_products`.`product_id` = `products`.`id`))) ;
# 14:45 ‎2021/‎10/‎29
ALTER TABLE `diy_forms`
CHANGE COLUMN `supplier_id` `merchant_id` INT(10) NOT NULL COMMENT '供应商ID或代理ID' AFTER `id`,
ADD COLUMN `type` TINYINT NOT NULL DEFAULT 1 COMMENT '1供应商,2代理商' AFTER `merchant_id`,
DROP INDEX `supplier_id`,
ADD INDEX `merchant_id_type` (`merchant_id`, `type`);
UPDATE `hainan`.`diy_forms` SET `type`=1;

15
app/AdminSupplier/Controllers/DiyFormController.php

@ -23,7 +23,7 @@ class DiyFormController extends AdminController
return Grid::make(new DiyForm(['fields']), function (Grid $grid) { return Grid::make(new DiyForm(['fields']), function (Grid $grid) {
$grid->disableViewButton(); $grid->disableViewButton();
$grid->model()->where('supplier_id', Admin::user()->id)->orderBy('id', 'desc');
$grid->model()->where(['merchant_id' => Admin::user()->id, 'type' => 1])->orderBy('id', 'desc');
$grid->column('id')->sortable(); $grid->column('id')->sortable();
$grid->column('name'); $grid->column('name');
@ -62,7 +62,7 @@ class DiyFormController extends AdminController
{ {
return Show::make($id, new DiyForm(['fields']), function (Show $show) { return Show::make($id, new DiyForm(['fields']), function (Show $show) {
//不允许查看非自己的数据 //不允许查看非自己的数据
if ($show->model()->supplier_id != Admin::user()->id) {
if ($show->model()->merchant_id != Admin::user()->id || $show->model()->type != 1) {
Admin::exit('数据不存在'); Admin::exit('数据不存在');
} }
@ -86,7 +86,7 @@ class DiyFormController extends AdminController
$form->disableViewButton(); $form->disableViewButton();
//不允许编辑非自己数据 //不允许编辑非自己数据
if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) {
if ($form->isEditing() && ($form->model()->merchant_id != Admin::user()->id || $form->model()->type != 1)) {
return $form->response()->error('数据不存在'); return $form->response()->error('数据不存在');
} }
@ -107,7 +107,7 @@ class DiyFormController extends AdminController
}); });
})->saving(function (Form $form) { })->saving(function (Form $form) {
//不允许编辑非自己数据 //不允许编辑非自己数据
if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) {
if ($form->isEditing() && ($form->model()->merchant_id != Admin::user()->id || $form->model()->type != 1)) {
return $form->response()->error('数据不存在'); return $form->response()->error('数据不存在');
} }
@ -115,11 +115,12 @@ class DiyFormController extends AdminController
return $form->response()->error('字段为空,请先新增字段'); return $form->response()->error('字段为空,请先新增字段');
} }
$form->hidden(['supplier_id']);
$form->supplier_id = Admin::user()->id;
$form->hidden(['merchant_id']);
$form->merchant_id = Admin::user()->id;
$form->type = 1;
})->deleting(function (Form $form) { })->deleting(function (Form $form) {
//不允许删除非自己的数据 //不允许删除非自己的数据
if (array_filter($form->model()->toArray(), fn($v) => $v['supplier_id'] != Admin::user()->id)) {
if (array_filter($form->model()->toArray(), fn($v) => $v['merchant_id'] != Admin::user()->id)) {
return $form->response()->error('数据不存在'); return $form->response()->error('数据不存在');
} }
}); });

2
app/AdminSupplier/Controllers/IndustryProductController.php

@ -116,7 +116,7 @@ class IndustryProductController extends AdminController
$options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); $options = Category::selectOptions(fn($query) => $query->where('agent_id', 0));
$form->select('category_id')->options(array_slice($options, 1, null, true))->required(); $form->select('category_id')->options(array_slice($options, 1, null, true))->required();
//信息收集表单 //信息收集表单
$options = DiyForm::where('supplier_id', Admin::user()->id)->pluck('name', 'id');
$options = DiyForm::where(['merchant_id' => Admin::user()->id, 'type' => 1])->pluck('name', 'id');
if ($options->isEmpty()) { if ($options->isEmpty()) {
$form->select('diy_form_id', '信息收集表单') $form->select('diy_form_id', '信息收集表单')
->help('提示:信息收集表单为空,请前往“<a href="' . admin_url('diy_form') . '">信息收集表单</a>”处新增') ->help('提示:信息收集表单为空,请前往“<a href="' . admin_url('diy_form') . '">信息收集表单</a>”处新增')

2
app/AdminSupplier/Controllers/ProductController.php

@ -150,7 +150,7 @@ class ProductController extends AdminController
$form->select('category_id')->options(array_slice($options, 1, null, true))->required(); $form->select('category_id')->options(array_slice($options, 1, null, true))->required();
//信息收集表单 //信息收集表单
$options = DiyForm::where('supplier_id', Admin::user()->id)->pluck('name', 'id');
$options = DiyForm::where(['merchant_id' => Admin::user()->id, 'type' => 1])->pluck('name', 'id');
if ($options->isEmpty()) { if ($options->isEmpty()) {
$form->select('diy_form_id', '信息收集表单') $form->select('diy_form_id', '信息收集表单')
->help('提示:信息收集表单为空,请前往“<a href="' . admin_url('diy_form') . '">信息收集表单</a>”处新增') ->help('提示:信息收集表单为空,请前往“<a href="' . admin_url('diy_form') . '">信息收集表单</a>”处新增')

3
resources/lang/zh_CN/diy-form.php

@ -6,7 +6,8 @@ return [
'diy_form' => '信息收集表单', 'diy_form' => '信息收集表单',
], ],
'fields' => [ 'fields' => [
'supplier_id' => '供应商ID',
'merchant_id' => '商家ID',
'type' => '商家类型',
'name' => '表单名', 'name' => '表单名',
'fields' => '字段列表', 'fields' => '字段列表',
], ],

Loading…
Cancel
Save