更新代码
This commit is contained in:
97
app/Api/Controllers/SellersController.php
Normal file
97
app/Api/Controllers/SellersController.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?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,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user