CategoryController.php 995 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace app\api\controller\store;
  3. use app\admin\model\system\SystemAdmin;
  4. use app\models\store\StoreCategory;
  5. use app\models\system\SystemStore;
  6. use app\models\user\User;
  7. use app\Request;
  8. class CategoryController
  9. {
  10. public function category(Request $request)
  11. {
  12. $model = StoreCategory::with('children')->where('is_show', 1)->order('sort desc,id desc')->where('pid', 0);
  13. $user = User::getUserInfo($request->uid());
  14. $store_user = 0;
  15. if ($user['admin_id']) {
  16. $admin = SystemAdmin::where('id', $user['admin_id'])->find();
  17. $store_user = SystemStore::where('id', $admin['store_id'] ?? 0)->value('see');
  18. }
  19. if (!$store_user) {
  20. $model = $model->where('only_store_user', 0);
  21. }
  22. $cateogry = $model->select();
  23. return app('json')->success($cateogry->hidden(['add_time', 'is_show', 'sort', 'children.sort', 'children.add_time', 'children.pid', 'children.is_show'])->toArray());
  24. }
  25. }