海南旅游SAAS
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.

24 lines
777 B

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Common\ProductStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\AgentProduct;
  6. use App\Models\Category;
  7. class CategoryController extends Controller
  8. {
  9. public function index()
  10. {
  11. $list = Category::query()
  12. ->where('agent_id', $this->agent_id)
  13. ->orderBy('sort')
  14. ->get(['id', 'name', 'pid']);
  15. if ($list->isEmpty()) { //如果是新入驻商户,显示默认数据
  16. if (AgentProduct::where('agent_id', $this->agent_id)->withTrashed()->count() === 0 && request('page', 1) <= 2) { //只获取2页数据
  17. $list = AgentProduct::list($this->agent_id)->orWhere([['status', '=', ProductStatus::ON_SALE], ['price', '>', 500]])->orderBy('id')->simplePaginate();
  18. }
  19. }
  20. return $this->success($list);
  21. }
  22. }