feat: #20220728 商品列表查询
This commit is contained in:
parent
2c17bb51b4
commit
85311a2308
@ -4,7 +4,7 @@ namespace App\Filters;
|
|||||||
|
|
||||||
class GoodsFilter extends Filters
|
class GoodsFilter extends Filters
|
||||||
{
|
{
|
||||||
protected function title($value)
|
protected function goodsTitle($value)
|
||||||
{
|
{
|
||||||
return $this->builder->where('title', 'like', "%$value%");
|
return $this->builder->where('title', 'like', "%$value%");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ namespace App\Filters;
|
|||||||
|
|
||||||
class GoodsSkuFilter extends Filters
|
class GoodsSkuFilter extends Filters
|
||||||
{
|
{
|
||||||
protected function title($value)
|
protected function skuTitle($value)
|
||||||
{
|
{
|
||||||
return $this->builder->where('title', '=', $value);
|
return $this->builder->where('title', '=', $value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,13 +15,19 @@ class GoodsController extends Controller
|
|||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
// $goodsIds = [];
|
$goods = Goods::query()->filter()->get()->toArray();
|
||||||
|
$goodsIds = array_column($goods, 'id');
|
||||||
|
// 状态变更时间查询,日志
|
||||||
|
$day = date('Y-m-d'); //早上7点之前是昨天,7点之后是今天
|
||||||
$goodsSkus = GoodsSku::query()
|
$goodsSkus = GoodsSku::query()
|
||||||
|
->whereIn('goods_id', $goodsIds)
|
||||||
->filter()
|
->filter()
|
||||||
->with(['goods' => function ($query) {
|
->with(['goods' => function ($query) {
|
||||||
$query->with(['type:id,name', 'brand:id,name'])->filter();
|
$query->with(['type:id,name', 'brand:id,name']);
|
||||||
|
}])
|
||||||
|
->with(['daily' => function ($query) use ($day){
|
||||||
|
$query->where('day', $day)->with(['daily:id,sku_id,day,arrived_today_num,loss_num,inventory']);
|
||||||
}])
|
}])
|
||||||
// ->whereIn('goods_id', $goodsIds)
|
|
||||||
->paginate();
|
->paginate();
|
||||||
|
|
||||||
return GoodsSkuResource::collection($goodsSkus);
|
return GoodsSkuResource::collection($goodsSkus);
|
||||||
|
|||||||
@ -10,7 +10,7 @@ class Goods extends Model
|
|||||||
|
|
||||||
//查询字段
|
//查询字段
|
||||||
public $fieldSearchable = [
|
public $fieldSearchable = [
|
||||||
'title',
|
'goods_title',
|
||||||
'type_id',
|
'type_id',
|
||||||
'brand_id',
|
'brand_id',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -10,7 +10,7 @@ class GoodsSku extends Model
|
|||||||
|
|
||||||
//查询字段
|
//查询字段
|
||||||
public $fieldSearchable = [
|
public $fieldSearchable = [
|
||||||
'title',
|
'sku_title',
|
||||||
'status',
|
'status',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -23,6 +23,22 @@ class GoodsSku extends Model
|
|||||||
|
|
||||||
protected $hidden = ['created_at'];
|
protected $hidden = ['created_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取状态
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStatusAttribute($value)
|
||||||
|
{
|
||||||
|
$map = [
|
||||||
|
0 => '下架',
|
||||||
|
1 => '在售',
|
||||||
|
2 => '预警',
|
||||||
|
];
|
||||||
|
return $map[$value];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 此规格从属于一个商品
|
* 此规格从属于一个商品
|
||||||
*/
|
*/
|
||||||
@ -30,4 +46,12 @@ class GoodsSku extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasOne(Goods::class, 'id', 'goods_id');
|
return $this->hasOne(Goods::class, 'id', 'goods_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此规格每日记录
|
||||||
|
*/
|
||||||
|
public function daily()
|
||||||
|
{
|
||||||
|
return $this->hasOne(DailyStockRecord::class, 'sku_id', 'id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user