Browse Source

同步信息到代理商产品和自动上架分离

master
李可松 4 years ago
parent
commit
8e759be66b
  1. 12
      app/Jobs/ProductSaved.php
  2. 10
      app/Models/Product.php

12
app/Jobs/ProductSaved.php

@ -48,19 +48,9 @@ class ProductSaved implements ShouldQueue
public function handle() public function handle()
{ {
$product = $this->product; $product = $this->product;
/** 同步信息到代理商产品 START */
AgentProduct::query()
->where(['type' => 0, 'product_id' => $product->id])
->update([
'title' => $product->title,
'know' => $product->know,
'content' => $product->content,
'pictures' => $product->pictures,
]);
/** 同步信息到代理商产品 END */
/** 自动上架 START */ /** 自动上架 START */
Agent::query()->where([
Agent::where([
['id', '>', 1], //1是总管理员,不处理 ['id', '>', 1], //1是总管理员,不处理
['type', '<>', AgentType::OPERATOR], ['type', '<>', AgentType::OPERATOR],
['status', '=', UserStatus::NORMAL] ['status', '=', UserStatus::NORMAL]

10
app/Models/Product.php

@ -27,6 +27,16 @@ class Product extends BaseModel
{ {
parent::booted(); parent::booted();
static::saved(function ($product) { static::saved(function ($product) {
/** 同步信息到代理商产品 START */
AgentProduct::where(['type' => 0, 'product_id' => $product->id])
->update([
'title' => $product->title,
'know' => $product->know,
'content' => $product->content,
'pictures' => $product->pictures,
]);
/** 同步信息到代理商产品 END */
if ($product->isDirty('status') && $product->status == ProductStatus::ON_SALE) { if ($product->isDirty('status') && $product->status == ProductStatus::ON_SALE) {
ProductSaved::dispatch($product); ProductSaved::dispatch($product);
} }

Loading…
Cancel
Save