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.
61 lines
1.7 KiB
61 lines
1.7 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AgentProduct;
|
|
|
|
/**
|
|
* 代理商产品
|
|
* Class AgentProductController
|
|
* @package App\Http\Controllers\Api
|
|
*/
|
|
class AgentProductController extends Controller
|
|
{
|
|
// 代理商产品列表
|
|
public function index()
|
|
{
|
|
$category_id = request()->input('category_id');
|
|
if ($category_id) {
|
|
$where['category_id'] = $category_id;
|
|
}
|
|
|
|
$where['agent_id'] = $this->agent_id;
|
|
|
|
$list = AgentProduct::where($where)
|
|
->with(['product' => fn($query) => $query->select('id', 'title', 'pictures')])
|
|
->select('id', 'sale', 'product_id', 'price', 'original_price')
|
|
->orderBy('id', 'DESC')
|
|
->simplePaginate();
|
|
return $this->success($list);
|
|
}
|
|
|
|
// 产品详情
|
|
public function show()
|
|
{
|
|
$id = (int)request()->input('id');
|
|
|
|
// TODO 优惠券查询待优化
|
|
$data = AgentProduct::query()
|
|
->with(['product' => fn($query) => $query->select('id', 'title', 'pictures', 'know', 'content')])
|
|
->with(['coupon' => fn($query) => $query->select('id', 'tag', 'agent_product_id')])
|
|
->firstWhere(['id' => $id, 'agent_id' => $this->agent_id, 'status' => 1]);
|
|
|
|
if (!$data) {
|
|
return $this->error('产品不存在或已下架');
|
|
}
|
|
unset($data->agent_id, $data->status, $data->created_at, $data->deleted_at);
|
|
return $this->success($data);
|
|
}
|
|
|
|
// 猜你喜欢
|
|
public function guessLike()
|
|
{
|
|
// TODO 此处需要再优化排序规则,并增加广告功能
|
|
$list = AgentProduct::where('agent_id', $this->agent_id)
|
|
->with(['product' => fn($query) => $query->select('id', 'title', 'pictures')])
|
|
->select('id', 'sale', 'product_id', 'price', 'original_price')
|
|
->orderBy('id', 'DESC')
|
|
->simplePaginate();
|
|
return $this->success($list);
|
|
}
|
|
}
|