You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Providers;
use App\Common\AgentType;use App\Common\ProductStatus;use App\Common\UserStatus;use App\Jobs\AgentProductShelve;use App\Models\AgentProduct;use App\Models\Agent;use App\Models\Product;use Illuminate\Support\ServiceProvider;
class ProductServiceProvider extends ServiceProvider{ /** * Register services. * * @return void */ public function register() { //
}
/** * Bootstrap services. * * @return void */ public function boot() { Product::updated(function ($product) { if ($product->isDirty('status') && $product->status == ProductStatus::ON_SALE) { /** 同步信息到代理商产品 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 */ $agentIds = Agent::query()->where([ ['id', '>', 1], //1是总管理员,不处理
['type', '<>', AgentType::OPERATOR], ['status', '=', UserStatus::NORMAL] ])->pluck('id');
foreach ($agentIds as $agent_id) { AgentProductShelve::dispatch($agent_id, $product->id); } /** 自动上架 END */ }
}); }}
|