GoodsController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $datas = GoodsService::make()->getCategoryList();
  29. return message(1010, true, $datas);
  30. }
  31. /**
  32. * 详情
  33. */
  34. public function info()
  35. {
  36. $params = request()->all();
  37. $id = isset($params['id'])? intval($params['id']) : 0;
  38. if(empty($id)){
  39. return message(1036, false);
  40. }
  41. if($info = GoodsService::make()->getInfo($id, $this->userId)){
  42. return message(1010, true, $info);
  43. }else{
  44. return message(1009, false);
  45. }
  46. }
  47. /**
  48. * 收藏
  49. */
  50. public function collect()
  51. {
  52. $params = request()->all();
  53. $id = isset($params['id']) ? intval($params['id']) : 0;
  54. if (empty($id)) {
  55. return message(1036, false);
  56. }
  57. try {
  58. if ($result = GoodsService::make()->collect($this->userId, $id)) {
  59. return message(GoodsService::make()->getError(), true, $result);
  60. } else {
  61. return message(GoodsService::make()->getError(), false);
  62. }
  63. } catch (\Exception $exception) {
  64. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  65. return showJson(1046, false, $error);
  66. }
  67. }
  68. }