GoodsController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\GoodsService;
  5. /**
  6. * 商品管理
  7. * @package App\Http\Controllers\Api
  8. */
  9. class GoodsController extends webApp
  10. {
  11. /**
  12. * 列表
  13. * @return array
  14. */
  15. public function index()
  16. {
  17. $params =request()->post();
  18. $pageSize = request()->post('pageSize', 12);
  19. $datas = GoodsService::make()->getDataList($params, $pageSize);
  20. return message(1010, true, $datas);
  21. }
  22. /**
  23. * 分类
  24. * @return array
  25. */
  26. public function categorys()
  27. {
  28. $params =request()->post();
  29. $pageSize = request()->post('pageSize', 12);
  30. $datas = GoodsService::make()->getCategoryList($params, $pageSize);
  31. return message(1010, true, $datas);
  32. }
  33. /**
  34. * 详情
  35. */
  36. public function info()
  37. {
  38. $params = request()->all();
  39. $id = isset($params['id'])? intval($params['id']) : 0;
  40. if(empty($id)){
  41. return message(1036, false);
  42. }
  43. if($info = GoodsService::make()->getInfo($id, $this->userId)){
  44. return message(1010, true, $info);
  45. }else{
  46. return message(1009, false);
  47. }
  48. }
  49. /**
  50. * 收藏
  51. */
  52. public function collect()
  53. {
  54. $params = request()->all();
  55. $id = isset($params['id']) ? intval($params['id']) : 0;
  56. if (empty($id)) {
  57. return message(1036, false);
  58. }
  59. try {
  60. if ($result = GoodsService::make()->collect($this->userId, $id)) {
  61. return message(GoodsService::make()->getError(), true, $result);
  62. } else {
  63. return message(GoodsService::make()->getError(), false);
  64. }
  65. } catch (\Exception $exception) {
  66. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  67. return showJson(1046, false, $error);
  68. }
  69. }
  70. }