Supplier.php 6.8 KB

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