Browse Source

规格同步

master
李可松 4 years ago
parent
commit
fffe4e7508
  1. 10
      MySQL_change.sql
  2. 30
      app/AdminSupplier/Controllers/ProductController.php

10
MySQL_change.sql

@ -319,3 +319,13 @@ ALTER TABLE `products`
# 10:43 ‎2021/‎10/‎18
ALTER TABLE `industry_orders`
CHANGE COLUMN `trade_deposit` `trade_deposit` DECIMAL(20,2) NOT NULL DEFAULT '0.00' COMMENT '需要扣除的交易金' AFTER `prepay_timeout`;
# 15:15 ‎2021/‎10/‎18
ALTER TABLE `agent_product_specs`
CHANGE COLUMN `product_spec_id` `product_spec_id` BIGINT(19) UNSIGNED NOT NULL COMMENT '供应商产品规格ID' AFTER `agent_product_id`;
# 16:20 ‎2021/‎10/‎18
ALTER TABLE `order_product_items`
CHANGE COLUMN `price` `price` DECIMAL(20,2) NOT NULL COMMENT '供应商成本价(成本单价*数量)' AFTER `num`;

30
app/AdminSupplier/Controllers/ProductController.php

@ -6,8 +6,10 @@ use App\AdminSupplier\Repositories\Product;
use App\Common\ProductStatus;
use App\Models\AgentProduct;
use App\Models\AgentProductItem;
use App\Models\AgentProductSpec;
use App\Models\Category;
use App\Models\DiyForm;
use App\Models\ProductSpec;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Form\NestedForm;
@ -328,7 +330,33 @@ class ProductController extends AdminController
]);
}
//TODO 还需要规格同步到代理商
$delete_specs = array_filter($form->spec, fn($v) => $v['_remove_'] !== null); //删除的规格
//同步删除代理商规格
AgentProductSpec::whereIn('product_spec_id', array_keys($delete_specs))->delete();
//最新销售价同步到代理商规格
$product_id = $form->getKey();
$agent_product_ids = AgentProduct::where('product_id', $product_id)->pluck('id')->toArray(); //获取当前供应商产品的所有供应商产品ID
$product_specs = ProductSpec::where('product_id', $product_id)->get();
$product_spec_old_ids = $form->model()->spec->pluck('id')->toArray(); //旧的规格ID(不包括新增的)
if ($agent_product_ids && $product_spec_old_ids) {
//将代理商规格价格小于供应商销售价的,设置代理商规格的价格设置为供应商的售价
foreach ($product_specs->whereIn('id', $product_spec_old_ids) as $v) {
AgentProductSpec::whereIn('agent_product_id', $agent_product_ids)
->where([['product_spec_id', '=', $v->id], ['price', '<', $v->price]])
->update(['price' => $v->price]);
}
}
/*if ($product_spec_old_ids) {
$product_spec_new_ids = $product_specs->whereNotIn('id', $product_spec_old_ids)->get()->toArray(); //新增的规格
if ($product_spec_new_ids) {
//暂时不处理新增的规格
}
}*/
}
})->deleting(function (Form $form) {
//不允许删除非自己的数据

Loading…
Cancel
Save