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

48 lines
1.2 KiB

  1. <?php
  2. namespace App\Jobs;
  3. use App\Common\ProductStatus;
  4. use App\Models\AgentProduct;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldBeUnique;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Queue\SerializesModels;
  11. /**
  12. * 登录后台下架代理商产品中含有库存不足、供应商已下架的产品
  13. */
  14. class UnshelveAgentProduct implements ShouldQueue
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. /**
  18. * Create a new job instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct(private int $agent_id)
  23. {
  24. }
  25. /**
  26. * Execute the job.
  27. *
  28. * @return void
  29. */
  30. public function handle()
  31. {
  32. //下架供应商产品状态不是上架或库存不足的产品
  33. AgentProduct::where('agent_id', $this->agent_id)
  34. ->whereHas('agentProductItem', function ($query) {
  35. return $query->whereHas('product', function ($query) {
  36. return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE);
  37. });
  38. })
  39. ->orWhere('stock', '<=', 0)
  40. ->update(['status' => ProductStatus::SOLD_OUT]);
  41. }
  42. }