0
0
Files
Babyclass/app/Api/Controllers/SellersController.php
2020-08-04 10:09:42 +08:00

97 lines
3.1 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: sunny
* Date: 2019/2/26
* Time: 11:33 AM
*/
namespace App\Api\Controllers;
use App\Api\Resources\GoodsListResource;
use App\Api\Resources\GoodsParamsListResource;
use App\Api\Resources\SellerListResource;
use App\Models\Goods;
use App\Models\Seller;
use App\User;
class SellersController extends Controller
{
public function __construct()
{
// $this->middleware('auth.api');
// $this->user = \Auth::guard('api')->user();
// $this->uid = \Auth::guard('api')->id();
$this->user = User::find(824);
$this->uid = 824;
}
public function index()
{
// if ($this->user->identity->identity_id == 0) {
// return $this->failed('请开通VIP后继续操作');
// }
$sellers = Seller::with(['storage'])->get();
return SellerListResource::collection($sellers)->additional([
'status' => 'SUCCESS',
'status_code' => 200,
]);
}
public function show(Seller $seller)
{
// if ($this->user->identity->identity_id == 0) {
// return $this->failed('请开通VIP后继续操作');
// }
$hotGoods = Goods::with(['storage'])
->where('status', 1)
->where('seller_id', $seller->id)
->where('status', 1)
->whereHas('params', function ($query) {
return $query->where('stock', '>', 0)->where('status', 1)->where('score', '>', 0)->whereRaw('price > score');
})
->select('id', 'title', 'description', 'storage_id', 'score')
->orderBy('created_at', 'desc')
->limit(500)
->get();
$hotGoodsScore = Goods::with(['storage'])
->where('status', 1)
->where('seller_id', $seller->id)
->where('status', 1)
->whereHas('params', function ($query) {
return $query->where('stock', '>', 0)->where('status', 1)->where('score', '>', 0)->whereRaw('price = score');
})
->select('id', 'title', 'description', 'storage_id', 'score')
->orderBy('created_at', 'desc')
->limit(500)
->get();
$hotGoodsCash = Goods::with(['storage'])
->where('status', 1)
->where('seller_id', $seller->id)
->where('status', 1)
->whereHas('params', function ($query) {
return $query->where('stock', '>', 0)->where('status', 1)->where('score', 0);
})
->select('id', 'title', 'description', 'storage_id', 'score')
->orderBy('created_at', 'desc')
->limit(500)
->get();
return [
'data' => [
'seller_info' => new SellerListResource($seller),
'hotGoods' => GoodsParamsListResource::collection($hotGoods),
'hotGoodsScore' => GoodsParamsListResource::collection($hotGoodsScore),
'hotGoodsCash' => GoodsParamsListResource::collection($hotGoodsCash),
],
'status' => 'SUCCESS',
'status_code' => 200,
];
}
}