Supplier.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\Service\SupplierService;
  4. /**
  5. * 供应商/工厂接口
  6. */
  7. class Supplier extends Base
  8. {
  9. // 无需登录的接口
  10. protected $noNeedLogin = ['getFactoryList', 'getFactoryOptions', 'searchFactory', 'getActiveFactoryList'];
  11. // 无需鉴权的接口
  12. protected $noNeedRight = ['getFactoryList', 'getFactoryOptions', 'searchFactory', 'getActiveFactoryList'];
  13. /**
  14. * 获取工厂/供应商列表
  15. *
  16. * @ApiTitle (获取工厂/供应商列表)
  17. * @ApiSummary (获取工厂/供应商列表信息,支持分页和搜索)
  18. * @ApiMethod (POST)
  19. * @ApiRoute (/api/inspection/supplier/getFactoryList)
  20. * @ApiParams (name="page", type="integer", required=false, description="页码,默认1")
  21. * @ApiParams (name="limit", type="integer", required=false, description="每页数量,默认10")
  22. * @ApiParams (name="name", type="string", required=false, description="供应商名称")
  23. * @ApiParams (name="category_id", type="integer", required=false, description="分类ID")
  24. * @ApiParams (name="status", type="string", required=false, description="状态:normal正常,hidden隐藏")
  25. * @ApiReturnParams (name="code", type="integer", required=true, sample="1")
  26. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  27. * @ApiReturnParams (name="data", type="object", description="返回数据")
  28. * @ApiReturn ({
  29. 'code':'1',
  30. 'msg':'返回成功',
  31. 'data': {
  32. 'list': [],
  33. 'total': 0,
  34. 'page': 1,
  35. 'limit': 10
  36. }
  37. })
  38. */
  39. public function getFactoryList()
  40. {
  41. $params = $this->request->param();
  42. $page = $params['page'] ?? 1;
  43. $limit = $params['limit'] ?? 10;
  44. $name = $params['name'] ?? '';
  45. $categoryId = $params['category_id'] ?? '';
  46. $status = $params['status'] ?? '';
  47. $searchParams = [
  48. 'page' => $page,
  49. 'limit' => $limit
  50. ];
  51. if ($name) {
  52. $searchParams['name'] = $name;
  53. }
  54. if ($categoryId) {
  55. $searchParams['category_id'] = $categoryId;
  56. }
  57. if ($status) {
  58. $searchParams['status'] = $status;
  59. }
  60. $supplierService = new SupplierService();
  61. $result = $supplierService->getFactoryList($searchParams);
  62. $this->success('获取成功', $result);
  63. }
  64. /**
  65. * 获取工厂/供应商选项列表
  66. *
  67. * @ApiTitle (获取工厂/供应商选项列表)
  68. * @ApiSummary (获取工厂/供应商选项列表,用于下拉选择)
  69. * @ApiMethod (POST)
  70. * @ApiRoute (/api/inspection/supplier/getFactoryOptions)
  71. * @ApiReturnParams (name="code", type="integer", required=true, sample="1")
  72. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  73. * @ApiReturnParams (name="data", type="object", description="返回数据")
  74. * @ApiReturn ({
  75. 'code':'1',
  76. 'msg':'返回成功',
  77. 'data': {
  78. '1': '供应商名称1',
  79. '2': '供应商名称2'
  80. }
  81. })
  82. */
  83. public function getFactoryOptions()
  84. {
  85. $supplierService = new SupplierService();
  86. $options = $supplierService->getFactoryOptions();
  87. $this->success('获取成功', $options);
  88. }
  89. /**
  90. * 搜索工厂/供应商
  91. *
  92. * @ApiTitle (搜索工厂/供应商)
  93. * @ApiSummary (根据关键词搜索工厂/供应商)
  94. * @ApiMethod (POST)
  95. * @ApiRoute (/api/inspection/supplier/searchFactory)
  96. * @ApiParams (name="keyword", type="string", required=true, description="搜索关键词")
  97. * @ApiParams (name="limit", type="integer", required=false, description="限制数量,默认10")
  98. * @ApiReturnParams (name="code", type="integer", required=true, sample="1")
  99. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  100. * @ApiReturnParams (name="data", type="array", description="返回数据")
  101. * @ApiReturn ({
  102. 'code':'1',
  103. 'msg':'返回成功',
  104. 'data': []
  105. })
  106. */
  107. public function searchFactory()
  108. {
  109. $params = $this->request->param();
  110. $keyword = $params['keyword'] ?? '';
  111. $limit = $params['limit'] ?? 10;
  112. if (empty($keyword)) {
  113. $this->error('请输入搜索关键词');
  114. }
  115. $supplierService = new SupplierService();
  116. $result = $supplierService->searchFactory($keyword, $limit);
  117. $this->success('搜索成功', $result);
  118. }
  119. /**
  120. * 获取工厂/供应商详情
  121. *
  122. * @ApiTitle (获取工厂/供应商详情)
  123. * @ApiSummary (根据ID获取工厂/供应商详情)
  124. * @ApiMethod (POST)
  125. * @ApiRoute (/api/inspection/supplier/getFactoryDetail)
  126. * @ApiParams (name="id", type="integer", required=true, description="供应商ID")
  127. * @ApiReturnParams (name="code", type="integer", required=true, sample="1")
  128. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  129. * @ApiReturnParams (name="data", type="object", description="返回数据")
  130. * @ApiReturn ({
  131. 'code':'1',
  132. 'msg':'返回成功',
  133. 'data': {}
  134. })
  135. */
  136. public function getFactoryDetail()
  137. {
  138. $params = $this->request->param();
  139. $id = $params['id'] ?? 0;
  140. if (empty($id)) {
  141. $this->error('请提供供应商ID');
  142. }
  143. $supplierService = new SupplierService();
  144. $result = $supplierService->getFactoryById($id);
  145. if (!$result) {
  146. $this->error('供应商不存在');
  147. }
  148. $this->success('获取成功', $result);
  149. }
  150. /**
  151. * 获取启用状态的工厂/供应商列表
  152. *
  153. * @ApiTitle (获取启用状态的工厂/供应商列表)
  154. * @ApiSummary (获取启用状态的工厂/供应商列表,带缓存)
  155. * @ApiMethod (POST)
  156. * @ApiRoute (/api/inspection/supplier/getActiveFactoryList)
  157. * @ApiReturnParams (name="code", type="integer", required=true, sample="1")
  158. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  159. * @ApiReturnParams (name="data", type="array", description="返回数据")
  160. * @ApiReturn ({
  161. 'code':'1',
  162. 'msg':'返回成功',
  163. 'data': []
  164. })
  165. */
  166. public function getActiveFactoryList()
  167. {
  168. $supplierService = new SupplierService();
  169. $result = $supplierService->getActiveFactoryListWithCache();
  170. $this->success('获取成功', $result);
  171. }
  172. }