海南旅游SAAS
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.

60 lines
1.4 KiB

4 years ago
  1. <?php
  2. namespace App\Providers;
  3. use App\Common\AgentType;
  4. use App\Common\ProductStatus;
  5. use App\Common\UserStatus;
  6. use App\Jobs\AgentProductShelve;
  7. use App\Models\AgentProduct;
  8. use App\Models\Agent;
  9. use App\Models\Product;
  10. use Illuminate\Support\ServiceProvider;
  11. class ProductServiceProvider extends ServiceProvider
  12. {
  13. /**
  14. * Register services.
  15. *
  16. * @return void
  17. */
  18. public function register()
  19. {
  20. //
  21. }
  22. /**
  23. * Bootstrap services.
  24. *
  25. * @return void
  26. */
  27. public function boot()
  28. {
  29. Product::saved(function ($product) {
  30. if ($product->isDirty('status') && $product->status == ProductStatus::ON_SALE) {
  31. /** 同步信息到代理商产品 START */
  32. AgentProduct::query()
  33. ->where(['type' => 0, 'product_id' => $product->id])
  34. ->update([
  35. 'title' => $product->title,
  36. 'know' => $product->know,
  37. 'content' => $product->content,
  38. 'pictures' => $product->pictures,
  39. ]);
  40. /** 同步信息到代理商产品 END */
  41. /** 自动上架 START */
  42. Agent::query()->where([
  43. ['id', '>', 1], //1是总管理员,不处理
  44. ['type', '<>', AgentType::OPERATOR],
  45. ['status', '=', UserStatus::NORMAL]
  46. ])->select(['id'])->chunk(100, function ($agents) use ($product) {
  47. foreach ($agents as $agent) {
  48. AgentProductShelve::dispatch($agent['id'], $product->id);
  49. }
  50. });
  51. /** 自动上架 END */
  52. }
  53. });
  54. }
  55. }