Product.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\service\ProductService;
  4. use app\BaseController;
  5. use app\Request;
  6. use think\App;
  7. class Product extends BaseController
  8. {
  9. private $service;
  10. public function __construct(App $app)
  11. {
  12. $this->service = new ProductService();
  13. parent::__construct($app);
  14. }
  15. public function search(Request $request) {
  16. $params = $request->param();
  17. predicate(isset($params['store_id']) && $params['store_id'] > 0, lang('Store information does not exist'));
  18. $res = $this->service->search(
  19. $params['store_id'],
  20. format_string($params['bar_code'] ?? null),
  21. format_string($params['product_name'] ?? null),
  22. $params['page'] ?? 1,
  23. $params['size'] ?? 10
  24. );
  25. return $this->ok($res);
  26. }
  27. /**
  28. * @return \think\response\Json
  29. */
  30. public function upload() {
  31. // 获取表单上传文件 例如上传了001.jpg
  32. $file = request()->file('file');
  33. // 上传到本地服务器
  34. $save_name = \think\facade\Filesystem::disk('public')->putFile( 'numerology', $file);
  35. return $this->ok(str_replace('\\',"/",'/storage/'.$save_name));
  36. }
  37. }