Category.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace addons\unishop\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 分类
  7. */
  8. class Category extends Api
  9. {
  10. protected $frequently = ['all','menu','inlist'];
  11. protected $noNeedLogin = ['all','menu','inlist'];
  12. protected $noNeedRight = ['*'];
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. $this->model = new \addons\unishop\model\Category();
  17. }
  18. /**
  19. * @ApiTitle (全部分类数据)
  20. * @ApiSummary (全部分类数据)
  21. * @ApiMethod (GET)
  22. * @ApiHeaders (name=token, type=string, required=true, description="用户登录的Token", sample="a2e3cc70-d2d1-41e6-9c14-f1d774ee5e1e")
  23. * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
  24. * @ApiReturn ({"code":1,"msg":"","data":[]})
  25. *
  26. * @ApiReturnParams (name="id", type="integer", description="分类id")
  27. * @ApiReturnParams (name="name", type="string", description="分类名称")
  28. * @ApiReturnParams (name="pid", type="integer", description="上级id")
  29. * @ApiReturnParams (name="image", type="string", description="图片")
  30. * @ApiReturnParams (name="type", type="string", description="类型")
  31. * @ApiReturnParams (name="flag", type="integer", description="标签/位置")
  32. * @ApiReturnParams (name="weigh", type="integer", description="排序")
  33. */
  34. public function all(){
  35. $all = $this->model
  36. ->where('type','product')
  37. ->where('status','normal')
  38. ->field('id,name,pid,image,type,flag,weigh')
  39. ->order('weigh ASC')
  40. ->select();
  41. if ($all) {
  42. $all = collection($all)->toArray();
  43. }
  44. $this->success('',$all);
  45. }
  46. public function inlist(){
  47. $list = Db::name('unishop_category')
  48. ->where('status','normal')
  49. ->field('id,name,image')
  50. ->order('weigh ASC')
  51. ->select();
  52. $list = list_domain_image($list,['image']);
  53. $this->success(1,$list);
  54. }
  55. /**
  56. * @ApiTitle (首页广告下面的分类)
  57. * @ApiSummary (首页广告下面的分类)
  58. * @ApiMethod (GET)
  59. * @ApiHeaders (name=token, type=string, required=true, description="用户登录的Token", sample="a2e3cc70-d2d1-41e6-9c14-f1d774ee5e1e")
  60. * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
  61. * @ApiReturn ({"code":1,"msg":"","data":{}})
  62. *
  63. * @ApiReturnParams (name="id", type="integer", description="分类id")
  64. * @ApiReturnParams (name="name", type="string", description="分类名称")
  65. * @ApiReturnParams (name="pid", type="integer", description="上级id")
  66. * @ApiReturnParams (name="image", type="string", description="图片")
  67. * @ApiReturnParams (name="type", type="string", description="类型")
  68. * @ApiReturnParams (name="flag", type="integer", description="标签/位置")
  69. * @ApiReturnParams (name="weigh", type="integer", description="排序")
  70. */
  71. public function menu()
  72. {
  73. $list = $this->model
  74. ->where('flag','index')
  75. ->where('status','normal')
  76. ->select();
  77. if ($list) {
  78. $list = collection($list)->toArray();
  79. }
  80. $this->success('菜单',$list);
  81. }
  82. }