修改商品添加运费模板以及权限
parent
b964db390a
commit
f60e8be3cc
|
|
@ -46,7 +46,7 @@ class SkuSyncSpu extends RowAction
|
|||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
ProductSku::skuSyncSpuById($this->getKey());
|
||||
ProductSku::syncSpuById($this->getKey());
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
|
|
|
|||
|
|
@ -2,21 +2,22 @@
|
|||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\SkuList;
|
||||
use App\Admin\Renderable\ProductSkuTable;
|
||||
use App\Admin\Repositories\ProductSpu;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\ProductBuynote;
|
||||
use App\Models\ProductFeature;
|
||||
use App\Models\ProductGroup;
|
||||
use App\Models\ProductSpu as ProductSpuModel;
|
||||
use Carbon\Carbon;
|
||||
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;
|
||||
use Dcat\Admin\Admin;
|
||||
use App\Models\ProductGroup;
|
||||
use App\Models\ProductBuynote;
|
||||
use App\Models\ProductFeature;
|
||||
use Dcat\Admin\Layout\Content;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\ShippingTemplate;
|
||||
use App\Admin\Actions\Grid\SkuList;
|
||||
use App\Admin\Repositories\ProductSpu;
|
||||
use App\Admin\Renderable\ProductSkuTable;
|
||||
use App\Models\ProductSpu as ProductSpuModel;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
|
||||
class ProductSpuController extends AdminController
|
||||
{
|
||||
|
|
@ -142,6 +143,7 @@ class ProductSpuController extends AdminController
|
|||
$form->editor('description');
|
||||
$form->select('buynote_id')->options(ProductBuynote::all()->pluck('name', 'id'));
|
||||
$form->number('weight');
|
||||
$form->select('shipping_template_id')->options(ShippingTemplate::all()->pluck('name', 'id'));
|
||||
$form->number('stock');
|
||||
$form->divider();
|
||||
$form->currency('sell_price')->symbol('¥')->default(0);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Admin\Controllers;
|
|||
|
||||
use App\Admin\Renderable\ShippingRuleTable;
|
||||
use App\Admin\Repositories\ShippingTemplate;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\ShippingTemplate as ShippingTemplateModel;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
|
|
@ -88,6 +89,17 @@ class ShippingTemplateController extends AdminController
|
|||
});
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
//如果有商品选择这个规则
|
||||
$template = ShippingTemplateModel::findOrFail($id);
|
||||
if ($template->hasSku()) {
|
||||
throw new BizException(__('shipping-template.options.deny_message'));
|
||||
}
|
||||
|
||||
return parent::destroy($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 运费模板的规则
|
||||
*
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class BatchSkuSyncSpu extends BatchAction
|
|||
try {
|
||||
DB::beginTransaction();
|
||||
foreach ($list as $sku) {
|
||||
ProductSku::skuSyncSpu($sku);
|
||||
ProductSku::syncSpu($sku);
|
||||
}
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use App\Admin\Extensions\Grid\Tools\Product\AddSku;
|
|||
use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseCancel;
|
||||
use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseDown;
|
||||
use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseUp;
|
||||
use App\Admin\Extensions\Grid\Tools\Product\BatchSkuSyncSpu;
|
||||
use App\Admin\Extensions\Grid\Tools\Product\InitSkuBySpecs;
|
||||
use App\Admin\Extensions\Grid\Tools\Product\SettingSpecs;
|
||||
use App\Models\ProductSku;
|
||||
|
|
@ -103,6 +104,12 @@ class ProductSkuTable extends Grid
|
|||
if ($spuId) {
|
||||
$grid->model()->where('spu_id', $spuId);
|
||||
$spu = ProductSpu::findOrFail($spuId);
|
||||
$grid->batchActions(function ($batch) {
|
||||
//批量同步主商品
|
||||
if (Admin::user()->can('dcat.admin.product_skus.batch_sku_sync_spu')) {
|
||||
$batch->add(new BatchSkuSyncSpu());
|
||||
}
|
||||
});
|
||||
$grid->tools(function (Grid\Tools $tools) use ($spu) {
|
||||
//设置规格
|
||||
if (Admin::user()->can('dcat.admin.product_spus.setting_specs')) {
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ class ProductSku extends Model
|
|||
'vip_price',
|
||||
'media',
|
||||
'weight',
|
||||
'shipping_template_id',
|
||||
'attrs',
|
||||
'specs',
|
||||
'stock',
|
||||
|
|
|
|||
|
|
@ -10,4 +10,14 @@ class ShippingTemplate extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
public function skus()
|
||||
{
|
||||
return $this->hasMany(ProductSku::class, 'shipping_template_id');
|
||||
}
|
||||
|
||||
public function hasSku()
|
||||
{
|
||||
return $this->skus()->exists();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,53 +109,4 @@ trait Release
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID同步SPU
|
||||
*
|
||||
* @param integer $id
|
||||
* @return void
|
||||
*/
|
||||
public static function skuSyncSpuById(int $id)
|
||||
{
|
||||
static::skuSyncSpu(ProductSku::with('spu')->findOrFail($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步spu的基本信息
|
||||
*
|
||||
* @param ProductSku $sku
|
||||
* @return void
|
||||
*/
|
||||
public static function skuSyncSpu(ProductSku $sku)
|
||||
{
|
||||
$_price = 0;
|
||||
foreach ($sku->specs as $id => $value) {
|
||||
$spuSpec = $sku->spu->specs->first(function ($item) use ($id) {
|
||||
return $item->id == $id;
|
||||
});
|
||||
foreach ($spuSpec->items as $item) {
|
||||
if ($item['name'] == $value) {
|
||||
$_price += $item['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$sku->update(
|
||||
[
|
||||
'name' => trim($sku->spu->name.' '.implode(' ', $sku->specs)),
|
||||
'subtitle'=> $sku->spu->subtitle,
|
||||
'cover' => $sku->spu->cover,
|
||||
// 'images' => $sku->spu->images,
|
||||
'description' => $sku->spu->description,
|
||||
'sell_price' => bcadd($sku->spu->sell_price, $_price),
|
||||
'market_price' => $sku->spu->market_price,
|
||||
'cost_price' => $sku->spu->cost_price,
|
||||
'vip_price' => !is_null($sku->spu->vip_price) ? bcadd($sku->spu->vip_price, $_price) : null,
|
||||
'media' => $sku->spu->media,
|
||||
'weight' => $sku->spu->weight,
|
||||
'attrs' => $sku->spu->attrs,
|
||||
'verify_state' => 0, //默认调整为正常
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ trait SkuInfo
|
|||
'attrs' => $spu->attrs,
|
||||
'specs' => $skuSpec['specs'],
|
||||
'buynote_id' => $spu->buynote_id,
|
||||
'shipping_template_id'=> $spu->shipping_template_id,
|
||||
'verify_state' => 0, //默认为正常
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class CreateProductSpusTable extends Migration
|
|||
$table->integer('sales')->unsigned()->default(0)->comment('销量');
|
||||
$table->timestamp('release_at')->nullable()->comment('上架时间');
|
||||
$table->unsignedBigInteger('buynote_id')->nullable()->comment('购买须知模板ID');
|
||||
$table->unsignedInteger('shipping_template_id')->nullable()->comment('运费模板ID');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('category_id');
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class CreateProductSkusTable extends Migration
|
|||
$table->timestamp('release_at')->nullable()->comment('上架时间');
|
||||
$table->tinyInteger('verify_state')->unsigned()->default(0)->comment('审核状态:0正常,1处理中,2处理失败');
|
||||
$table->unsignedBigInteger('buynote_id')->nullable()->comment('购买须知模板ID');
|
||||
$table->unsignedInteger('shipping_template_id')->nullable()->comment('运费模板ID');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('spu_id');
|
||||
|
|
|
|||
|
|
@ -143,6 +143,17 @@ class AdminPermissionSeeder extends Seeder
|
|||
'name' =>'优惠使用范围管理',
|
||||
'curd' => ['create', 'store', 'edit', 'update', 'destroy'],
|
||||
],
|
||||
'shipping_templates'=>[
|
||||
'name' =>'运费模板管理',
|
||||
'curd' => true,
|
||||
'children'=>[
|
||||
'rule_list' => '运费规则',
|
||||
],
|
||||
],
|
||||
'shipping_rules'=>[
|
||||
'name' =>'运费规则管理',
|
||||
'curd' => ['create', 'store', 'edit', 'update', 'destroy'],
|
||||
],
|
||||
];
|
||||
try {
|
||||
DB::begintransaction();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ return [
|
|||
'vip_price' => '会员价格',
|
||||
'media' => '媒体地址',
|
||||
'weight' => '重量:g',
|
||||
'shipping_template_id'=>'运费模板',
|
||||
'stock' => '库存',
|
||||
'sales'=>'销量',
|
||||
'attrs' => '属性文本',
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ return [
|
|||
'name' => '模板名称',
|
||||
],
|
||||
'options' => [
|
||||
'deny_message'=>'该运费模板仍在使用,无法删除',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue