Browse Source

进入后台下架代理商产品中供应商已经下架或者库存不足的产品

master
李可松 4 years ago
parent
commit
86f72687b2
  1. 4
      app/AdminAgent/Controllers/HomeController.php
  2. 48
      app/Jobs/UnshelveAgentProduct.php

4
app/AdminAgent/Controllers/HomeController.php

@ -4,6 +4,7 @@ namespace App\AdminAgent\Controllers;
use App\AdminAgent\Metrics\Examples;
use App\Http\Controllers\Controller;
use App\Jobs\UnshelveAgentProduct;
use Dcat\Admin\Admin;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
@ -13,6 +14,9 @@ class HomeController extends Controller
{
public function index(Content $content)
{
# 进入后台下架代理商产品中供应商已经下架或者库存不足的产品
UnshelveAgentProduct::dispatch(Admin::user()->id);
Admin::style(
<<<CSS
.col-sm-10.d-flex{

48
app/Jobs/UnshelveAgentProduct.php

@ -0,0 +1,48 @@
<?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]);
}
}
Loading…
Cancel
Save