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

<?php
namespace App\Jobs;
use App\Common\ProductStatus;
use App\Models\AgentProduct;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
/**
* 登录后台下架代理商产品中含有库存不足、供应商已下架的产品
*/
class UnshelveAgentProduct implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(private int $agent_id)
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//下架供应商产品状态不是上架或库存不足的产品
AgentProduct::where('agent_id', $this->agent_id)
->whereHas('agentProductItem', function ($query) {
return $query->whereHas('product', function ($query) {
return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE);
});
})
->orWhere('stock', '<=', 0)
->update(['status' => ProductStatus::SOLD_OUT]);
}
}